-
Notifications
You must be signed in to change notification settings - Fork 110
/
get-registry.test.js
44 lines (35 loc) · 1.66 KB
/
get-registry.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
import path from 'path';
import test from 'ava';
import {appendFile} from 'fs-extra';
import tempy from 'tempy';
import getRegistry from '../lib/get-registry';
test('Get default registry', t => {
const cwd = tempy.directory();
t.is(getRegistry({name: 'package-name'}, {cwd, env: {}}), 'https://registry.npmjs.org/');
t.is(getRegistry({name: 'package-name', publishConfig: {}}, {cwd, env: {}}), 'https://registry.npmjs.org/');
});
test('Get the registry configured in ".npmrc" and normalize trailing slash', async t => {
const cwd = tempy.directory();
await appendFile(path.resolve(cwd, '.npmrc'), 'registry = https://custom1.registry.com');
t.is(getRegistry({name: 'package-name'}, {cwd, env: {}}), 'https://custom1.registry.com/');
});
test('Get the registry configured from "publishConfig"', async t => {
const cwd = tempy.directory();
await appendFile(path.resolve(cwd, '.npmrc'), 'registry = https://custom2.registry.com');
t.is(
getRegistry({name: 'package-name', publishConfig: {registry: 'https://custom3.registry.com/'}}, {cwd, env: {}}),
'https://custom3.registry.com/'
);
});
test('Get the registry configured in "NPM_CONFIG_REGISTRY"', t => {
const cwd = tempy.directory();
t.is(
getRegistry({name: 'package-name'}, {cwd, env: {NPM_CONFIG_REGISTRY: 'https://custom1.registry.com/'}}),
'https://custom1.registry.com/'
);
});
test('Get the registry configured in ".npmrc" for scoped package', async t => {
const cwd = tempy.directory();
await appendFile(path.resolve(cwd, '.npmrc'), '@scope:registry = https://custom3.registry.com');
t.is(getRegistry({name: '@scope/package-name'}, {cwd, env: {}}), 'https://custom3.registry.com/');
});