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

test(cli-e2e): move helper functions, clean up tests and setup #412

Merged
merged 1 commit into from
Jan 15, 2024
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
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"onlyDependOnLibsWithTags": [
"type:app",
"type:feature",
"type:util",
"type:testing-util"
]
},
Expand Down
12 changes: 12 additions & 0 deletions e2e/cli-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*", "code-pushup.config.ts"],
"overrides": [
{
"files": ["*.ts", "*.tsx"],
"parserOptions": {
"project": ["e2e/cli-e2e/tsconfig.*?.json"]
}
}
]
}
30 changes: 0 additions & 30 deletions e2e/cli-e2e/mocks/code-pushup.config.js

This file was deleted.

30 changes: 0 additions & 30 deletions e2e/cli-e2e/mocks/code-pushup.config.mjs

This file was deleted.

31 changes: 0 additions & 31 deletions e2e/cli-e2e/mocks/code-pushup.config.ts

This file was deleted.

27 changes: 27 additions & 0 deletions e2e/cli-e2e/mocks/fixtures/code-pushup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
upload: {
organization: 'code-pushup',
project: 'cli-js',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
],
plugins: [
await eslintPlugin({ eslintrc: '.eslintrc.json', patterns: '**/*.ts' }),
],
};
27 changes: 27 additions & 0 deletions e2e/cli-e2e/mocks/fixtures/code-pushup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
upload: {
organization: 'code-pushup',
project: 'cli-mjs',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
],
plugins: [
await eslintPlugin({ eslintrc: '.eslintrc.json', patterns: '**/*.ts' }),
],
};
28 changes: 28 additions & 0 deletions e2e/cli-e2e/mocks/fixtures/code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import eslintPlugin from '@code-pushup/eslint-plugin';
import { CoreConfig } from '@code-pushup/models';

export default {
upload: {
organization: 'code-pushup',
project: 'cli-ts',
apiKey: 'e2e-api-key',
server: 'https://e2e.com/api',
},
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
],
plugins: [
await eslintPlugin({ eslintrc: '.eslintrc.json', patterns: '**/*.ts' }),
],
} satisfies CoreConfig;
43 changes: 0 additions & 43 deletions e2e/cli-e2e/mocks/fs.mock.ts

This file was deleted.

33 changes: 0 additions & 33 deletions e2e/cli-e2e/mocks/utils.ts

This file was deleted.

7 changes: 7 additions & 0 deletions e2e/cli-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"sourceRoot": "examples/cli-e2e/src",
"projectType": "application",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/cli-e2e/**/*.ts"]
}
},
"e2e": {
"executor": "@nx/vite:test",
"outputs": ["{options.reportsDirectory}"],
Expand Down
19 changes: 5 additions & 14 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
import { afterEach, beforeEach, vi } from 'vitest';
import { PluginReport, Report, reportSchema } from '@code-pushup/models';
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
import { cleanFolderPutGitKeep } from '../mocks/fs.mock';

describe('CLI collect', () => {
const exampleCategoryTitle = 'Code style';
const exampleAuditTitle = 'Require `const` declarations for variables';

/* eslint-disable @typescript-eslint/no-unused-vars */
const omitVariableData = ({
date,
duration,
version,
...report
}: Report | PluginReport) => report;
/* eslint-enable @typescript-eslint/no-unused-vars */

const omitVariableReportData = (report: Report) =>
omitVariableData({
...report,
plugins: report.plugins.map(omitVariableData) as PluginReport[],
});

beforeEach(async () => {
vi.clearAllMocks();
cleanFolderPutGitKeep();
});

afterEach(() => {
cleanFolderPutGitKeep();
});

it('should run ESLint plugin and create report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
Expand All @@ -43,7 +34,7 @@ describe('CLI collect', () => {

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
}, 120000);
});

it('should create report.md', async () => {
const { code, stderr } = await executeProcess({
Expand All @@ -60,7 +51,7 @@ describe('CLI collect', () => {
expect(md).toContain('# Code PushUp Report');
expect(md).toContain(exampleCategoryTitle);
expect(md).toContain(exampleAuditTitle);
}, 120000);
});

it('should print report summary to stdout', async () => {
const { code, stdout, stderr } = await executeProcess({
Expand All @@ -76,5 +67,5 @@ describe('CLI collect', () => {
expect(stdout).not.toContain('Generated reports');
expect(stdout).toContain(exampleCategoryTitle);
expect(stdout).toContain(exampleAuditTitle);
}, 120000);
});
});
16 changes: 14 additions & 2 deletions e2e/cli-e2e/tests/help.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ describe('CLI help', () => {
expect(code).toBe(0);
expect(stderr).toBe('');
expect(stdout).toMatchSnapshot();
}, 120000);
});

// @TODO 'should print help with help command'
it('should produce the same output to stdout for both help argument and help command', async () => {
const helpArgResult = await executeProcess({
command: 'code-pushup',
args: ['help'],
});
const helpCommandResult = await executeProcess({
command: 'code-pushup',
args: ['--help'],
});
expect(helpArgResult.code).toBe(0);
expect(helpCommandResult.code).toBe(0);
expect(helpArgResult.stdout).toBe(helpCommandResult.stdout);
});
});
Loading