Skip to content

Commit

Permalink
fix create-cli e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 28, 2024
1 parent 06bfdb2 commit f76c354
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 16 deletions.
28 changes: 21 additions & 7 deletions e2e/create-cli-e2e/tests/init.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { dirname } from 'knip/dist/util/path';
import { join, relative } from 'node:path';
import { afterEach, expect } from 'vitest';
import { teardownTestFolder } from '@code-pushup/test-setup';
import { removeColorCodes } from '@code-pushup/test-utils';
import { createNpmWorkspace, removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils';
import { createNpmWorkspace } from '../mocks/create-npm-workshpace';

describe('create-cli-inti', () => {
const workspaceRoot = 'tmp/e2e/create-cli-e2e';
Expand All @@ -19,7 +19,12 @@ describe('create-cli-inti', () => {
await createNpmWorkspace(cwd);
const { code, stdout } = await executeProcess({
command: 'npm',
args: ['exec', '@code-pushup/create-cli', `--userconfig=${userconfig}`],
args: [
'exec',
'@code-pushup/create-cli',
`--userconfig=${userconfig}`,
`--prefix=${dirname(userconfig)}`,
],
cwd,
});

Expand Down Expand Up @@ -48,16 +53,20 @@ describe('create-cli-inti', () => {
);
});

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

await createNpmWorkspace(cwd);

const { code, stdout } = await executeProcess({
command: 'npm',
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
args: [
'init',
'@code-pushup/cli',
`--userconfig=${userconfig}`,
`--prefix=${dirname(userconfig)}`,
],
cwd,
});

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

await executeProcess({
command: 'npm',
args: ['init', '@code-pushup/cli', `--userconfig=${userconfig}`],
args: [
'init',
'@code-pushup/cli',
`--userconfig=${userconfig}`,
`--prefix=${dirname(userconfig)}`,
],
cwd,
});

Expand Down
15 changes: 10 additions & 5 deletions global-setup.verdaccio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ const projectName = process.env['NX_TASK_TARGET_PROJECT'];
export async function setup() {
await globalSetup();

activeRegistry = await nxStartVerdaccioAndSetupEnv({
projectName,
});
try {
activeRegistry = await nxStartVerdaccioAndSetupEnv({
projectName: projectName,
verbose: true,
});
} catch (error) {
console.error('Error starting local verdaccio registry:\n' + error.message);
throw error;
}

const { userconfig, workspaceRoot } = activeRegistry;
await executeProcess({
Expand All @@ -32,7 +38,6 @@ export async function setup() {
export async function teardown() {
// NOTICE - Time saving optimization
// We skip uninstalling packages as the folder is deleted anyway

// comment out to see the folder and web interface
await nxStopVerdaccioAndTeardownEnv(activeRegistry);
// await nxStopVerdaccioAndTeardownEnv(activeRegistry);
}
1 change: 0 additions & 1 deletion testing/test-setup/src/lib/test-folder.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function cleanTestFolder(dirName: string) {

export async function teardownTestFolder(dirName: string) {
try {
// eslint-disable-next-line no-magic-numbers
await rm(dirName, {
recursive: true,
force: true,
Expand Down
2 changes: 1 addition & 1 deletion testing/test-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export * from './lib/utils/env';
export * from './lib/utils/git';
export * from './lib/utils/string';
export * from './lib/utils/file-system';
export * from './lib/utils/omit-report-data';
export * from './lib/utils/create-npm-workshpace';
export * from './lib/utils/omit-report-data';

// static mocks
export * from './lib/utils/commit.mock';
Expand Down
2 changes: 1 addition & 1 deletion tools/src/debug/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function listProcess({ pid, commandMatch }: ProcessListOption = {}): {
export function killProcessPid(pid: number | string, command?: string): void {
const commandString = command ? `, command: ${command}` : '';
try {
// sometimes pid is NaN
// @TODO sometimes pid is NaN, figure out if this is caused by trying to kill a process that is already stopped
if (Number.isNaN(Number(pid))) {
console.info(
`Can't kill process as pid is not a number. \nPID: ${pid} for command ${commandString}`,
Expand Down
20 changes: 20 additions & 0 deletions tools/src/npm/npm.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,25 @@ function npmTargets({
'npm-uninstall': {
command: `npm uninstall ${packageName} --prefix={args.prefix} --userconfig={args.userconfig}`,
},
'npm-install-e2e': {
dependsOn: [
{
target: 'publish-e2e',
projects: 'self',
params: 'forward',
},
{
target: 'npm-install-e2e',
projects: 'dependencies',
params: 'forward',
},
{
target: 'publish-e2e',
projects: 'dependencies',
params: 'forward',
},
],
command: `npm install -D --no-fund ${packageName}@{args.pkgVersion} --prefix={args.prefix} --userconfig={args.userconfig}`,
},
};
}
16 changes: 15 additions & 1 deletion tools/src/publish/publish.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,21 @@ function publishTargets({
}) {
return {
publish: {
dependsOn: ['build'],
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}`,
options: {
script: publishScript,
tsconfig,
},
},
'publish-e2e': {
dependsOn: [
'build',
{
target: 'publish-e2e',
projects: 'dependencies',
params: 'forward',
},
],
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}`,
options: {
script: publishScript,
Expand Down

0 comments on commit f76c354

Please sign in to comment.