Skip to content

Commit 37ea0a5

Browse files
feat(cli): setup yargs for cli (#42)
This PR includes: - yargs setup - chalk usage - test cli-e2e - update plugins to new model structure - test plugins closes #6 closes #38 --------- Co-authored-by: Matěj Chalk <[email protected]> Co-authored-by: Matěj Chalk <[email protected]>
1 parent dacaaf7 commit 37ea0a5

39 files changed

+3032
-3147
lines changed

examples/cli-e2e/mocks/config.mock.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
22
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';
33

44
export default {
5+
persist: { outputPath: 'cli-config-out.json' },
6+
categories: [],
57
plugins: [
68
eslintPlugin({ config: '.eslintrc.json' }),
79
lighthousePlugin({ config: '.lighthouserc.json' }),

examples/cli-e2e/mocks/config.mock.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
22
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';
33

44
export default {
5+
persist: { outputPath: 'cli-config-out.json' },
6+
categories: [],
57
plugins: [
68
eslintPlugin({ config: '.eslintrc.json' }),
79
lighthousePlugin({ config: '.lighthouserc.json' }),

examples/cli-e2e/mocks/config.mock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
22
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';
33

44
export default {
5+
persist: { outputPath: 'cli-config-out.json' },
6+
categories: [],
57
plugins: [
68
eslintPlugin({ config: '.eslintrc.json' }),
79
lighthousePlugin({ config: '.lighthouserc.json' }),

examples/cli-e2e/tests/cli.spec.ts

+16-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { describe, it, expect, beforeAll } from 'vitest';
22
import { cli } from '@quality-metrics/cli';
33
import { execSync } from 'child_process';
4+
import { join } from 'path';
5+
6+
const configFile = (ext: 'ts' | 'js' | 'mjs') =>
7+
join(process.cwd(), `examples/cli-e2e/mocks/config.mock.${ext}`);
48

59
describe('cli', () => {
610
beforeAll(() => {
@@ -9,35 +13,23 @@ describe('cli', () => {
913
});
1014

1115
it('should load .js config file', async () => {
12-
await expect(
13-
cli('./examples/cli-e2e/mocks/config.mock.js'),
14-
).resolves.toEqual({
15-
plugins: [
16-
{ name: 'eslint', version: '8.46.0' },
17-
{ name: 'lighthouse', defaultConfig: expect.any(Object) },
18-
],
19-
});
16+
const argv = await cli(['--configPath', configFile('js'), '--verbose'])
17+
.argv;
18+
expect(argv.plugins[0].meta.slug).toEqual('eslint');
19+
expect(argv.plugins[1].meta.slug).toEqual('lighthouse');
2020
});
2121

2222
it('should load .mjs config file', async () => {
23-
await expect(
24-
cli('./examples/cli-e2e/mocks/config.mock.mjs'),
25-
).resolves.toEqual({
26-
plugins: [
27-
{ name: 'eslint', version: '8.46.0' },
28-
{ name: 'lighthouse', defaultConfig: expect.any(Object) },
29-
],
30-
});
23+
const argv = await cli(['--configPath', configFile('mjs'), '--verbose'])
24+
.argv;
25+
expect(argv.plugins[0].meta.slug).toEqual('eslint');
26+
expect(argv.plugins[1].meta.slug).toEqual('lighthouse');
3127
});
3228

3329
it('should load .ts config file', async () => {
34-
await expect(
35-
cli('./examples/cli-e2e/mocks/config.mock.ts'),
36-
).resolves.toEqual({
37-
plugins: [
38-
{ name: 'eslint', version: '8.46.0' },
39-
{ name: 'lighthouse', defaultConfig: expect.any(Object) },
40-
],
41-
});
30+
const argv = await cli(['--configPath', configFile('ts'), '--verbose'])
31+
.argv;
32+
expect(argv.plugins[0].meta.slug).toEqual('eslint');
33+
expect(argv.plugins[1].meta.slug).toEqual('lighthouse');
4234
});
4335
});

0 commit comments

Comments
 (0)