Skip to content

Commit 4f304f2

Browse files
authored
refactor: structure verdaccio environment (#805)
1 parent 9e20e91 commit 4f304f2

24 files changed

+690
-327
lines changed

e2e/nx-plugin-e2e/tests/__snapshots__/create-nodes-plugin.e2e.test.ts.snap

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2+
3+
exports[`nx-plugin > should NOT add config targets dynamically if the project is configured 1`] = `
4+
{
5+
"code-pushup": {
6+
"configurations": {},
7+
"executor": "@code-pushup/nx-plugin:autorun",
8+
"options": {},
9+
},
10+
}
11+
`;
12+
13+
exports[`nx-plugin > should add configuration target dynamically 1`] = `
14+
{
15+
"code-pushup--configuration": {
16+
"configurations": {},
17+
"executor": "nx:run-commands",
18+
"options": {
19+
"command": "nx g @code-pushup/nx-plugin:configuration --skipTarget --targetName="code-pushup" --project="my-lib"",
20+
},
21+
},
22+
}
23+
`;
24+
25+
exports[`nx-plugin > should add executor target dynamically if the project is configured 1`] = `
26+
{
27+
"code-pushup": {
28+
"configurations": {},
29+
"executor": "@code-pushup/nx-plugin:autorun",
30+
"options": {},
31+
},
32+
}
33+
`;
34+
35+
exports[`nx-plugin > should execute dynamic configuration target 1`] = `
36+
"import type { CoreConfig } from '@code-pushup/models';
37+
38+
// see: https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#coreconfig
39+
export default {
40+
plugins: [],
41+
} satisfies CoreConfig;
42+
"
43+
`;

e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts renamed to e2e/nx-plugin-e2e/tests/executor-cli.e2e.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,16 @@ async function addTargetToWorkspace(
2727
targets: {
2828
...projectCfg.targets,
2929
['code-pushup']: {
30-
executor: `${join(
31-
relativePathToCwd(cwd),
32-
'dist/packages/nx-plugin',
33-
)}:autorun`,
30+
executor: '@code-pushup/nx-plugin:autorun',
3431
},
3532
},
3633
});
3734
const { root } = projectCfg;
3835
generateCodePushupConfig(tree, root, {
39-
fileImports: `import type {CoreConfig} from "${join(
40-
relativePathToCwd(cwd),
41-
pathRelativeToPackage,
42-
'dist/packages/models',
43-
)}";`,
36+
fileImports: `import type {CoreConfig} from "@code-pushup/models";`,
4437
plugins: [
4538
{
39+
// @TODO replace with inline plugin
4640
fileImports: `import {customPlugin} from "${join(
4741
relativePathToCwd(cwd),
4842
pathRelativeToPackage,
@@ -58,7 +52,7 @@ async function addTargetToWorkspace(
5852
describe('executor autorun', () => {
5953
let tree: Tree;
6054
const project = 'my-lib';
61-
const baseDir = 'tmp/nx-plugin-e2e/executor';
55+
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli';
6256

6357
beforeEach(async () => {
6458
tree = await generateWorkspaceAndProject(project);

e2e/nx-plugin-e2e/tests/generator-configuration.e2e.test.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Tree } from '@nx/devkit';
22
import { readFile, rm } from 'node:fs/promises';
3-
import { join, relative } from 'node:path';
3+
import { join } from 'node:path';
44
import { afterEach, expect } from 'vitest';
55
import { generateCodePushupConfig } from '@code-pushup/nx-plugin';
66
import {
@@ -10,19 +10,11 @@ import {
1010
import { removeColorCodes } from '@code-pushup/test-utils';
1111
import { executeProcess } from '@code-pushup/utils';
1212

13-
// @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643
14-
function relativePathToDist(testDir: string): string {
15-
return relative(
16-
join(process.cwd(), testDir),
17-
join(process.cwd(), 'dist/packages/nx-plugin'),
18-
);
19-
}
20-
2113
describe('nx-plugin g configuration', () => {
2214
let tree: Tree;
2315
const project = 'my-lib';
2416
const projectRoot = join('libs', project);
25-
const baseDir = 'tmp/nx-plugin-e2e/generators/configuration';
17+
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/generators/configuration';
2618

2719
beforeEach(async () => {
2820
tree = await generateWorkspaceAndProject(project);
@@ -41,7 +33,7 @@ describe('nx-plugin g configuration', () => {
4133
args: [
4234
'nx',
4335
'g',
44-
`${relativePathToDist(cwd)}:configuration `,
36+
'@code-pushup/nx-plugin:configuration',
4537
project,
4638
'--targetName=code-pushup',
4739
],
@@ -58,7 +50,7 @@ describe('nx-plugin g configuration', () => {
5850
const cleanedStdout = removeColorCodes(stdout);
5951

6052
expect(cleanedStdout).toContain(
61-
`NX Generating ${relativePathToDist(cwd)}:configuration`,
53+
'NX Generating @code-pushup/nx-plugin:configuration',
6254
);
6355
expect(cleanedStdout).toMatch(/^CREATE.*code-pushup.config.ts/m);
6456
expect(cleanedStdout).toMatch(/^UPDATE.*project.json/m);
@@ -89,7 +81,7 @@ describe('nx-plugin g configuration', () => {
8981

9082
const { code, stdout, stderr } = await executeProcess({
9183
command: 'npx',
92-
args: ['nx', 'g', `${relativePathToDist(cwd)}:configuration `, project],
84+
args: ['nx', 'g', '@code-pushup/nx-plugin:configuration', project],
9385
cwd,
9486
});
9587

@@ -102,7 +94,7 @@ describe('nx-plugin g configuration', () => {
10294

10395
const cleanedStdout = removeColorCodes(stdout);
10496
expect(cleanedStdout).toContain(
105-
`NX Generating ${relativePathToDist(cwd)}:configuration`,
97+
'NX Generating @code-pushup/nx-plugin:configuration',
10698
);
10799
expect(cleanedStdout).not.toMatch(/^CREATE.*code-pushup.config.ts/m);
108100
expect(cleanedStdout).toMatch(/^UPDATE.*project.json/m);
@@ -131,7 +123,7 @@ describe('nx-plugin g configuration', () => {
131123
args: [
132124
'nx',
133125
'g',
134-
`${relativePathToDist(cwd)}:configuration `,
126+
'@code-pushup/nx-plugin:configuration',
135127
project,
136128
'--skipConfig',
137129
],
@@ -143,7 +135,7 @@ describe('nx-plugin g configuration', () => {
143135
const cleanedStdout = removeColorCodes(stdout);
144136

145137
expect(cleanedStdout).toContain(
146-
`NX Generating ${relativePathToDist(cwd)}:configuration`,
138+
'NX Generating @code-pushup/nx-plugin:configuration',
147139
);
148140
expect(cleanedStdout).not.toMatch(/^CREATE.*code-pushup.config.ts/m);
149141
expect(cleanedStdout).toMatch(/^UPDATE.*project.json/m);
@@ -176,7 +168,7 @@ describe('nx-plugin g configuration', () => {
176168
args: [
177169
'nx',
178170
'g',
179-
`${relativePathToDist(cwd)}:configuration `,
171+
'@code-pushup/nx-plugin:configuration',
180172
project,
181173
'--skipTarget',
182174
],
@@ -187,7 +179,7 @@ describe('nx-plugin g configuration', () => {
187179
const cleanedStdout = removeColorCodes(stdout);
188180

189181
expect(cleanedStdout).toContain(
190-
`NX Generating ${relativePathToDist(cwd)}:configuration`,
182+
'NX Generating @code-pushup/nx-plugin:configuration',
191183
);
192184
expect(cleanedStdout).toMatch(/^CREATE.*code-pushup.config.ts/m);
193185
expect(cleanedStdout).not.toMatch(/^UPDATE.*project.json/m);
@@ -220,7 +212,7 @@ describe('nx-plugin g configuration', () => {
220212
args: [
221213
'nx',
222214
'g',
223-
`${relativePathToDist(cwd)}:configuration `,
215+
'@code-pushup/nx-plugin:configuration',
224216
project,
225217
'--dryRun',
226218
],

e2e/nx-plugin-e2e/tests/generator-init.e2e.test.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Tree } from '@nx/devkit';
22
import { readFile, rm } from 'node:fs/promises';
3-
import { join, relative } from 'node:path';
3+
import { join } from 'node:path';
44
import { afterEach, expect } from 'vitest';
55
import {
66
generateWorkspaceAndProject,
@@ -9,17 +9,10 @@ import {
99
import { removeColorCodes } from '@code-pushup/test-utils';
1010
import { executeProcess } from '@code-pushup/utils';
1111

12-
function relativePathToDist(testDir: string): string {
13-
return relative(
14-
join(process.cwd(), testDir),
15-
join(process.cwd(), 'dist/packages/nx-plugin'),
16-
);
17-
}
18-
1912
describe('nx-plugin g init', () => {
2013
let tree: Tree;
2114
const project = 'my-lib';
22-
const baseDir = 'tmp/nx-plugin-e2e/generators/init';
15+
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/generators/init';
2316

2417
beforeEach(async () => {
2518
tree = await generateWorkspaceAndProject(project);
@@ -35,13 +28,7 @@ describe('nx-plugin g init', () => {
3528

3629
const { stderr } = await executeProcess({
3730
command: 'npx',
38-
args: [
39-
'nx',
40-
'g',
41-
`${relativePathToDist(cwd)}:init `,
42-
project,
43-
'--dryRun',
44-
],
31+
args: ['nx', 'g', '@code-pushup/nx-plugin:init', project, '--dryRun'],
4532
cwd,
4633
});
4734

@@ -60,7 +47,7 @@ describe('nx-plugin g init', () => {
6047
args: [
6148
'nx',
6249
'g',
63-
`${relativePathToDist(cwd)}:init `,
50+
'@code-pushup/nx-plugin:init',
6451
project,
6552
'--skipInstall',
6653
],
@@ -70,7 +57,7 @@ describe('nx-plugin g init', () => {
7057
expect(code).toBe(0);
7158
const cleanedStdout = removeColorCodes(stdout);
7259
expect(cleanedStdout).toContain(
73-
`NX Generating ${relativePathToDist(cwd)}:init`,
60+
'NX Generating @code-pushup/nx-plugin:init',
7461
);
7562
expect(cleanedStdout).toMatch(/^UPDATE package.json/m);
7663
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);
@@ -109,7 +96,7 @@ describe('nx-plugin g init', () => {
10996
args: [
11097
'nx',
11198
'g',
112-
`${relativePathToDist(cwd)}:init`,
99+
'@code-pushup/nx-plugin:init',
113100
project,
114101
'--skipInstall',
115102
'--skipPackageJson',
@@ -120,7 +107,7 @@ describe('nx-plugin g init', () => {
120107
expect(code).toBe(0);
121108
const cleanedStdout = removeColorCodes(stdout);
122109
expect(cleanedStdout).toContain(
123-
`NX Generating ${relativePathToDist(cwd)}:init`,
110+
'NX Generating @code-pushup/nx-plugin:init',
124111
);
125112
expect(cleanedStdout).not.toMatch(/^UPDATE package.json/m);
126113
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);

0 commit comments

Comments
 (0)