-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.js
50 lines (37 loc) · 1.36 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
import fs from 'fs';
import test from 'ava';
import pify from 'pify';
import requireUncached from 'require-uncached';
const fsP = pify(fs, Promise);
test.afterEach(async () => {
try {
await fsP.unlink('.npmrc');
} catch (err) {
if (err.code !== 'ENOENT') {
throw err;
}
}
});
test('get the npm registry URL globally', t => {
t.truthy(requireUncached('./')().length);
});
test('get the npm registry URL locally', async t => {
await fsP.writeFile('.npmrc', 'registry=http://registry.npmjs.eu/');
t.is(requireUncached('./')(), 'http://registry.npmjs.eu/');
});
test('get local scope registry URL', async t => {
await fsP.writeFile('.npmrc', '@myco:registry=http://reg.example.com/');
t.is(requireUncached('./')('@myco'), 'http://reg.example.com/');
});
test('return default npm registry when scope registry is not set', async t => {
await fsP.writeFile('.npmrc', '');
t.is(requireUncached('./')('@invalidScope'), 'https://registry.npmjs.org/');
});
test('add trailing slash to local npm registry URL', async t => {
await fsP.writeFile('.npmrc', 'registry=http://registry.npmjs.eu');
t.is(requireUncached('./')(), 'http://registry.npmjs.eu/');
});
test('add trailing slash to local scope registry URL', async t => {
await fsP.writeFile('.npmrc', '@myco:registry=http://reg.example.com');
t.is(requireUncached('./')('@myco'), 'http://reg.example.com/');
});