forked from kevva/npm-conf
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test.js
33 lines (25 loc) · 1.16 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// load `npmDefaults` first and clone them into a new object as `npmCore` mutates them
const npmDefaults = Object.assign({}, require('./node_modules/npm/lib/config/defaults').defaults);
const npmCore = require('npm/lib/config/core');
const { promisify } = require('util');
const m = require('.');
// The 'unicode' property is determined based on OS type and environment variables
delete npmDefaults.unicode;
test('mirror npm config', async () => {
const { config: conf } = m();
const npmConf = await promisify(npmCore.load)();
expect(conf.globalPrefix).toBe(npmConf.globalPrefix);
expect(conf.localPrefix).toBe(npmConf.localPrefix);
expect(conf.get('prefix')).toBe(npmConf.get('prefix'));
expect(conf.get('registry')).toBe(npmConf.get('registry'));
expect(conf.get('tmp')).toBe(npmConf.get('tmp'));
});
test('mirror npm defaults', () => {
delete npmDefaults['node-version']
expect(m.defaults).toMatchObject(npmDefaults);
});
test('npm builtin configs require failed', async () => {
// In the scope of jest, require.resolve.paths('npm') cannot reach global npm path by default
const { failedToLoadBuiltInConfig } = m();
expect(failedToLoadBuiltInConfig).toBeTruthy();
})