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

feat(test): moving unit tests over to vitest #857

Merged
merged 25 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f8a4e55
feat(test): moving unit tests over to vitest
erunion Aug 10, 2023
46c7731
fix: prettier issues
erunion Aug 10, 2023
51c71c3
ci: stop testing node 14
erunion Aug 10, 2023
27b7781
fix: schema updater for prettier 3
erunion Aug 10, 2023
1a4c78c
fix: install missing vitest coverage dep
erunion Aug 10, 2023
cf1aef9
chore: better link
kanadgupta Aug 10, 2023
5664dd9
ci: let other node versions run if one fails
kanadgupta Aug 10, 2023
0376bee
ci: try skipping some tests
kanadgupta Aug 11, 2023
b658139
chore(deps): bump eslint config
kanadgupta Aug 14, 2023
0283788
test: don't return in before* hooks
kanadgupta Aug 14, 2023
9c823fe
test: more before* hook fixes
kanadgupta Aug 14, 2023
029d4d4
test: try using stubEnv in a few places
kanadgupta Aug 14, 2023
b1d9175
chore: typo
kanadgupta Aug 14, 2023
dad18a5
Merge branch 'next' into feat/vitest
kanadgupta Aug 21, 2023
f3b9a5d
Merge branch 'next' into feat/vitest
kanadgupta Aug 23, 2023
0071e90
Merge branch 'next' into feat/vitest
kanadgupta Sep 5, 2023
13249fe
Merge branch 'next' into feat/vitest
kanadgupta Sep 5, 2023
1e573ed
chore: rebuild lockfile using npm i
kanadgupta Sep 5, 2023
3298545
chore: wait this happened after i ran "npm i" again?
kanadgupta Sep 5, 2023
22f7904
Merge branch 'next' into feat/vitest
kanadgupta Sep 5, 2023
f3dc0ac
Revert "Merge branch 'next' into feat/vitest"
kanadgupta Sep 5, 2023
ed480ed
fix(vitest): split out tests (#870)
kanadgupta Sep 5, 2023
104c00b
fix: don't nest timers
kanadgupta Sep 5, 2023
bcbe0af
chore: remove unnecessary globals file
kanadgupta Sep 5, 2023
f2ef333
chore: bumping eslint-config
erunion Sep 7, 2023
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
11 changes: 3 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
name: Test Suite
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 14
Expand All @@ -28,14 +29,8 @@ jobs:
node-version: ${{ matrix.node-version }}
cache: npm

- name: Install deps
run: npm ci

- name: Build dist
run: npm run build

- name: Run tests
run: npm test
- name: Build and run tests
run: npm cit

lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ __tests__/
.prettier*
bin/*.js
coverage/
jest.*.js
packages/
vitest.*
2 changes: 1 addition & 1 deletion __tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "@readme/eslint-config/testing/jest"
"extends": "@readme/eslint-config/testing/vitest"
}
10 changes: 5 additions & 5 deletions __tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`cli --help should not surface args that are designated as hidden 1`] = `
exports[`cli > --help > should not surface args that are designated as hidden 1`] = `
"
Upload, or resync, your OpenAPI/Swagger definition to ReadMe.

Expand Down Expand Up @@ -47,7 +47,7 @@ Related commands
"
`;

exports[`cli --help should print usage for a given command 1`] = `
exports[`cli > --help > should print usage for a given command 1`] = `
"
Upload, or resync, your OpenAPI/Swagger definition to ReadMe.

Expand Down Expand Up @@ -94,7 +94,7 @@ Related commands
"
`;

exports[`cli --help should print usage for a given command if supplied as \`help <command>\` 1`] = `
exports[`cli > --help > should print usage for a given command if supplied as \`help <command>\` 1`] = `
"
Upload, or resync, your OpenAPI/Swagger definition to ReadMe.

Expand Down Expand Up @@ -141,7 +141,7 @@ Related commands
"
`;

exports[`cli --help should show related commands for a subcommands help menu 1`] = `
exports[`cli > --help > should show related commands for a subcommands help menu 1`] = `
"
List versions available in your project or get a version by SemVer (https://semver.org/).

Expand Down
2 changes: 2 additions & 0 deletions __tests__/bin.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { exec } from 'child_process';

import { describe, it, expect } from 'vitest';

describe('bin', () => {
it('should show our help screen', async () => {
expect.assertions(1);
Expand Down
4 changes: 2 additions & 2 deletions __tests__/cmds/__snapshots__/whoami.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`rdme whoami should return the authenticated user 1`] = `"You are currently logged in as [email protected] to the subdomain project."`;
exports[`rdme whoami > should return the authenticated user 1`] = `"You are currently logged in as [email protected] to the subdomain project."`;
7 changes: 5 additions & 2 deletions __tests__/cmds/categories/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterEach, it, expect, vi } from 'vitest';

import CategoriesCreateCommand from '../../../src/cmds/categories/create';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock';
Expand All @@ -10,12 +11,14 @@ const key = 'API_KEY';
const version = '1.0.0';

describe('rdme categories:create', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterEach(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(categoriesCreate.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
7 changes: 5 additions & 2 deletions __tests__/cmds/categories/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterEach, it, expect, vi } from 'vitest';

import CategoriesCommand from '../../../src/cmds/categories';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock';
Expand All @@ -10,12 +11,14 @@ const key = 'API_KEY';
const version = '1.0.0';

describe('rdme categories', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterEach(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(categories.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
7 changes: 5 additions & 2 deletions __tests__/cmds/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chalk from 'chalk';
import frontMatter from 'gray-matter';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, it, expect, vi } from 'vitest';

import ChangelogsCommand from '../../../src/cmds/changelogs';
import APIError from '../../../src/lib/apiError';
Expand All @@ -18,12 +19,14 @@ const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme changelogs', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(changelogs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
7 changes: 5 additions & 2 deletions __tests__/cmds/changelogs/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chalk from 'chalk';
import frontMatter from 'gray-matter';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, it, expect, vi } from 'vitest';

import ChangelogsCommand from '../../../src/cmds/changelogs';
import APIError from '../../../src/lib/apiError';
Expand All @@ -18,12 +19,14 @@ const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme changelogs (single)', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(changelogs.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
7 changes: 5 additions & 2 deletions __tests__/cmds/custompages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chalk from 'chalk';
import frontMatter from 'gray-matter';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, it, expect, vi } from 'vitest';

import CustomPagesCommand from '../../../src/cmds/custompages';
import APIError from '../../../src/lib/apiError';
Expand All @@ -18,12 +19,14 @@ const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme custompages', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(custompages.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
7 changes: 5 additions & 2 deletions __tests__/cmds/custompages/single.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import chalk from 'chalk';
import frontMatter from 'gray-matter';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, it, expect, vi } from 'vitest';

import CustomPagesCommand from '../../../src/cmds/custompages';
import APIError from '../../../src/lib/apiError';
Expand All @@ -18,12 +19,14 @@ const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme custompages (single)', () => {
beforeAll(() => nock.disableNetConnect());
beforeAll(() => {
nock.disableNetConnect();
});

afterAll(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(custompages.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand Down
14 changes: 7 additions & 7 deletions __tests__/cmds/docs/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed as opt (github flag enabled) 1`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed as opt (github flag enabled) 1`] = `
"
Your GitHub Actions workflow file has been created! ✨

Expand All @@ -14,7 +14,7 @@ Almost done! Just a couple more steps:
"
`;

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed as opt (github flag enabled) 2`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed as opt (github flag enabled) 2`] = `
"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z
# You can view our full documentation here: https://docs.readme.com/docs/rdme
name: ReadMe GitHub Action 🦉
Expand All @@ -41,7 +41,7 @@ jobs:
"
`;

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed in via opt 1`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed in via opt 1`] = `
"
Your GitHub Actions workflow file has been created! ✨

Expand All @@ -55,7 +55,7 @@ Almost done! Just a couple more steps:
"
`;

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed in via opt 2`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed in via opt 2`] = `
"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z
# You can view our full documentation here: https://docs.readme.com/docs/rdme
name: ReadMe GitHub Action 🦉
Expand All @@ -82,7 +82,7 @@ jobs:
"
`;

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed in via prompt 1`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed in via prompt 1`] = `
"
Your GitHub Actions workflow file has been created! ✨

Expand All @@ -96,7 +96,7 @@ Almost done! Just a couple more steps:
"
`;

exports[`rdme docs GHA onboarding E2E tests should create GHA workflow with version passed in via prompt 2`] = `
exports[`rdme docs > GHA onboarding E2E tests > should create GHA workflow with version passed in via prompt 2`] = `
"# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z
# You can view our full documentation here: https://docs.readme.com/docs/rdme
name: ReadMe GitHub Action 🦉
Expand Down
13 changes: 8 additions & 5 deletions __tests__/cmds/docs/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';

import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, afterEach, it, expect, vi } from 'vitest';

import DocsEditCommand from '../../../src/cmds/docs/edit';
import APIError from '../../../src/lib/apiError';
Expand All @@ -20,20 +21,22 @@ describe('rdme docs:edit', () => {
return [consoleWarnSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n');
}

beforeAll(() => {
nock.disableNetConnect();
});

beforeEach(() => {
consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
});

afterEach(() => {
consoleWarnSpy.mockRestore();
});

beforeAll(() => nock.disableNetConnect());

afterAll(() => nock.cleanAll());

it('should prompt for login if no API key provided', async () => {
const consoleInfoSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
prompts.inject(['this-is-not-an-email', 'password', 'subdomain']);
await expect(docsEdit.run({})).rejects.toStrictEqual(new Error('You must provide a valid email address.'));
consoleInfoSpy.mockRestore();
Expand All @@ -60,7 +63,7 @@ describe('rdme docs:edit', () => {

it('should fetch the doc from the api', async () => {
expect.assertions(5);
const consoleSpy = jest.spyOn(console, 'info').mockImplementation();
const consoleSpy = vi.spyOn(console, 'info').mockImplementation(() => {});
const slug = 'getting-started';
const body = 'abcdef';
const edits = 'ghijkl';
Expand Down
Loading
Loading