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: split eslint e2e #871

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bd1b8e1
cherry-pick
BioPhoton Nov 9, 2024
d92bf46
adjust target name
BioPhoton Nov 9, 2024
8cc75ee
test: add eslint e2e project
BioPhoton Nov 9, 2024
71ff81a
test: add eslint e2e env project
BioPhoton Nov 9, 2024
7718c06
wip
BioPhoton Nov 9, 2024
a0ef58e
wip
BioPhoton Nov 9, 2024
ba625bb
wip
BioPhoton Nov 9, 2024
3060275
wip
BioPhoton Nov 9, 2024
d4b84ad
wip
BioPhoton Nov 9, 2024
edaa857
use minimal eslint rules
BioPhoton Nov 9, 2024
efd1b07
wip
BioPhoton Nov 9, 2024
f4253d0
wip
BioPhoton Nov 9, 2024
f9911fb
wip
BioPhoton Nov 9, 2024
5f0dfbe
reduce configuration
BioPhoton Nov 9, 2024
14ad3c0
wip
BioPhoton Nov 9, 2024
83bdb98
update nx-verdaccio to alpha.26
BioPhoton Nov 9, 2024
7dad5b5
test: split coverage tests
BioPhoton Nov 9, 2024
e8cba86
config
BioPhoton Nov 9, 2024
436673f
remove duplicate test
BioPhoton Nov 9, 2024
69eba25
polish
BioPhoton Nov 9, 2024
ff44111
polish
BioPhoton Nov 9, 2024
9ddce4d
remove duplicate CP runs
BioPhoton Nov 9, 2024
3239423
add test script
BioPhoton Nov 9, 2024
3ad8ee4
verbose gh action
BioPhoton Nov 9, 2024
a624b5a
adjust tests
BioPhoton Nov 10, 2024
1647e38
colocate e2e files
BioPhoton Nov 11, 2024
4a61524
cleanup
BioPhoton Nov 11, 2024
c32e158
cleanup
BioPhoton Nov 11, 2024
6b93d24
wip
BioPhoton Nov 11, 2024
8d8ecc4
wip
BioPhoton Nov 11, 2024
3334e3a
wip
BioPhoton Nov 11, 2024
385f0e3
test(plugin-eslint-e2e): fix tests by separating fixtures from test e…
matejchalk Nov 13, 2024
fa90bcd
refactor e2e env setup
BioPhoton Nov 18, 2024
ded72c0
refactor e2e env setup
BioPhoton Nov 18, 2024
cb4e0f9
cleanup env setup
BioPhoton Nov 18, 2024
22a6908
fix snapshots
BioPhoton Nov 18, 2024
0a477cb
remove check for warning and error
BioPhoton Nov 18, 2024
1b066e0
Update .github/workflows/ci.yml
BioPhoton Nov 18, 2024
d165ddd
Update .github/workflows/ci.yml
BioPhoton Nov 18, 2024
d451294
Merge branch 'split-coverage-e2e' into split-eslint-e2e
BioPhoton Nov 18, 2024
acc5993
clean up merge
BioPhoton Nov 18, 2024
806ab5e
fix lint
BioPhoton Nov 18, 2024
a31d78f
fix format
BioPhoton Nov 18, 2024
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,000 changes: 0 additions & 1,000 deletions e2e/cli-e2e/tests/__snapshots__/collect.e2e.test.ts.snap

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions e2e/cli-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ describe('CLI collect', () => {
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'],
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();
matejchalk marked this conversation as resolved.
Show resolved Hide resolved
});

it('should run Code coverage plugin which collects passed results and creates report.json', async () => {
/**
* The stats passed in the fixture are as follows
Expand Down
12 changes: 12 additions & 0 deletions e2e/plugin-eslint-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/plugin-eslint-e2e/tsconfig.*?.json"]
}
}
]
}
20 changes: 20 additions & 0 deletions e2e/plugin-eslint-e2e/mocks/fixtures/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"root": true,
"ignorePatterns": ["code-pushup.config.ts"],
"overrides": [
{
"files": ["*.js"],
"env": {
"node": true
},
"parserOptions": {
"sourceType": "script"
},
"rules": {
"no-unused-vars": "error",
"no-console": "warn",
"no-undef": "error"
}
}
]
}
27 changes: 27 additions & 0 deletions e2e/plugin-eslint-e2e/mocks/fixtures/code-pushup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
plugins: [
await eslintPlugin({
eslintrc: '.eslintrc.json',
patterns: ['src/*.js'],
}),
],
categories: [
{
slug: 'bug-prevention',
title: 'Bug prevention',
description: 'Lint rules that find **potential bugs** in your code.',
refs: [{ type: 'group', plugin: 'eslint', slug: 'problems', weight: 1 }],
},
{
slug: 'code-style',
title: 'Code style',
description:
'Lint rules that promote **good practices** and consistency in your code.',
refs: [
{ type: 'group', plugin: 'eslint', slug: 'suggestions', weight: 1 },
],
},
],
};
7 changes: 7 additions & 0 deletions e2e/plugin-eslint-e2e/mocks/fixtures/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function unusedFn() {
return '42';
}

module.exports = function consoleLog() {
console.log('No console.log()!');
};
33 changes: 33 additions & 0 deletions e2e/plugin-eslint-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "plugin-eslint-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "e2e/plugin-eslint-e2e/src",
"projectType": "application",
"targets": {
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["e2e/plugin-eslint-e2e/**/*.ts"]
}
},
"nxv-e2e": {
"options": {
"environmentRoot": "tmp/plugin-eslint-e2e/__test-env__"
}
},
"nxv-env-setup": {
"options": {
"environmentRoot": "tmp/plugin-eslint-e2e/__test-env__"
}
},
"e2e": {
"executor": "@nx/vite:test",
"options": {
"configFile": "e2e/plugin-eslint-e2e/vite.config.e2e.ts"
}
}
},
"implicitDependencies": ["cli", "plugin-eslint"],
"tags": ["scope:plugin", "type:e2e"]
}
139 changes: 139 additions & 0 deletions e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`collect report with eslint-plugin NPM package > should run ESLint plugin and create report.json 1`] = `
{
"categories": [
{
"description": "Lint rules that find **potential bugs** in your code.",
"refs": [
{
"plugin": "eslint",
"slug": "problems",
"type": "group",
"weight": 1,
},
],
"slug": "bug-prevention",
"title": "Bug prevention",
},
{
"description": "Lint rules that promote **good practices** and consistency in your code.",
"refs": [
{
"plugin": "eslint",
"slug": "suggestions",
"type": "group",
"weight": 1,
},
],
"slug": "code-style",
"title": "Code style",
},
],
"packageName": "@code-pushup/core",
"plugins": [
{
"audits": [
{
"description": "ESLint rule **no-unused-vars**.",
"details": {
"issues": [
{
"message": "'unusedFn' is defined but never used.",
"severity": "error",
"source": {
"file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js",
"position": {
"endColumn": 18,
"endLine": 1,
"startColumn": 10,
"startLine": 1,
},
},
},
],
},
"displayValue": "1 error",
"docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars",
"score": 0,
"slug": "no-unused-vars",
"title": "Disallow unused variables",
"value": 1,
},
{
"description": "ESLint rule **no-console**.",
"details": {
"issues": [
{
"message": "Unexpected console statement.",
"severity": "warning",
"source": {
"file": "tmp/plugin-eslint-e2e/__test-env__/src/index.js",
"position": {
"endColumn": 14,
"endLine": 6,
"startColumn": 3,
"startLine": 6,
},
},
},
],
},
"displayValue": "1 warning",
"docsUrl": "https://eslint.org/docs/latest/rules/no-console",
"score": 0,
"slug": "no-console",
"title": "Disallow the use of \`console\`",
"value": 1,
},
{
"description": "ESLint rule **no-undef**.",
"details": {
"issues": [],
},
"displayValue": "passed",
"docsUrl": "https://eslint.org/docs/latest/rules/no-undef",
"score": 1,
"slug": "no-undef",
"title": "Disallow the use of undeclared variables unless mentioned in \`/*global */\` comments",
"value": 0,
},
],
"description": "Official Code PushUp ESLint plugin",
"docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin",
"groups": [
{
"description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.",
"refs": [
{
"slug": "no-unused-vars",
"weight": 1,
},
{
"slug": "no-undef",
"weight": 1,
},
],
"slug": "problems",
"title": "Problems",
},
{
"description": "Something that could be done in a better way but no errors will occur if the code isn't changed.",
"refs": [
{
"slug": "no-console",
"weight": 1,
},
],
"slug": "suggestions",
"title": "Suggestions",
},
],
"icon": "eslint",
"packageName": "@code-pushup/eslint-plugin",
"slug": "eslint",
"title": "ESLint",
},
],
}
`;
46 changes: 46 additions & 0 deletions e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { cp, rm } from 'node:fs/promises';
import { join } from 'node:path';
import { afterEach } from 'vitest';
import { type Report, reportSchema } from '@code-pushup/models';
import { teardownTestFolder } from '@code-pushup/test-setup';
import { omitVariableReportData } from '@code-pushup/test-utils';
import { executeProcess, readJsonFile } from '@code-pushup/utils';

describe('collect report with eslint-plugin NPM package', () => {
const fixturesDir = join('e2e', 'plugin-eslint-e2e', 'mocks', 'fixtures');
const envRoot = join('tmp', 'plugin-eslint-e2e', '__test-env__');
const outputDir = join(envRoot, '.code-pushup');

beforeAll(async () => {
await cp(fixturesDir, envRoot, { recursive: true });
});

afterAll(async () => {
await rm(envRoot, { recursive: true, force: true });
});

afterEach(async () => {
await teardownTestFolder(outputDir);
});

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

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

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

expect(() => reportSchema.parse(report)).not.toThrow();
expect(omitVariableReportData(report as Report)).toMatchSnapshot();
});
});
20 changes: 20 additions & 0 deletions e2e/plugin-eslint-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"types": ["vitest"]
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.test.json"
}
]
}
15 changes: 15 additions & 0 deletions e2e/plugin-eslint-e2e/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"],
"target": "ES2020"
},
"exclude": ["__test-env__/**"],
"include": [
"vite.config.e2e.ts",
"tests/**/*.e2e.test.ts",
"tests/**/*.d.ts",
"mocks/**/*.ts"
]
}
21 changes: 21 additions & 0 deletions e2e/plugin-eslint-e2e/vite.config.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite';
import { tsconfigPathAliases } from '../../tools/vitest-tsconfig-path-aliases';

export default defineConfig({
cacheDir: '../../node_modules/.vite/plugin-lighthouse-e2e',
test: {
reporters: ['basic'],
testTimeout: 120_000,
globals: true,
alias: tsconfigPathAliases(),
pool: 'threads',
poolOptions: { threads: { singleThread: true } },
cache: {
dir: '../../node_modules/.vitest',
},
environment: 'node',
include: ['tests/**/*.e2e.test.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
setupFiles: ['../../testing/test-setup/src/lib/reset.mocks.ts'],
},
});
Loading