From 7a8e3bb8a909c95bc34bf1c018e0020f2373c949 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 13:55:29 +0200 Subject: [PATCH 01/14] refactor(nx-plugin): process projectPrefix option --- e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts | 42 +++++++++--- packages/nx-plugin/src/internal/types.ts | 1 - .../nx-plugin/src/plugin/plugin.unit.test.ts | 68 ++++++++++++++++++- .../src/plugin/target/executor-target.ts | 14 +++- .../target/executor.target.unit.test.ts | 9 +++ .../nx-plugin/src/plugin/target/targets.ts | 11 +-- .../src/plugin/target/targets.unit.test.ts | 25 +++++++ packages/nx-plugin/src/plugin/types.ts | 6 +- 8 files changed, 154 insertions(+), 22 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts index dd02aa1d5..47c550b22 100644 --- a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts @@ -189,30 +189,24 @@ describe('nx-plugin', () => { )}";`, plugins: [ { - fileImports: `import jsPackagesPlugin from "${join( + fileImports: `import {dummyPlugin} from "${join( relativePathToCwd(cwd), pathRelativeToPackage, - 'dist/packages/plugin-js-packages', + 'dist/testing/test-utils', )}";`, - // @TODO improve formatObjectToJsString to get rid of the "`" hack - codeStrings: 'await jsPackagesPlugin({packageManager: `npm`})', + codeStrings: 'dummyPluginConfig', }, ], }); + await materializeTree(tree, cwd); - const { stdout, stderr } = await executeProcess({ + const { stdout } = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup -- --dryRun`], cwd, }); - const cleanStderr = removeColorCodes(stderr); - // @TODO create test environment for working plugin. This here misses package-lock.json to execute correctly - expect(cleanStderr).toContain( - 'DryRun execution of: npx @code-pushup/cli autorun', - ); - const cleanStdout = removeColorCodes(stdout); expect(cleanStdout).toContain( 'NX Successfully ran target code-pushup for project my-lib', @@ -242,6 +236,32 @@ describe('nx-plugin', () => { }); }); + it('should consider plugin option projectPrefix in executor target', async () => { + const cwd = join(baseDir, 'configuration-option-bin'); + registerPluginInWorkspace(tree, { + plugin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), + options: { + projectPrefix: 'cli', + }, + }); + const { root } = readProjectConfiguration(tree, project); + generateCodePushupConfig(tree, root); + await materializeTree(tree, cwd); + + const { code, projectJson } = await nxShowProjectJson(cwd, project); + + expect(code).toBe(0); + + expect(projectJson.targets).toStrictEqual({ + ['code-pushup']: expect.objectContaining({ + executor: `@code-pushup/nx-plugin:autorun`, + options: { + projectPrefix: 'cli', + }, + }), + }); + }); + it('should NOT add targets dynamically if plugin is not registered', async () => { const cwd = join(baseDir, 'plugin-not-registered'); await materializeTree(tree, cwd); diff --git a/packages/nx-plugin/src/internal/types.ts b/packages/nx-plugin/src/internal/types.ts index 6468db0be..bf3a2d047 100644 --- a/packages/nx-plugin/src/internal/types.ts +++ b/packages/nx-plugin/src/internal/types.ts @@ -1,5 +1,4 @@ export type DynamicTargetOptions = { - // @TODO add prefix https://github.com/code-pushup/cli/issues/619 targetName?: string; bin?: string; }; diff --git a/packages/nx-plugin/src/plugin/plugin.unit.test.ts b/packages/nx-plugin/src/plugin/plugin.unit.test.ts index df7f99a2f..56854b225 100644 --- a/packages/nx-plugin/src/plugin/plugin.unit.test.ts +++ b/packages/nx-plugin/src/plugin/plugin.unit.test.ts @@ -20,7 +20,7 @@ describe('@code-pushup/nx-plugin/plugin', () => { vol.reset(); }); - it('should normalize context and use it to create target on ROOT project', async () => { + it('should normalize context and use it to create the configuration target on ROOT project', async () => { const projectRoot = '.'; const matchingFilesData = { [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ @@ -46,7 +46,7 @@ describe('@code-pushup/nx-plugin/plugin', () => { }); }); - it('should normalize context and use it to create target on PACKAGE project', async () => { + it('should normalize context and use it to create the configuration target on PACKAGE project', async () => { const projectRoot = 'apps/my-app'; const matchingFilesData = { [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ @@ -71,4 +71,68 @@ describe('@code-pushup/nx-plugin/plugin', () => { }, }); }); + + it('should create the executor target on ROOT project if configured', async () => { + const projectRoot = '.'; + const matchingFilesData = { + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ + name: '@org/empty-root', + })}`, + [`${projectRoot}/code-pushup.config.ts`]: '{}', + }; + + await expect( + invokeCreateNodesOnVirtualFiles( + createNodes, + context, + { + projectPrefix: 'cli', + }, + { matchingFilesData }, + ), + ).resolves.toStrictEqual({ + [projectRoot]: { + targets: { + [CP_TARGET_NAME]: { + executor: `${PACKAGE_NAME}:autorun`, + options: { + projectPrefix: 'cli', + }, + }, + }, + }, + }); + }); + + it('should create the executor target on PACKAGE project if configured', async () => { + const projectRoot = 'apps/my-app'; + const matchingFilesData = { + [`${projectRoot}/${PROJECT_JSON_FILE_NAME}`]: `${JSON.stringify({ + name: '@org/empty-root', + })}`, + [`${projectRoot}/code-pushup.config.ts`]: '{}', + }; + + await expect( + invokeCreateNodesOnVirtualFiles( + createNodes, + context, + { + projectPrefix: 'cli', + }, + { matchingFilesData }, + ), + ).resolves.toStrictEqual({ + [projectRoot]: { + targets: { + [CP_TARGET_NAME]: { + executor: `${PACKAGE_NAME}:autorun`, + options: { + projectPrefix: 'cli', + }, + }, + }, + }, + }); + }); }); diff --git a/packages/nx-plugin/src/plugin/target/executor-target.ts b/packages/nx-plugin/src/plugin/target/executor-target.ts index 14eaaff07..2a2517b32 100644 --- a/packages/nx-plugin/src/plugin/target/executor-target.ts +++ b/packages/nx-plugin/src/plugin/target/executor-target.ts @@ -1,12 +1,20 @@ import { TargetConfiguration } from '@nx/devkit'; -import { RunCommandsOptions } from 'nx/src/executors/run-commands/run-commands.impl'; import { PACKAGE_NAME } from '../../internal/constants'; +import { ProjectPrefixOptions } from '../types'; export function createExecutorTarget(options?: { bin?: string; -}): TargetConfiguration { - const { bin = PACKAGE_NAME } = options ?? {}; + projectPrefix?: string; +}): TargetConfiguration { + const { bin = PACKAGE_NAME, projectPrefix } = options ?? {}; return { executor: `${bin}:autorun`, + ...(projectPrefix + ? { + options: { + projectPrefix, + }, + } + : {}), }; } diff --git a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts index 245fc4c66..c0c2563d0 100644 --- a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts +++ b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts @@ -13,4 +13,13 @@ describe('createExecutorTarget', () => { executor: 'xyz:autorun', }); }); + + it('should use projectPrefix if provides', () => { + expect(createExecutorTarget({ projectPrefix: 'cli' })).toStrictEqual({ + executor: '@code-pushup/nx-plugin:autorun', + options: { + projectPrefix: 'cli', + }, + }); + }); }); diff --git a/packages/nx-plugin/src/plugin/target/targets.ts b/packages/nx-plugin/src/plugin/target/targets.ts index 66521c88f..ce348f76e 100644 --- a/packages/nx-plugin/src/plugin/target/targets.ts +++ b/packages/nx-plugin/src/plugin/target/targets.ts @@ -7,14 +7,17 @@ import { createExecutorTarget } from './executor-target'; export async function createTargets( normalizedContext: NormalizedCreateNodesContext, ) { - const { targetName = CP_TARGET_NAME, bin } = normalizedContext.createOptions; + const { + targetName = CP_TARGET_NAME, + bin, + projectPrefix, + } = normalizedContext.createOptions; const rootFiles = await readdir(normalizedContext.projectRoot); return rootFiles.some(filename => filename.match(/^code-pushup\.config.(\w*\.)*(ts|js|mjs)$/), ) - ? // @TODO return code-pushup cli target https://github.com/code-pushup/cli/issues/619 - { - [targetName]: createExecutorTarget({ bin }), + ? { + [targetName]: createExecutorTarget({ bin, projectPrefix }), } : // if NO code-pushup.config.*.(ts|js|mjs) is present return configuration target { diff --git a/packages/nx-plugin/src/plugin/target/targets.unit.test.ts b/packages/nx-plugin/src/plugin/target/targets.unit.test.ts index fcb6fc0f4..a784bde7e 100644 --- a/packages/nx-plugin/src/plugin/target/targets.unit.test.ts +++ b/packages/nx-plugin/src/plugin/target/targets.unit.test.ts @@ -161,4 +161,29 @@ describe('createTargets', () => { }, }); }); + + it('should include projectPrefix options in executor targets if given', async () => { + const projectName = 'plugin-my-plugin'; + vol.fromJSON( + { + [`code-pushup.config.ts`]: `{}`, + }, + MEMFS_VOLUME, + ); + await expect( + createTargets({ + projectRoot: '.', + projectJson: { + name: projectName, + }, + createOptions: { + projectPrefix: 'cli', + }, + } as NormalizedCreateNodesContext), + ).resolves.toStrictEqual({ + [DEFAULT_TARGET_NAME]: expect.objectContaining({ + options: { projectPrefix: 'cli' }, + }), + }); + }); }); diff --git a/packages/nx-plugin/src/plugin/types.ts b/packages/nx-plugin/src/plugin/types.ts index de4717abb..5e55eb8e8 100644 --- a/packages/nx-plugin/src/plugin/types.ts +++ b/packages/nx-plugin/src/plugin/types.ts @@ -2,7 +2,11 @@ import type { CreateNodesContext, ProjectConfiguration } from '@nx/devkit'; import { WithRequired } from '@code-pushup/utils'; import { DynamicTargetOptions } from '../internal/types'; -export type CreateNodesOptions = DynamicTargetOptions; +export type ProjectPrefixOptions = { + projectPrefix?: string; +}; + +export type CreateNodesOptions = DynamicTargetOptions & ProjectPrefixOptions; export type ProjectConfigurationWithName = WithRequired< ProjectConfiguration, From 59be1ab6182b2680b8270ca05fa22de81bbca564 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 13:59:03 +0200 Subject: [PATCH 02/14] refactor(nx-plugin): introduce constants --- packages/nx-plugin/src/plugin/target/constants.ts | 2 ++ packages/nx-plugin/src/plugin/target/targets.ts | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 packages/nx-plugin/src/plugin/target/constants.ts diff --git a/packages/nx-plugin/src/plugin/target/constants.ts b/packages/nx-plugin/src/plugin/target/constants.ts new file mode 100644 index 000000000..843209a03 --- /dev/null +++ b/packages/nx-plugin/src/plugin/target/constants.ts @@ -0,0 +1,2 @@ +export const CODE_PUSHUP_CONFIG_REGEX = + /^code-pushup\.config.(\w*\.)*(ts|js|mjs)$/; diff --git a/packages/nx-plugin/src/plugin/target/targets.ts b/packages/nx-plugin/src/plugin/target/targets.ts index ce348f76e..e6d62e03a 100644 --- a/packages/nx-plugin/src/plugin/target/targets.ts +++ b/packages/nx-plugin/src/plugin/target/targets.ts @@ -2,6 +2,7 @@ import { readdir } from 'node:fs/promises'; import { CP_TARGET_NAME } from '../constants'; import type { NormalizedCreateNodesContext } from '../types'; import { createConfigurationTarget } from './configuration-target'; +import { CODE_PUSHUP_CONFIG_REGEX } from './constants'; import { createExecutorTarget } from './executor-target'; export async function createTargets( @@ -13,9 +14,7 @@ export async function createTargets( projectPrefix, } = normalizedContext.createOptions; const rootFiles = await readdir(normalizedContext.projectRoot); - return rootFiles.some(filename => - filename.match(/^code-pushup\.config.(\w*\.)*(ts|js|mjs)$/), - ) + return rootFiles.some(filename => filename.match(CODE_PUSHUP_CONFIG_REGEX)) ? { [targetName]: createExecutorTarget({ bin, projectPrefix }), } From 0c6f9ab19430e6d1c5d7da5a73c1bfd07d8ba2f2 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 14:29:10 +0200 Subject: [PATCH 03/14] refactor(nx-plugin): remove dryRun --- e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts | 6 +++--- testing/test-utils/src/index.ts | 1 + .../test-utils/src/lib/fixtures/configs/custom-plugin.ts | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts index 47c550b22..c96d3f19c 100644 --- a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts @@ -189,12 +189,12 @@ describe('nx-plugin', () => { )}";`, plugins: [ { - fileImports: `import {dummyPlugin} from "${join( + fileImports: `import {customPlugin} from "${join( relativePathToCwd(cwd), pathRelativeToPackage, 'dist/testing/test-utils', )}";`, - codeStrings: 'dummyPluginConfig', + codeStrings: 'customPlugin()', }, ], }); @@ -203,7 +203,7 @@ describe('nx-plugin', () => { const { stdout } = await executeProcess({ command: 'npx', - args: ['nx', 'run', `${project}:code-pushup -- --dryRun`], + args: ['nx', 'run', `${project}:code-pushup`], cwd, }); diff --git a/testing/test-utils/src/index.ts b/testing/test-utils/src/index.ts index 19e1fa5ac..a2de808ca 100644 --- a/testing/test-utils/src/index.ts +++ b/testing/test-utils/src/index.ts @@ -12,6 +12,7 @@ export * from './lib/utils/commit.mock'; export * from './lib/utils/core-config.mock'; export * from './lib/utils/minimal-config.mock'; export * from './lib/utils/report.mock'; +export * from './lib/fixtures/configs/custom-plugin'; // dynamic mocks export * from './lib/utils/dynamic-mocks/categories.mock'; diff --git a/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts b/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts index d385c066a..f296f8b9d 100644 --- a/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts +++ b/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts @@ -1,4 +1,4 @@ -const customPlugin = { +const customPluginConfig = { slug: 'good-feels', title: 'Good feels', icon: 'javascript', @@ -18,4 +18,7 @@ const customPlugin = { ], }; -export default customPlugin; +export function customPlugin() { + return customPluginConfig; +}; +export default customPluginConfig; From b2addcb82939e7d7e9dad0503715e754155603e6 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 14:43:13 +0200 Subject: [PATCH 04/14] refactor(nx-plugin): add implicit dependency --- e2e/nx-plugin-e2e/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/project.json b/e2e/nx-plugin-e2e/project.json index b3acce3eb..b683fc5d1 100644 --- a/e2e/nx-plugin-e2e/project.json +++ b/e2e/nx-plugin-e2e/project.json @@ -18,6 +18,6 @@ } } }, - "implicitDependencies": ["nx-plugin"], + "implicitDependencies": ["nx-plugin", "test-utils"], "tags": ["scope:tooling", "type:e2e"] } From fb2e76a94f1e0bfa81979154c9fdb957e1a2443d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 14:45:51 +0200 Subject: [PATCH 05/14] refactor: format --- testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts b/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts index f296f8b9d..6afe6bc80 100644 --- a/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts +++ b/testing/test-utils/src/lib/fixtures/configs/custom-plugin.ts @@ -20,5 +20,5 @@ const customPluginConfig = { export function customPlugin() { return customPluginConfig; -}; +} export default customPluginConfig; From 35b0fd0a0614d16b754814a6463f54548cd92e2d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 14:57:34 +0200 Subject: [PATCH 06/14] refactor: add test for report.json --- e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts | 64 ++++++++++++------- 1 file changed, 40 insertions(+), 24 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts index c96d3f19c..7c590d392 100644 --- a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts @@ -1,17 +1,17 @@ -import { Tree } from '@nx/devkit'; -import { rm } from 'node:fs/promises'; -import { join, relative } from 'node:path'; -import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; -import { afterEach, expect } from 'vitest'; -import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; +import {Tree} from '@nx/devkit'; +import {rm} from 'node:fs/promises'; +import {join, relative} from 'node:path'; +import {readProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; +import {afterEach, expect} from 'vitest'; +import {generateCodePushupConfig} from '@code-pushup/nx-plugin'; import { generateWorkspaceAndProject, materializeTree, nxShowProjectJson, registerPluginInWorkspace, } from '@code-pushup/test-nx-utils'; -import { removeColorCodes } from '@code-pushup/test-utils'; -import { executeProcess, readTextFile } from '@code-pushup/utils'; +import {removeColorCodes} from '@code-pushup/test-utils'; +import {executeProcess, readJsonFile, readTextFile} from '@code-pushup/utils'; // @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643 export function relativePathToCwd(testDir: string): string { @@ -29,7 +29,7 @@ describe('nx-plugin', () => { }); afterEach(async () => { - await rm(baseDir, { recursive: true, force: true }); + await rm(baseDir, {recursive: true, force: true}); }); it('should add configuration target dynamically', async () => { @@ -40,7 +40,7 @@ describe('nx-plugin', () => { ); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -66,7 +66,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const { code, stdout } = await executeProcess({ + const {code, stdout} = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup--configuration`], cwd, @@ -93,7 +93,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -112,7 +112,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -131,11 +131,11 @@ describe('nx-plugin', () => { tree, join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), ); - const { root } = readProjectConfiguration(tree, project); + const {root} = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -153,11 +153,11 @@ describe('nx-plugin', () => { tree, join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), ); - const { root } = readProjectConfiguration(tree, project); + const {root} = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -180,7 +180,7 @@ describe('nx-plugin', () => { bin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), }, }); - const { root } = readProjectConfiguration(tree, project); + const {root} = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root, { fileImports: `import type {CoreConfig} from "${join( relativePathToCwd(cwd), @@ -201,7 +201,7 @@ describe('nx-plugin', () => { await materializeTree(tree, cwd); - const { stdout } = await executeProcess({ + const {stdout} = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup`], cwd, @@ -211,6 +211,22 @@ describe('nx-plugin', () => { expect(cleanStdout).toContain( 'NX Successfully ran target code-pushup for project my-lib', ); + + const report = await readJsonFile(join(cwd, '.code-pushup', project, 'report.json')); + expect(report).toStrictEqual(expect.objectContaining({ + plugins: [ + expect.objectContaining({ + slug: "good-feels", + audits: [ + expect.objectContaining({ + displayValue: "βœ… Perfect! πŸ‘Œ", + slug: "always-perfect" + }) + ] + }) + ] + })); + }); it('should consider plugin option bin in executor target', async () => { @@ -221,11 +237,11 @@ describe('nx-plugin', () => { bin: 'XYZ', }, }); - const { root } = readProjectConfiguration(tree, project); + const {root} = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -244,11 +260,11 @@ describe('nx-plugin', () => { projectPrefix: 'cli', }, }); - const { root } = readProjectConfiguration(tree, project); + const {root} = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -266,7 +282,7 @@ describe('nx-plugin', () => { const cwd = join(baseDir, 'plugin-not-registered'); await materializeTree(tree, cwd); - const { code, projectJson } = await nxShowProjectJson(cwd, project); + const {code, projectJson} = await nxShowProjectJson(cwd, project); expect(code).toBe(0); From 87a80564c7fbb1ffa3d4415bcd4d73ffd351eac9 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 15:14:28 +0200 Subject: [PATCH 07/14] test(nx-plugin-e2e): add executor tests --- ...p => create-nodes-plugin.e2e.test.ts.snap} | 0 ...est.ts => create-nodes-plugin.e2e.test.ts} | 81 +++++++------- .../tests/executor-autorun.e2e.test.ts | 103 ++++++++++++++++++ ...ts => generator-configuration.e2e.test.ts} | 0 ...e2e.test.ts => generator-init.e2e.test.ts} | 0 5 files changed, 145 insertions(+), 39 deletions(-) rename e2e/nx-plugin-e2e/tests/__snapshots__/{nx-plugin.e2e.test.ts.snap => create-nodes-plugin.e2e.test.ts.snap} (100%) rename e2e/nx-plugin-e2e/tests/{nx-plugin.e2e.test.ts => create-nodes-plugin.e2e.test.ts} (78%) create mode 100644 e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts rename e2e/nx-plugin-e2e/tests/{configuration.e2e.test.ts => generator-configuration.e2e.test.ts} (100%) rename e2e/nx-plugin-e2e/tests/{init.e2e.test.ts => generator-init.e2e.test.ts} (100%) diff --git a/e2e/nx-plugin-e2e/tests/__snapshots__/nx-plugin.e2e.test.ts.snap b/e2e/nx-plugin-e2e/tests/__snapshots__/create-nodes-plugin.e2e.test.ts.snap similarity index 100% rename from e2e/nx-plugin-e2e/tests/__snapshots__/nx-plugin.e2e.test.ts.snap rename to e2e/nx-plugin-e2e/tests/__snapshots__/create-nodes-plugin.e2e.test.ts.snap diff --git a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts b/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts similarity index 78% rename from e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts rename to e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts index 7c590d392..fc8c60acb 100644 --- a/e2e/nx-plugin-e2e/tests/nx-plugin.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts @@ -1,17 +1,17 @@ -import {Tree} from '@nx/devkit'; -import {rm} from 'node:fs/promises'; -import {join, relative} from 'node:path'; -import {readProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; -import {afterEach, expect} from 'vitest'; -import {generateCodePushupConfig} from '@code-pushup/nx-plugin'; +import { Tree } from '@nx/devkit'; +import { rm } from 'node:fs/promises'; +import { join, relative } from 'node:path'; +import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; +import { afterEach, expect } from 'vitest'; +import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; import { generateWorkspaceAndProject, materializeTree, nxShowProjectJson, registerPluginInWorkspace, } from '@code-pushup/test-nx-utils'; -import {removeColorCodes} from '@code-pushup/test-utils'; -import {executeProcess, readJsonFile, readTextFile} from '@code-pushup/utils'; +import { removeColorCodes } from '@code-pushup/test-utils'; +import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; // @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643 export function relativePathToCwd(testDir: string): string { @@ -29,7 +29,7 @@ describe('nx-plugin', () => { }); afterEach(async () => { - await rm(baseDir, {recursive: true, force: true}); + await rm(baseDir, { recursive: true, force: true }); }); it('should add configuration target dynamically', async () => { @@ -40,7 +40,7 @@ describe('nx-plugin', () => { ); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -66,7 +66,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const {code, stdout} = await executeProcess({ + const { code, stdout } = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup--configuration`], cwd, @@ -93,7 +93,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -112,7 +112,7 @@ describe('nx-plugin', () => { }); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -131,11 +131,11 @@ describe('nx-plugin', () => { tree, join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), ); - const {root} = readProjectConfiguration(tree, project); + const { root } = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -153,11 +153,11 @@ describe('nx-plugin', () => { tree, join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), ); - const {root} = readProjectConfiguration(tree, project); + const { root } = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); expect(projectJson.targets).toStrictEqual({ @@ -180,7 +180,7 @@ describe('nx-plugin', () => { bin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), }, }); - const {root} = readProjectConfiguration(tree, project); + const { root } = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root, { fileImports: `import type {CoreConfig} from "${join( relativePathToCwd(cwd), @@ -201,7 +201,7 @@ describe('nx-plugin', () => { await materializeTree(tree, cwd); - const {stdout} = await executeProcess({ + const { stdout } = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup`], cwd, @@ -212,21 +212,24 @@ describe('nx-plugin', () => { 'NX Successfully ran target code-pushup for project my-lib', ); - const report = await readJsonFile(join(cwd, '.code-pushup', project, 'report.json')); - expect(report).toStrictEqual(expect.objectContaining({ - plugins: [ - expect.objectContaining({ - slug: "good-feels", - audits: [ - expect.objectContaining({ - displayValue: "βœ… Perfect! πŸ‘Œ", - slug: "always-perfect" - }) - ] - }) - ] - })); - + const report = await readJsonFile( + join(cwd, '.code-pushup', project, 'report.json'), + ); + expect(report).toStrictEqual( + expect.objectContaining({ + plugins: [ + expect.objectContaining({ + slug: 'good-feels', + audits: [ + expect.objectContaining({ + displayValue: 'βœ… Perfect! πŸ‘Œ', + slug: 'always-perfect', + }), + ], + }), + ], + }), + ); }); it('should consider plugin option bin in executor target', async () => { @@ -237,11 +240,11 @@ describe('nx-plugin', () => { bin: 'XYZ', }, }); - const {root} = readProjectConfiguration(tree, project); + const { root } = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -260,11 +263,11 @@ describe('nx-plugin', () => { projectPrefix: 'cli', }, }); - const {root} = readProjectConfiguration(tree, project); + const { root } = readProjectConfiguration(tree, project); generateCodePushupConfig(tree, root); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); @@ -282,7 +285,7 @@ describe('nx-plugin', () => { const cwd = join(baseDir, 'plugin-not-registered'); await materializeTree(tree, cwd); - const {code, projectJson} = await nxShowProjectJson(cwd, project); + const { code, projectJson } = await nxShowProjectJson(cwd, project); expect(code).toBe(0); diff --git a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts new file mode 100644 index 000000000..4efaa5445 --- /dev/null +++ b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts @@ -0,0 +1,103 @@ +import { Tree, updateProjectConfiguration } from '@nx/devkit'; +import { rm } from 'node:fs/promises'; +import { join, relative } from 'node:path'; +import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; +import { afterEach, expect } from 'vitest'; +import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; +import { + generateWorkspaceAndProject, + materializeTree, + registerPluginInWorkspace, +} from '@code-pushup/test-nx-utils'; +import { removeColorCodes } from '@code-pushup/test-utils'; +import { executeProcess, readJsonFile } from '@code-pushup/utils'; + +// @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643 +export function relativePathToCwd(testDir: string): string { + return relative(join(process.cwd(), testDir), process.cwd()); +} + +describe('executor autorun', () => { + let tree: Tree; + const project = 'my-lib'; + const baseDir = 'tmp/nx-plugin-e2e/executor'; + + beforeEach(async () => { + tree = await generateWorkspaceAndProject(project); + }); + + afterEach(async () => { + await rm(baseDir, { recursive: true, force: true }); + }); + + it('should execute autorun executor', async () => { + const cwd = join(baseDir, 'execute-dynamic-executor'); + const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); + registerPluginInWorkspace(tree, { + plugin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), + options: { + bin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), + }, + }); + const projectCfg = readProjectConfiguration(tree, project); + updateProjectConfiguration(tree, project, { + ...projectCfg, + targets: { + ...projectCfg.targets, + ['code-pushup']: { + executor: '@code-pushup/nx-plugin:autorun', + }, + }, + }); + const { root } = readProjectConfiguration(tree, project); + generateCodePushupConfig(tree, root, { + fileImports: `import type {CoreConfig} from "${join( + relativePathToCwd(cwd), + pathRelativeToPackage, + 'dist/packages/models', + )}";`, + plugins: [ + { + fileImports: `import {customPlugin} from "${join( + relativePathToCwd(cwd), + pathRelativeToPackage, + 'dist/testing/test-utils', + )}";`, + codeStrings: 'customPlugin()', + }, + ], + }); + + await materializeTree(tree, cwd); + + const { stdout } = await executeProcess({ + command: 'npx', + args: ['nx', 'run', `${project}:code-pushup`], + cwd, + }); + + const cleanStdout = removeColorCodes(stdout); + expect(cleanStdout).toContain( + 'NX Successfully ran target code-pushup for project my-lib', + ); + + const report = await readJsonFile( + join(cwd, '.code-pushup', project, 'report.json'), + ); + expect(report).toStrictEqual( + expect.objectContaining({ + plugins: [ + expect.objectContaining({ + slug: 'good-feels', + audits: [ + expect.objectContaining({ + displayValue: 'βœ… Perfect! πŸ‘Œ', + slug: 'always-perfect', + }), + ], + }), + ], + }), + ); + }); +}); diff --git a/e2e/nx-plugin-e2e/tests/configuration.e2e.test.ts b/e2e/nx-plugin-e2e/tests/generator-configuration.e2e.test.ts similarity index 100% rename from e2e/nx-plugin-e2e/tests/configuration.e2e.test.ts rename to e2e/nx-plugin-e2e/tests/generator-configuration.e2e.test.ts diff --git a/e2e/nx-plugin-e2e/tests/init.e2e.test.ts b/e2e/nx-plugin-e2e/tests/generator-init.e2e.test.ts similarity index 100% rename from e2e/nx-plugin-e2e/tests/init.e2e.test.ts rename to e2e/nx-plugin-e2e/tests/generator-init.e2e.test.ts From b6993caedc9aaa57085c0d9d31d3ab18ccf4f10f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 15:22:40 +0200 Subject: [PATCH 08/14] refactor tests --- .../tests/executor-autorun.e2e.test.ts | 81 ++++++++++--------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts index 4efaa5445..f13212187 100644 --- a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts @@ -7,16 +7,55 @@ import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; import { generateWorkspaceAndProject, materializeTree, - registerPluginInWorkspace, } from '@code-pushup/test-nx-utils'; import { removeColorCodes } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; // @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643 -export function relativePathToCwd(testDir: string): string { +function relativePathToCwd(testDir: string): string { return relative(join(process.cwd(), testDir), process.cwd()); } +async function addTargetToWorkspace( + tree: Tree, + options: { cwd: string; project: string }, +) { + const { cwd, project } = options; + const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); + const projectCfg = readProjectConfiguration(tree, project); + updateProjectConfiguration(tree, project, { + ...projectCfg, + targets: { + ...projectCfg.targets, + ['code-pushup']: { + executor: `${join( + relativePathToCwd(cwd), + 'dist/packages/nx-plugin', + )}:autorun`, + }, + }, + }); + const { root } = projectCfg; + generateCodePushupConfig(tree, root, { + fileImports: `import type {CoreConfig} from "${join( + relativePathToCwd(cwd), + pathRelativeToPackage, + 'dist/packages/models', + )}";`, + plugins: [ + { + fileImports: `import {customPlugin} from "${join( + relativePathToCwd(cwd), + pathRelativeToPackage, + 'dist/testing/test-utils', + )}";`, + codeStrings: 'customPlugin()', + }, + ], + }); + await materializeTree(tree, cwd); +} + describe('executor autorun', () => { let tree: Tree; const project = 'my-lib'; @@ -32,43 +71,7 @@ describe('executor autorun', () => { it('should execute autorun executor', async () => { const cwd = join(baseDir, 'execute-dynamic-executor'); - const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); - registerPluginInWorkspace(tree, { - plugin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), - options: { - bin: join(relativePathToCwd(cwd), 'dist/packages/nx-plugin'), - }, - }); - const projectCfg = readProjectConfiguration(tree, project); - updateProjectConfiguration(tree, project, { - ...projectCfg, - targets: { - ...projectCfg.targets, - ['code-pushup']: { - executor: '@code-pushup/nx-plugin:autorun', - }, - }, - }); - const { root } = readProjectConfiguration(tree, project); - generateCodePushupConfig(tree, root, { - fileImports: `import type {CoreConfig} from "${join( - relativePathToCwd(cwd), - pathRelativeToPackage, - 'dist/packages/models', - )}";`, - plugins: [ - { - fileImports: `import {customPlugin} from "${join( - relativePathToCwd(cwd), - pathRelativeToPackage, - 'dist/testing/test-utils', - )}";`, - codeStrings: 'customPlugin()', - }, - ], - }); - - await materializeTree(tree, cwd); + await addTargetToWorkspace(tree, { cwd, project }); const { stdout } = await executeProcess({ command: 'npx', From 78163444d8714576916ddad8cdedd35772bfe78f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 16:26:53 +0200 Subject: [PATCH 09/14] fix test --- .../tests/executor-autorun.e2e.test.ts | 56 ++++++------------- 1 file changed, 17 insertions(+), 39 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts index f13212187..145502ba2 100644 --- a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts @@ -1,15 +1,12 @@ -import { Tree, updateProjectConfiguration } from '@nx/devkit'; -import { rm } from 'node:fs/promises'; -import { join, relative } from 'node:path'; -import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; -import { afterEach, expect } from 'vitest'; -import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; -import { - generateWorkspaceAndProject, - materializeTree, -} from '@code-pushup/test-nx-utils'; -import { removeColorCodes } from '@code-pushup/test-utils'; -import { executeProcess, readJsonFile } from '@code-pushup/utils'; +import {Tree, updateProjectConfiguration} from '@nx/devkit'; +import {rm} from 'node:fs/promises'; +import {join, relative} from 'node:path'; +import {readProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; +import {afterEach, expect} from 'vitest'; +import {generateCodePushupConfig} from '@code-pushup/nx-plugin'; +import {generateWorkspaceAndProject, materializeTree,} from '@code-pushup/test-nx-utils'; +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 relativePathToCwd(testDir: string): string { @@ -20,7 +17,7 @@ async function addTargetToWorkspace( tree: Tree, options: { cwd: string; project: string }, ) { - const { cwd, project } = options; + const {cwd, project} = options; const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); const projectCfg = readProjectConfiguration(tree, project); updateProjectConfiguration(tree, project, { @@ -35,7 +32,7 @@ async function addTargetToWorkspace( }, }, }); - const { root } = projectCfg; + const {root} = projectCfg; generateCodePushupConfig(tree, root, { fileImports: `import type {CoreConfig} from "${join( relativePathToCwd(cwd), @@ -66,41 +63,22 @@ describe('executor autorun', () => { }); afterEach(async () => { - await rm(baseDir, { recursive: true, force: true }); + await rm(baseDir, {recursive: true, force: true}); }); it('should execute autorun executor', async () => { const cwd = join(baseDir, 'execute-dynamic-executor'); - await addTargetToWorkspace(tree, { cwd, project }); + await addTargetToWorkspace(tree, {cwd, project}); - const { stdout } = await executeProcess({ + const {stdout, code} = await executeProcess({ command: 'npx', - args: ['nx', 'run', `${project}:code-pushup`], + args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'], cwd, }); + expect(code).toBe(0); const cleanStdout = removeColorCodes(stdout); - expect(cleanStdout).toContain( - 'NX Successfully ran target code-pushup for project my-lib', - ); + expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); - const report = await readJsonFile( - join(cwd, '.code-pushup', project, 'report.json'), - ); - expect(report).toStrictEqual( - expect.objectContaining({ - plugins: [ - expect.objectContaining({ - slug: 'good-feels', - audits: [ - expect.objectContaining({ - displayValue: 'βœ… Perfect! πŸ‘Œ', - slug: 'always-perfect', - }), - ], - }), - ], - }), - ); }); }); From 19624f53737d5d085a8d6da75bac90cd96f611c2 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 16:27:17 +0200 Subject: [PATCH 10/14] fix format --- .../tests/executor-autorun.e2e.test.ts | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts index 145502ba2..5557e4e97 100644 --- a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts @@ -1,12 +1,15 @@ -import {Tree, updateProjectConfiguration} from '@nx/devkit'; -import {rm} from 'node:fs/promises'; -import {join, relative} from 'node:path'; -import {readProjectConfiguration} from 'nx/src/generators/utils/project-configuration'; -import {afterEach, expect} from 'vitest'; -import {generateCodePushupConfig} from '@code-pushup/nx-plugin'; -import {generateWorkspaceAndProject, materializeTree,} from '@code-pushup/test-nx-utils'; -import {removeColorCodes} from '@code-pushup/test-utils'; -import {executeProcess} from '@code-pushup/utils'; +import { Tree, updateProjectConfiguration } from '@nx/devkit'; +import { rm } from 'node:fs/promises'; +import { join, relative } from 'node:path'; +import { readProjectConfiguration } from 'nx/src/generators/utils/project-configuration'; +import { afterEach, expect } from 'vitest'; +import { generateCodePushupConfig } from '@code-pushup/nx-plugin'; +import { + generateWorkspaceAndProject, + materializeTree, +} from '@code-pushup/test-nx-utils'; +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 relativePathToCwd(testDir: string): string { @@ -17,7 +20,7 @@ async function addTargetToWorkspace( tree: Tree, options: { cwd: string; project: string }, ) { - const {cwd, project} = options; + const { cwd, project } = options; const pathRelativeToPackage = relative(join(cwd, 'libs', project), cwd); const projectCfg = readProjectConfiguration(tree, project); updateProjectConfiguration(tree, project, { @@ -32,7 +35,7 @@ async function addTargetToWorkspace( }, }, }); - const {root} = projectCfg; + const { root } = projectCfg; generateCodePushupConfig(tree, root, { fileImports: `import type {CoreConfig} from "${join( relativePathToCwd(cwd), @@ -63,14 +66,14 @@ describe('executor autorun', () => { }); afterEach(async () => { - await rm(baseDir, {recursive: true, force: true}); + await rm(baseDir, { recursive: true, force: true }); }); it('should execute autorun executor', async () => { const cwd = join(baseDir, 'execute-dynamic-executor'); - await addTargetToWorkspace(tree, {cwd, project}); + await addTargetToWorkspace(tree, { cwd, project }); - const {stdout, code} = await executeProcess({ + const { stdout, code } = await executeProcess({ command: 'npx', args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'], cwd, @@ -79,6 +82,5 @@ describe('executor autorun', () => { expect(code).toBe(0); const cleanStdout = removeColorCodes(stdout); expect(cleanStdout).toContain('nx run my-lib:code-pushup --dryRun'); - }); }); From d27866d4698446028781386a12e0590d5bfb0659 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 14 Aug 2024 16:39:56 +0200 Subject: [PATCH 11/14] fix test --- .../tests/create-nodes-plugin.e2e.test.ts | 23 ++----------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts b/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts index fc8c60acb..92a25e874 100644 --- a/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/create-nodes-plugin.e2e.test.ts @@ -11,7 +11,7 @@ import { registerPluginInWorkspace, } from '@code-pushup/test-nx-utils'; import { removeColorCodes } from '@code-pushup/test-utils'; -import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; +import { executeProcess, readTextFile } from '@code-pushup/utils'; // @TODO replace with default bin after https://github.com/code-pushup/cli/issues/643 export function relativePathToCwd(testDir: string): string { @@ -203,7 +203,7 @@ describe('nx-plugin', () => { const { stdout } = await executeProcess({ command: 'npx', - args: ['nx', 'run', `${project}:code-pushup`], + args: ['nx', 'run', `${project}:code-pushup`, '--dryRun'], cwd, }); @@ -211,25 +211,6 @@ describe('nx-plugin', () => { expect(cleanStdout).toContain( 'NX Successfully ran target code-pushup for project my-lib', ); - - const report = await readJsonFile( - join(cwd, '.code-pushup', project, 'report.json'), - ); - expect(report).toStrictEqual( - expect.objectContaining({ - plugins: [ - expect.objectContaining({ - slug: 'good-feels', - audits: [ - expect.objectContaining({ - displayValue: 'βœ… Perfect! πŸ‘Œ', - slug: 'always-perfect', - }), - ], - }), - ], - }), - ); }); it('should consider plugin option bin in executor target', async () => { From d6631bd931ebc0e1b94af367067017715733269a Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Wed, 14 Aug 2024 16:57:47 +0200 Subject: [PATCH 12/14] Update e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts --- e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts index 5557e4e97..c265949bc 100644 --- a/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts +++ b/e2e/nx-plugin-e2e/tests/executor-autorun.e2e.test.ts @@ -11,7 +11,6 @@ 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 relativePathToCwd(testDir: string): string { return relative(join(process.cwd(), testDir), process.cwd()); } From 18e16ef6982afc917a5066d822acc9f021e4722a Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Wed, 21 Aug 2024 02:07:20 +0200 Subject: [PATCH 13/14] Update constants.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MatΔ›j Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/nx-plugin/src/plugin/target/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nx-plugin/src/plugin/target/constants.ts b/packages/nx-plugin/src/plugin/target/constants.ts index 843209a03..79e804e40 100644 --- a/packages/nx-plugin/src/plugin/target/constants.ts +++ b/packages/nx-plugin/src/plugin/target/constants.ts @@ -1,2 +1,2 @@ export const CODE_PUSHUP_CONFIG_REGEX = - /^code-pushup\.config.(\w*\.)*(ts|js|mjs)$/; + /^code-pushup\.config\.(\w*\.)*(ts|js|mjs)$/; From dd3aa3fefb9d3d559c223bb493632309b3d18af4 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Wed, 21 Aug 2024 02:07:33 +0200 Subject: [PATCH 14/14] Update executor.target.unit.test.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: MatΔ›j Chalk <34691111+matejchalk@users.noreply.github.com> --- .../nx-plugin/src/plugin/target/executor.target.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts index c0c2563d0..198027b9f 100644 --- a/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts +++ b/packages/nx-plugin/src/plugin/target/executor.target.unit.test.ts @@ -14,7 +14,7 @@ describe('createExecutorTarget', () => { }); }); - it('should use projectPrefix if provides', () => { + it('should use projectPrefix if provided', () => { expect(createExecutorTarget({ projectPrefix: 'cli' })).toStrictEqual({ executor: '@code-pushup/nx-plugin:autorun', options: {