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(breaking/docs): deprecate docs:edit #646

Merged
merged 1 commit into from
Oct 27, 2022
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
21 changes: 21 additions & 0 deletions __tests__/cmds/docs/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ const version = '1.0.0';
const category = 'CATEGORY_ID';

describe('rdme docs:edit', () => {
let consoleWarnSpy;

function getWarningCommandOutput() {
return [consoleWarnSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n');
}

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

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

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

afterAll(() => nock.cleanAll());
Expand All @@ -31,6 +45,13 @@ describe('rdme docs:edit', () => {
delete process.env.TEST_CI;
});

it('should log deprecation notice', async () => {
process.env.TEST_CI = 'true';
await expect(docsEdit.run({})).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.'));
delete process.env.TEST_CI;
expect(getWarningCommandOutput()).toMatch('is now deprecated');
});

it('should error if no slug provided', () => {
return expect(docsEdit.run({ key, version: '1.0.0' })).rejects.toThrow(
'No slug provided. Usage `rdme docs:edit <slug> [options]`.'
Expand Down
19 changes: 1 addition & 18 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import nock from 'nock';
import prompts from 'prompts';

import { version } from '../package.json';
Expand Down Expand Up @@ -33,17 +32,6 @@ describe('cli', () => {
'Command not found.'
);
});

it('should not be returned if `--version` is being used on a subcommand', async () => {
nock.disableNetConnect();

await expect(cli(['docs:edit', 'getting-started', '--version', '1.0.0', '--key=abcdef'])).rejects.not.toThrow(
// We're testing that the docs:edit command does NOT return an error about `--version` not
// being here because if it throws that error, then that means that `--version` wasn't
// passed in as expected.
'No project version provided. Please use `--version`.'
);
});
});

describe('--help', () => {
Expand Down Expand Up @@ -95,13 +83,8 @@ describe('cli', () => {
});

describe('subcommands', () => {
// docs:edit will make a backend connection
beforeAll(() => nock.disableNetConnect());

it('should load subcommands from the folder', async () => {
await expect(cli(['docs:edit', 'getting-started', '--version=1.0.0', '--key=abcdef'])).rejects.not.toThrow(
'Command not found.'
);
await expect(cli(['openapi:validate', 'package.json'])).rejects.not.toThrow('Command not found.');
});
});

Expand Down
4 changes: 2 additions & 2 deletions __tests__/lib/__snapshots__/commands.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ exports[`utils #listByCategory should list commands by category 1`] = `
"position": 1,
},
{
"description": "Edit a single file from your ReadMe project without saving locally.",
"hidden": false,
"description": "Edit a single file from your ReadMe project without saving locally. [deprecated]",
"hidden": true,
"name": "docs:edit",
"position": 2,
},
Expand Down
5 changes: 4 additions & 1 deletion src/cmds/docs/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import editor from 'editor';

import APIError from '../../lib/apiError';
import Command, { CommandCategories } from '../../lib/baseCommand';
import isHidden from '../../lib/decorators/isHidden';
import fetch, { cleanHeaders, handleRes } from '../../lib/fetch';
import { getProjectVersion } from '../../lib/versionSelect';

Expand All @@ -22,13 +23,14 @@ export type Options = {
slug?: string;
};

@isHidden
export default class EditDocsCommand extends Command {
constructor() {
super();

this.command = 'docs:edit';
this.usage = 'docs:edit <slug> [options]';
this.description = 'Edit a single file from your ReadMe project without saving locally.';
this.description = 'Edit a single file from your ReadMe project without saving locally. [deprecated]';
this.cmdCategory = CommandCategories.DOCS;
this.position = 2;

Expand All @@ -45,6 +47,7 @@ export default class EditDocsCommand extends Command {
}

async run(opts: CommandOptions<Options>): Promise<undefined> {
Command.warn('`rdme docs:edit` is now deprecated and will be removed in a future release.');
await super.run(opts);

const { slug, key, version } = opts;
Expand Down