Skip to content

Commit 6e54084

Browse files
committed
Merge branch 'main' into reduce-e2e-targets
# Conflicts: # e2e/cli-e2e/tests/print-config.e2e.test.ts # e2e/create-cli-e2e/tests/init.e2e.test.ts # e2e/nx-plugin-e2e/project.json # global-setup.verdaccio.ts # testing/test-setup/src/lib/test-folder.setup.ts # tools/src/debug/utils.ts # tools/src/verdaccio/verdaccio.plugin.ts
2 parents 9060c2d + 5f7b758 commit 6e54084

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+938
-438
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ jobs:
135135
run: npm ci
136136
- name: E2E test affected projects
137137
run: npx nx affected:e2e --parallel=1
138+
- name: E2E test cli-e2e project (due to bugs in the setup it has to run last :( )
139+
run: npx nx run cli-e2e:e2e-old
138140

139141
build:
140142
runs-on: ubuntu-latest

e2e/cli-e2e/project.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
"lintFilePatterns": ["e2e/cli-e2e/**/*.ts"]
1212
}
1313
},
14-
"e2e": {
14+
"e2e-old": {
1515
"executor": "@nx/vite:test",
1616
"options": {
1717
"configFile": "e2e/cli-e2e/vite.config.e2e.ts"
1818
}
1919
}
2020
},
2121
"implicitDependencies": [
22+
"models",
23+
"utils",
24+
"core",
25+
"cli",
2226
"cli",
2327
"plugin-eslint",
2428
"plugin-lighthouse",

e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ Global Options:
2626
.(ts|mjs|js). [string]
2727
--tsconfig Path to a TypeScript config, to be used when loading config
2828
file. [string]
29-
--onlyPlugins List of plugins to run. If not set all plugins are run.
29+
-p, --onlyPlugins List of plugins to run. If not set all plugins are run.
3030
[array] [default: []]
31-
--skipPlugins List of plugins to skip. If not set all plugins are run.
31+
-P, --skipPlugins List of plugins to skip. If not set all plugins are run.
3232
[array] [default: []]
3333
3434
Persist Options:

e2e/cli-e2e/tests/print-config.e2e.test.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ describe('CLI print-config', () => {
1111
it.each(extensions)(
1212
'should load .%s config file with correct arguments',
1313
async ext => {
14-
const { code, stderr, stdout } = await executeProcess({
15-
command: 'npx',
14+
const { code, stdout } = await executeProcess({
15+
command: 'code-pushup',
1616
args: [
1717
'@code-pushup/cli',
1818
'print-config',
@@ -23,13 +23,11 @@ describe('CLI print-config', () => {
2323
'--persist.format=md',
2424
`--persist.filename=${ext}-report`,
2525
'--onlyPlugins=coverage',
26-
'--skipPlugins=eslint',
2726
],
2827
cwd: EXAMPLES_REACT_TODOS_APP,
2928
});
3029

3130
expect(code).toBe(0);
32-
expect(stderr).toBe('');
3331

3432
expect(JSON.parse(stdout)).toEqual(
3533
expect.objectContaining({
@@ -55,8 +53,6 @@ describe('CLI print-config', () => {
5553
],
5654
categories: [expect.objectContaining({ slug: 'code-coverage' })],
5755
onlyPlugins: ['coverage'],
58-
skipPlugins: ['eslint'],
59-
cwd: EXAMPLES_REACT_TODOS_APP,
6056
}),
6157
);
6258
},

e2e/create-cli-e2e/project.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
}
1919
}
2020
},
21-
"implicitDependencies": ["create-cli"],
21+
"implicitDependencies": [
22+
"models",
23+
"utils",
24+
"core",
25+
"cli",
26+
"nx-plugin",
27+
"create-cli"
28+
],
2229
"tags": ["scope:tooling", "type:e2e"]
2330
}

e2e/create-cli-e2e/tests/init.e2e.test.ts

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { join, relative } from 'node:path';
22
import { afterEach, expect } from 'vitest';
33
import { teardownTestFolder } from '@code-pushup/test-setup';
44
import { removeColorCodes } from '@code-pushup/test-utils';
5-
import { executeProcess } from '@code-pushup/utils';
5+
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
66
import { createNpmWorkspace } from '../mocks/create-npm-workshpace';
77

88
describe('create-cli-inti', () => {
@@ -26,11 +26,30 @@ describe('create-cli-inti', () => {
2626
expect(code).toBe(0);
2727
const cleanedStdout = removeColorCodes(stdout);
2828
expect(cleanedStdout).toContain(
29-
'<↗> Generating @code-pushup/nx-plugin:configuration',
29+
'<✓> Generating @code-pushup/nx-plugin:configuration',
30+
);
31+
32+
await expect(
33+
readJsonFile(join(cwd, 'package.json')),
34+
).resolves.toStrictEqual(
35+
expect.objectContaining({
36+
devDependencies: {
37+
'@code-pushup/cli': expect.any(String),
38+
'@code-pushup/models': expect.any(String),
39+
'@code-pushup/nx-plugin': expect.any(String),
40+
'@code-pushup/utils': expect.any(String),
41+
},
42+
}),
43+
);
44+
await expect(
45+
readTextFile(join(cwd, 'code-pushup.config.ts')),
46+
).resolves.toContain(
47+
"import type { CoreConfig } from '@code-pushup/models';",
3048
);
3149
});
3250

33-
it('should execute package correctly over npm init', async () => {
51+
// eslint-disable-next-line vitest/no-disabled-tests
52+
it.skip('should execute package correctly over npm init', async () => {
3453
const cwd = join(baseDir, 'npm-init');
3554
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
3655

@@ -45,7 +64,48 @@ describe('create-cli-inti', () => {
4564
expect(code).toBe(0);
4665
const cleanedStdout = removeColorCodes(stdout);
4766
expect(cleanedStdout).toContain(
48-
'<↗> Generating @code-pushup/nx-plugin:configuration',
67+
'<✓> Generating @code-pushup/nx-plugin:configuration',
68+
);
69+
70+
await expect(
71+
readJsonFile(join(cwd, 'package.json')),
72+
).resolves.toStrictEqual(
73+
expect.objectContaining({
74+
devDependencies: {
75+
'@code-pushup/cli': expect.any(String),
76+
'@code-pushup/models': expect.any(String),
77+
'@code-pushup/nx-plugin': expect.any(String),
78+
'@code-pushup/utils': expect.any(String),
79+
},
80+
}),
4981
);
82+
await expect(
83+
readTextFile(join(cwd, 'code-pushup.config.ts')),
84+
).resolves.toContain(
85+
"import type { CoreConfig } from '@code-pushup/models';",
86+
);
87+
});
88+
89+
it('should produce an executable setup when running npm init', async () => {
90+
const cwd = join(baseDir, 'npm-init-executable');
91+
const userconfig = relative(cwd, join(workspaceRoot, '.npmrc'));
92+
93+
await createNpmWorkspace(cwd);
94+
95+
await executeProcess({
96+
command: 'npm',
97+
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
98+
cwd,
99+
});
100+
101+
await expect(
102+
executeProcess({
103+
command: 'npx',
104+
args: ['@code-pushup/cli print-config', `--userconfig=${userconfig}`],
105+
cwd,
106+
}),
107+
)
108+
// @TODO: Generate an executable setup. Edit configuration generator defaults
109+
.rejects.toThrow('Array must contain at least 1 element(s)');
50110
});
51111
});

e2e/create-cli-e2e/vite.config.e2e.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ export default defineConfig({
66
cacheDir: '../../node_modules/.vite/create-cli-e2e',
77
test: {
88
reporters: ['basic'],
9-
testTimeout: 60_000,
9+
testTimeout: 120_000,
10+
hookTimeout: 20_000,
1011
globals: true,
1112
alias: tsconfigPathAliases(),
1213
pool: 'threads',

e2e/nx-plugin-e2e/project.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
}
1919
}
2020
},
21-
"implicitDependencies": ["test-utils", "nx-plugin"],
21+
"implicitDependencies": [
22+
"test-utils",
23+
"models",
24+
"utils",
25+
"core",
26+
"cli",
27+
"nx-plugin"
28+
],
2229
"tags": ["scope:tooling", "type:e2e"]
2330
}

global-setup.verdaccio.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,28 @@ import {
88

99
let activeRegistry: VerdaccioEnvResult;
1010
const projectName = process.env['NX_TASK_TARGET_PROJECT'];
11-
const teardownWorkspaceRoot: boolean = projectName === 'cli-e2e' ? false : true;
12-
const teardownStorage: boolean = projectName === 'cli-e2e' ? true : false;
13-
const workspaceRoot = projectName === 'cli-e2e' ? 'examples/react-todos-app' : undefined;
1411

1512
export async function setup() {
1613
await globalSetup();
1714

18-
activeRegistry = await nxStartVerdaccioAndSetupEnv({
19-
projectName,
20-
workspaceRoot
21-
});
15+
try {
16+
activeRegistry = await nxStartVerdaccioAndSetupEnv({
17+
projectName: projectName,
18+
verbose: true,
19+
});
20+
} catch (error) {
21+
console.error('Error starting local verdaccio registry:\n' + error.message);
22+
throw error;
23+
}
2224

23-
const { userconfig, workspaceRoot: prefix } = activeRegistry;
25+
const { userconfig, workspaceRoot } = activeRegistry;
2426
await executeProcess({
2527
command: 'npx',
2628
args: objectToCliArgs({
27-
_: ['nx', 'setup-e2e-deps', projectName],
29+
_: ['nx', 'setup-deps', projectName],
2830
registry: activeRegistry.registry.url, // publish
2931
userconfig, // publish & install
30-
prefix, // install
32+
prefix: workspaceRoot, // install
3133
}),
3234
observer: { onStdout: stdout => console.info(stdout) },
3335
});
@@ -38,9 +40,5 @@ export async function teardown() {
3840
// We skip uninstalling packages as the folder is deleted anyway
3941

4042
// comment out to see the folder and web interface
41-
await nxStopVerdaccioAndTeardownEnv(
42-
activeRegistry,
43-
teardownWorkspaceRoot,
44-
teardownStorage,
45-
);
43+
await nxStopVerdaccioAndTeardownEnv(activeRegistry);
4644
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { filterItemRefsBy } from '@code-pushup/utils';
2+
import type { OnlyPluginsOptions } from './only-plugins.model';
3+
import type { SkipPluginsOptions } from './skip-plugins.model';
4+
import { validatePluginFilterOption } from './validate-plugin-filter-options.utils';
5+
6+
export function filterPluginsMiddleware<
7+
T extends SkipPluginsOptions & OnlyPluginsOptions,
8+
>(originalProcessArgs: T): T {
9+
const {
10+
plugins,
11+
categories = [],
12+
skipPlugins = [],
13+
onlyPlugins = [],
14+
verbose,
15+
} = originalProcessArgs;
16+
17+
if (skipPlugins.length === 0 && onlyPlugins.length === 0) {
18+
return { ...originalProcessArgs, categories };
19+
}
20+
21+
validatePluginFilterOption(
22+
'skipPlugins',
23+
{ plugins, categories },
24+
{ pluginsToFilter: skipPlugins, verbose },
25+
);
26+
validatePluginFilterOption(
27+
'onlyPlugins',
28+
{ plugins, categories },
29+
{ pluginsToFilter: onlyPlugins, verbose },
30+
);
31+
32+
const validSkipPlugins = new Set(
33+
skipPlugins.filter(sP => plugins.some(p => p.slug === sP)),
34+
);
35+
const pluginsAfterSkip = plugins.filter(
36+
({ slug }) => !validSkipPlugins.has(slug),
37+
);
38+
39+
const validOnlyPlugins = new Set(
40+
onlyPlugins.filter(oP => pluginsAfterSkip.some(p => p.slug === oP)),
41+
);
42+
const filteredPlugins =
43+
validOnlyPlugins.size > 0
44+
? pluginsAfterSkip.filter(({ slug }) => validOnlyPlugins.has(slug))
45+
: pluginsAfterSkip;
46+
47+
const filteredCategories =
48+
filteredPlugins.length > 0
49+
? filterItemRefsBy(categories, ({ plugin }) =>
50+
filteredPlugins.some(({ slug }) => slug === plugin),
51+
)
52+
: categories;
53+
54+
return {
55+
...originalProcessArgs,
56+
plugins: filteredPlugins,
57+
categories: filteredCategories,
58+
};
59+
}

0 commit comments

Comments
 (0)