Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: type fixes for tests #903

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/cmds/categories/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ describe('rdme categories:create', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(categoriesCreate.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(categoriesCreate.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/categories/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ describe('rdme categories', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(categories.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(categories.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ describe('rdme changelogs', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(changelogs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(changelogs.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/changelogs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ describe('rdme changelogs (single)', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(changelogs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(changelogs.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/custompages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ describe('rdme custompages', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(custompages.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(custompages.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/custompages/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ describe('rdme custompages (single)', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(custompages.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(custompages.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
3 changes: 3 additions & 0 deletions __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('rdme docs', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(docs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});
Expand All @@ -60,6 +61,7 @@ describe('rdme docs', () => {
.basicAuth({ user: key })
.reply(200, [{ version }]);

// @ts-expect-error deliberately passing in bad data
await expect(docs.run({})).rejects.toStrictEqual(
new Error('No path provided. Usage `rdme docs <path> [options]`.'),
);
Expand Down Expand Up @@ -627,6 +629,7 @@ describe('rdme docs', () => {
afterEach(afterGHAEnv);

it('should error in CI if no API key provided', () => {
// @ts-expect-error deliberately passing in bad data
return expect(docs.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.'));
});

Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/docs/prune.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ describe('rdme docs:prune', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(docsPrune.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(docsPrune.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/docs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('rdme docs (single)', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(docs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});
Expand Down Expand Up @@ -354,6 +355,7 @@ describe('rdme docs (single)', () => {
afterEach(afterGHAEnv);

it('should error in CI if no API key provided', () => {
// @ts-expect-error deliberately passing in bad data
return expect(docs.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.'));
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/open.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('rdme open', () => {
return Promise.resolve();
}

await expect(cmd.run({ mockOpen, dash: true, key: '12345' })).resolves.toBe(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow it actually caught something!

await expect(cmd.run({ mockOpen, dash: true })).resolves.toBe(
`Opening ${chalk.green(dashUrl)} in your browser...`,
);
mockRequest.done();
Expand All @@ -81,7 +81,7 @@ describe('rdme open', () => {
return Promise.resolve();
}

return expect(cmd.run({ mockOpen, dash: true, key: '12345' })).rejects.toStrictEqual(
return expect(cmd.run({ mockOpen, dash: true })).rejects.toStrictEqual(
new Error(`Please login using \`${config.cli} login\`.`),
);
});
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/openapi/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ describe('rdme openapi', () => {
describe('error handling', () => {
it('should prompt for login if no API key provided', () => {
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
return expect(openapi.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
});

Expand Down Expand Up @@ -1300,6 +1301,7 @@ describe('rdme openapi', () => {
afterEach(afterGHAEnv);

it('should error in CI if no API key provided', () => {
// @ts-expect-error deliberately passing in bad data
return expect(openapi.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/versions/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ describe('rdme versions:create', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(createVersion.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(createVersion.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/versions/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ describe('rdme versions:delete', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(deleteVersion.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(deleteVersion.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/versions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ describe('rdme versions', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(versions.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(versions.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.'));
delete process.env.TEST_RDME_CI;
});
Expand Down
2 changes: 2 additions & 0 deletions __tests__/cmds/versions/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ describe('rdme versions:update', () => {
it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
// @ts-expect-error deliberately passing in bad data
await expect(updateVersion.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
});

it('should error in CI if no API key provided', async () => {
process.env.TEST_RDME_CI = 'true';
// @ts-expect-error deliberately passing in bad data
await expect(updateVersion.run({})).rejects.toStrictEqual(
new Error('No project API key provided. Please use `--key`.'),
);
Expand Down
1 change: 1 addition & 0 deletions __tests__/helpers/get-api-mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export function getAPIMockMSW(
) {
return rest.get(`${proxy}${config.host}${path}`, (req, res, ctx) => {
try {
// @ts-expect-error once we move off node-fetch, we can make these types consistent
validateHeaders(req.headers, basicAuthUser, expectedReqHeaders);
let responseTransformer: ResponseTransformer;
if (response?.json) {
Expand Down
2 changes: 2 additions & 0 deletions __tests__/helpers/vitest.matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function toBeValidSchema(
/** The JSON schema file */
schema: AnySchema,
): ExpectationResult {
// @ts-expect-error this still works, not sure why TS is flagging it
const ajv = new Ajv({ strictTypes: false, strictTuples: false });

const data = jsYaml.load(yaml);
Expand All @@ -58,6 +59,7 @@ function toBeValidSchema(
let output = 'expected YAML to be valid';

if (validate.errors)
// @ts-expect-error this still works, not sure why TS is flagging it
output = `${output}, here's the validation error\n\n${betterAjvErrors(schema, data, validate.errors)}`;

return {
Expand Down
5 changes: 5 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
"strict": false
},
"include": ["*.ts", "**/*"]
}