Skip to content

Commit

Permalink
refactor: structure verdaccio environment (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton authored Aug 28, 2024
1 parent 9e20e91 commit 4f304f2
Show file tree
Hide file tree
Showing 24 changed files with 690 additions and 327 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`nx-plugin > should NOT add config targets dynamically if the project is configured 1`] = `
{
"code-pushup": {
"configurations": {},
"executor": "@code-pushup/nx-plugin:autorun",
"options": {},
},
}
`;

exports[`nx-plugin > should add configuration target dynamically 1`] = `
{
"code-pushup--configuration": {
"configurations": {},
"executor": "nx:run-commands",
"options": {
"command": "nx g @code-pushup/nx-plugin:configuration --skipTarget --targetName="code-pushup" --project="my-lib"",
},
},
}
`;

exports[`nx-plugin > should add executor target dynamically if the project is configured 1`] = `
{
"code-pushup": {
"configurations": {},
"executor": "@code-pushup/nx-plugin:autorun",
"options": {},
},
}
`;

exports[`nx-plugin > should execute dynamic configuration target 1`] = `
"import type { CoreConfig } from '@code-pushup/models';
// see: https://github.com/code-pushup/cli/blob/main/packages/models/docs/models-reference.md#coreconfig
export default {
plugins: [],
} satisfies CoreConfig;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,16 @@ async function addTargetToWorkspace(
targets: {
...projectCfg.targets,
['code-pushup']: {
executor: `${join(
relativePathToCwd(cwd),
'dist/packages/nx-plugin',
)}:autorun`,
executor: '@code-pushup/nx-plugin:autorun',
},
},
});
const { root } = projectCfg;
generateCodePushupConfig(tree, root, {
fileImports: `import type {CoreConfig} from "${join(
relativePathToCwd(cwd),
pathRelativeToPackage,
'dist/packages/models',
)}";`,
fileImports: `import type {CoreConfig} from "@code-pushup/models";`,
plugins: [
{
// @TODO replace with inline plugin
fileImports: `import {customPlugin} from "${join(
relativePathToCwd(cwd),
pathRelativeToPackage,
Expand All @@ -58,7 +52,7 @@ async function addTargetToWorkspace(
describe('executor autorun', () => {
let tree: Tree;
const project = 'my-lib';
const baseDir = 'tmp/nx-plugin-e2e/executor';
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/executor/cli';

beforeEach(async () => {
tree = await generateWorkspaceAndProject(project);
Expand Down
30 changes: 11 additions & 19 deletions e2e/nx-plugin-e2e/tests/generator-configuration.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Tree } from '@nx/devkit';
import { readFile, rm } from 'node:fs/promises';
import { join, relative } from 'node:path';
import { join } from 'node:path';
import { afterEach, expect } from 'vitest';
import { generateCodePushupConfig } from '@code-pushup/nx-plugin';
import {
Expand All @@ -10,19 +10,11 @@ import {
import { removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';

// @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643
function relativePathToDist(testDir: string): string {
return relative(
join(process.cwd(), testDir),
join(process.cwd(), 'dist/packages/nx-plugin'),
);
}

describe('nx-plugin g configuration', () => {
let tree: Tree;
const project = 'my-lib';
const projectRoot = join('libs', project);
const baseDir = 'tmp/nx-plugin-e2e/generators/configuration';
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/generators/configuration';

beforeEach(async () => {
tree = await generateWorkspaceAndProject(project);
Expand All @@ -41,7 +33,7 @@ describe('nx-plugin g configuration', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:configuration `,
'@code-pushup/nx-plugin:configuration',
project,
'--targetName=code-pushup',
],
Expand All @@ -58,7 +50,7 @@ describe('nx-plugin g configuration', () => {
const cleanedStdout = removeColorCodes(stdout);

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

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

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

const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
`NX Generating ${relativePathToDist(cwd)}:configuration`,
'NX Generating @code-pushup/nx-plugin:configuration',
);
expect(cleanedStdout).not.toMatch(/^CREATE.*code-pushup.config.ts/m);
expect(cleanedStdout).toMatch(/^UPDATE.*project.json/m);
Expand Down Expand Up @@ -131,7 +123,7 @@ describe('nx-plugin g configuration', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:configuration `,
'@code-pushup/nx-plugin:configuration',
project,
'--skipConfig',
],
Expand All @@ -143,7 +135,7 @@ describe('nx-plugin g configuration', () => {
const cleanedStdout = removeColorCodes(stdout);

expect(cleanedStdout).toContain(
`NX Generating ${relativePathToDist(cwd)}:configuration`,
'NX Generating @code-pushup/nx-plugin:configuration',
);
expect(cleanedStdout).not.toMatch(/^CREATE.*code-pushup.config.ts/m);
expect(cleanedStdout).toMatch(/^UPDATE.*project.json/m);
Expand Down Expand Up @@ -176,7 +168,7 @@ describe('nx-plugin g configuration', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:configuration `,
'@code-pushup/nx-plugin:configuration',
project,
'--skipTarget',
],
Expand All @@ -187,7 +179,7 @@ describe('nx-plugin g configuration', () => {
const cleanedStdout = removeColorCodes(stdout);

expect(cleanedStdout).toContain(
`NX Generating ${relativePathToDist(cwd)}:configuration`,
'NX Generating @code-pushup/nx-plugin:configuration',
);
expect(cleanedStdout).toMatch(/^CREATE.*code-pushup.config.ts/m);
expect(cleanedStdout).not.toMatch(/^UPDATE.*project.json/m);
Expand Down Expand Up @@ -220,7 +212,7 @@ describe('nx-plugin g configuration', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:configuration `,
'@code-pushup/nx-plugin:configuration',
project,
'--dryRun',
],
Expand Down
27 changes: 7 additions & 20 deletions e2e/nx-plugin-e2e/tests/generator-init.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Tree } from '@nx/devkit';
import { readFile, rm } from 'node:fs/promises';
import { join, relative } from 'node:path';
import { join } from 'node:path';
import { afterEach, expect } from 'vitest';
import {
generateWorkspaceAndProject,
Expand All @@ -9,17 +9,10 @@ import {
import { removeColorCodes } from '@code-pushup/test-utils';
import { executeProcess } from '@code-pushup/utils';

function relativePathToDist(testDir: string): string {
return relative(
join(process.cwd(), testDir),
join(process.cwd(), 'dist/packages/nx-plugin'),
);
}

describe('nx-plugin g init', () => {
let tree: Tree;
const project = 'my-lib';
const baseDir = 'tmp/nx-plugin-e2e/generators/init';
const baseDir = 'tmp/e2e/nx-plugin-e2e/__test__/generators/init';

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

const { stderr } = await executeProcess({
command: 'npx',
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:init `,
project,
'--dryRun',
],
args: ['nx', 'g', '@code-pushup/nx-plugin:init', project, '--dryRun'],
cwd,
});

Expand All @@ -60,7 +47,7 @@ describe('nx-plugin g init', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:init `,
'@code-pushup/nx-plugin:init',
project,
'--skipInstall',
],
Expand All @@ -70,7 +57,7 @@ describe('nx-plugin g init', () => {
expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
`NX Generating ${relativePathToDist(cwd)}:init`,
'NX Generating @code-pushup/nx-plugin:init',
);
expect(cleanedStdout).toMatch(/^UPDATE package.json/m);
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);
Expand Down Expand Up @@ -109,7 +96,7 @@ describe('nx-plugin g init', () => {
args: [
'nx',
'g',
`${relativePathToDist(cwd)}:init`,
'@code-pushup/nx-plugin:init',
project,
'--skipInstall',
'--skipPackageJson',
Expand All @@ -120,7 +107,7 @@ describe('nx-plugin g init', () => {
expect(code).toBe(0);
const cleanedStdout = removeColorCodes(stdout);
expect(cleanedStdout).toContain(
`NX Generating ${relativePathToDist(cwd)}:init`,
'NX Generating @code-pushup/nx-plugin:init',
);
expect(cleanedStdout).not.toMatch(/^UPDATE package.json/m);
expect(cleanedStdout).toMatch(/^UPDATE nx.json/m);
Expand Down
Loading

0 comments on commit 4f304f2

Please sign in to comment.