Skip to content

Commit

Permalink
fixup: add test cases for missing trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous committed Mar 29, 2024
1 parent d25abcd commit 4c8bc45
Showing 1 changed file with 58 additions and 38 deletions.
96 changes: 58 additions & 38 deletions src/npm/__tests__/use-npm-environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,62 @@ describe("useNpmEnvironment", () => {
await fs.rm(directory, { recursive: true, force: true });
});

it("create an npmrc file ", async () => {
const inputManifest = { name: "fizzbuzz" } as PackageManifest;
const inputOptions = {
token: "abc123",
registry: new URL("http://example.com/cool-registry/"),
temporaryDirectory: directory,
} as NormalizedOptions;

let npmrcPath: string | undefined;
let npmrcContents: string | undefined;

const result = await subject.useNpmEnvironment(
inputManifest,
inputOptions,
async (manifest, options, environment) => {
npmrcPath = environment["npm_config_userconfig"]!;
npmrcContents = await fs.readFile(npmrcPath, "utf8");
return { manifest, options, environment };
}
);

expect(result).toEqual({
manifest: inputManifest,
options: inputOptions,
environment: {
NODE_AUTH_TOKEN: "abc123",
npm_config_userconfig: npmrcPath,
},
});
expect(npmrcContents).toContain(
"//example.com/cool-registry/:_authToken=${NODE_AUTH_TOKEN}"
);
expect(npmrcContents).toContain(
"registry=http://example.com/cool-registry/"
);

await expect(fs.access(npmrcPath!)).rejects.toThrow(/ENOENT/);
});
it.each([
{
registryUrl: "http://example.com/",
expectedAuthConfig: "//example.com/:_authToken=${NODE_AUTH_TOKEN}",
expectedRegistryConfig: "registry=http://example.com/",
},
{
registryUrl: "http://example.com",
expectedAuthConfig: "//example.com/:_authToken=${NODE_AUTH_TOKEN}",
expectedRegistryConfig: "registry=http://example.com/",
},
{
registryUrl: "http://example.com/hello/",
expectedAuthConfig: "//example.com/hello/:_authToken=${NODE_AUTH_TOKEN}",
expectedRegistryConfig: "registry=http://example.com/hello/",
},
{
registryUrl: "http://example.com/hello",
expectedAuthConfig: "//example.com/hello/:_authToken=${NODE_AUTH_TOKEN}",
expectedRegistryConfig: "registry=http://example.com/hello/",
},
])(
"creates an npmrc file for $registryUrl",
async ({ registryUrl, expectedAuthConfig, expectedRegistryConfig }) => {
const inputManifest = { name: "fizzbuzz" } as PackageManifest;
const inputOptions = {
token: "abc123",
registry: new URL(registryUrl),
temporaryDirectory: directory,
} as NormalizedOptions;

let npmrcPath: string | undefined;
let npmrcContents: string | undefined;

const result = await subject.useNpmEnvironment(
inputManifest,
inputOptions,
async (manifest, options, environment) => {
npmrcPath = environment["npm_config_userconfig"]!;
npmrcContents = await fs.readFile(npmrcPath, "utf8");
return { manifest, options, environment };
}
);

expect(result).toEqual({
manifest: inputManifest,
options: inputOptions,
environment: {
NODE_AUTH_TOKEN: "abc123",
npm_config_userconfig: npmrcPath,
},
});
expect(npmrcContents).toContain(expectedAuthConfig);

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 16 / ubuntu-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 18 / ubuntu-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 20 / ubuntu-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 16 / macos-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 18 / macos-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 20 / macos-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\n…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 16 / windows-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\r…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 18 / windows-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\r…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29

Check failure on line 74 in src/npm/__tests__/use-npm-environment.test.ts

View workflow job for this annotation

GitHub Actions / Unit tests / Node.js 20 / windows-latest

src/npm/__tests__/use-npm-environment.test.ts > useNpmEnvironment > creates an npmrc file for 'http://example.com/hello'

AssertionError: expected '; created by jsdevtools/npm-publish\r…' to include '//example.com/hello/:_authToken=${NOD…' ❯ src/npm/__tests__/use-npm-environment.test.ts:74:29
expect(npmrcContents).toContain(expectedRegistryConfig);

await expect(fs.access(npmrcPath!)).rejects.toThrow(/ENOENT/);
}
);
});

0 comments on commit 4c8bc45

Please sign in to comment.