Skip to content

Commit 4c8bc45

Browse files
committed
fixup: add test cases for missing trailing slash
1 parent d25abcd commit 4c8bc45

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

src/npm/__tests__/use-npm-environment.test.ts

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,42 +19,62 @@ describe("useNpmEnvironment", () => {
1919
await fs.rm(directory, { recursive: true, force: true });
2020
});
2121

22-
it("create an npmrc file ", async () => {
23-
const inputManifest = { name: "fizzbuzz" } as PackageManifest;
24-
const inputOptions = {
25-
token: "abc123",
26-
registry: new URL("http://example.com/cool-registry/"),
27-
temporaryDirectory: directory,
28-
} as NormalizedOptions;
29-
30-
let npmrcPath: string | undefined;
31-
let npmrcContents: string | undefined;
32-
33-
const result = await subject.useNpmEnvironment(
34-
inputManifest,
35-
inputOptions,
36-
async (manifest, options, environment) => {
37-
npmrcPath = environment["npm_config_userconfig"]!;
38-
npmrcContents = await fs.readFile(npmrcPath, "utf8");
39-
return { manifest, options, environment };
40-
}
41-
);
42-
43-
expect(result).toEqual({
44-
manifest: inputManifest,
45-
options: inputOptions,
46-
environment: {
47-
NODE_AUTH_TOKEN: "abc123",
48-
npm_config_userconfig: npmrcPath,
49-
},
50-
});
51-
expect(npmrcContents).toContain(
52-
"//example.com/cool-registry/:_authToken=${NODE_AUTH_TOKEN}"
53-
);
54-
expect(npmrcContents).toContain(
55-
"registry=http://example.com/cool-registry/"
56-
);
57-
58-
await expect(fs.access(npmrcPath!)).rejects.toThrow(/ENOENT/);
59-
});
22+
it.each([
23+
{
24+
registryUrl: "http://example.com/",
25+
expectedAuthConfig: "//example.com/:_authToken=${NODE_AUTH_TOKEN}",
26+
expectedRegistryConfig: "registry=http://example.com/",
27+
},
28+
{
29+
registryUrl: "http://example.com",
30+
expectedAuthConfig: "//example.com/:_authToken=${NODE_AUTH_TOKEN}",
31+
expectedRegistryConfig: "registry=http://example.com/",
32+
},
33+
{
34+
registryUrl: "http://example.com/hello/",
35+
expectedAuthConfig: "//example.com/hello/:_authToken=${NODE_AUTH_TOKEN}",
36+
expectedRegistryConfig: "registry=http://example.com/hello/",
37+
},
38+
{
39+
registryUrl: "http://example.com/hello",
40+
expectedAuthConfig: "//example.com/hello/:_authToken=${NODE_AUTH_TOKEN}",
41+
expectedRegistryConfig: "registry=http://example.com/hello/",
42+
},
43+
])(
44+
"creates an npmrc file for $registryUrl",
45+
async ({ registryUrl, expectedAuthConfig, expectedRegistryConfig }) => {
46+
const inputManifest = { name: "fizzbuzz" } as PackageManifest;
47+
const inputOptions = {
48+
token: "abc123",
49+
registry: new URL(registryUrl),
50+
temporaryDirectory: directory,
51+
} as NormalizedOptions;
52+
53+
let npmrcPath: string | undefined;
54+
let npmrcContents: string | undefined;
55+
56+
const result = await subject.useNpmEnvironment(
57+
inputManifest,
58+
inputOptions,
59+
async (manifest, options, environment) => {
60+
npmrcPath = environment["npm_config_userconfig"]!;
61+
npmrcContents = await fs.readFile(npmrcPath, "utf8");
62+
return { manifest, options, environment };
63+
}
64+
);
65+
66+
expect(result).toEqual({
67+
manifest: inputManifest,
68+
options: inputOptions,
69+
environment: {
70+
NODE_AUTH_TOKEN: "abc123",
71+
npm_config_userconfig: npmrcPath,
72+
},
73+
});
74+
expect(npmrcContents).toContain(expectedAuthConfig);
75+
expect(npmrcContents).toContain(expectedRegistryConfig);
76+
77+
await expect(fs.access(npmrcPath!)).rejects.toThrow(/ENOENT/);
78+
}
79+
);
6080
});

0 commit comments

Comments
 (0)