-
Notifications
You must be signed in to change notification settings - Fork 15
test: split eslint e2e #871
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
Merged
Merged
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
bd1b8e1
cherry-pick
BioPhoton d92bf46
adjust target name
BioPhoton 8cc75ee
test: add eslint e2e project
BioPhoton 71ff81a
test: add eslint e2e env project
BioPhoton 7718c06
wip
BioPhoton a0ef58e
wip
BioPhoton ba625bb
wip
BioPhoton 3060275
wip
BioPhoton d4b84ad
wip
BioPhoton edaa857
use minimal eslint rules
BioPhoton efd1b07
wip
BioPhoton f4253d0
wip
BioPhoton f9911fb
wip
BioPhoton 5f0dfbe
reduce configuration
BioPhoton 14ad3c0
wip
BioPhoton 83bdb98
update nx-verdaccio to alpha.26
BioPhoton 7dad5b5
test: split coverage tests
BioPhoton e8cba86
config
BioPhoton 436673f
remove duplicate test
BioPhoton 69eba25
polish
BioPhoton ff44111
polish
BioPhoton 9ddce4d
remove duplicate CP runs
BioPhoton 3239423
add test script
BioPhoton 3ad8ee4
verbose gh action
BioPhoton a624b5a
adjust tests
BioPhoton 1647e38
colocate e2e files
BioPhoton 4a61524
cleanup
BioPhoton c32e158
cleanup
BioPhoton 6b93d24
wip
BioPhoton 8d8ecc4
wip
BioPhoton 3334e3a
wip
BioPhoton 385f0e3
test(plugin-eslint-e2e): fix tests by separating fixtures from test e…
matejchalk fa90bcd
refactor e2e env setup
BioPhoton ded72c0
refactor e2e env setup
BioPhoton cb4e0f9
cleanup env setup
BioPhoton 22a6908
fix snapshots
BioPhoton 0a477cb
remove check for warning and error
BioPhoton 1b066e0
Update .github/workflows/ci.yml
BioPhoton d165ddd
Update .github/workflows/ci.yml
BioPhoton d451294
Merge branch 'split-coverage-e2e' into split-eslint-e2e
BioPhoton acc5993
clean up merge
BioPhoton 806ab5e
fix lint
BioPhoton a31d78f
fix format
BioPhoton 545edc6
Merge branch 'main' into split-eslint-e2e
BioPhoton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| }, | ||
| "dependencies": {}, | ||
| "description": "" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
20
e2e/plugin-eslint-e2e/mocks/fixtures/old-version/.eslintrc.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
27
e2e/plugin-eslint-e2e/mocks/fixtures/old-version/code-pushup.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
7
e2e/plugin-eslint-e2e/mocks/fixtures/old-version/src/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()!'); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "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"] | ||
| } | ||
| }, | ||
| "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
139
e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/e2e/plugin-eslint-e2e/old-version/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/e2e/plugin-eslint-e2e/old-version/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", | ||
| }, | ||
| ], | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { cp } from 'node:fs/promises'; | ||
| import { join } from 'node:path'; | ||
| import { afterAll, afterEach, beforeAll, describe, expect, it } 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 fixturesOldVersionDir = join( | ||
| 'e2e', | ||
| 'plugin-eslint-e2e', | ||
| 'mocks', | ||
| 'fixtures', | ||
| 'old-version', | ||
| ); | ||
| const envRoot = join('tmp', 'e2e', 'plugin-eslint-e2e'); | ||
| const oldVersionDir = join(envRoot, 'old-version'); | ||
| const oldVersionOutputDir = join(oldVersionDir, '.code-pushup'); | ||
|
|
||
| beforeAll(async () => { | ||
| await cp(fixturesOldVersionDir, oldVersionDir, { recursive: true }); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await teardownTestFolder(oldVersionDir); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await teardownTestFolder(oldVersionOutputDir); | ||
| }); | ||
|
|
||
| it('should run ESLint plugin and create report.json', async () => { | ||
| const { code, stderr } = await executeProcess({ | ||
| command: 'npx', | ||
| args: ['@code-pushup/cli', 'collect', '--no-progress'], | ||
| cwd: oldVersionDir, | ||
| }); | ||
|
|
||
| expect(code).toBe(0); | ||
| expect(stderr).toBe(''); | ||
|
|
||
| const report = await readJsonFile(join(oldVersionOutputDir, 'report.json')); | ||
|
|
||
| expect(() => reportSchema.parse(report)).not.toThrow(); | ||
| expect(omitVariableReportData(report as Report)).toMatchSnapshot(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'], | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.