Skip to content

Commit 40d7e01

Browse files
authored
Update coverage (#29)
1 parent 8b0230e commit 40d7e01

File tree

4 files changed

+65
-50
lines changed

4 files changed

+65
-50
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ install:
88
- npm install --ignore-scripts
99

1010
script:
11-
- nyc npm run install
12-
- npm test
11+
- nyc npm run install-test
1312

1413
after_script:
1514
- npm run report-coverage

appveyor.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ install:
1919

2020
# to run your custom scripts instead of automatic tests
2121
test_script:
22-
- node_modules/.bin/nyc npm run install
23-
- npm test
22+
- node_modules/.bin/nyc npm run install-test
2423

2524
# to run your custom scripts instead of provider deployments
2625
after_test:

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"install": "node lib/install",
4848
"pretest": "eslint lib test *.js",
4949
"report-coverage": "codecov",
50-
"test": "mocha"
50+
"install-test": "npm run install && npm test",
51+
"test": "mocha --no-timeouts"
5152
},
5253
"version": "2.3.1"
5354
}

test/index.js

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const assert = require('assert');
33
const path = require('path');
44
const os = require('os');
5-
// const fs = require('fs');
65
const util = require('util');
6+
const config = require('../lib/config.js');
77

88
if (!util.promisify) {
99
util.promisify = require('util.promisify');
@@ -12,59 +12,66 @@ if (!util.promisify) {
1212
const exec = util.promisify(require('child_process').execFile);
1313
const readFile = util.promisify(require('fs').readFile);
1414

15-
function getRegEnv (platform) {
16-
const args = [
17-
'QUERY',
18-
'HKCU\\Environment'
19-
];
15+
function initWinEnv () {
16+
function getRegEnv (platform) {
17+
const args = [
18+
'QUERY',
19+
'HKCU\\Environment'
20+
];
2021

21-
if (platform) {
22-
args.push('/reg:' + platform);
22+
if (platform) {
23+
args.push('/reg:' + platform);
24+
}
25+
return exec('REG', args).then(
26+
regQuery => regQuery.stdout,
27+
() => {}
28+
);
2329
}
24-
return exec('REG', args).then(
25-
regQuery => regQuery.stdout,
26-
() => {}
30+
return Promise.all([
31+
getRegEnv(64),
32+
getRegEnv(32),
33+
getRegEnv()
34+
]).then(
35+
regs => regs.filter(
36+
Boolean
37+
).forEach(
38+
regs => regs.replace(
39+
/^\s*(\w+)\s+REG_\w+\s*(.+)$/gm,
40+
(s, key, value) => {
41+
process.env[key] = value;
42+
}
43+
)
44+
)
45+
);
46+
}
47+
48+
function initEnv () {
49+
const home = os.homedir();
50+
const files = [
51+
'.bash_profile',
52+
'.bashrc',
53+
'.zshrc'
54+
].map(
55+
file => path.join(home, file)
2756
);
57+
return Promise.all(files.map(file => {
58+
return readFile(file, 'utf8').then(sh => {
59+
sh.replace(
60+
/^export\s+(.+?)=("|')?(.+?)\2\s*$/igm,
61+
(s, key, quote, value) => {
62+
process.env[key] = value;
63+
}
64+
);
65+
}, () => {});
66+
}));
2867
}
2968

3069
describe('environment variables', () => {
3170
before(() => {
3271
if (process.platform === 'win32') {
33-
return Promise.all([
34-
getRegEnv(64),
35-
getRegEnv(32),
36-
getRegEnv()
37-
]).then(
38-
regs => regs.filter(
39-
Boolean
40-
).forEach(
41-
regs => regs.replace(
42-
/^\s*(\w+)\s+REG_\w+\s*(.+)$/gm,
43-
(s, key, value) => {
44-
process.env[key] = value;
45-
}
46-
)
47-
)
48-
);
72+
return initWinEnv();
4973
} else {
50-
const home = os.homedir();
51-
const files = [
52-
'.bash_profile',
53-
'.bashrc',
54-
'.zshrc'
55-
].map(
56-
file => path.join(home, file)
57-
);
58-
return Promise.all(files.map(file => {
59-
return readFile(file, 'utf8').then(sh => {
60-
sh.replace(
61-
/^export\s+(.+?)=("|')?(.+?)\2\s*$/igm,
62-
(s, key, quote, value) => {
63-
process.env[key] = value;
64-
}
65-
);
66-
}, () => {});
67-
}));
74+
return initEnv();
6875
}
6976
});
7077

@@ -117,3 +124,12 @@ describe('npm config', () => {
117124
assert.equal(process.env.npm_config_puppeteer_download_host, 'https://npm.taobao.org/mirrors');
118125
});
119126
});
127+
128+
describe('get config', () => {
129+
it('--registry', () => {
130+
assert.equal(config(['--registry=https://r.cnpmjs.org']).registry, 'https://r.cnpmjs.org');
131+
});
132+
it('--disturl', () => {
133+
assert.equal(config(['--disturl=https://cnpmjs.org/dist']).disturl, 'https://cnpmjs.org/dist');
134+
});
135+
});

0 commit comments

Comments
 (0)