Skip to content

Commit 7ac93ab

Browse files
committed
refactor: add e2e tests
1 parent 2572866 commit 7ac93ab

File tree

17 files changed

+5229
-1281
lines changed

17 files changed

+5229
-1281
lines changed

.verdaccio/config.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# path to a directory with all packages
2+
storage: ../tmp/local-registry/storage
3+
4+
# a list of other known repositories we can talk to
5+
uplinks:
6+
npmjs:
7+
url: https://registry.npmjs.org/
8+
maxage: 60m
9+
10+
packages:
11+
# exceptions for external @code-pushup packages
12+
'@code-pushup/models':
13+
access: $all
14+
proxy: npmjs
15+
'@code-pushup/utils':
16+
access: $all
17+
proxy: npmjs
18+
'@code-pushup/core':
19+
access: $all
20+
proxy: npmjs
21+
'@code-pushup/cli':
22+
access: $all
23+
proxy: npmjs
24+
'@code-pushup/portal-client':
25+
access: $all
26+
proxy: npmjs
27+
'@code-pushup/eslint-config':
28+
access: $all
29+
proxy: npmjs
30+
31+
# allow publishing local packages
32+
'@code-pushup/*':
33+
access: $all
34+
publish: $all
35+
unpublish: $all
36+
37+
# proxy other packages to official NPM registry
38+
'**':
39+
access: $all
40+
proxy: npmjs
41+
42+
# log settings
43+
log:
44+
type: stdout
45+
format: pretty
46+
level: warn
47+
48+
publish:
49+
allow_offline: true # set offline to true to allow publish offline
50+
51+
middlewares:
52+
audit:
53+
enabled: true # needed to run npm audit in e2e test folder
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
[
2+
{
3+
"filePath": "/Users/michael_hladky/WebstormProjects/cli/e2e/plugin-knip-e2e/eslint.config.js",
4+
"messages": [],
5+
"suppressedMessages": [],
6+
"errorCount": 0,
7+
"fatalErrorCount": 0,
8+
"warningCount": 0,
9+
"fixableErrorCount": 0,
10+
"fixableWarningCount": 0,
11+
"usedDeprecatedRules": []
12+
},
13+
{
14+
"filePath": "/Users/michael_hladky/WebstormProjects/cli/e2e/plugin-knip-e2e/tests/collect.e2e.test.ts",
15+
"messages": [],
16+
"suppressedMessages": [],
17+
"errorCount": 0,
18+
"fatalErrorCount": 0,
19+
"warningCount": 0,
20+
"fixableErrorCount": 0,
21+
"fixableWarningCount": 0,
22+
"usedDeprecatedRules": [
23+
{
24+
"ruleId": "vitest/no-done-callback",
25+
"replacedBy": []
26+
}
27+
]
28+
},
29+
{
30+
"filePath": "/Users/michael_hladky/WebstormProjects/cli/e2e/plugin-knip-e2e/vitest.e2e.config.ts",
31+
"messages": [],
32+
"suppressedMessages": [],
33+
"errorCount": 0,
34+
"fatalErrorCount": 0,
35+
"warningCount": 0,
36+
"fixableErrorCount": 0,
37+
"fixableWarningCount": 0,
38+
"usedDeprecatedRules": []
39+
}
40+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import tseslint from 'typescript-eslint';
2+
import baseConfig from '../../eslint.config.js';
3+
4+
export default tseslint.config(...baseConfig, {
5+
files: ['**/*.ts'],
6+
languageOptions: {
7+
parserOptions: {
8+
projectService: true,
9+
tsconfigRootDir: import.meta.dirname,
10+
},
11+
},
12+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import knipPlugin from '@code-pushup/knip-plugin';
2+
import type { CoreConfig } from '@code-pushup/models';
3+
4+
export default {
5+
plugins: [await knipPlugin()],
6+
} satisfies CoreConfig;

e2e/plugin-knip-e2e/project.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "plugin-knip-e2e",
3+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "e2e/plugin-knip-e2e/src",
5+
"projectType": "application",
6+
"targets": {
7+
"lint": {},
8+
"e2e": {
9+
"executor": "@nx/vitest:test",
10+
"options": {
11+
"configFile": "{projectRoot}/vitest.e2e.config.ts"
12+
}
13+
}
14+
},
15+
"implicitDependencies": ["@code-pushup/plugin-knip"],
16+
"tags": ["scope:plugin", "type:e2e"]
17+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { cp } from 'node:fs/promises';
2+
import path from 'node:path';
3+
import { afterAll, beforeAll, expect } from 'vitest';
4+
import { type Report, reportSchema } from '@code-pushup/models';
5+
import { nxTargetProject } from '@code-pushup/test-nx-utils';
6+
import {
7+
E2E_ENVIRONMENTS_DIR,
8+
TEST_OUTPUT_DIR,
9+
omitVariableReportData,
10+
restoreNxIgnoredFiles,
11+
teardownTestFolder,
12+
} from '@code-pushup/test-utils';
13+
import { executeProcess, readJsonFile } from '@code-pushup/utils';
14+
15+
describe('PLUGIN collect report with knip-plugin NPM package', () => {
16+
const testFileDir = path.join(
17+
E2E_ENVIRONMENTS_DIR,
18+
nxTargetProject(),
19+
TEST_OUTPUT_DIR,
20+
'collect',
21+
);
22+
const defaultSetupDir = path.join(testFileDir, 'default-setup');
23+
24+
const fixturesDir = path.join('e2e', nxTargetProject(), 'mocks/fixtures');
25+
26+
beforeAll(async () => {
27+
await cp(fixturesDir, testFileDir, { recursive: true });
28+
await restoreNxIgnoredFiles(testFileDir);
29+
});
30+
31+
afterAll(async () => {
32+
await teardownTestFolder(testFileDir);
33+
});
34+
35+
it('should run plugin over CLI and creates report.json', async () => {
36+
const { code, stdout } = await executeProcess({
37+
command: 'npx',
38+
// verbose exposes audits with perfect scores that are hidden in the default stdout
39+
args: ['@code-pushup/cli', 'collect', '--verbose'],
40+
cwd: defaultSetupDir,
41+
});
42+
43+
expect(code).toBe(0);
44+
// TODO: test knip output with toContain
45+
expect(stdout).toBe('knip string');
46+
47+
const report = await readJsonFile(
48+
path.join(defaultSetupDir, '.code-pushup', 'report.json'),
49+
);
50+
expect(() => reportSchema.parse(report)).not.toThrow();
51+
expect(
52+
omitVariableReportData(report as Report, { omitAuditData: true }),
53+
).toMatchSnapshot();
54+
});
55+
});

e2e/plugin-knip-e2e/tsconfig.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"compilerOptions": {
4+
"module": "ESNext",
5+
"forceConsistentCasingInFileNames": true,
6+
"strict": true,
7+
"noImplicitOverride": true,
8+
"noPropertyAccessFromIndexSignature": true,
9+
"noImplicitReturns": true,
10+
"noFallthroughCasesInSwitch": true,
11+
"types": ["vitest"]
12+
},
13+
"files": [],
14+
"include": [],
15+
"references": [
16+
{
17+
"path": "./tsconfig.test.json"
18+
}
19+
]
20+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"],
6+
"target": "ES2020"
7+
},
8+
"include": [
9+
"vitest.e2e.config.ts",
10+
"tests/**/*.e2e.test.ts",
11+
"tests/**/*.d.ts",
12+
"mocks/**/*.ts"
13+
]
14+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { createE2ETestConfig } from '../../testing/test-setup-config/src/index.js';
2+
3+
export default createE2ETestConfig('plugin-knip-e2e', {
4+
testTimeout: 80_000,
5+
});

global-setup.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
export async function setup() {
1+
/* eslint-disable functional/immutable-data */
2+
3+
const originalCI = process.env['CI'];
4+
5+
export function setup() {
26
process.env.TZ = 'UTC';
7+
8+
// package is expected to run in CI environment
9+
process.env['CI'] = 'true';
10+
}
11+
12+
export function teardown() {
13+
if (originalCI === undefined) {
14+
delete process.env['CI'];
15+
} else {
16+
process.env['CI'] = originalCI;
17+
}
318
}

0 commit comments

Comments
 (0)