Skip to content

Commit

Permalink
test: fix e2e tests
Browse files Browse the repository at this point in the history
inspiration from #810

Signed-off-by: Vojtech Masek <[email protected]>
  • Loading branch information
vmasek committed Sep 6, 2024
1 parent 6e16658 commit 9218855
Show file tree
Hide file tree
Showing 41 changed files with 301 additions and 220 deletions.
2 changes: 1 addition & 1 deletion e2e/cli-e2e/mocks/fixtures/code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'node:path';
import coveragePlugin from '@code-pushup/coverage-plugin';
import eslintPlugin from '@code-pushup/eslint-plugin';
import { CoreConfig } from '@code-pushup/models';
import type { CoreConfig } from '@code-pushup/models';

export default {
upload: {
Expand Down
2 changes: 1 addition & 1 deletion e2e/cli-e2e/tests/__snapshots__/compare.report-diff.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code PushUp

🥳 Code PushUp report has **improved** – compared target commit `<commit-sha>` with source commit `<commit-sha>`.
🥳 Code PushUp Report has **improved** – compared target commit `<commit-sha>` with source commit `<commit-sha>`.

## 🏷️ Categories

Expand Down
48 changes: 18 additions & 30 deletions e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,38 @@ Commands:
code-pushup Shortcut for running collect followed by upload
[default]
code-pushup autorun Shortcut for running collect followed by upload
code-pushup collect Run Plugins and collect results
code-pushup upload Upload report results to the portal
code-pushup history Collect reports for commit history
code-pushup compare Compare 2 report files and create a diff file
code-pushup print-config Print config
code-pushup merge-diffs Combine many report diffs into a single diff file
Global Options:
--progress Show progress bar in stdout.
[boolean] [default: true]
--progress Show progress bar in stdout. [boolean] [default: true]
--verbose When true creates more verbose output. This is helpful when
debugging. [boolean] [default: false]
--config Path to config file. By default it loads code-pushup.config
.(ts|mjs|js). [string]
debugging. [boolean] [default: false]
--config Path to config file, e.g. code-pushup.config.ts. By default
it loads code-pushup.config.(ts|mjs|js). [string]
--tsconfig Path to a TypeScript config, to be used when loading config
file. [string]
file. [string]
--onlyPlugins List of plugins to run. If not set all plugins are run.
[array] [default: []]
[array] [default: []]
--skipPlugins List of plugins to skip. If not set all plugins are run.
[array] [default: []]
[array] [default: []]
Persist Options:
--persist.outputDir Directory for the produced reports
[string]
--persist.filename Filename for the produced reports.
[string]
--persist.format Format of the report output. e.g. \`md\`, \`json\`
[array]
--persist.outputDir Directory for the produced reports [string]
--persist.filename Filename for the produced reports. [string]
--persist.format Format of the report output. e.g. \`md\`, \`json\`[array]
Upload Options:
--upload.organization Organization slug from portal
[string]
--upload.project Project slug from portal[string]
--upload.server URL to your portal server
[string]
--upload.apiKey API key for the portal server
[string]
--upload.organization Organization slug from portal [string]
--upload.project Project slug from portal [string]
--upload.server URL to your portal server [string]
--upload.apiKey API key for the portal server [string]
Options:
--version Show version [boolean]
-h, --help Show help [boolean]
-h, --help Show help [boolean]
Examples:
code-pushup Run collect followed by upload based
Expand All @@ -64,9 +52,9 @@ Examples:
code-pushup collect --skipPlugins=covera Run collect skiping the coverage plu
ge gin, other plugins from config file
will be included.
code-pushup upload --persist.outputDir=d Upload dist/report.json to portal us
ist --upload.apiKey=$CP_API_KEY ing API key from environment variabl
e
code-pushup upload --persist.outputDir=d Upload dist/cp-report.json to portal
ist --persist.filename=cp-report --uploa using API key from environment vari
d.apiKey=$CP_API_KEY able
code-pushup print-config --config code-p Print resolved config object parsed
ushup.config.test.js from custom config location
"
Expand Down
64 changes: 39 additions & 25 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ describe('CLI collect', () => {
/* eslint-enable @typescript-eslint/no-unused-vars */

beforeEach(async () => {
await cleanTestFolder('tmp/e2e');
await cleanTestFolder('tmp/e2e/react-todos-app');
});

it('should run ESLint plugin and create report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress', '--onlyPlugins=eslint'],
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--no-progress',
'--onlyPlugins=eslint',
],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

Expand All @@ -82,9 +86,10 @@ describe('CLI collect', () => {
'code-pushup.config.ts',
);

const { code, stderr } = await executeProcess({
command: 'code-pushup',
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--no-progress',
`--config=${configPath}`,
Expand All @@ -94,7 +99,6 @@ describe('CLI collect', () => {
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile(join('tmp', 'e2e', 'report.json'));

Expand All @@ -103,14 +107,18 @@ describe('CLI collect', () => {
});

it('should run Code coverage plugin that runs coverage tool and creates report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress', '--onlyPlugins=coverage'],
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--no-progress',
'--onlyPlugins=coverage',
],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');

Expand All @@ -119,30 +127,37 @@ describe('CLI collect', () => {
});

it('should run Lighthouse plugin that runs lighthouse CLI and creates report.json', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress', '--onlyPlugins=lighthouse'],
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--no-progress',
'--onlyPlugins=lighthouse',
],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const report = await readJsonFile('tmp/e2e/react-todos-app/report.json');
expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});

it('should create report.md', async () => {
const { code, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--persist.format=md', '--no-progress'],
const { code } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--persist.format=md',
'--no-progress',
],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

const md = await readTextFile('tmp/e2e/react-todos-app/report.md');

expect(md).toContain('# Code PushUp Report');
Expand All @@ -151,14 +166,13 @@ describe('CLI collect', () => {
});

it('should print report summary to stdout', async () => {
const { code, stdout, stderr } = await executeProcess({
command: 'code-pushup',
args: ['collect', '--no-progress'],
const { code, stdout } = await executeProcess({
command: 'npx',
args: ['@code-pushup/cli', 'collect', '--no-progress'],
cwd: 'examples/react-todos-app',
});

expect(code).toBe(0);
expect(stderr).toBe('');

expect(stdout).toContain('Code PushUp Report');
expect(stdout).not.toContain('Generated reports');
Expand Down
14 changes: 9 additions & 5 deletions e2e/cli-e2e/tests/compare.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ describe('CLI compare', () => {
'Unstaged changes found in examples/react-todos-app, please stage or commit them to prevent E2E tests interfering',
);
}
await cleanTestFolder('tmp/e2e');
await cleanTestFolder('tmp/e2e/react-todos-app');
await executeProcess({
command: 'code-pushup',
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--persist.filename=source-report',
'--onlyPlugins=eslint',
Expand All @@ -28,8 +29,9 @@ describe('CLI compare', () => {
cwd: 'examples/react-todos-app',
});
await executeProcess({
command: 'code-pushup',
command: 'npx',
args: [
'@code-pushup/cli',
'collect',
'--persist.filename=target-report',
'--onlyPlugins=eslint',
Expand All @@ -43,10 +45,12 @@ describe('CLI compare', () => {
await cleanTestFolder('tmp/e2e');
});

it('should compare report.json files and create report-diff.json and report-diff.md', async () => {
// eslint-disable-next-line vitest/no-disabled-tests
it.skip('should compare report.json files and create report-diff.json and report-diff.md', async () => {
await executeProcess({
command: 'code-pushup',
command: 'npx',
args: [
'@code-pushup/cli',
'compare',
'--before=../../tmp/e2e/react-todos-app/source-report.json',
'--after=../../tmp/e2e/react-todos-app/target-report.json',
Expand Down
12 changes: 6 additions & 6 deletions e2e/cli-e2e/tests/help.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { executeProcess } from '@code-pushup/utils';
describe('CLI help', () => {
it('should print help with help command', async () => {
const { code, stdout, stderr } = await executeProcess({
command: 'code-pushup',
args: ['help'],
command: 'npx',
args: ['@code-pushup/cli', 'help'],
});
expect(code).toBe(0);
expect(stderr).toBe('');
Expand All @@ -14,12 +14,12 @@ describe('CLI help', () => {

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'],
command: 'npx',
args: ['@code-pushup/cli', 'help'],
});
const helpCommandResult = await executeProcess({
command: 'code-pushup',
args: ['--help'],
command: 'npx',
args: ['@code-pushup/cli', '--help'],
});
expect(helpArgResult.code).toBe(0);
expect(helpCommandResult.code).toBe(0);
Expand Down
8 changes: 4 additions & 4 deletions e2e/cli-e2e/tests/print-config.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ const extensions = ['js', 'mjs', 'ts'] as const;
export const configFilePath = (ext: (typeof extensions)[number]) =>
join(process.cwd(), `e2e/cli-e2e/mocks/fixtures/code-pushup.config.${ext}`);

describe('print-config', () => {
describe('CLI print-config', () => {
it.each(extensions)(
'should load .%s config file with correct arguments',
async ext => {
const { code, stderr, stdout } = await executeProcess({
command: 'code-pushup',
const { code, stdout } = await executeProcess({
command: 'npx',
args: [
'@code-pushup/cli',
'print-config',
'--no-progress',
`--config=${configFilePath(ext)}`,
Expand All @@ -26,7 +27,6 @@ describe('print-config', () => {
});

expect(code).toBe(0);
expect(stderr).toBe('');

expect(JSON.parse(stdout)).toEqual(
expect.objectContaining({
Expand Down
3 changes: 2 additions & 1 deletion e2e/cli-e2e/vite.config.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
test: {
reporters: ['basic'],
testTimeout: 140_000,
hookTimeout: 20_000,
globals: true,
alias: tsconfigPathAliases(),
pool: 'threads',
Expand All @@ -16,7 +17,7 @@ export default defineConfig({
},
environment: 'node',
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
globalSetup: ['../../global-setup.e2e.ts'],
globalSetup: ['../../global-setup.verdaccio.ts'],
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
},
});
Loading

0 comments on commit 9218855

Please sign in to comment.