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 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
import {promisify} from 'util';
import fs from 'fs';
import test from 'tape';
// 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;
const afterEach = async () => {
try {
await unlinkP('.npmrc');
} catch {}
};
test('get the npm registry URL globally', async t => {
t.ok((await importFresh('./index.js')).default().length);
afterEach();
t.end();
});
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;
afterEach();
t.end();
});
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/');
afterEach();
t.end();
});
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/');
afterEach();
t.end();
});
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/');
afterEach();
t.end();
});
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/');
afterEach();
t.end();
});
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/');
afterEach();
t.end();
});
|