Skip to content

Commit

Permalink
feat: add @oclif/plugin-not-found, other cleanups (#1074)
Browse files Browse the repository at this point in the history
## 🧰 Changes

- [x] introduces
[`@oclif/plugin-not-found`](https://github.com/oclif/plugin-not-found/tree/main)
into the mix
- [x] shuffles around our `npm` scripts a tiny bit
- [x] stronger test assertions
- [x] various lint/test output cleanups
  • Loading branch information
kanadgupta authored Nov 19, 2024
1 parent eae8ee7 commit 6529b03
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 114 deletions.
2 changes: 1 addition & 1 deletion __tests__/commands/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ describe('rdme changelogs', () => {
message: `Error uploading ${chalk.underline(`${fullDirectory}/${slug}.md`)}:\n\n${errorObject.message}`,
};

await expect(run([`./${fullDirectory}`, '--key', key])).rejects.toThrow(new APIError(formattedErrorObject));
await expect(run([`./${fullDirectory}`, '--key', key])).rejects.toStrictEqual(new APIError(formattedErrorObject));

getMocks.done();
postMocks.done();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/changelogs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('rdme changelogs (single)', () => {
message: `Error uploading ${chalk.underline(`${filePath}`)}:\n\n${errorObject.message}`,
};

await expect(run([filePath, '--key', key])).rejects.toThrow(new APIError(formattedErrorObject));
await expect(run([filePath, '--key', key])).rejects.toStrictEqual(new APIError(formattedErrorObject));

getMock.done();
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/custompages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe('rdme custompages', () => {
message: `Error uploading ${chalk.underline(`${fullDirectory}/${slug}.md`)}:\n\n${errorObject.message}`,
};

await expect(run([`./${fullDirectory}`, '--key', key])).rejects.toThrow(new APIError(formattedErrorObject));
await expect(run([`./${fullDirectory}`, '--key', key])).rejects.toStrictEqual(new APIError(formattedErrorObject));

getMocks.done();
postMocks.done();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/custompages/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('rdme custompages (single)', () => {
message: `Error uploading ${chalk.underline(`${filePath}`)}:\n\n${errorObject.message}`,
};

await expect(run([filePath, '--key', key])).rejects.toThrow(new APIError(formattedErrorObject));
await expect(run([filePath, '--key', key])).rejects.toStrictEqual(new APIError(formattedErrorObject));

getMock.done();
});
Expand Down
3 changes: 3 additions & 0 deletions __tests__/commands/docs/__snapshots__/multiple.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`rdme docs (multiple) > should return an error message when it encounters a cycle 1`] = `[Error: Cyclic dependency, node was:{"content":"\\n# Parent Body\\n","data":{"title":"Parent","parentDocSlug":"grandparent"},"filePath":"__tests__/__fixtures__/docs/multiple-docs-cycle/parent.md","hash":"0fc832371f8e240047bfc14bc8be9e37d50c8bb8","slug":"parent"}]`;
2 changes: 1 addition & 1 deletion __tests__/commands/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ describe('rdme docs', () => {
message: `Error uploading ${chalk.underline(`${fullDirectory}/${slug}.md`)}:\n\n${errorObject.message}`,
};

await expect(run([`./${fullDirectory}`, '--key', key, '--version', version])).rejects.toThrow(
await expect(run([`./${fullDirectory}`, '--key', key, '--version', version])).rejects.toStrictEqual(
new APIError(formattedErrorObject),
);

Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/docs/multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('rdme docs (multiple)', () => {

const promise = run([`./__tests__/${fixturesBaseDir}/${dir}`, '--key', key, '--version', version]);

await expect(promise).rejects.toThrow('Cyclic dependency');
await expect(promise).rejects.toMatchSnapshot();
versionMock.done();
});
});
4 changes: 2 additions & 2 deletions __tests__/commands/docs/prune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('rdme docs:prune', () => {
it('should error if the argument is not a folder', async () => {
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

await expect(run(['--key', key, '--version', version, 'not-a-folder'])).rejects.toThrow(
"ENOENT: no such file or directory, scandir 'not-a-folder'",
await expect(run(['--key', key, '--version', version, 'not-a-folder'])).rejects.toStrictEqual(
new Error("ENOENT: no such file or directory, scandir 'not-a-folder'"),
);

versionMock.done();
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/docs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ describe('rdme docs (single)', () => {
message: `Error uploading ${chalk.underline(`${filePath}`)}:\n\n${errorObject.message}`,
};

await expect(run([filePath, '--key', key, '--version', version])).rejects.toThrow(
await expect(run([filePath, '--key', key, '--version', version])).rejects.toStrictEqual(
new APIError(formattedErrorObject),
);

Expand Down
4 changes: 2 additions & 2 deletions __tests__/commands/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('rdme login', () => {

const mock = getAPIMock().post('/api/v1/login', { email, password, project }).reply(401, errorResponse);

await expect(run()).rejects.toThrow(new APIError(errorResponse));
await expect(run()).rejects.toStrictEqual(new APIError(errorResponse));
mock.done();
});

Expand Down Expand Up @@ -147,7 +147,7 @@ describe('rdme login', () => {
.post('/api/v1/login', { email, password, project: projectThatIsNotYours })
.reply(404, errorResponse);

await expect(run()).rejects.toThrow(new APIError(errorResponse));
await expect(run()).rejects.toStrictEqual(new APIError(errorResponse));
mock.done();
});
});
2 changes: 2 additions & 0 deletions __tests__/commands/openapi/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ jobs:
"
`;

exports[`rdme openapi > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `[MissingPointerError: Token "Error" does not exist.]`;

exports[`rdme openapi > error handling > should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = `
[SyntaxError: OpenAPI schema validation failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ ADDITIONAL PROPERTY must NOT have additional properties
29 | "summary": "Finds Pets by status",]
`;
exports[`rdme openapi:validate > error handling > should throw an error if an invalid OpenAPI 3.0 definition is supplied 1`] = `[MissingPointerError: Token "Error" does not exist.]`;
exports[`rdme openapi:validate > error handling > should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = `
[SyntaxError: OpenAPI schema validation failed.
Expand Down
14 changes: 7 additions & 7 deletions __tests__/commands/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ describe('rdme openapi', () => {
'--version',
invalidVersion,
]),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

return mock.done();
});
Expand Down Expand Up @@ -824,15 +824,15 @@ describe('rdme openapi', () => {

await expect(
run([require.resolve('@readme/oas-examples/3.1/json/petstore.json'), '--key', 'key']),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

return mock.done();
});

it('should throw an error if an invalid OpenAPI 3.0 definition is supplied', () => {
return expect(
run(['./__tests__/__fixtures__/invalid-oas.json', '--key', key, '--id', id, '--version', version]),
).rejects.toThrow('Token "Error" does not exist.');
).rejects.toMatchSnapshot();
});

it('should throw an error if an invalid OpenAPI 3.1 definition is supplied', () => {
Expand Down Expand Up @@ -874,7 +874,7 @@ describe('rdme openapi', () => {

await expect(
run(['./__tests__/__fixtures__/swagger-with-invalid-extensions.json', '--key', key, '--version', version]),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

mockWithHeader.done();
return mock.done();
Expand Down Expand Up @@ -909,7 +909,7 @@ describe('rdme openapi', () => {
'--version',
version,
]),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

putMock.done();
return mock.done();
Expand All @@ -932,7 +932,7 @@ describe('rdme openapi', () => {

await expect(
run(['./__tests__/__fixtures__/swagger-with-invalid-extensions.json', '--key', key, '--version', version]),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

return mock.done();
});
Expand Down Expand Up @@ -965,7 +965,7 @@ describe('rdme openapi', () => {

await expect(
run([require.resolve('@readme/oas-examples/2.0/json/petstore.json'), '--key', key, '--version', version]),
).rejects.toThrow(new APIError(errorObject));
).rejects.toStrictEqual(new APIError(errorObject));

mockWithHeader.done();
return mock.done();
Expand Down
6 changes: 2 additions & 4 deletions __tests__/commands/openapi/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ describe('rdme openapi:validate', () => {
describe('error handling', () => {
it('should throw an error if invalid JSON is supplied', () => {
return expect(run(['./__tests__/__fixtures__/invalid-json/yikes.json'])).rejects.toStrictEqual(
new Error('Unexpected end of JSON input'),
new SyntaxError('Unexpected end of JSON input'),
);
});

it('should throw an error if an invalid OpenAPI 3.0 definition is supplied', () => {
return expect(run(['./__tests__/__fixtures__/invalid-oas.json'])).rejects.toThrow(
'Token "Error" does not exist.',
);
return expect(run(['./__tests__/__fixtures__/invalid-oas.json'])).rejects.toMatchSnapshot();
});

it('should throw an error if an invalid OpenAPI 3.1 definition is supplied', () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/versions/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('rdme versions:create', () => {

const mockRequest = getAPIMock().post('/api/v1/version').basicAuth({ user: key }).reply(400, errorResponse);

await expect(run(['--key', key, version, '--fork', '0.0.5'])).rejects.toThrow(new APIError(errorResponse));
await expect(run(['--key', key, version, '--fork', '0.0.5'])).rejects.toStrictEqual(new APIError(errorResponse));
mockRequest.done();
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/versions/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('rdme versions:delete', () => {
.basicAuth({ user: key })
.reply(200, { version });

await expect(run(['--key', key, version])).rejects.toThrow(new APIError(errorResponse));
await expect(run(['--key', key, version])).rejects.toStrictEqual(new APIError(errorResponse));
mockRequest.done();
});
});
2 changes: 1 addition & 1 deletion __tests__/commands/versions/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ describe('rdme versions:update', () => {
.basicAuth({ user: key })
.reply(400, errorResponse);

await expect(run(['--key', key, version])).rejects.toThrow(new APIError(errorResponse));
await expect(run(['--key', key, version])).rejects.toStrictEqual(new APIError(errorResponse));
mockRequest.done();
});

Expand Down
4 changes: 1 addition & 3 deletions __tests__/helpers/setup-oclif-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ export function runCommand<T extends typeof OclifCommand>(Command: T) {
return captureOutput<string>(() => Command.run(args, oclifConfig), { testNodeEnv: 'rdme-test' }).then(
({ error, result }) => {
if (error) {
const e = new Error(error.message);
if (error.name) e.name = error.name;
throw e;
throw error;
}
return result;
},
Expand Down
1 change: 0 additions & 1 deletion knip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const config: KnipConfig = {
entry: ['src/index.ts', 'src/lib/help.ts', 'bin/*.js'],
ignore: ['dist-gha/**'],
ignoreBinaries: ['semantic-release'],
ignoreDependencies: ['oclif'],
};

export default config;
Loading

0 comments on commit 6529b03

Please sign in to comment.