Skip to content

Commit d1c9dfb

Browse files
erunionkanadgupta
authored andcommitted
chore(deps-dev): upgrading our eslint standards (#1174)
The owner of `eslint-plugin-vitest` lost their NPM access to it was moved into `@vitest/eslint-plugin` a little over a year ago. This upgrades our `@readme/eslint-config` package to pull that in.
1 parent acb9ab6 commit d1c9dfb

File tree

11 files changed

+52
-9
lines changed

11 files changed

+52
-9
lines changed

__tests__/.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"rules": {
44
// vitest currently allows for __dirname, require, etc.
55
// see https://github.com/vitest-dev/vitest/issues/2841
6-
"unicorn/prefer-module": "off"
6+
"unicorn/prefer-module": "off",
7+
8+
"@vitest/require-mock-type-parameters": "off",
79
}
810
}

__tests__/bin.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('bin', () => {
99
await new Promise(resolve => {
1010
exec(`node ${__dirname}/../bin/run.js`, (error, stdout) => {
1111
expect(stdout).toContain("ReadMe's official CLI and GitHub Action");
12+
1213
resolve(true);
1314
});
1415
});

__tests__/commands/login.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ describe('rdme login', () => {
102102
const mock = getAPIv1Mock().post('/api/v1/login', { email, password, project }).reply(401, errorResponse);
103103

104104
await expect(run()).rejects.toStrictEqual(new APIv1Error(errorResponse));
105+
105106
mock.done();
106107
});
107108

@@ -144,6 +145,7 @@ describe('rdme login', () => {
144145
.reply(404, errorResponse);
145146

146147
await expect(run()).rejects.toStrictEqual(new APIv1Error(errorResponse));
148+
147149
mock.done();
148150
});
149151
});

__tests__/commands/openapi/inspect.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable vitest/no-conditional-expect */
1+
/* eslint-disable @vitest/no-conditional-expect */
22
import assert from 'node:assert';
33

44
import { describe, it, expect, beforeAll } from 'vitest';
@@ -69,6 +69,7 @@ describe('rdme openapi inspect', () => {
6969
const args = [require.resolve(spec)].concat(...feature.map(f => ['--feature', f]));
7070
if (!shouldSoftError) {
7171
await expect(run(args)).resolves.toMatchSnapshot();
72+
7273
return;
7374
}
7475

__tests__/commands/openapi/reduce.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('rdme openapi reduce', () => {
7676
expect(console.info).toHaveBeenCalledTimes(1);
7777

7878
const output = getCommandOutput();
79+
7980
expect(output).toBe(chalk.yellow(`ℹ️ We found ${spec} and are attempting to reduce it.`));
8081

8182
expect(Object.keys(reducedSpec.paths)).toStrictEqual(['/user']);
@@ -98,6 +99,7 @@ describe('rdme openapi reduce', () => {
9899
expect(console.info).toHaveBeenCalledTimes(1);
99100

100101
const output = getCommandOutput();
102+
101103
expect(output).toBe(chalk.yellow(`ℹ️ We found ${spec} and are attempting to reduce it.`));
102104

103105
expect(Object.keys(reducedSpec.paths)).toStrictEqual(['/user']);
@@ -147,6 +149,7 @@ describe('rdme openapi reduce', () => {
147149
expect(console.info).toHaveBeenCalledTimes(1);
148150

149151
const output = getCommandOutput();
152+
150153
expect(output).toBe(chalk.yellow(`ℹ️ We found ${spec} and are attempting to reduce it.`));
151154

152155
expect(fsWriteFileSyncSpy).toHaveBeenCalledWith('output.json', expect.any(String));
@@ -181,6 +184,7 @@ describe('rdme openapi reduce', () => {
181184
expect(console.info).toHaveBeenCalledTimes(1);
182185

183186
const output = getCommandOutput();
187+
184188
expect(output).toBe(chalk.yellow(`ℹ️ We found ${spec} and are attempting to reduce it.`));
185189

186190
expect(fsWriteFileSyncSpy).toHaveBeenCalledWith('output.json', expect.any(String));

__tests__/commands/openapi/validate.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('rdme openapi validate', () => {
4444
['OpenAPI 3.1', 'yaml', '3.1'],
4545
])('should support validating a %s definition (format: %s)', (_, format, specVersion) => {
4646
expect(console.info).toHaveBeenCalledTimes(0);
47+
4748
return expect(
4849
run([require.resolve(`@readme/oas-examples/${specVersion}/${format}/petstore.${format}`)]),
4950
).resolves.toContain(
@@ -59,6 +60,7 @@ describe('rdme openapi validate', () => {
5960
expect(console.info).toHaveBeenCalledTimes(1);
6061

6162
const output = getCommandOutput();
63+
6264
expect(output).toBe(chalk.yellow('ℹ️ We found petstore.json and are attempting to validate it.'));
6365
});
6466

@@ -115,6 +117,7 @@ describe('rdme openapi validate', () => {
115117
it('should successfully validate prompt and not run GHA onboarding', async () => {
116118
vi.stubEnv('TEST_RDME_CREATEGHA', 'true');
117119
const spec = '__tests__/__fixtures__/petstore-simple-weird-version.json';
120+
118121
await expect(run([spec])).resolves.toBe(chalk.green(`${spec} is a valid OpenAPI API definition!`));
119122
});
120123

@@ -146,6 +149,7 @@ describe('rdme openapi validate', () => {
146149

147150
it('should create GHA workflow if user passes in spec via prompts', async () => {
148151
expect.assertions(6);
152+
149153
const spec = '__tests__/__fixtures__/petstore-simple-weird-version.json';
150154
const fileName = 'validate-test-file';
151155
prompts.inject([spec, true, 'validate-test-branch', fileName]);
@@ -155,13 +159,16 @@ describe('rdme openapi validate', () => {
155159
expect(yamlOutput).toMatchSnapshot();
156160
expect(fs.writeFileSync).toHaveBeenCalledWith(`.github/workflows/${fileName}.yml`, expect.any(String));
157161
expect(console.info).toHaveBeenCalledTimes(2);
162+
158163
const output = getCommandOutput();
164+
159165
expect(output).toMatch("Looks like you're running this command in a GitHub Repository!");
160166
expect(output).toMatch('is a valid OpenAPI API definition!');
161167
});
162168

163169
it('should create GHA workflow if user passes in spec via opt', async () => {
164170
expect.assertions(3);
171+
165172
const spec = '__tests__/__fixtures__/petstore-simple-weird-version.json';
166173
const fileName = 'validate-test-opt-spec-file';
167174
prompts.inject([true, 'validate-test-opt-spec-branch', fileName]);
@@ -174,6 +181,7 @@ describe('rdme openapi validate', () => {
174181

175182
it('should create GHA workflow if user passes in spec via opt (including workingDirectory)', async () => {
176183
expect.assertions(3);
184+
177185
const spec = 'petstore.json';
178186
const fileName = 'validate-test-opt-spec-workdir-file';
179187
prompts.inject([true, 'validate-test-opt-spec-github-branch', fileName]);
@@ -188,6 +196,7 @@ describe('rdme openapi validate', () => {
188196

189197
it('should create GHA workflow if user passes in spec via opt (github flag enabled)', async () => {
190198
expect.assertions(3);
199+
191200
const spec = '__tests__/__fixtures__/petstore-simple-weird-version.json';
192201
const fileName = 'validate-test-opt-spec-github-file';
193202
prompts.inject(['validate-test-opt-spec-github-branch', fileName]);

__tests__/lib/createGHA.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable vitest/no-disabled-tests */
1+
/* eslint-disable @vitest/no-disabled-tests */
22
/* eslint-disable no-console */
33
import type { Command, Config } from '@oclif/core';
44
import type { Response } from 'simple-git';
@@ -89,22 +89,27 @@ describe('#createGHA', () => {
8989

9090
it('should run GHA creation workflow and generate valid workflow file', async () => {
9191
expect.assertions(6);
92+
9293
const fileName = `rdme-${cmd}`;
9394
prompts.inject([true, 'some-branch', fileName]);
9495

9596
const res = await oclifConfig.runHook('createGHA', { command: CurrentCommand, parsedOpts: opts, result: '' });
97+
9698
expect(res.successes[0].result).toMatchSnapshot();
9799

98100
expect(yamlOutput).toBeValidSchema(ghaWorkflowSchema);
99101
expect(yamlOutput).toMatchSnapshot();
100102
expect(fs.writeFileSync).toHaveBeenCalledWith(getGHAFileName(fileName), expect.any(String));
101103
expect(console.info).toHaveBeenCalledTimes(1);
104+
102105
const output = getCommandOutput();
106+
103107
expect(output).toMatch("Looks like you're running this command in a GitHub Repository!");
104108
});
105109

106110
it('should run GHA creation workflow with `--github` flag and messy file name and generate valid workflow file', async () => {
107111
expect.assertions(4);
112+
108113
const fileName = `rdme-${cmd} with GitHub flag`;
109114
prompts.inject(['another-branch', fileName]);
110115

@@ -113,6 +118,7 @@ describe('#createGHA', () => {
113118
parsedOpts: { ...opts, github: true },
114119
result: '',
115120
});
121+
116122
expect(res.successes[0].result).toMatchSnapshot();
117123

118124
expect(yamlOutput).toBeValidSchema(ghaWorkflowSchema);
@@ -123,6 +129,7 @@ describe('#createGHA', () => {
123129
// skipping because these mocks aren't playing nicely with oclif
124130
it.skip('should create workflow directory if it does not exist', async () => {
125131
expect.assertions(3);
132+
126133
const repoRoot = '__tests__/__fixtures__';
127134

128135
git.revparse = vi.fn(() => {
@@ -137,7 +144,8 @@ describe('#createGHA', () => {
137144
});
138145

139146
const res = await oclifConfig.runHook('createGHA', { command: CurrentCommand, parsedOpts: opts, result: '' });
140-
expect(res.successes[0].result).toBeTruthy();
147+
148+
expect(res.successes[0].result).toBe(true);
141149

142150
expect(fs.mkdirSync).toHaveBeenCalledWith('.github/workflows', { recursive: true });
143151
expect(fs.writeFileSync).toHaveBeenCalledWith(getGHAFileName(fileName), expect.any(String));
@@ -157,6 +165,7 @@ describe('#createGHA', () => {
157165

158166
it('should set config and exit if user does not want to set up GHA', async () => {
159167
expect.assertions(2);
168+
160169
prompts.inject([false]);
161170

162171
const repoRoot = process.cwd();
@@ -166,6 +175,7 @@ describe('#createGHA', () => {
166175
});
167176

168177
const res = await oclifConfig.runHook('createGHA', { command: CurrentCommand, parsedOpts: opts, result: '' });
178+
169179
expect(res.failures[0].error).toStrictEqual(
170180
new Error(
171181
'GitHub Actions workflow creation cancelled. If you ever change your mind, you can run this command again with the `--github` flag.',
@@ -239,9 +249,11 @@ describe('#createGHA', () => {
239249
parsedOpts: opts,
240250
result: 'success!',
241251
});
252+
242253
expect(res.successes[0].result).toBe('success!');
243254
// asserts that git commands aren't run in CI
244255
expect(git.checkIsRepo).not.toHaveBeenCalled();
256+
245257
delete process.env.TEST_RDME_CI;
246258
});
247259

@@ -252,9 +264,11 @@ describe('#createGHA', () => {
252264
parsedOpts: opts,
253265
result: 'success!',
254266
});
267+
255268
expect(res.successes[0].result).toBe('success!');
256269
// asserts that git commands aren't run in CI
257270
expect(git.checkIsRepo).not.toHaveBeenCalled();
271+
258272
delete process.env.TEST_RDME_NPM_SCRIPT;
259273
});
260274

__tests__/lib/fetch.test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('#readmeAPIv1Fetch()', () => {
3535
expect(headers['x-github-run-number']).toBe('3');
3636
expect(headers['x-github-sha']).toBe('ffac537e6cbbf934b08745a378932722df287a53');
3737
expect(headers['x-rdme-ci']).toBe('GitHub Actions (test)');
38+
3839
mock.done();
3940
});
4041

@@ -61,6 +62,7 @@ describe('#readmeAPIv1Fetch()', () => {
6162
expect(headers['x-readme-source-url']).toBe(
6263
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/openapi.json',
6364
);
65+
6466
mock.done();
6567
});
6668

@@ -86,6 +88,7 @@ describe('#readmeAPIv1Fetch()', () => {
8688
expect(headers['x-readme-source-url']).toBe(
8789
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/%F0%9F%93%88%20Dashboard%20&%20Metrics/openapi.json',
8890
);
91+
8992
mock.done();
9093
});
9194

@@ -110,6 +113,7 @@ describe('#readmeAPIv1Fetch()', () => {
110113
).then(handleAPIv1Res);
111114

112115
expect(headers['x-readme-source-url']).toBeUndefined();
116+
113117
mock.done();
114118
});
115119

@@ -135,6 +139,7 @@ describe('#readmeAPIv1Fetch()', () => {
135139
expect(headers['x-readme-source-url']).toBe(
136140
'https://github.com/octocat/Hello-World/blob/ffac537e6cbbf934b08745a378932722df287a53/openapi.json',
137141
);
142+
138143
mock.done();
139144
});
140145

@@ -159,6 +164,7 @@ describe('#readmeAPIv1Fetch()', () => {
159164
).then(handleAPIv1Res);
160165

161166
expect(headers['x-readme-source-url']).toBe(filePath);
167+
162168
mock.done();
163169
});
164170
});
@@ -186,6 +192,7 @@ describe('#readmeAPIv1Fetch()', () => {
186192
expect(headers['x-github-run-id']).toBeUndefined();
187193
expect(headers['x-github-run-number']).toBeUndefined();
188194
expect(headers['x-github-sha']).toBeUndefined();
195+
189196
mock.done();
190197
});
191198

@@ -205,6 +212,7 @@ describe('#readmeAPIv1Fetch()', () => {
205212
expect(headers['x-github-run-id']).toBeUndefined();
206213
expect(headers['x-github-run-number']).toBeUndefined();
207214
expect(headers['x-github-sha']).toBeUndefined();
215+
208216
mock.done();
209217
});
210218

@@ -297,7 +305,7 @@ describe('#readmeAPIv1Fetch()', () => {
297305

298306
await readmeAPIv1Fetch('/api/v1/proxy');
299307

300-
mock.done();
308+
expect(mock.isDone()).toBe(true);
301309
});
302310

303311
it('should support proxies via https_proxy env variable', async () => {
@@ -309,7 +317,7 @@ describe('#readmeAPIv1Fetch()', () => {
309317

310318
await readmeAPIv1Fetch('/api/v1/proxy');
311319

312-
mock.done();
320+
expect(mock.isDone()).toBe(true);
313321
});
314322

315323
it('should handle trailing slash in proxy URL', async () => {
@@ -321,7 +329,7 @@ describe('#readmeAPIv1Fetch()', () => {
321329

322330
await readmeAPIv1Fetch('/api/v1/proxy');
323331

324-
mock.done();
332+
expect(mock.isDone()).toBe(true);
325333
});
326334
});
327335
});

__tests__/lib/getPkgVersion.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('#getNodeVersion()', () => {
99
it('should extract version that matches range in package.json', () => {
1010
const version = getNodeVersion();
1111
const cleanedVersion = semver.valid(semver.coerce(version));
12+
1213
expect(semver.satisfies(cleanedVersion as string, pkg.engines.node)).toBe(true);
1314
});
1415
});

__tests__/lib/validatePromptInput.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('#validateFilePath', () => {
1515

1616
it('should return error if path already exists', () => {
1717
expect.assertions(2);
18+
1819
const testPath = 'path-that-already-exists';
1920

2021
fs.existsSync = vi.fn(() => true);
@@ -25,6 +26,7 @@ describe('#validateFilePath', () => {
2526

2627
it("should return true if the path doesn't exist", () => {
2728
expect.assertions(2);
29+
2830
const testPath = 'path-that-does-not-exist';
2931

3032
fs.existsSync = vi.fn(() => false);

0 commit comments

Comments
 (0)