-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathget-registry.test.js
65 lines (54 loc) · 2.23 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import path from "path";
import test from "ava";
import fs from "fs-extra";
import { temporaryDirectory } from "tempy";
import getRegistry from "../lib/get-registry.js";
test("Get default registry", (t) => {
const cwd = temporaryDirectory();
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 = temporaryDirectory();
await fs.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 = temporaryDirectory();
await fs.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 = temporaryDirectory();
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 = temporaryDirectory();
await fs.appendFile(path.resolve(cwd, ".npmrc"), "@scope:registry = https://custom3.registry.com");
t.is(getRegistry({ name: "@scope/package-name" }, { cwd, env: {} }), "https://custom3.registry.com/");
});
test.serial('Get the registry configured via "NPM_CONFIG_USERCONFIG" for scoped package', async (t) => {
const cwd = temporaryDirectory();
await fs.appendFile(path.resolve(cwd, ".custom-npmrc"), "@scope:registry = https://custom4.registry.com");
t.is(
getRegistry(
{
name: "@scope/package-name",
},
{
cwd,
env: { NPM_CONFIG_USERCONFIG: path.resolve(cwd, ".custom-npmrc") },
}
),
"https://custom4.registry.com/"
);
});