Skip to content

Commit

Permalink
chore: update dependencies to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Feb 27, 2020
1 parent a23127b commit 77a7480
Show file tree
Hide file tree
Showing 8 changed files with 6,391 additions and 7,077 deletions.
3 changes: 1 addition & 2 deletions __mocks__/bin-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const src = jest.fn(() => binWrapperObject);
const dest = jest.fn(() => binWrapperObject);
const path = jest.fn(() => binWrapperObject);
const run = jest.fn((_, cb) => {
cb();
const run = jest.fn(async () => {
return binWrapperObject;
});
const use = jest.fn(() => binWrapperObject);
Expand Down
17 changes: 10 additions & 7 deletions __tests__/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,25 @@ describe('install', () => {

test('runs after installation', async () => {
await install();
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
expect(run).toHaveBeenCalledWith(['version']);
expect(run).toHaveBeenCalledTimes(1);
});

test('runs after installation', async () => {
await install();
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
expect(run).toHaveBeenCalledWith(['version']);
expect(run).toHaveBeenCalledTimes(1);
});

test('rejects promise if error in installation run', () => {
test('rejects promise if error in installation run', async () => {
const errorMessage = 'some err';
run.mockImplementationOnce((_, cb) => {
cb(errorMessage);
});
run.mockRejectedValue(errorMessage);

expect(install()).rejects.toMatch(errorMessage);
expect.assertions(1);
try {
await install();
} catch(err) {
expect(err.message).toMatch(errorMessage);
}
});
});
1 change: 1 addition & 0 deletions __tests__/themekit.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const {spawn} = require('child_process');

const cfg = require('../lib/config');
const themekit = require('../lib/themekit');

Expand Down
4 changes: 3 additions & 1 deletion __tests__/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fsMock = require('mock-fs');
const fs = require('fs');

const fsMock = require('mock-fs');

const {cleanFile, getFlagArrayFromObject} = require('../lib/utils');

describe('getFlagArrayFromObject', () => {
Expand Down
59 changes: 28 additions & 31 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const BinWrapper = require('bin-wrapper');
const spinner = require('simple-spinner');

const config = require('./config');
const {cleanFile} = require('./utils');

Expand All @@ -8,37 +9,33 @@ const {cleanFile} = require('./utils');
* Call this on npm postinstall.
* @param {string} logLevel Log level
*/
function install(logLevel) {
return new Promise((resolve, reject) => {
const logger = require('./logger')(logLevel);
const urlAndPath = `${config.baseURL}/v${config.version}`;

logger.silly('Theme Kit installation starting');
spinner.start();

const installer = new BinWrapper()
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
.src(`${urlAndPath}/linux-386/theme`, 'linux')
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
.dest(config.destination)
.use(config.binName);

const pathToExecutable = installer.path();

cleanFile(pathToExecutable);

installer.run(['version'], (runErr) => {
if (runErr) {
reject(runErr);
}

spinner.stop();
logger.info(`Theme Kit path: ${pathToExecutable}`);
resolve();
});
});
async function install(logLevel) {
const logger = require('./logger')(logLevel);
const urlAndPath = `${config.baseURL}/v${config.version}`;

logger.silly('Theme Kit installation starting');
spinner.start();

const installer = new BinWrapper()
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
.src(`${urlAndPath}/linux-386/theme`, 'linux')
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
.dest(config.destination)
.use(config.binName);

const pathToExecutable = installer.path();

cleanFile(pathToExecutable);

try {
await installer.run(['version']);
spinner.stop();
logger.info(`Theme Kit path: ${pathToExecutable}`);
} catch (err) {
throw new Error(err);
}
}

module.exports = install;
4 changes: 1 addition & 3 deletions lib/themekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ const themekit = {
* @param {Object} options additional options (cwd and logLevel)
*/
command(cmd, flagObj = {}, options = {cwd: process.cwd()}) {
const updatedFlagObj = Object.assign({}, flagObj, {
noUpdateNotifier: true
});
const updatedFlagObj = {...flagObj, noUpdateNotifier: true};
const flagArr = getFlagArrayFromObject(updatedFlagObj);

return runExecutable(
Expand Down
Loading

0 comments on commit 77a7480

Please sign in to comment.