Skip to content

Commit

Permalink
test: migrate a bunch of commands over
Browse files Browse the repository at this point in the history
...with the exception of the openapi family of commands

this uses a new test wrapper that uses @oclif/test, so we can actually get proper module reloading when editing a command 🥹

chore: smol typefix
  • Loading branch information
kanadgupta committed Nov 9, 2024
1 parent 4d0968e commit 76388e4
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 160 deletions.
3 changes: 0 additions & 3 deletions __tests__/cmds/__snapshots__/whoami.test.ts.snap

This file was deleted.

13 changes: 5 additions & 8 deletions __tests__/cmds/categories/create.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import type { Config } from '@oclif/core';

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

import Command from '../../../src/cmds/categories/create.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const key = 'API_KEY';
const version = '1.0.0';

describe('rdme categories:create', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('categories:create', args);
beforeEach(() => {
run = runCommand(Command);
});

afterEach(() => nock.cleanAll());
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/categories/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import type { Config } from '@oclif/core';

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

import Command from '../../../src/cmds/categories/index.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const key = 'API_KEY';
const version = '1.0.0';

describe('rdme categories', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('categories', args);
beforeEach(() => {
run = runCommand(Command);
});

afterEach(() => nock.cleanAll());
Expand Down
11 changes: 5 additions & 6 deletions __tests__/cmds/changelogs/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ import frontMatter from 'gray-matter';
import nock from 'nock';
import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest';

import Command from '../../../src/cmds/changelogs.js';
import APIError from '../../../src/lib/apiError.js';
import getAPIMock from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/changelogs';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme changelogs', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('changelogs', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/changelogs/single.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Config } from '@oclif/core';

import fs from 'node:fs';
import path from 'node:path';

Expand All @@ -8,26 +6,25 @@ import frontMatter from 'gray-matter';
import nock from 'nock';
import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest';

import Command from '../../../src/cmds/changelogs.js';
import APIError from '../../../src/lib/apiError.js';
import getAPIMock from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/changelogs';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme changelogs (single)', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('changelogs', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/custompages/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Config } from '@oclif/core';

import fs from 'node:fs';
import path from 'node:path';

Expand All @@ -8,26 +6,25 @@ import frontMatter from 'gray-matter';
import nock from 'nock';
import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest';

import Command from '../../../src/cmds/custompages.js';
import APIError from '../../../src/lib/apiError.js';
import getAPIMock from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/custompages';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme custompages', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('custompages', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/custompages/single.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type { Config } from '@oclif/core';

import fs from 'node:fs';
import path from 'node:path';

Expand All @@ -8,26 +6,25 @@ import frontMatter from 'gray-matter';
import nock from 'nock';
import { describe, beforeAll, afterAll, beforeEach, it, expect } from 'vitest';

import Command from '../../../src/cmds/custompages.js';
import APIError from '../../../src/lib/apiError.js';
import getAPIMock from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/custompages';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
const key = 'API_KEY';

describe('rdme custompages (single)', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('custompages', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/docker-gha.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import type { Config } from '@oclif/core';

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

import setupOclifConfig from '../helpers/setup-oclif-config.js';
import Command from '../../src/cmds/docker-gha.js';
import { runCommand } from '../helpers/setup-oclif-config.js';

describe('rdme docker-gha (single arg string from GitHub Actions runner)', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('docker-gha', args);
beforeEach(() => {
run = runCommand(Command);
});

it('should return version from package.json for help command', async () => {
Expand Down
17 changes: 8 additions & 9 deletions __tests__/cmds/docs/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/* eslint-disable no-console */
import type { Config } from '@oclif/core';

import fs from 'node:fs';
import path from 'node:path';

import { runCommand as oclifRunCommand } from '@oclif/test';
import chalk from 'chalk';
import frontMatter from 'gray-matter';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, afterAll, beforeEach, afterEach, it, expect, vi } from 'vitest';

import Command from '../../../src/cmds/docs/index.js';
import APIError from '../../../src/lib/apiError.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import { after, before } from '../../helpers/get-gha-setup.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import { after as afterGHAEnv, before as beforeGHAEnv } from '../../helpers/setup-gha-env.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/docs';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
Expand All @@ -25,16 +26,14 @@ const version = '1.0.0';
const category = 'CATEGORY_ID';

describe('rdme docs', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('docs', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down Expand Up @@ -719,8 +718,8 @@ describe('rdme docs', () => {
});

describe('rdme guides', () => {
it('should error if no path provided', () => {
return expect(oclifConfig.runCommand('guides', ['--key', key, '--version', '1.0.0'])).rejects.toThrow(
it('should error if no path provided', async () => {
return expect((await oclifRunCommand(['guides', '--key', key, '--version', '1.0.0'])).error.message).toContain(
'Missing 1 required arg:\npath',
);
});
Expand Down
13 changes: 5 additions & 8 deletions __tests__/cmds/docs/multiple.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { Config } from '@oclif/core';

import fs from 'node:fs';
import path from 'node:path';

import frontMatter from 'gray-matter';
import nock from 'nock';
import { describe, beforeAll, beforeEach, afterAll, it, expect } from 'vitest';

import Command from '../../../src/cmds/docs/index.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/docs';
const fullFixturesDir = `${__dirname}./../../${fixturesBaseDir}`;
Expand All @@ -18,16 +17,14 @@ const key = 'API_KEY';
const version = '1.0.0';

describe('rdme docs (multiple)', () => {
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('docs', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down
22 changes: 10 additions & 12 deletions __tests__/cmds/docs/prune.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Config } from '@oclif/core';

import { runCommand as oclifRunCommand } from '@oclif/test';
import nock from 'nock';
import prompts from 'prompts';
import { describe, beforeAll, beforeEach, afterAll, it, expect } from 'vitest';

import Command from '../../../src/cmds/docs/prune.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import setupOclifConfig from '../../helpers/setup-oclif-config.js';
import { runCommand } from '../../helpers/setup-oclif-config.js';

const fixturesBaseDir = '__fixtures__/docs';

Expand All @@ -14,16 +14,14 @@ const version = '1.0.0';

describe('rdme docs:prune', () => {
const folder = `./__tests__/${fixturesBaseDir}/delete-docs`;
let oclifConfig: Config;
let run: (args?: string[]) => Promise<unknown>;
let run: (args?: string[]) => Promise<string>;

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

beforeEach(async () => {
oclifConfig = await setupOclifConfig();
run = (args?: string[]) => oclifConfig.runCommand('docs:prune', args);
beforeEach(() => {
run = runCommand(Command);
});

afterAll(() => nock.cleanAll());
Expand Down Expand Up @@ -151,10 +149,10 @@ describe('rdme docs:prune', () => {
});

describe('rdme guides:prune', () => {
it('should error if no folder provided', () => {
return expect(oclifConfig.runCommand('guides:prune', ['--key', key, '--version', version])).rejects.toThrow(
'Missing 1 required arg:\nfolder',
);
it('should error if no folder provided', async () => {
return expect(
(await oclifRunCommand(['guides:prune', '--key', key, '--version', version])).error.message,
).toContain('Missing 1 required arg:\nfolder');
});
});
});
Loading

0 comments on commit 76388e4

Please sign in to comment.