Skip to content

Commit

Permalink
feat(cli): setup yargs for cli (#42)
Browse files Browse the repository at this point in the history
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 <34691111+matejchalk@users.noreply.github.com>
Co-authored-by: Matěj Chalk <matej.chalk@flowup.cz>
  • Loading branch information
3 people authored Sep 8, 2023
1 parent dacaaf7 commit 37ea0a5
Show file tree
Hide file tree
Showing 39 changed files with 3,032 additions and 3,147 deletions.
2 changes: 2 additions & 0 deletions examples/cli-e2e/mocks/config.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';

export default {
persist: { outputPath: 'cli-config-out.json' },
categories: [],
plugins: [
eslintPlugin({ config: '.eslintrc.json' }),
lighthousePlugin({ config: '.lighthouserc.json' }),
Expand Down
2 changes: 2 additions & 0 deletions examples/cli-e2e/mocks/config.mock.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';

export default {
persist: { outputPath: 'cli-config-out.json' },
categories: [],
plugins: [
eslintPlugin({ config: '.eslintrc.json' }),
lighthousePlugin({ config: '.lighthouserc.json' }),
Expand Down
2 changes: 2 additions & 0 deletions examples/cli-e2e/mocks/config.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import eslintPlugin from '@quality-metrics/eslint-plugin';
import lighthousePlugin from '@quality-metrics/lighthouse-plugin';

export default {
persist: { outputPath: 'cli-config-out.json' },
categories: [],
plugins: [
eslintPlugin({ config: '.eslintrc.json' }),
lighthousePlugin({ config: '.lighthouserc.json' }),
Expand Down
40 changes: 16 additions & 24 deletions examples/cli-e2e/tests/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { cli } from '@quality-metrics/cli';
import { execSync } from 'child_process';
import { join } from 'path';

const configFile = (ext: 'ts' | 'js' | 'mjs') =>
join(process.cwd(), `examples/cli-e2e/mocks/config.mock.${ext}`);

describe('cli', () => {
beforeAll(() => {
Expand All @@ -9,35 +13,23 @@ describe('cli', () => {
});

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

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

it('should load .ts config file', async () => {
await expect(
cli('./examples/cli-e2e/mocks/config.mock.ts'),
).resolves.toEqual({
plugins: [
{ name: 'eslint', version: '8.46.0' },
{ name: 'lighthouse', defaultConfig: expect.any(Object) },
],
});
const argv = await cli(['--configPath', configFile('ts'), '--verbose'])
.argv;
expect(argv.plugins[0].meta.slug).toEqual('eslint');
expect(argv.plugins[1].meta.slug).toEqual('lighthouse');
});
});
Loading

0 comments on commit 37ea0a5

Please sign in to comment.