Skip to content

Commit a40b461

Browse files
chore: update dependencies to latest (#56)
Co-authored-by: Helen Lin <[email protected]>
1 parent a23127b commit a40b461

File tree

8 files changed

+5401
-6905
lines changed

8 files changed

+5401
-6905
lines changed

__mocks__/bin-wrapper.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
const src = jest.fn(() => binWrapperObject);
33
const dest = jest.fn(() => binWrapperObject);
44
const path = jest.fn(() => binWrapperObject);
5-
const run = jest.fn((_, cb) => {
6-
cb();
5+
const run = jest.fn(async () => {
76
return binWrapperObject;
87
});
98
const use = jest.fn(() => binWrapperObject);

__tests__/install.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,25 @@ describe('install', () => {
6262

6363
test('runs after installation', async () => {
6464
await install();
65-
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
65+
expect(run).toHaveBeenCalledWith(['version']);
6666
expect(run).toHaveBeenCalledTimes(1);
6767
});
6868

6969
test('runs after installation', async () => {
7070
await install();
71-
expect(run).toHaveBeenCalledWith(['version'], expect.any(Function));
71+
expect(run).toHaveBeenCalledWith(['version']);
7272
expect(run).toHaveBeenCalledTimes(1);
7373
});
7474

75-
test('rejects promise if error in installation run', () => {
75+
test('rejects promise if error in installation run', async () => {
7676
const errorMessage = 'some err';
77-
run.mockImplementationOnce((_, cb) => {
78-
cb(errorMessage);
79-
});
77+
run.mockRejectedValue(errorMessage);
8078

81-
expect(install()).rejects.toMatch(errorMessage);
79+
expect.assertions(1);
80+
try {
81+
await install();
82+
} catch (err) {
83+
expect(err.message).toMatch(errorMessage);
84+
}
8285
});
8386
});

__tests__/themekit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const path = require('path');
22
const {spawn} = require('child_process');
3+
34
const cfg = require('../lib/config');
45
const themekit = require('../lib/themekit');
56

__tests__/utils.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const fsMock = require('mock-fs');
21
const fs = require('fs');
2+
3+
const fsMock = require('mock-fs');
4+
35
const {cleanFile, getFlagArrayFromObject} = require('../lib/utils');
46

57
describe('getFlagArrayFromObject', () => {

lib/install.js

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const BinWrapper = require('bin-wrapper');
22
const spinner = require('simple-spinner');
3+
34
const config = require('./config');
45
const {cleanFile} = require('./utils');
56

@@ -8,37 +9,33 @@ const {cleanFile} = require('./utils');
89
* Call this on npm postinstall.
910
* @param {string} logLevel Log level
1011
*/
11-
function install(logLevel) {
12-
return new Promise((resolve, reject) => {
13-
const logger = require('./logger')(logLevel);
14-
const urlAndPath = `${config.baseURL}/v${config.version}`;
15-
16-
logger.silly('Theme Kit installation starting');
17-
spinner.start();
18-
19-
const installer = new BinWrapper()
20-
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
21-
.src(`${urlAndPath}/linux-386/theme`, 'linux')
22-
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
23-
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
24-
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
25-
.dest(config.destination)
26-
.use(config.binName);
27-
28-
const pathToExecutable = installer.path();
29-
30-
cleanFile(pathToExecutable);
31-
32-
installer.run(['version'], (runErr) => {
33-
if (runErr) {
34-
reject(runErr);
35-
}
36-
37-
spinner.stop();
38-
logger.info(`Theme Kit path: ${pathToExecutable}`);
39-
resolve();
40-
});
41-
});
12+
async function install(logLevel) {
13+
const logger = require('./logger')(logLevel);
14+
const urlAndPath = `${config.baseURL}/v${config.version}`;
15+
16+
logger.silly('Theme Kit installation starting');
17+
spinner.start();
18+
19+
const installer = new BinWrapper()
20+
.src(`${urlAndPath}/darwin-amd64/theme`, 'darwin')
21+
.src(`${urlAndPath}/linux-386/theme`, 'linux')
22+
.src(`${urlAndPath}/linux-amd64/theme`, 'linux', 'x64')
23+
.src(`${urlAndPath}/windows-386/theme.exe`, 'win32')
24+
.src(`${urlAndPath}/windows-amd64/theme.exe`, 'win32', 'x64')
25+
.dest(config.destination)
26+
.use(config.binName);
27+
28+
const pathToExecutable = installer.path();
29+
30+
cleanFile(pathToExecutable);
31+
32+
try {
33+
await installer.run(['version']);
34+
spinner.stop();
35+
logger.info(`Theme Kit path: ${pathToExecutable}`);
36+
} catch (err) {
37+
throw new Error(err);
38+
}
4239
}
4340

4441
module.exports = install;

lib/themekit.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ const themekit = {
1212
* @param {Object} options additional options (cwd and logLevel)
1313
*/
1414
command(cmd, flagObj = {}, options = {cwd: process.cwd()}) {
15-
const updatedFlagObj = Object.assign({}, flagObj, {
16-
noUpdateNotifier: true
17-
});
15+
const updatedFlagObj = {...flagObj, noUpdateNotifier: true};
1816
const flagArr = getFlagArrayFromObject(updatedFlagObj);
1917

2018
return runExecutable(

0 commit comments

Comments
 (0)