Skip to content

Commit f76c354

Browse files
committed
fix create-cli e2e
1 parent 06bfdb2 commit f76c354

File tree

7 files changed

+68
-16
lines changed

7 files changed

+68
-16
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { dirname } from 'knip/dist/util/path';
12
import { join, relative } from 'node:path';
23
import { afterEach, expect } from 'vitest';
34
import { teardownTestFolder } from '@code-pushup/test-setup';
4-
import { removeColorCodes } from '@code-pushup/test-utils';
5+
import { createNpmWorkspace, removeColorCodes } from '@code-pushup/test-utils';
56
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
6-
import { createNpmWorkspace } from '../mocks/create-npm-workshpace';
77

88
describe('create-cli-inti', () => {
99
const workspaceRoot = 'tmp/e2e/create-cli-e2e';
@@ -19,7 +19,12 @@ describe('create-cli-inti', () => {
1919
await createNpmWorkspace(cwd);
2020
const { code, stdout } = await executeProcess({
2121
command: 'npm',
22-
args: ['exec', '@code-pushup/create-cli', `--userconfig=${userconfig}`],
22+
args: [
23+
'exec',
24+
'@code-pushup/create-cli',
25+
`--userconfig=${userconfig}`,
26+
`--prefix=${dirname(userconfig)}`,
27+
],
2328
cwd,
2429
});
2530

@@ -48,16 +53,20 @@ describe('create-cli-inti', () => {
4853
);
4954
});
5055

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

5660
await createNpmWorkspace(cwd);
5761

5862
const { code, stdout } = await executeProcess({
5963
command: 'npm',
60-
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
64+
args: [
65+
'init',
66+
'@code-pushup/cli',
67+
`--userconfig=${userconfig}`,
68+
`--prefix=${dirname(userconfig)}`,
69+
],
6170
cwd,
6271
});
6372

@@ -94,7 +103,12 @@ describe('create-cli-inti', () => {
94103

95104
await executeProcess({
96105
command: 'npm',
97-
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
106+
args: [
107+
'init',
108+
'@code-pushup/cli',
109+
`--userconfig=${userconfig}`,
110+
`--prefix=${dirname(userconfig)}`,
111+
],
98112
cwd,
99113
});
100114

global-setup.verdaccio.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@ const projectName = process.env['NX_TASK_TARGET_PROJECT'];
1212
export async function setup() {
1313
await globalSetup();
1414

15-
activeRegistry = await nxStartVerdaccioAndSetupEnv({
16-
projectName,
17-
});
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+
}
1824

1925
const { userconfig, workspaceRoot } = activeRegistry;
2026
await executeProcess({
@@ -32,7 +38,6 @@ export async function setup() {
3238
export async function teardown() {
3339
// NOTICE - Time saving optimization
3440
// We skip uninstalling packages as the folder is deleted anyway
35-
3641
// comment out to see the folder and web interface
37-
await nxStopVerdaccioAndTeardownEnv(activeRegistry);
42+
// await nxStopVerdaccioAndTeardownEnv(activeRegistry);
3843
}

testing/test-setup/src/lib/test-folder.setup.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export async function cleanTestFolder(dirName: string) {
1313

1414
export async function teardownTestFolder(dirName: string) {
1515
try {
16-
// eslint-disable-next-line no-magic-numbers
1716
await rm(dirName, {
1817
recursive: true,
1918
force: true,

testing/test-utils/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export * from './lib/utils/env';
66
export * from './lib/utils/git';
77
export * from './lib/utils/string';
88
export * from './lib/utils/file-system';
9-
export * from './lib/utils/omit-report-data';
109
export * from './lib/utils/create-npm-workshpace';
10+
export * from './lib/utils/omit-report-data';
1111

1212
// static mocks
1313
export * from './lib/utils/commit.mock';

tools/src/debug/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function listProcess({ pid, commandMatch }: ProcessListOption = {}): {
9797
export function killProcessPid(pid: number | string, command?: string): void {
9898
const commandString = command ? `, command: ${command}` : '';
9999
try {
100-
// sometimes pid is NaN
100+
// @TODO sometimes pid is NaN, figure out if this is caused by trying to kill a process that is already stopped
101101
if (Number.isNaN(Number(pid))) {
102102
console.info(
103103
`Can't kill process as pid is not a number. \nPID: ${pid} for command ${commandString}`,

tools/src/npm/npm.plugin.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,25 @@ function npmTargets({
7575
'npm-uninstall': {
7676
command: `npm uninstall ${packageName} --prefix={args.prefix} --userconfig={args.userconfig}`,
7777
},
78+
'npm-install-e2e': {
79+
dependsOn: [
80+
{
81+
target: 'publish-e2e',
82+
projects: 'self',
83+
params: 'forward',
84+
},
85+
{
86+
target: 'npm-install-e2e',
87+
projects: 'dependencies',
88+
params: 'forward',
89+
},
90+
{
91+
target: 'publish-e2e',
92+
projects: 'dependencies',
93+
params: 'forward',
94+
},
95+
],
96+
command: `npm install -D --no-fund ${packageName}@{args.pkgVersion} --prefix={args.prefix} --userconfig={args.userconfig}`,
97+
},
7898
};
7999
}

tools/src/publish/publish.plugin.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,21 @@ function publishTargets({
7373
}) {
7474
return {
7575
publish: {
76-
dependsOn: ['build'],
76+
command: `tsx --tsconfig={args.tsconfig} {args.script} --projectName=${projectName} --directory=${directory} --registry={args.registry} --userconfig={args.userconfig} --nextVersion={args.nextVersion} --tag={args.tag} --verbose=${verbose}`,
77+
options: {
78+
script: publishScript,
79+
tsconfig,
80+
},
81+
},
82+
'publish-e2e': {
83+
dependsOn: [
84+
'build',
85+
{
86+
target: 'publish-e2e',
87+
projects: 'dependencies',
88+
params: 'forward',
89+
},
90+
],
7791
command: `tsx --tsconfig={args.tsconfig} {args.script} --projectName=${projectName} --directory=${directory} --registry={args.registry} --userconfig={args.userconfig} --nextVersion={args.nextVersion} --tag={args.tag} --verbose=${verbose}`,
7892
options: {
7993
script: publishScript,

0 commit comments

Comments
 (0)