Skip to content

Commit

Permalink
chore: backfill changes to a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Feb 16, 2024
1 parent 08d4a00 commit 23c1198
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions __tests__/cmds/docs/multiple.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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, afterAll, afterEach, it, expect, vi } from 'vitest';
import { describe, beforeAll, beforeEach, afterAll, it, expect } from 'vitest';

import DocsCommand from '../../../src/cmds/docs/index.js';
import getAPIMock, { getAPIMockWithVersionHeader } from '../../helpers/get-api-mock.js';
import hashFileContents from '../../helpers/hash-file-contents.js';

const docs = new DocsCommand();
import setupOclifConfig from '../../helpers/setup-oclif-config.js';

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

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

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

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

afterAll(() => nock.cleanAll());
Expand Down Expand Up @@ -57,7 +61,7 @@ describe('rdme docs (multiple)', () => {

const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

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

await expect(promise).resolves.toStrictEqual(
[
Expand Down Expand Up @@ -101,7 +105,7 @@ describe('rdme docs (multiple)', () => {

const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

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

await expect(promise).resolves.toStrictEqual(
[
Expand Down Expand Up @@ -145,7 +149,7 @@ describe('rdme docs (multiple)', () => {

const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

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

await expect(promise).resolves.toStrictEqual(
[
Expand All @@ -162,7 +166,7 @@ describe('rdme docs (multiple)', () => {
const dir = 'multiple-docs-cycle';
const versionMock = getAPIMock().get(`/api/v1/version/${version}`).basicAuth({ user: key }).reply(200, { version });

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

await expect(promise).rejects.toThrow('Cyclic dependency');
versionMock.done();
Expand Down

0 comments on commit 23c1198

Please sign in to comment.