-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.js
57 lines (42 loc) · 1.89 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import {promisify} from 'util';
import fs from 'fs';
import test from 'ava';
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const importFresh = async modulePath => import(`${modulePath}?x=${new Date()}`);
const unlinkP = promisify(fs.unlink);
const writeFileP = promisify(fs.writeFile);
delete process.env.npm_config_registry;
test.afterEach(async () => {
try {
await unlinkP('.npmrc');
} catch {}
});
test('get the npm registry URL globally', async t => {
t.truthy((await importFresh('./index.js')).default().length);
});
test('works with npm_config_registry in the environment', async t => {
// eslint-disable-next-line camelcase
process.env.npm_config_registry = 'http://registry.example';
t.is((await importFresh('./index.js')).default(), 'http://registry.example/');
delete process.env.npm_config_registry;
});
test('get the npm registry URL locally', async t => {
await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu/');
t.is((await importFresh('./index.js')).default(), 'http://registry.npmjs.eu/');
});
test('get local scope registry URL', async t => {
await writeFileP('.npmrc', '@myco:registry=http://reg.example.com/');
t.is((await importFresh('./index.js')).default('@myco'), 'http://reg.example.com/');
});
test('return default npm registry when scope registry is not set', async t => {
await writeFileP('.npmrc', '');
t.is((await importFresh('./index.js')).default('@invalidScope'), 'https://registry.npmjs.org/');
});
test('add trailing slash to local npm registry URL', async t => {
await writeFileP('.npmrc', 'registry=http://registry.npmjs.eu');
t.is((await importFresh('./index.js')).default(), 'http://registry.npmjs.eu/');
});
test('add trailing slash to local scope registry URL', async t => {
await writeFileP('.npmrc', '@myco:registry=http://reg.example.com');
t.is((await importFresh('./index.js')).default('@myco'), 'http://reg.example.com/');
});