From b7bad50985aa0ba58959e87da243260333df7c2e Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 18:04:58 +0100 Subject: [PATCH 01/17] refactor: rename test mock files to remove .nxignore --- .nxignore | 34 +++++++++++++- .../fixtures/npm-workspaces/_package.json | 4 ++ .../fixtures/npm-workspaces/package.json | 6 --- .../cli/{package.json => _package.json} | 0 .../core/{package.json => _package.json} | 0 .../utils/{package.json => _package.json} | 0 .../nx-monorepo/{nx.json => _nx.json} | 0 .../apps/api/{project.json => _project.json} | 0 .../apps/cms/{project.json => _project.json} | 0 .../apps/web/{project.json => _project.json} | 0 .../libs/ui/{project.json => _project.json} | 0 .../utils/{project.json => _project.json} | 0 e2e/ci-e2e/mocks/setup.ts | 3 ++ e2e/cli-e2e/tests/collect.e2e.test.ts | 3 ++ e2e/cli-e2e/tests/compare.e2e.test.ts | 3 ++ .../{package.json => _package.json} | 0 .../tests/collect.e2e.test.ts | 5 ++ .../npm-repo/{package.json => _package.json} | 0 .../tests/plugin-js-packages.e2e.test.ts | 3 ++ .../tests/collect.e2e.test.ts | 4 ++ .../tests/collect.e2e.test.ts | 3 ++ .../tests/collect.e2e.test.ts | 3 ++ .../api/{package.json => _package.json} | 0 .../auth/{package.json => _package.json} | 0 .../frontend/{package.json => _package.json} | 0 .../fixtures/monorepos/npm/_package.json | 4 ++ .../mocks/fixtures/monorepos/npm/package.json | 6 --- .../cli/{package.json => _package.json} | 0 .../core/{package.json => _package.json} | 0 .../utils/{package.json => _package.json} | 0 .../monorepos/nx/{nx.json => _nx.json} | 0 .../nx/{package.json => _package.json} | 0 .../cli/{project.json => _project.json} | 0 .../core/{project.json => _project.json} | 0 .../utils/{project.json => _project.json} | 0 .../pnpm/{package.json => _package.json} | 0 .../cli/{package.json => _package.json} | 0 .../core/{package.json => _package.json} | 0 .../utils/{package.json => _package.json} | 0 .../turbo/{package.json => _package.json} | 4 +- .../cli/{package.json => _package.json} | 0 .../core/{package.json => _package.json} | 0 .../utils/{package.json => _package.json} | 0 .../yarn/{package.json => _package.json} | 4 +- .../cli/{package.json => _package.json} | 0 .../core/{package.json => _package.json} | 0 .../utils/{package.json => _package.json} | 0 packages/ci/src/lib/run.int.test.ts | 4 ++ .../nx-monorepo/{nx.json => _nx.json} | 0 .../{package.json => _package.json} | 0 .../cli/{project.json => _project.json} | 0 .../core/{project.json => _project.json} | 0 .../nx-plugin/{project.json => _project.json} | 0 .../utils/{project.json => _project.json} | 0 .../todos-app/{package.json => _package.json} | 0 .../src/lib/utils/test-folder-setup.ts | 46 ++++++++++++++++++- 56 files changed, 119 insertions(+), 20 deletions(-) create mode 100644 e2e/ci-e2e/mocks/fixtures/npm-workspaces/_package.json delete mode 100644 e2e/ci-e2e/mocks/fixtures/npm-workspaces/package.json rename e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/{package.json => _package.json} (100%) rename e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/core/{package.json => _package.json} (100%) rename e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/utils/{package.json => _package.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/{nx.json => _nx.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/{project.json => _project.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/{project.json => _project.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/{project.json => _project.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/{project.json => _project.json} (100%) rename e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/{project.json => _project.json} (100%) rename e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/{package.json => _package.json} (100%) rename e2e/plugin-js-packages-e2e/mocks/fixtures/npm-repo/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/custom/backend/api/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/custom/backend/auth/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/custom/frontend/{package.json => _package.json} (100%) create mode 100644 packages/ci/mocks/fixtures/monorepos/npm/_package.json delete mode 100644 packages/ci/mocks/fixtures/monorepos/npm/package.json rename packages/ci/mocks/fixtures/monorepos/npm/packages/cli/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/npm/packages/core/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/npm/packages/utils/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/nx/{nx.json => _nx.json} (100%) rename packages/ci/mocks/fixtures/monorepos/nx/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/nx/packages/cli/{project.json => _project.json} (100%) rename packages/ci/mocks/fixtures/monorepos/nx/packages/core/{project.json => _project.json} (100%) rename packages/ci/mocks/fixtures/monorepos/nx/packages/utils/{project.json => _project.json} (100%) rename packages/ci/mocks/fixtures/monorepos/pnpm/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/pnpm/packages/cli/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/pnpm/packages/core/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/pnpm/packages/utils/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/turbo/{package.json => _package.json} (60%) rename packages/ci/mocks/fixtures/monorepos/turbo/packages/cli/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/turbo/packages/core/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/turbo/packages/utils/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/yarn/{package.json => _package.json} (59%) rename packages/ci/mocks/fixtures/monorepos/yarn/packages/cli/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/yarn/packages/core/{package.json => _package.json} (100%) rename packages/ci/mocks/fixtures/monorepos/yarn/packages/utils/{package.json => _package.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/{nx.json => _nx.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/{package.json => _package.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/{project.json => _project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/{project.json => _project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/{project.json => _project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/{project.json => _project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/todos-app/{package.json => _package.json} (100%) diff --git a/.nxignore b/.nxignore index ec58c2555..b001c0620 100644 --- a/.nxignore +++ b/.nxignore @@ -1,2 +1,34 @@ # exclude mock Nx monorepos used for testing -mocks +# mocks + +# explicit paths excluded by "mocks" glob +# e2e/ci-e2e/mocks +# e2e/cli-e2e/mocks +# e2e/nx-plugin-e2e/mocks +# e2e/packages/ci/mocks +# e2e/packages/cli/mocks +# e2e/packages/plugin-coverage/mocks +# e2e/packages/plugin-eslint/mocks +# e2e/packages/plugin-jsdocs/mocks +# e2e/packages/plugin-typescript/mocks +# e2e/packages/utils/mocks +# e2e/plugin-coverage-e2e/mocks +# e2e/plugin-eslint-e2e/mocks +# e2e/plugin-js-packages-e2e/mocks +# e2e/plugin-jsdocs-e2e/mocks +# e2e/plugin-lighthouse-e2e/mocks +# e2e/plugin-typescript-e2e/mocks +# examples/plugins/mocks +# packages/ci/mocks +# packages/cli/mocks +# packages/plugin-coverage/mocks +# packages/plugin-eslint/mocks +# packages/plugin-jsdocs/mocks +# packages/plugin-typescript/mocks +# packages/utils/mocks + +# explicit paths excluded containing Nx workspace mock assets + +# e2e/ci-e2e/mocks/fixtures/nx-monorepo +# packages/ci/mocks/fixtures/monorepos/nx +# packages/plugin-eslint/mocks/fixtures/nx-monorepo diff --git a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/_package.json b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/_package.json new file mode 100644 index 000000000..aad9ea832 --- /dev/null +++ b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/_package.json @@ -0,0 +1,4 @@ +{ + "private": true, + "workspaces": ["packages/*"] +} diff --git a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/package.json b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/package.json deleted file mode 100644 index 9f0acdba5..000000000 --- a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "workspaces": [ - "packages/*" - ] -} diff --git a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/package.json b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/_package.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/package.json rename to e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/cli/_package.json diff --git a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/core/package.json b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/core/_package.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/core/package.json rename to e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/core/_package.json diff --git a/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/utils/package.json b/e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/utils/_package.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/utils/package.json rename to e2e/ci-e2e/mocks/fixtures/npm-workspaces/packages/utils/_package.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/nx.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/_nx.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/nx.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/_nx.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/project.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/_project.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/project.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/api/_project.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/project.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/_project.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/project.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/cms/_project.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/project.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/_project.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/project.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/apps/web/_project.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/project.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/_project.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/project.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/ui/_project.json diff --git a/e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/project.json b/e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/_project.json similarity index 100% rename from e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/project.json rename to e2e/ci-e2e/mocks/fixtures/nx-monorepo/libs/utils/_project.json diff --git a/e2e/ci-e2e/mocks/setup.ts b/e2e/ci-e2e/mocks/setup.ts index c1598d99e..19657d104 100644 --- a/e2e/ci-e2e/mocks/setup.ts +++ b/e2e/ci-e2e/mocks/setup.ts @@ -5,8 +5,10 @@ import { simpleGit } from 'simple-git'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, + restoreRenamedFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -28,6 +30,7 @@ export async function setupTestRepo(folder: string) { ); await cp(fixturesDir, baseDir, { recursive: true }); + await restoreRenamedFiles(baseDir, NX_IGNORED_FILES_TO_RESTORE); const git = await initGitRepo(simpleGit, { baseDir }); await simulateGitFetch(git); diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index 39f341885..af244ce0b 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -4,7 +4,9 @@ import { afterEach, beforeAll, describe, expect, it } from 'vitest'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { @@ -36,6 +38,7 @@ describe('CLI collect', () => { beforeAll(async () => { await cp(fixtureDummyDir, dummyDir, { recursive: true }); + await restoreRenamedFiles(dummyDir, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/e2e/cli-e2e/tests/compare.e2e.test.ts b/e2e/cli-e2e/tests/compare.e2e.test.ts index 4108d9b9e..b4cc9dc91 100644 --- a/e2e/cli-e2e/tests/compare.e2e.test.ts +++ b/e2e/cli-e2e/tests/compare.e2e.test.ts @@ -5,7 +5,9 @@ import type { ReportsDiff } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; @@ -30,6 +32,7 @@ describe('CLI compare', () => { beforeAll(async () => { await cp(fixtureDummyDir, existingDir, { recursive: true }); + await restoreRenamedFiles(existingDir, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json b/e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/_package.json similarity index 100% rename from e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/package.json rename to e2e/plugin-coverage-e2e/mocks/fixtures/basic-setup/_package.json diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index bbfada16a..05a071b5a 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -5,8 +5,10 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -43,6 +45,9 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { await cp(fixturesArtifactsConfigDir, artifactsConfigDir, { recursive: true, }); + await restoreRenamedFiles(flatConfigDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreRenamedFiles(legacyConfigDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreRenamedFiles(artifactsConfigDir, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/e2e/plugin-js-packages-e2e/mocks/fixtures/npm-repo/package.json b/e2e/plugin-js-packages-e2e/mocks/fixtures/npm-repo/_package.json similarity index 100% rename from e2e/plugin-js-packages-e2e/mocks/fixtures/npm-repo/package.json rename to e2e/plugin-js-packages-e2e/mocks/fixtures/npm-repo/_package.json diff --git a/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts b/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts index 5e884aaa5..144a25d93 100644 --- a/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts +++ b/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts @@ -9,7 +9,9 @@ import { import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -32,6 +34,7 @@ describe('plugin-js-packages', () => { beforeAll(async () => { await cp(fixturesNPMDir, npmRepoDir, { recursive: true }); + await restoreRenamedFiles(npmRepoDir, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts b/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts index dc94cdfbe..0ad88474e 100644 --- a/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts @@ -6,9 +6,11 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -36,6 +38,8 @@ describe('PLUGIN collect report with jsdocs-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesAngularDir, angularDir, { recursive: true }); await cp(fixturesReactDir, reactDir, { recursive: true }); + await restoreRenamedFiles(angularDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreRenamedFiles(reactDir, NX_IGNORED_FILES_TO_RESTORE); await initGitRepo(simpleGit, { baseDir: angularDir }); await initGitRepo(simpleGit, { baseDir: reactDir }); }); diff --git a/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts b/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts index e1c255e70..e05fbb936 100644 --- a/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts @@ -5,9 +5,11 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, removeColorCodes, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -25,6 +27,7 @@ describe('PLUGIN collect report with lighthouse-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, testFileDir, { recursive: true }); + await restoreRenamedFiles(testFileDir, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 1d3766c37..1ab5cb7ed 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -5,10 +5,12 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, osAgnosticAuditOutputs, osAgnosticPath, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -50,6 +52,7 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, envRoot, { recursive: true }); + await restoreRenamedFiles(envRoot, NX_IGNORED_FILES_TO_RESTORE); }); afterAll(async () => { diff --git a/packages/ci/mocks/fixtures/monorepos/custom/backend/api/package.json b/packages/ci/mocks/fixtures/monorepos/custom/backend/api/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/custom/backend/api/package.json rename to packages/ci/mocks/fixtures/monorepos/custom/backend/api/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/custom/backend/auth/package.json b/packages/ci/mocks/fixtures/monorepos/custom/backend/auth/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/custom/backend/auth/package.json rename to packages/ci/mocks/fixtures/monorepos/custom/backend/auth/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/custom/frontend/package.json b/packages/ci/mocks/fixtures/monorepos/custom/frontend/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/custom/frontend/package.json rename to packages/ci/mocks/fixtures/monorepos/custom/frontend/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/npm/_package.json b/packages/ci/mocks/fixtures/monorepos/npm/_package.json new file mode 100644 index 000000000..aad9ea832 --- /dev/null +++ b/packages/ci/mocks/fixtures/monorepos/npm/_package.json @@ -0,0 +1,4 @@ +{ + "private": true, + "workspaces": ["packages/*"] +} diff --git a/packages/ci/mocks/fixtures/monorepos/npm/package.json b/packages/ci/mocks/fixtures/monorepos/npm/package.json deleted file mode 100644 index 9f0acdba5..000000000 --- a/packages/ci/mocks/fixtures/monorepos/npm/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "private": true, - "workspaces": [ - "packages/*" - ] -} diff --git a/packages/ci/mocks/fixtures/monorepos/npm/packages/cli/package.json b/packages/ci/mocks/fixtures/monorepos/npm/packages/cli/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/npm/packages/cli/package.json rename to packages/ci/mocks/fixtures/monorepos/npm/packages/cli/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/npm/packages/core/package.json b/packages/ci/mocks/fixtures/monorepos/npm/packages/core/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/npm/packages/core/package.json rename to packages/ci/mocks/fixtures/monorepos/npm/packages/core/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/npm/packages/utils/package.json b/packages/ci/mocks/fixtures/monorepos/npm/packages/utils/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/npm/packages/utils/package.json rename to packages/ci/mocks/fixtures/monorepos/npm/packages/utils/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/nx/nx.json b/packages/ci/mocks/fixtures/monorepos/nx/_nx.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/nx/nx.json rename to packages/ci/mocks/fixtures/monorepos/nx/_nx.json diff --git a/packages/ci/mocks/fixtures/monorepos/nx/package.json b/packages/ci/mocks/fixtures/monorepos/nx/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/nx/package.json rename to packages/ci/mocks/fixtures/monorepos/nx/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/nx/packages/cli/project.json b/packages/ci/mocks/fixtures/monorepos/nx/packages/cli/_project.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/nx/packages/cli/project.json rename to packages/ci/mocks/fixtures/monorepos/nx/packages/cli/_project.json diff --git a/packages/ci/mocks/fixtures/monorepos/nx/packages/core/project.json b/packages/ci/mocks/fixtures/monorepos/nx/packages/core/_project.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/nx/packages/core/project.json rename to packages/ci/mocks/fixtures/monorepos/nx/packages/core/_project.json diff --git a/packages/ci/mocks/fixtures/monorepos/nx/packages/utils/project.json b/packages/ci/mocks/fixtures/monorepos/nx/packages/utils/_project.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/nx/packages/utils/project.json rename to packages/ci/mocks/fixtures/monorepos/nx/packages/utils/_project.json diff --git a/packages/ci/mocks/fixtures/monorepos/pnpm/package.json b/packages/ci/mocks/fixtures/monorepos/pnpm/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/pnpm/package.json rename to packages/ci/mocks/fixtures/monorepos/pnpm/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/pnpm/packages/cli/package.json b/packages/ci/mocks/fixtures/monorepos/pnpm/packages/cli/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/pnpm/packages/cli/package.json rename to packages/ci/mocks/fixtures/monorepos/pnpm/packages/cli/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/pnpm/packages/core/package.json b/packages/ci/mocks/fixtures/monorepos/pnpm/packages/core/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/pnpm/packages/core/package.json rename to packages/ci/mocks/fixtures/monorepos/pnpm/packages/core/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/pnpm/packages/utils/package.json b/packages/ci/mocks/fixtures/monorepos/pnpm/packages/utils/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/pnpm/packages/utils/package.json rename to packages/ci/mocks/fixtures/monorepos/pnpm/packages/utils/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/turbo/package.json b/packages/ci/mocks/fixtures/monorepos/turbo/_package.json similarity index 60% rename from packages/ci/mocks/fixtures/monorepos/turbo/package.json rename to packages/ci/mocks/fixtures/monorepos/turbo/_package.json index 19179f45a..c3c6d7eae 100644 --- a/packages/ci/mocks/fixtures/monorepos/turbo/package.json +++ b/packages/ci/mocks/fixtures/monorepos/turbo/_package.json @@ -1,7 +1,5 @@ { "packageManager": "yarn@1.22.19", "private": true, - "workspaces": [ - "packages/*" - ] + "workspaces": ["packages/*"] } diff --git a/packages/ci/mocks/fixtures/monorepos/turbo/packages/cli/package.json b/packages/ci/mocks/fixtures/monorepos/turbo/packages/cli/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/turbo/packages/cli/package.json rename to packages/ci/mocks/fixtures/monorepos/turbo/packages/cli/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/turbo/packages/core/package.json b/packages/ci/mocks/fixtures/monorepos/turbo/packages/core/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/turbo/packages/core/package.json rename to packages/ci/mocks/fixtures/monorepos/turbo/packages/core/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/turbo/packages/utils/package.json b/packages/ci/mocks/fixtures/monorepos/turbo/packages/utils/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/turbo/packages/utils/package.json rename to packages/ci/mocks/fixtures/monorepos/turbo/packages/utils/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/yarn/package.json b/packages/ci/mocks/fixtures/monorepos/yarn/_package.json similarity index 59% rename from packages/ci/mocks/fixtures/monorepos/yarn/package.json rename to packages/ci/mocks/fixtures/monorepos/yarn/_package.json index b9bff8df0..f5dcc539b 100644 --- a/packages/ci/mocks/fixtures/monorepos/yarn/package.json +++ b/packages/ci/mocks/fixtures/monorepos/yarn/_package.json @@ -1,7 +1,5 @@ { "packageManager": "yarn@4.5.0", "private": true, - "workspaces": [ - "packages/*" - ] + "workspaces": ["packages/*"] } diff --git a/packages/ci/mocks/fixtures/monorepos/yarn/packages/cli/package.json b/packages/ci/mocks/fixtures/monorepos/yarn/packages/cli/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/yarn/packages/cli/package.json rename to packages/ci/mocks/fixtures/monorepos/yarn/packages/cli/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/yarn/packages/core/package.json b/packages/ci/mocks/fixtures/monorepos/yarn/packages/core/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/yarn/packages/core/package.json rename to packages/ci/mocks/fixtures/monorepos/yarn/packages/core/_package.json diff --git a/packages/ci/mocks/fixtures/monorepos/yarn/packages/utils/package.json b/packages/ci/mocks/fixtures/monorepos/yarn/packages/utils/_package.json similarity index 100% rename from packages/ci/mocks/fixtures/monorepos/yarn/packages/utils/package.json rename to packages/ci/mocks/fixtures/monorepos/yarn/packages/utils/_package.json diff --git a/packages/ci/src/lib/run.int.test.ts b/packages/ci/src/lib/run.int.test.ts index 0a43e01ba..4d15f0dfc 100644 --- a/packages/ci/src/lib/run.int.test.ts +++ b/packages/ci/src/lib/run.int.test.ts @@ -21,8 +21,10 @@ import { DEFAULT_PERSIST_SKIP_REPORT, } from '@code-pushup/models'; import { + NX_IGNORED_FILES_TO_RESTORE, cleanTestFolder, initGitRepo, + restoreRenamedFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -624,6 +626,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', tool); await cp(monorepoDir, workDir, { recursive: true }); + await restoreRenamedFiles(workDir, NX_IGNORED_FILES_TO_RESTORE); await git.add('.'); await git.commit(`Create packages in ${tool} monorepo`); setup?.(); @@ -1137,6 +1140,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', 'custom'); await cp(monorepoDir, workDir, { recursive: true }); + await restoreRenamedFiles(workDir, NX_IGNORED_FILES_TO_RESTORE); await git.add('.'); await git.commit('Create projects in monorepo'); }); diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/todos-app/package.json b/packages/plugin-eslint/mocks/fixtures/todos-app/_package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/todos-app/package.json rename to packages/plugin-eslint/mocks/fixtures/todos-app/_package.json diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.ts b/testing/test-utils/src/lib/utils/test-folder-setup.ts index 8e3853011..7d951fe40 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.ts @@ -1,5 +1,6 @@ import { bold } from 'ansis'; -import { mkdir, rm, stat } from 'node:fs/promises'; +import { mkdir, readdir, rename, rm, stat } from 'node:fs/promises'; +import path from 'node:path'; export async function cleanTestFolder(dirName: string) { await teardownTestFolder(dirName); @@ -36,3 +37,46 @@ export async function teardownTestFolder(dirName: string) { ); } } + +/** + * File names that need to be restored by removing the "_" prefix. + * These files are prefixed with "_" in mock fixtures to avoid Nx detection. + */ +export const NX_IGNORED_FILES_TO_RESTORE = [ + '_package.json', + '_nx.json', + '_project.json', +] as const; + +/** + * Recursively renames specific files by removing the "_" prefix. + * This is needed because mock fixtures have "_" prefix to avoid Nx detection, + * but tests need the original filenames. + * + * @param dir - Directory to process recursively + * @param fileNames - Array of file names to restore (e.g., ['_package.json', '_nx.json', '_project.json']) + */ +export async function restoreRenamedFiles( + dir: string, + fileNames: readonly string[], +): Promise { + try { + const entries = await readdir(dir, { withFileTypes: true }); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + await restoreRenamedFiles(fullPath, fileNames); + } else if (entry.isFile() && fileNames.includes(entry.name)) { + const newName = entry.name.slice(1); // Remove leading "_" + const newPath = path.join(dir, newName); + try { + await rename(fullPath, newPath); + } catch (error) { + // Ignore errors if file doesn't exist or can't be renamed + } + } + } + } catch (error) { + // Ignore errors if directory doesn't exist + } +} From cc308d374b704701b7c277804d095c518c85f2b6 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 18:25:05 +0100 Subject: [PATCH 02/17] refactor: fix file names --- e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index fd70eac00..d8a814183 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -6,9 +6,11 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, + NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, + restoreRenamedFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -24,6 +26,7 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => { beforeAll(async () => { await cp(fixtureDir, testFileDir, { recursive: true }); + await restoreRenamedFiles(testFileDir, NX_IGNORED_FILES_TO_RESTORE); await initGitRepo(simpleGit, { baseDir: basicDir }); await initGitRepo(simpleGit, { baseDir: existingDir }); }); From f8c65aeae97ff68ed31775a2b263f27f266c12e3 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 18:29:08 +0100 Subject: [PATCH 03/17] refactor: fix file names 2 --- packages/plugin-eslint/src/lib/meta/rules.int.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts index 6526243d7..0da8585ef 100644 --- a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts +++ b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts @@ -1,6 +1,10 @@ import path from 'node:path'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; +import { + NX_IGNORED_FILES_TO_RESTORE, + restoreRenamedFiles, +} from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; import { listRules } from './rules.js'; @@ -95,7 +99,8 @@ describe('listRules', () => { const patterns = ['packages/utils/**/*.ts', 'packages/utils/**/*.json']; const targets: ESLintTarget[] = [{ eslintrc, patterns }]; - beforeAll(() => { + beforeAll(async () => { + await restoreRenamedFiles(nxRootDir, NX_IGNORED_FILES_TO_RESTORE); cwdSpy.mockReturnValue(nxRootDir); }); From 78ca28fa45c0ee6142f1d4e3761a1805853f4202 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 18:57:54 +0100 Subject: [PATCH 04/17] refactor: fix file names 3 --- .../src/lib/meta/rules.int.test.ts | 25 +++++++++-- .../src/lib/utils/test-folder-setup.ts | 42 +++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts index 0da8585ef..a3ac0b60c 100644 --- a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts +++ b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts @@ -1,9 +1,11 @@ +import { cp } from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; import { NX_IGNORED_FILES_TO_RESTORE, restoreRenamedFiles, + teardownTestFolder, } from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; @@ -93,15 +95,30 @@ describe('listRules', () => { }); describe('Nx monorepo project', () => { - const nxRootDir = path.join(fixturesDir, 'nx-monorepo'); - const eslintrc = path.join(nxRootDir, 'packages/utils/eslint.config.js'); + const fixtureNxMonorepoDir = path.join(fixturesDir, 'nx-monorepo'); + const testNxMonorepoDir = path.join( + process.cwd(), + 'tmp', + 'plugin-eslint', + 'rules-test', + 'nx-monorepo', + ); + const eslintrc = path.join( + testNxMonorepoDir, + 'packages/utils/eslint.config.js', + ); const patterns = ['packages/utils/**/*.ts', 'packages/utils/**/*.json']; const targets: ESLintTarget[] = [{ eslintrc, patterns }]; beforeAll(async () => { - await restoreRenamedFiles(nxRootDir, NX_IGNORED_FILES_TO_RESTORE); - cwdSpy.mockReturnValue(nxRootDir); + await cp(fixtureNxMonorepoDir, testNxMonorepoDir, { recursive: true }); + await restoreRenamedFiles(testNxMonorepoDir, NX_IGNORED_FILES_TO_RESTORE); + cwdSpy.mockReturnValue(testNxMonorepoDir); + }); + + afterAll(async () => { + await teardownTestFolder(testNxMonorepoDir); }); it('should list expected number of rules', async () => { diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.ts b/testing/test-utils/src/lib/utils/test-folder-setup.ts index 7d951fe40..b6dbeadd2 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.ts @@ -48,6 +48,15 @@ export const NX_IGNORED_FILES_TO_RESTORE = [ '_project.json', ] as const; +/** + * File names that need to be prefixed with "_" to avoid Nx detection. + */ +export const NX_IGNORED_FILES_TO_PREFIX = [ + 'package.json', + 'nx.json', + 'project.json', +] as const; + /** * Recursively renames specific files by removing the "_" prefix. * This is needed because mock fixtures have "_" prefix to avoid Nx detection, @@ -80,3 +89,36 @@ export async function restoreRenamedFiles( // Ignore errors if directory doesn't exist } } + +/** + * Recursively renames specific files by adding the "_" prefix. + * This is needed to restore files back to their prefixed state after tests, + * so they are excluded from Nx detection. + * + * @param dir - Directory to process recursively + * @param fileNames - Array of file names to prefix (e.g., ['package.json', 'nx.json', 'project.json']) + */ +export async function prefixRenamedFiles( + dir: string, + fileNames: readonly string[], +): Promise { + try { + const entries = await readdir(dir, { withFileTypes: true }); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + await prefixRenamedFiles(fullPath, fileNames); + } else if (entry.isFile() && fileNames.includes(entry.name)) { + const newName = `_${entry.name}`; + const newPath = path.join(dir, newName); + try { + await rename(fullPath, newPath); + } catch (error) { + // Ignore errors if file doesn't exist or can't be renamed + } + } + } + } catch (error) { + // Ignore errors if directory doesn't exist + } +} From 0b13ace3c58fb56312c27c133c52ce1bf0536b24 Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 20:55:33 +0100 Subject: [PATCH 05/17] refactor: ignore plugin-eslint mocks --- .nxignore | 2 +- .../nx-monorepo/{_nx.json => nx.json} | 0 .../{_package.json => package.json} | 0 .../cli/{_project.json => project.json} | 0 .../core/{_project.json => project.json} | 0 .../nx-plugin/{_project.json => project.json} | 0 .../utils/{_project.json => project.json} | 0 .../todos-app/{_package.json => package.json} | 0 .../src/lib/meta/rules.int.test.ts | 30 +++---------------- 9 files changed, 5 insertions(+), 27 deletions(-) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/{_nx.json => nx.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/{_package.json => package.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/{_project.json => project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/{_project.json => project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/{_project.json => project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/{_project.json => project.json} (100%) rename packages/plugin-eslint/mocks/fixtures/todos-app/{_package.json => package.json} (100%) diff --git a/.nxignore b/.nxignore index b001c0620..f8f30a5ec 100644 --- a/.nxignore +++ b/.nxignore @@ -31,4 +31,4 @@ # e2e/ci-e2e/mocks/fixtures/nx-monorepo # packages/ci/mocks/fixtures/monorepos/nx -# packages/plugin-eslint/mocks/fixtures/nx-monorepo +packages/plugin-eslint/mocks/fixtures/nx-monorepo diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json diff --git a/packages/plugin-eslint/mocks/fixtures/todos-app/_package.json b/packages/plugin-eslint/mocks/fixtures/todos-app/package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/todos-app/_package.json rename to packages/plugin-eslint/mocks/fixtures/todos-app/package.json diff --git a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts index a3ac0b60c..6526243d7 100644 --- a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts +++ b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts @@ -1,12 +1,6 @@ -import { cp } from 'node:fs/promises'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; -import { - NX_IGNORED_FILES_TO_RESTORE, - restoreRenamedFiles, - teardownTestFolder, -} from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; import { listRules } from './rules.js'; @@ -95,30 +89,14 @@ describe('listRules', () => { }); describe('Nx monorepo project', () => { - const fixtureNxMonorepoDir = path.join(fixturesDir, 'nx-monorepo'); - const testNxMonorepoDir = path.join( - process.cwd(), - 'tmp', - 'plugin-eslint', - 'rules-test', - 'nx-monorepo', - ); - const eslintrc = path.join( - testNxMonorepoDir, - 'packages/utils/eslint.config.js', - ); + const nxRootDir = path.join(fixturesDir, 'nx-monorepo'); + const eslintrc = path.join(nxRootDir, 'packages/utils/eslint.config.js'); const patterns = ['packages/utils/**/*.ts', 'packages/utils/**/*.json']; const targets: ESLintTarget[] = [{ eslintrc, patterns }]; - beforeAll(async () => { - await cp(fixtureNxMonorepoDir, testNxMonorepoDir, { recursive: true }); - await restoreRenamedFiles(testNxMonorepoDir, NX_IGNORED_FILES_TO_RESTORE); - cwdSpy.mockReturnValue(testNxMonorepoDir); - }); - - afterAll(async () => { - await teardownTestFolder(testNxMonorepoDir); + beforeAll(() => { + cwdSpy.mockReturnValue(nxRootDir); }); it('should list expected number of rules', async () => { From 33edf3f0ffb7ab89e01a56957eaa2a6f2b43078f Mon Sep 17 00:00:00 2001 From: John Doe Date: Sun, 9 Nov 2025 23:39:13 +0100 Subject: [PATCH 06/17] refactor: add comment fos TODO --- .nxignore | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/.nxignore b/.nxignore index f8f30a5ec..1e023ac00 100644 --- a/.nxignore +++ b/.nxignore @@ -1,34 +1,3 @@ -# exclude mock Nx monorepos used for testing -# mocks - -# explicit paths excluded by "mocks" glob -# e2e/ci-e2e/mocks -# e2e/cli-e2e/mocks -# e2e/nx-plugin-e2e/mocks -# e2e/packages/ci/mocks -# e2e/packages/cli/mocks -# e2e/packages/plugin-coverage/mocks -# e2e/packages/plugin-eslint/mocks -# e2e/packages/plugin-jsdocs/mocks -# e2e/packages/plugin-typescript/mocks -# e2e/packages/utils/mocks -# e2e/plugin-coverage-e2e/mocks -# e2e/plugin-eslint-e2e/mocks -# e2e/plugin-js-packages-e2e/mocks -# e2e/plugin-jsdocs-e2e/mocks -# e2e/plugin-lighthouse-e2e/mocks -# e2e/plugin-typescript-e2e/mocks -# examples/plugins/mocks -# packages/ci/mocks -# packages/cli/mocks -# packages/plugin-coverage/mocks -# packages/plugin-eslint/mocks -# packages/plugin-jsdocs/mocks -# packages/plugin-typescript/mocks -# packages/utils/mocks - -# explicit paths excluded containing Nx workspace mock assets - -# e2e/ci-e2e/mocks/fixtures/nx-monorepo -# packages/ci/mocks/fixtures/monorepos/nx +# HACK: exclude mock Nx monorepos used for testing (this makes test working but changed in our mocks are ignored and don't invalidate caching) +# @TODO prefix Nx related files with "_" (not detected by Nx or test) and copy/rename them under folder `tmp` (excluded by Nx, detected by test) see #1102 packages/plugin-eslint/mocks/fixtures/nx-monorepo From a94e27d6e61ac010018b9d923d6ba974d15b6e6a Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 12:43:55 +0100 Subject: [PATCH 07/17] refactor: add unit tests to restoreNxIgnoredFiles --- .../src/lib/utils/test-folder-setup.ts | 79 ++------- .../lib/utils/test-folder-setup.unit.test.ts | 155 ++++++++++++++++++ 2 files changed, 168 insertions(+), 66 deletions(-) create mode 100644 testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.ts b/testing/test-utils/src/lib/utils/test-folder-setup.ts index b6dbeadd2..6e7e47518 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.ts @@ -42,20 +42,11 @@ export async function teardownTestFolder(dirName: string) { * File names that need to be restored by removing the "_" prefix. * These files are prefixed with "_" in mock fixtures to avoid Nx detection. */ -export const NX_IGNORED_FILES_TO_RESTORE = [ +export const NX_IGNORED_FILES_TO_RESTORE: string[] = [ '_package.json', '_nx.json', '_project.json', -] as const; - -/** - * File names that need to be prefixed with "_" to avoid Nx detection. - */ -export const NX_IGNORED_FILES_TO_PREFIX = [ - 'package.json', - 'nx.json', - 'project.json', -] as const; +]; /** * Recursively renames specific files by removing the "_" prefix. @@ -63,62 +54,18 @@ export const NX_IGNORED_FILES_TO_PREFIX = [ * but tests need the original filenames. * * @param dir - Directory to process recursively - * @param fileNames - Array of file names to restore (e.g., ['_package.json', '_nx.json', '_project.json']) */ -export async function restoreRenamedFiles( - dir: string, - fileNames: readonly string[], -): Promise { - try { - const entries = await readdir(dir, { withFileTypes: true }); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - await restoreRenamedFiles(fullPath, fileNames); - } else if (entry.isFile() && fileNames.includes(entry.name)) { - const newName = entry.name.slice(1); // Remove leading "_" - const newPath = path.join(dir, newName); - try { - await rename(fullPath, newPath); - } catch (error) { - // Ignore errors if file doesn't exist or can't be renamed - } - } - } - } catch (error) { - // Ignore errors if directory doesn't exist - } -} - -/** - * Recursively renames specific files by adding the "_" prefix. - * This is needed to restore files back to their prefixed state after tests, - * so they are excluded from Nx detection. - * - * @param dir - Directory to process recursively - * @param fileNames - Array of file names to prefix (e.g., ['package.json', 'nx.json', 'project.json']) - */ -export async function prefixRenamedFiles( - dir: string, - fileNames: readonly string[], -): Promise { - try { - const entries = await readdir(dir, { withFileTypes: true }); - for (const entry of entries) { - const fullPath = path.join(dir, entry.name); - if (entry.isDirectory()) { - await prefixRenamedFiles(fullPath, fileNames); - } else if (entry.isFile() && fileNames.includes(entry.name)) { - const newName = `_${entry.name}`; - const newPath = path.join(dir, newName); - try { - await rename(fullPath, newPath); - } catch (error) { - // Ignore errors if file doesn't exist or can't be renamed - } - } +export async function restoreNxIgnoredFiles(dir: string): Promise { + const entries = await readdir(dir, { withFileTypes: true }); + for (const entry of entries) { + const fullPath = path.join(dir, entry.name); + if (entry.isDirectory()) { + await restoreNxIgnoredFiles(fullPath); + } else if ( + entry.isFile() && + NX_IGNORED_FILES_TO_RESTORE.includes(entry.name) + ) { + await rename(fullPath, path.join(dir, entry.name.slice(1))); } - } catch (error) { - // Ignore errors if directory doesn't exist } } diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts new file mode 100644 index 000000000..75c83ed4c --- /dev/null +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -0,0 +1,155 @@ +import { bold } from 'ansis'; +import { vol } from 'memfs'; +import * as fsPromises from 'node:fs/promises'; +import { describe, expect, it, vi } from 'vitest'; +import { MEMFS_VOLUME } from '@code-pushup/test-utils'; +import { + cleanTestFolder, + restoreNxIgnoredFiles, + teardownTestFolder, +} from './test-folder-setup.js'; + +describe('restoreNxIgnoredFiles', () => { + it('should rename Nx ignored files in a folder', async () => { + vol.fromJSON( + { + '/_nx.json': '{}', + '/_package.json': '{}', + '/_project.json': '{}', + }, + MEMFS_VOLUME, + ); + + await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); + + expect(vol.existsSync('/nx.json')).toBe(true); + expect(vol.existsSync('/_nx.json')).toBe(false); + expect(vol.existsSync('/package.json')).toBe(true); + expect(vol.existsSync('/_package.json')).toBe(false); + expect(vol.existsSync('/project.json')).toBe(true); + expect(vol.existsSync('/_project.json')).toBe(false); + }); + + it('should throw if target folder does not exist', async () => { + vol.fromJSON({}, MEMFS_VOLUME); + + await expect(restoreNxIgnoredFiles('/non-existent')).rejects.toThrow( + "ENOENT: no such file or directory, readdir '/non-existent'", + ); + }); + + it('should rename Nx ignored files in nested folders', async () => { + vol.fromJSON( + { + '/workspaces/workspace1/_nx.json': '{}', + '/workspaces/workspace1/_package.json': '{}', + '/workspaces/workspace1/lib1/_project.json': '{}', + }, + MEMFS_VOLUME, + ); + + await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); + + expect(vol.existsSync('/workspaces/workspace1/nx.json')).toBe(true); + expect(vol.existsSync('/workspaces/workspace1/_nx.json')).toBe(false); + expect(vol.existsSync('/workspaces/workspace1/package.json')).toBe(true); + expect(vol.existsSync('/workspaces/workspace1/_package.json')).toBe(false); + expect(vol.existsSync('/workspaces/workspace1/lib1/project.json')).toBe( + true, + ); + expect(vol.existsSync('/workspaces/workspace1/lib1/_project.json')).toBe( + false, + ); + }); +}); + +describe('cleanTestFolder', () => { + it('should clean and create a test folder', async () => { + vol.fromJSON( + { + '/tmp/unit/package.json': '{}', + }, + MEMFS_VOLUME, + ); + + await expect(cleanTestFolder('/tmp/unit')).resolves.not.toThrow(); + + expect(vol.existsSync('/tmp/unit')).toBe(true); + }); +}); + +describe('teardownTestFolder', () => { + const statSpy = vi.spyOn(fsPromises, 'stat'); + const rmSpy = vi.spyOn(fsPromises, 'rm'); + + it('should handle non-existent folder', async () => { + vol.fromJSON({}, MEMFS_VOLUME); + + statSpy.mockRejectedValue(new Error('ENOENT: no such file or directory')); + + await expect(teardownTestFolder('/tmp/unit')).resolves.not.toThrow(); + }); + + it('should delete existing directory', async () => { + statSpy.mockResolvedValue({ + isDirectory: () => true, + } as Awaited>); + rmSpy.mockResolvedValue(undefined); + + await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); + + expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); + expect(rmSpy).toHaveBeenCalledWith('/tmp/unit', { + recursive: true, + force: true, + maxRetries: 2, + retryDelay: 100, + }); + }); + + it('should warn when path is a file instead of directory', async () => { + statSpy.mockResolvedValue({ + isDirectory: () => false, + } as Awaited>); + rmSpy.mockResolvedValue(undefined); + + await expect(teardownTestFolder('/tmp/unit/package.json')).resolves.toEqual( + undefined, + ); + + expect(statSpy).toHaveBeenCalledWith('/tmp/unit/package.json'); + expect(console.warn).toHaveBeenCalledWith( + `⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`, + ); + }); + + it('should ignore stat failure', async () => { + statSpy.mockResolvedValue({ + isDirectory: () => true, + } as Awaited>); + + await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); + + expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); + }); + + it('should handle deletion failure', async () => { + statSpy.mockResolvedValue({ + isDirectory: () => true, + } as Awaited>); + rmSpy.mockRejectedValue(new Error('Deletion failed')); + + await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); + + expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); + expect(rmSpy).toHaveBeenCalledWith('/tmp/unit', { + recursive: true, + force: true, + maxRetries: 2, + retryDelay: 100, + }); + expect(console.warn).toHaveBeenCalledWith( + `⚠️ Failed to delete test artefact ${bold('/tmp/unit')} so the folder is still in the file system!\nIt may require a deletion before running e2e tests again.`, + ); + }); +}); From 5b796432ecefefdacb133d68da0b1c8f16c4fe71 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 12:46:16 +0100 Subject: [PATCH 08/17] refactor: adjust logic --- e2e/cli-e2e/tests/collect.e2e.test.ts | 5 ++--- e2e/cli-e2e/tests/compare.e2e.test.ts | 5 ++--- e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts | 5 ++--- e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts | 9 ++++----- .../tests/plugin-js-packages.e2e.test.ts | 5 ++--- e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts | 7 +++---- e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts | 5 ++--- e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts | 5 ++--- packages/ci/src/lib/run.int.test.ts | 7 +++---- 9 files changed, 22 insertions(+), 31 deletions(-) diff --git a/e2e/cli-e2e/tests/collect.e2e.test.ts b/e2e/cli-e2e/tests/collect.e2e.test.ts index af244ce0b..c0c2688f1 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -4,9 +4,8 @@ import { afterEach, beforeAll, describe, expect, it } from 'vitest'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { @@ -38,7 +37,7 @@ describe('CLI collect', () => { beforeAll(async () => { await cp(fixtureDummyDir, dummyDir, { recursive: true }); - await restoreRenamedFiles(dummyDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(dummyDir); }); afterAll(async () => { diff --git a/e2e/cli-e2e/tests/compare.e2e.test.ts b/e2e/cli-e2e/tests/compare.e2e.test.ts index b4cc9dc91..3869581f2 100644 --- a/e2e/cli-e2e/tests/compare.e2e.test.ts +++ b/e2e/cli-e2e/tests/compare.e2e.test.ts @@ -5,9 +5,8 @@ import type { ReportsDiff } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; @@ -32,7 +31,7 @@ describe('CLI compare', () => { beforeAll(async () => { await cp(fixtureDummyDir, existingDir, { recursive: true }); - await restoreRenamedFiles(existingDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(existingDir); }); afterAll(async () => { diff --git a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index d8a814183..974c258c5 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -6,11 +6,10 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -26,7 +25,7 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => { beforeAll(async () => { await cp(fixtureDir, testFileDir, { recursive: true }); - await restoreRenamedFiles(testFileDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(testFileDir); await initGitRepo(simpleGit, { baseDir: basicDir }); await initGitRepo(simpleGit, { baseDir: existingDir }); }); diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 05a071b5a..93ae1e4f9 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -5,10 +5,9 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -41,13 +40,13 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true }); + await restoreNxIgnoredFiles(flatConfigDir); await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true }); + await restoreNxIgnoredFiles(legacyConfigDir); await cp(fixturesArtifactsConfigDir, artifactsConfigDir, { recursive: true, }); - await restoreRenamedFiles(flatConfigDir, NX_IGNORED_FILES_TO_RESTORE); - await restoreRenamedFiles(legacyConfigDir, NX_IGNORED_FILES_TO_RESTORE); - await restoreRenamedFiles(artifactsConfigDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(artifactsConfigDir); }); afterAll(async () => { diff --git a/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts b/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts index 144a25d93..bec2b8129 100644 --- a/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts +++ b/e2e/plugin-js-packages-e2e/tests/plugin-js-packages.e2e.test.ts @@ -9,9 +9,8 @@ import { import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -34,7 +33,7 @@ describe('plugin-js-packages', () => { beforeAll(async () => { await cp(fixturesNPMDir, npmRepoDir, { recursive: true }); - await restoreRenamedFiles(npmRepoDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(npmRepoDir); }); afterAll(async () => { diff --git a/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts b/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts index 0ad88474e..5f38a5422 100644 --- a/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts @@ -6,11 +6,10 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -38,8 +37,8 @@ describe('PLUGIN collect report with jsdocs-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesAngularDir, angularDir, { recursive: true }); await cp(fixturesReactDir, reactDir, { recursive: true }); - await restoreRenamedFiles(angularDir, NX_IGNORED_FILES_TO_RESTORE); - await restoreRenamedFiles(reactDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(angularDir); + await restoreNxIgnoredFiles(reactDir); await initGitRepo(simpleGit, { baseDir: angularDir }); await initGitRepo(simpleGit, { baseDir: reactDir }); }); diff --git a/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts b/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts index e05fbb936..63337fa90 100644 --- a/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts @@ -5,11 +5,10 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, removeColorCodes, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -27,7 +26,7 @@ describe('PLUGIN collect report with lighthouse-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, testFileDir, { recursive: true }); - await restoreRenamedFiles(testFileDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(testFileDir); }); afterAll(async () => { diff --git a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts index 1ab5cb7ed..c1e5af653 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -5,12 +5,11 @@ import { type Report, reportSchema } from '@code-pushup/models'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, omitVariableReportData, osAgnosticAuditOutputs, osAgnosticPath, - restoreRenamedFiles, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -52,7 +51,7 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, envRoot, { recursive: true }); - await restoreRenamedFiles(envRoot, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(envRoot); }); afterAll(async () => { diff --git a/packages/ci/src/lib/run.int.test.ts b/packages/ci/src/lib/run.int.test.ts index 4d15f0dfc..973a97044 100644 --- a/packages/ci/src/lib/run.int.test.ts +++ b/packages/ci/src/lib/run.int.test.ts @@ -21,10 +21,9 @@ import { DEFAULT_PERSIST_SKIP_REPORT, } from '@code-pushup/models'; import { - NX_IGNORED_FILES_TO_RESTORE, cleanTestFolder, initGitRepo, - restoreRenamedFiles, + restoreNxIgnoredFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -626,7 +625,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', tool); await cp(monorepoDir, workDir, { recursive: true }); - await restoreRenamedFiles(workDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(workDir); await git.add('.'); await git.commit(`Create packages in ${tool} monorepo`); setup?.(); @@ -1140,7 +1139,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', 'custom'); await cp(monorepoDir, workDir, { recursive: true }); - await restoreRenamedFiles(workDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(workDir); await git.add('.'); await git.commit('Create projects in monorepo'); }); From 6564760c728a7154e9d101a7dbc36949f693db73 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 12:46:26 +0100 Subject: [PATCH 09/17] refactor: use restoreNxIgnoredFiles --- e2e/ci-e2e/mocks/setup.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/e2e/ci-e2e/mocks/setup.ts b/e2e/ci-e2e/mocks/setup.ts index 19657d104..829cee7c8 100644 --- a/e2e/ci-e2e/mocks/setup.ts +++ b/e2e/ci-e2e/mocks/setup.ts @@ -5,10 +5,9 @@ import { simpleGit } from 'simple-git'; import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, - NX_IGNORED_FILES_TO_RESTORE, TEST_OUTPUT_DIR, initGitRepo, - restoreRenamedFiles, + restoreNxIgnoredFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -30,7 +29,7 @@ export async function setupTestRepo(folder: string) { ); await cp(fixturesDir, baseDir, { recursive: true }); - await restoreRenamedFiles(baseDir, NX_IGNORED_FILES_TO_RESTORE); + await restoreNxIgnoredFiles(baseDir); const git = await initGitRepo(simpleGit, { baseDir }); await simulateGitFetch(git); From 10534f78fd6a3158c4544aba0bd81ae3f8349227 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 13:23:00 +0100 Subject: [PATCH 10/17] refactor: copy nx-monorepo for partial refactoring --- .nxignore | 1 + .../mocks/fixtures/nx-workspace/.gitignore | 1 + .../mocks/fixtures/nx-workspace/_nx.json | 8 ++++ .../mocks/fixtures/nx-workspace/_package.json | 4 ++ .../fixtures/nx-workspace/eslint.config.js | 41 +++++++++++++++++++ .../nx-workspace/packages/cli/_project.json | 10 +++++ .../packages/cli/eslint.config.js | 19 +++++++++ .../nx-workspace/packages/cli/src/index.ts | 3 ++ .../nx-workspace/packages/cli/tsconfig.json | 3 ++ .../nx-workspace/packages/core/_project.json | 10 +++++ .../packages/core/eslint.config.js | 19 +++++++++ .../nx-workspace/packages/core/src/index.ts | 5 +++ .../nx-workspace/packages/core/tsconfig.json | 3 ++ .../packages/nx-plugin/_project.json | 10 +++++ .../packages/nx-plugin/eslint.config.js | 28 +++++++++++++ .../packages/nx-plugin/src/index.ts | 5 +++ .../packages/nx-plugin/tsconfig.json | 3 ++ .../nx-workspace/packages/utils/_project.json | 10 +++++ .../packages/utils/eslint.config.js | 19 +++++++++ .../nx-workspace/packages/utils/src/index.ts | 1 + .../nx-workspace/packages/utils/tsconfig.json | 3 ++ .../fixtures/nx-workspace/tsconfig.base.json | 25 +++++++++++ .../src/lib/eslint-plugin.int.test.ts | 16 ++++++-- 23 files changed, 243 insertions(+), 4 deletions(-) create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json create mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json diff --git a/.nxignore b/.nxignore index 1e023ac00..116c98314 100644 --- a/.nxignore +++ b/.nxignore @@ -1,3 +1,4 @@ # HACK: exclude mock Nx monorepos used for testing (this makes test working but changed in our mocks are ignored and don't invalidate caching) # @TODO prefix Nx related files with "_" (not detected by Nx or test) and copy/rename them under folder `tmp` (excluded by Nx, detected by test) see #1102 +# Note: nx-workspace uses "_" prefix pattern (like other e2e folders), so Nx won't detect it, but keeping entry for backwards compatibility packages/plugin-eslint/mocks/fixtures/nx-monorepo diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore b/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore new file mode 100644 index 000000000..f21d80021 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore @@ -0,0 +1 @@ +.nx diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json new file mode 100644 index 000000000..743dfa5bf --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json @@ -0,0 +1,8 @@ +{ + "pluginsConfig": { + "@nx/js": { + "analyzeSourceFiles": true + } + }, + "useDaemonProcess": false +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json new file mode 100644 index 000000000..0fef86e33 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json @@ -0,0 +1,4 @@ +{ + "private": true, + "type": "commonjs" +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js new file mode 100644 index 000000000..6ef27db4c --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js @@ -0,0 +1,41 @@ +const nx = require('@nx/eslint-plugin'); + +module.exports = [ + { + files: ['**/*.json'], + // Override or add rules here + rules: {}, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, + ...nx.configs['flat/base'], + ...nx.configs['flat/typescript'], + ...nx.configs['flat/javascript'], + { + ignores: ['**/dist'], + }, + { + files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + rules: { + '@nx/enforce-module-boundaries': [ + 'warn', + { + enforceBuildableLibDependency: true, + allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?js$'], + depConstraints: [ + { + sourceTag: '*', + onlyDependOnLibsWithTags: ['*'], + }, + ], + }, + ], + }, + }, + { + files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], + // Override or add rules here + rules: {}, + }, +]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json new file mode 100644 index 000000000..eb92b91ee --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json @@ -0,0 +1,10 @@ +{ + "name": "cli", + "sourceRoot": "packages/cli/src", + "projectType": "application", + "targets": { + "lint": { + "executor": "@nx/eslint:lint" + } + } +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js new file mode 100644 index 000000000..9d2af7a3d --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../eslint.config.js'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], + }, + ], + }, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, +]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts new file mode 100644 index 000000000..a51f5d7d0 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts @@ -0,0 +1,3 @@ +import { exampleCore } from '@example/core'; + +exampleCore(); diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json new file mode 100644 index 000000000..9536a0f41 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json new file mode 100644 index 000000000..c39496eb4 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json @@ -0,0 +1,10 @@ +{ + "name": "core", + "sourceRoot": "packages/core/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/eslint:lint" + } + } +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js new file mode 100644 index 000000000..9d2af7a3d --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../eslint.config.js'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], + }, + ], + }, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, +]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts new file mode 100644 index 000000000..6a00d8538 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts @@ -0,0 +1,5 @@ +import { exampleSharedUtil } from '@example/utils'; + +export function exampleCore() { + exampleSharedUtil(); +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json new file mode 100644 index 000000000..9536a0f41 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json new file mode 100644 index 000000000..7c8b0a3d7 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json @@ -0,0 +1,10 @@ +{ + "name": "nx-plugin", + "sourceRoot": "packages/nx-plugin/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/eslint:lint" + } + } +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js new file mode 100644 index 000000000..9327f3f52 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js @@ -0,0 +1,28 @@ +const baseConfig = require('../../eslint.config.js'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], + }, + ], + }, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, + { + files: ['**/package.json', '**/package.json', '**/generators.json'], + rules: { + '@nx/nx-plugin-checks': 'error', + }, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, +]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts new file mode 100644 index 000000000..d4b78efbd --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts @@ -0,0 +1,5 @@ +import { exampleSharedUtil } from '@example/utils'; + +export function exampleNxPlugin() { + exampleSharedUtil(); +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json new file mode 100644 index 000000000..9536a0f41 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json new file mode 100644 index 000000000..e13c52b59 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json @@ -0,0 +1,10 @@ +{ + "name": "utils", + "sourceRoot": "packages/utils/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nx/eslint:lint" + } + } +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js new file mode 100644 index 000000000..9d2af7a3d --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js @@ -0,0 +1,19 @@ +const baseConfig = require('../../eslint.config.js'); + +module.exports = [ + ...baseConfig, + { + files: ['**/*.json'], + rules: { + '@nx/dependency-checks': [ + 'error', + { + ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], + }, + ], + }, + languageOptions: { + parser: require('jsonc-eslint-parser'), + }, + }, +]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts new file mode 100644 index 000000000..02e4dccc0 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts @@ -0,0 +1 @@ +export function exampleSharedUtil() {} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json new file mode 100644 index 000000000..9536a0f41 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tsconfig.base.json" +} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json new file mode 100644 index 000000000..6fc9deaa6 --- /dev/null +++ b/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json @@ -0,0 +1,25 @@ +{ + "compileOnSave": false, + "compilerOptions": { + "rootDir": ".", + "sourceMap": true, + "declaration": false, + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "importHelpers": true, + "target": "ES2022", + "module": "esnext", + "lib": ["ES2022", "dom"], + "skipLibCheck": true, + "skipDefaultLibCheck": true, + "baseUrl": ".", + "paths": { + "@example/cli": ["packages/cli/src/index.ts"], + "@example/core": ["packages/core/src/index.ts"], + "@example/nx-plugin": ["packages/nx-plugin/src/index.ts"], + "@example/utils": ["packages/utils/src/index.ts"] + } + }, + "exclude": ["node_modules", "tmp"] +} diff --git a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts index 02273d462..b5ae1631b 100644 --- a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts +++ b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts @@ -1,21 +1,29 @@ import ansis from 'ansis'; +import { cp } from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; import type { Audit } from '@code-pushup/models'; +import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; import { eslintPlugin } from './eslint-plugin.js'; describe('eslintPlugin', () => { const thisDir = fileURLToPath(path.dirname(import.meta.url)); const fixturesDir = path.join(thisDir, '..', '..', 'mocks', 'fixtures'); - + const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint'); let cwdSpy: MockInstance<[], string>; let platformSpy: MockInstance<[], NodeJS.Platform>; - beforeAll(() => { + beforeAll(async () => { + await cp( + path.join(fixturesDir, 'nx-workspace'), + path.join(tmpDir, 'nx-workspace'), + { recursive: true }, + ); + await restoreNxIgnoredFiles(path.join(tmpDir, 'nx-workspace')); cwdSpy = vi.spyOn(process, 'cwd'); // Linux produces extra quotation marks for globs platformSpy = vi.spyOn(os, 'platform').mockReturnValue('linux'); @@ -40,7 +48,7 @@ describe('eslintPlugin', () => { }); it('should initialize ESLint plugin for Nx project', async () => { - cwdSpy.mockReturnValue(path.join(fixturesDir, 'nx-monorepo')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-workspace')); const plugin = await eslintPlugin({ eslintrc: './packages/nx-plugin/eslint.config.js', patterns: ['packages/nx-plugin/**/*.ts', 'packages/nx-plugin/**/*.json'], @@ -62,7 +70,7 @@ describe('eslintPlugin', () => { }); it('should initialize with plugin options for custom groups', async () => { - cwdSpy.mockReturnValue(path.join(fixturesDir, 'nx-monorepo')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-workspace')); const plugin = await eslintPlugin( { eslintrc: './packages/nx-plugin/eslint.config.js', From ac495623855024c67e4727f841d9c07b3a813f38 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 13:32:04 +0100 Subject: [PATCH 11/17] refactor: remove copy --- .nxignore | 4 ---- .../{nx-workspace => nx-monorepo}/_nx.json | 0 .../_package.json | 0 .../mocks/fixtures/nx-monorepo/nx.json | 8 -------- .../mocks/fixtures/nx-monorepo/package.json | 4 ---- .../packages/cli/_project.json | 0 .../nx-monorepo/packages/cli/project.json | 10 ---------- .../packages/core/_project.json | 0 .../nx-monorepo/packages/core/project.json | 10 ---------- .../packages/nx-plugin/_project.json | 0 .../packages/nx-plugin/project.json | 10 ---------- .../packages/utils/_project.json | 0 .../nx-monorepo/packages/utils/project.json | 10 ---------- .../mocks/fixtures/nx-workspace/.gitignore | 1 - .../nx-workspace/packages/cli/src/index.ts | 3 --- .../nx-workspace/packages/core/src/index.ts | 5 ----- .../packages/nx-plugin/src/index.ts | 5 ----- .../nx-workspace/packages/utils/src/index.ts | 1 - .../src/lib/eslint-plugin.int.test.ts | 10 +++++----- .../src/lib/meta/rules.int.test.ts | 12 ++++++++++-- packages/plugin-eslint/src/lib/nx.int.test.ts | 18 ++++++++++-------- 21 files changed, 25 insertions(+), 86 deletions(-) delete mode 100644 .nxignore rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/_nx.json (100%) rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/_package.json (100%) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/packages/cli/_project.json (100%) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/packages/core/_project.json (100%) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/packages/nx-plugin/_project.json (100%) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json rename packages/plugin-eslint/mocks/fixtures/{nx-workspace => nx-monorepo}/packages/utils/_project.json (100%) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts diff --git a/.nxignore b/.nxignore deleted file mode 100644 index 116c98314..000000000 --- a/.nxignore +++ /dev/null @@ -1,4 +0,0 @@ -# HACK: exclude mock Nx monorepos used for testing (this makes test working but changed in our mocks are ignored and don't invalidate caching) -# @TODO prefix Nx related files with "_" (not detected by Nx or test) and copy/rename them under folder `tmp` (excluded by Nx, detected by test) see #1102 -# Note: nx-workspace uses "_" prefix pattern (like other e2e folders), so Nx won't detect it, but keeping entry for backwards compatibility -packages/plugin-eslint/mocks/fixtures/nx-monorepo diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/_nx.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/_nx.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/_package.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/_package.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json deleted file mode 100644 index 743dfa5bf..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/nx.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "pluginsConfig": { - "@nx/js": { - "analyzeSourceFiles": true - } - }, - "useDaemonProcess": false -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json deleted file mode 100644 index 0fef86e33..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "private": true, - "type": "commonjs" -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json deleted file mode 100644 index eb92b91ee..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/cli/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "cli", - "sourceRoot": "packages/cli/src", - "projectType": "application", - "targets": { - "lint": { - "executor": "@nx/eslint:lint" - } - } -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json deleted file mode 100644 index c39496eb4..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/core/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "core", - "sourceRoot": "packages/core/src", - "projectType": "library", - "targets": { - "lint": { - "executor": "@nx/eslint:lint" - } - } -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json deleted file mode 100644 index 7c8b0a3d7..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/nx-plugin/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "nx-plugin", - "sourceRoot": "packages/nx-plugin/src", - "projectType": "library", - "targets": { - "lint": { - "executor": "@nx/eslint:lint" - } - } -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/_project.json rename to packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/_project.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json b/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json deleted file mode 100644 index e13c52b59..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-monorepo/packages/utils/project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "utils", - "sourceRoot": "packages/utils/src", - "projectType": "library", - "targets": { - "lint": { - "executor": "@nx/eslint:lint" - } - } -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore b/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore deleted file mode 100644 index f21d80021..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.nx diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts deleted file mode 100644 index a51f5d7d0..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { exampleCore } from '@example/core'; - -exampleCore(); diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts deleted file mode 100644 index 6a00d8538..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { exampleSharedUtil } from '@example/utils'; - -export function exampleCore() { - exampleSharedUtil(); -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts deleted file mode 100644 index d4b78efbd..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { exampleSharedUtil } from '@example/utils'; - -export function exampleNxPlugin() { - exampleSharedUtil(); -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts deleted file mode 100644 index 02e4dccc0..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export function exampleSharedUtil() {} diff --git a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts index b5ae1631b..537cd3f67 100644 --- a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts +++ b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts @@ -19,11 +19,11 @@ describe('eslintPlugin', () => { beforeAll(async () => { await cp( - path.join(fixturesDir, 'nx-workspace'), - path.join(tmpDir, 'nx-workspace'), + path.join(fixturesDir, 'nx-monorepo'), + path.join(tmpDir, 'nx-monorepo'), { recursive: true }, ); - await restoreNxIgnoredFiles(path.join(tmpDir, 'nx-workspace')); + await restoreNxIgnoredFiles(path.join(tmpDir, 'nx-monorepo')); cwdSpy = vi.spyOn(process, 'cwd'); // Linux produces extra quotation marks for globs platformSpy = vi.spyOn(os, 'platform').mockReturnValue('linux'); @@ -48,7 +48,7 @@ describe('eslintPlugin', () => { }); it('should initialize ESLint plugin for Nx project', async () => { - cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-workspace')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-monorepo')); const plugin = await eslintPlugin({ eslintrc: './packages/nx-plugin/eslint.config.js', patterns: ['packages/nx-plugin/**/*.ts', 'packages/nx-plugin/**/*.json'], @@ -70,7 +70,7 @@ describe('eslintPlugin', () => { }); it('should initialize with plugin options for custom groups', async () => { - cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-workspace')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'nx-monorepo')); const plugin = await eslintPlugin( { eslintrc: './packages/nx-plugin/eslint.config.js', diff --git a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts index 6526243d7..ee771c1d8 100644 --- a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts +++ b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts @@ -1,6 +1,9 @@ +import { cp } from 'node:fs/promises'; import path from 'node:path'; +import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; +import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; import { listRules } from './rules.js'; @@ -14,6 +17,7 @@ describe('listRules', () => { 'mocks', 'fixtures', ); + const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint'); let cwdSpy: MockInstance<[], string>; @@ -89,13 +93,17 @@ describe('listRules', () => { }); describe('Nx monorepo project', () => { - const nxRootDir = path.join(fixturesDir, 'nx-monorepo'); + const nxRootDir = path.join(tmpDir, 'nx-monorepo'); const eslintrc = path.join(nxRootDir, 'packages/utils/eslint.config.js'); const patterns = ['packages/utils/**/*.ts', 'packages/utils/**/*.json']; const targets: ESLintTarget[] = [{ eslintrc, patterns }]; - beforeAll(() => { + beforeAll(async () => { + await cp(path.join(fixturesDir, 'nx-monorepo'), nxRootDir, { + recursive: true, + }); + await restoreNxIgnoredFiles(nxRootDir); cwdSpy.mockReturnValue(nxRootDir); }); diff --git a/packages/plugin-eslint/src/lib/nx.int.test.ts b/packages/plugin-eslint/src/lib/nx.int.test.ts index 9ac98ee4c..026e14dff 100644 --- a/packages/plugin-eslint/src/lib/nx.int.test.ts +++ b/packages/plugin-eslint/src/lib/nx.int.test.ts @@ -1,7 +1,9 @@ +import { cp } from 'node:fs/promises'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; +import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; import { executeProcess } from '@code-pushup/utils'; import type { ESLintTarget } from './config.js'; import { eslintConfigFromNxProject } from './nx/find-project-without-deps.js'; @@ -14,17 +16,17 @@ type Project = 'cli' | 'core' | 'nx-plugin' | 'utils'; // skipping tests on Windows due to a problem with createProjectGraphAsync that hangs forever, issue seems to be connected to nested git or some other Nx graph related problem https://github.com/nrwl/nx/issues/27494#issuecomment-2633836688 describe.skipIf(process.platform === 'win32')('Nx helpers', () => { + const thisDir = fileURLToPath(path.dirname(import.meta.url)); + const fixturesDir = path.join(thisDir, '..', '..', 'mocks', 'fixtures'); + const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint'); let cwdSpy: MockInstance<[], string>; beforeAll(async () => { - const workspaceDir = path.join( - fileURLToPath(path.dirname(import.meta.url)), - '..', - '..', - 'mocks', - 'fixtures', - 'nx-monorepo', - ); + const workspaceDir = path.join(tmpDir, 'nx-monorepo'); + await cp(path.join(fixturesDir, 'nx-monorepo'), workspaceDir, { + recursive: true, + }); + await restoreNxIgnoredFiles(workspaceDir); cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(workspaceDir); // HACK: somehow prevents "Failed to process project graph" errors From 5879368bac14958f28a04a0c76d51700165e3ec4 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 13:34:43 +0100 Subject: [PATCH 12/17] refactor: remove copy 2 --- .../fixtures/nx-workspace/eslint.config.js | 41 ------------------- .../packages/cli/eslint.config.js | 19 --------- .../nx-workspace/packages/cli/tsconfig.json | 3 -- .../packages/core/eslint.config.js | 19 --------- .../nx-workspace/packages/core/tsconfig.json | 3 -- .../packages/nx-plugin/eslint.config.js | 28 ------------- .../packages/nx-plugin/tsconfig.json | 3 -- .../packages/utils/eslint.config.js | 19 --------- .../nx-workspace/packages/utils/tsconfig.json | 3 -- .../fixtures/nx-workspace/tsconfig.base.json | 25 ----------- 10 files changed, 163 deletions(-) delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json delete mode 100644 packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js deleted file mode 100644 index 6ef27db4c..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/eslint.config.js +++ /dev/null @@ -1,41 +0,0 @@ -const nx = require('@nx/eslint-plugin'); - -module.exports = [ - { - files: ['**/*.json'], - // Override or add rules here - rules: {}, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, - ...nx.configs['flat/base'], - ...nx.configs['flat/typescript'], - ...nx.configs['flat/javascript'], - { - ignores: ['**/dist'], - }, - { - files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], - rules: { - '@nx/enforce-module-boundaries': [ - 'warn', - { - enforceBuildableLibDependency: true, - allow: ['^.*/eslint(\\.base)?\\.config\\.[cm]?js$'], - depConstraints: [ - { - sourceTag: '*', - onlyDependOnLibsWithTags: ['*'], - }, - ], - }, - ], - }, - }, - { - files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'], - // Override or add rules here - rules: {}, - }, -]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js deleted file mode 100644 index 9d2af7a3d..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/eslint.config.js +++ /dev/null @@ -1,19 +0,0 @@ -const baseConfig = require('../../eslint.config.js'); - -module.exports = [ - ...baseConfig, - { - files: ['**/*.json'], - rules: { - '@nx/dependency-checks': [ - 'error', - { - ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], - }, - ], - }, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, -]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json deleted file mode 100644 index 9536a0f41..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/cli/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.base.json" -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js deleted file mode 100644 index 9d2af7a3d..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/eslint.config.js +++ /dev/null @@ -1,19 +0,0 @@ -const baseConfig = require('../../eslint.config.js'); - -module.exports = [ - ...baseConfig, - { - files: ['**/*.json'], - rules: { - '@nx/dependency-checks': [ - 'error', - { - ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], - }, - ], - }, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, -]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json deleted file mode 100644 index 9536a0f41..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/core/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.base.json" -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js deleted file mode 100644 index 9327f3f52..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/eslint.config.js +++ /dev/null @@ -1,28 +0,0 @@ -const baseConfig = require('../../eslint.config.js'); - -module.exports = [ - ...baseConfig, - { - files: ['**/*.json'], - rules: { - '@nx/dependency-checks': [ - 'error', - { - ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], - }, - ], - }, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, - { - files: ['**/package.json', '**/package.json', '**/generators.json'], - rules: { - '@nx/nx-plugin-checks': 'error', - }, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, -]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json deleted file mode 100644 index 9536a0f41..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/nx-plugin/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.base.json" -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js deleted file mode 100644 index 9d2af7a3d..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/eslint.config.js +++ /dev/null @@ -1,19 +0,0 @@ -const baseConfig = require('../../eslint.config.js'); - -module.exports = [ - ...baseConfig, - { - files: ['**/*.json'], - rules: { - '@nx/dependency-checks': [ - 'error', - { - ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs}'], - }, - ], - }, - languageOptions: { - parser: require('jsonc-eslint-parser'), - }, - }, -]; diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json deleted file mode 100644 index 9536a0f41..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/packages/utils/tsconfig.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "../../tsconfig.base.json" -} diff --git a/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json b/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json deleted file mode 100644 index 6fc9deaa6..000000000 --- a/packages/plugin-eslint/mocks/fixtures/nx-workspace/tsconfig.base.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "rootDir": ".", - "sourceMap": true, - "declaration": false, - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "importHelpers": true, - "target": "ES2022", - "module": "esnext", - "lib": ["ES2022", "dom"], - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "baseUrl": ".", - "paths": { - "@example/cli": ["packages/cli/src/index.ts"], - "@example/core": ["packages/core/src/index.ts"], - "@example/nx-plugin": ["packages/nx-plugin/src/index.ts"], - "@example/utils": ["packages/utils/src/index.ts"] - } - }, - "exclude": ["node_modules", "tmp"] -} From da0e18ecaa432f842a839db05ad8568ccd7c40b6 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 14:20:23 +0100 Subject: [PATCH 13/17] refactor: apply renaming to test-app --- .../todos-app/{package.json => _package.json} | 0 .../src/lib/eslint-plugin.int.test.ts | 18 +++++++++--- .../src/lib/meta/rules.int.test.ts | 16 ++++++++--- packages/plugin-eslint/src/lib/nx.int.test.ts | 8 ++++-- .../plugin-eslint/src/lib/runner.int.test.ts | 28 +++++++++++-------- 5 files changed, 49 insertions(+), 21 deletions(-) rename packages/plugin-eslint/mocks/fixtures/todos-app/{package.json => _package.json} (100%) diff --git a/packages/plugin-eslint/mocks/fixtures/todos-app/package.json b/packages/plugin-eslint/mocks/fixtures/todos-app/_package.json similarity index 100% rename from packages/plugin-eslint/mocks/fixtures/todos-app/package.json rename to packages/plugin-eslint/mocks/fixtures/todos-app/_package.json diff --git a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts index 537cd3f67..34ef4628f 100644 --- a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts +++ b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts @@ -6,7 +6,10 @@ import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; import type { Audit } from '@code-pushup/models'; -import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; +import { + restoreNxIgnoredFiles, + teardownTestFolder, +} from '@code-pushup/test-utils'; import { eslintPlugin } from './eslint-plugin.js'; describe('eslintPlugin', () => { @@ -24,18 +27,25 @@ describe('eslintPlugin', () => { { recursive: true }, ); await restoreNxIgnoredFiles(path.join(tmpDir, 'nx-monorepo')); + await cp( + path.join(fixturesDir, 'todos-app'), + path.join(tmpDir, 'todos-app'), + { recursive: true }, + ); + await restoreNxIgnoredFiles(path.join(tmpDir, 'todos-app')); cwdSpy = vi.spyOn(process, 'cwd'); // Linux produces extra quotation marks for globs platformSpy = vi.spyOn(os, 'platform').mockReturnValue('linux'); }); - afterAll(() => { + afterAll(async () => { cwdSpy.mockRestore(); platformSpy.mockRestore(); + await teardownTestFolder(tmpDir); }); it('should initialize ESLint plugin for React application', async () => { - cwdSpy.mockReturnValue(path.join(fixturesDir, 'todos-app')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'todos-app')); const plugin = await eslintPlugin({ eslintrc: 'eslint.config.js', @@ -148,7 +158,7 @@ describe('eslintPlugin', () => { }); it('should initialize with artifact options', async () => { - cwdSpy.mockReturnValue(path.join(fixturesDir, 'todos-app')); + cwdSpy.mockReturnValue(path.join(tmpDir, 'todos-app')); const plugin = await eslintPlugin( { eslintrc: 'eslint.config.js', diff --git a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts index ee771c1d8..9214b8999 100644 --- a/packages/plugin-eslint/src/lib/meta/rules.int.test.ts +++ b/packages/plugin-eslint/src/lib/meta/rules.int.test.ts @@ -3,7 +3,10 @@ import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; -import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; +import { + restoreNxIgnoredFiles, + teardownTestFolder, +} from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; import { listRules } from './rules.js'; @@ -25,18 +28,23 @@ describe('listRules', () => { cwdSpy = vi.spyOn(process, 'cwd'); }); - afterAll(() => { + afterAll(async () => { cwdSpy.mockRestore(); + await teardownTestFolder(tmpDir); }); describe('React app', () => { - const appRootDir = path.join(fixturesDir, 'todos-app'); + const appRootDir = path.join(tmpDir, 'todos-app'); const eslintrc = path.join(appRootDir, 'eslint.config.js'); const patterns = ['src/**/*.js', 'src/**/*.jsx']; const targets: ESLintTarget[] = [{ eslintrc, patterns }]; - beforeAll(() => { + beforeAll(async () => { + await cp(path.join(fixturesDir, 'todos-app'), appRootDir, { + recursive: true, + }); + await restoreNxIgnoredFiles(appRootDir); cwdSpy.mockReturnValue(appRootDir); }); diff --git a/packages/plugin-eslint/src/lib/nx.int.test.ts b/packages/plugin-eslint/src/lib/nx.int.test.ts index 026e14dff..efa8db941 100644 --- a/packages/plugin-eslint/src/lib/nx.int.test.ts +++ b/packages/plugin-eslint/src/lib/nx.int.test.ts @@ -3,7 +3,10 @@ import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import type { MockInstance } from 'vitest'; -import { restoreNxIgnoredFiles } from '@code-pushup/test-utils'; +import { + restoreNxIgnoredFiles, + teardownTestFolder, +} from '@code-pushup/test-utils'; import { executeProcess } from '@code-pushup/utils'; import type { ESLintTarget } from './config.js'; import { eslintConfigFromNxProject } from './nx/find-project-without-deps.js'; @@ -36,8 +39,9 @@ describe.skipIf(process.platform === 'win32')('Nx helpers', () => { }); }); - afterAll(() => { + afterAll(async () => { cwdSpy.mockRestore(); + await teardownTestFolder(tmpDir); }); describe('create config from all Nx projects', () => { diff --git a/packages/plugin-eslint/src/lib/runner.int.test.ts b/packages/plugin-eslint/src/lib/runner.int.test.ts index 865724d9f..a8c3f4a25 100644 --- a/packages/plugin-eslint/src/lib/runner.int.test.ts +++ b/packages/plugin-eslint/src/lib/runner.int.test.ts @@ -1,3 +1,4 @@ +import { cp } from 'node:fs/promises'; import os from 'node:os'; import path from 'node:path'; import process from 'node:process'; @@ -10,7 +11,11 @@ import { DEFAULT_PERSIST_CONFIG, type Issue, } from '@code-pushup/models'; -import { osAgnosticAuditOutputs } from '@code-pushup/test-utils'; +import { + osAgnosticAuditOutputs, + restoreNxIgnoredFiles, + teardownTestFolder, +} from '@code-pushup/test-utils'; import type { ESLintTarget } from './config.js'; import { listAuditsAndGroups } from './meta/index.js'; import { createRunnerFunction } from './runner/index.js'; @@ -28,24 +33,25 @@ describe('executeRunner', () => { return { audits, targets }; }; - const appDir = path.join( - fileURLToPath(path.dirname(import.meta.url)), - '..', - '..', - 'mocks', - 'fixtures', - 'todos-app', - ); + const thisDir = fileURLToPath(path.dirname(import.meta.url)); + const fixturesDir = path.join(thisDir, '..', '..', 'mocks', 'fixtures'); + const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint'); + const appDir = path.join(tmpDir, 'todos-app'); - beforeAll(() => { + beforeAll(async () => { + await cp(path.join(fixturesDir, 'todos-app'), appDir, { + recursive: true, + }); + await restoreNxIgnoredFiles(appDir); cwdSpy = vi.spyOn(process, 'cwd').mockReturnValue(appDir); // Windows does not require additional quotation marks for globs platformSpy = vi.spyOn(os, 'platform').mockReturnValue('win32'); }); - afterAll(() => { + afterAll(async () => { cwdSpy.mockRestore(); platformSpy.mockRestore(); + await teardownTestFolder(tmpDir); }); it('should execute ESLint and create audit results for React application', async () => { From 8ae5322a1d99016820dc13cb724af9070b8b2433 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 15:08:15 +0100 Subject: [PATCH 14/17] refactor: improve tests --- .../lib/utils/test-folder-setup.unit.test.ts | 58 +++++++++++++------ 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts index 75c83ed4c..65cf97e4e 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -10,6 +10,32 @@ import { } from './test-folder-setup.js'; describe('restoreNxIgnoredFiles', () => { + it('should rename Nx ignored files target folder and keep the rest unchanged', async () => { + vol.fromJSON( + { + '/_nx.json': '', + '/_package.json': '', + '/_project.json': '', + '/projects/lib1/_package.json': '', + '/projects/lib1/_project.json': '', + '/projects/lib2/_package.json': '', + '/projects/lib2/_project.json': '', + }, + MEMFS_VOLUME, + ); + + await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); + + expect(vol.toJSON()).toStrictEqual({ + '/nx.json': '', + '/package.json': '', + '/project.json': '', + '/projects/lib1/package.json': '', + '/projects/lib1/project.json': '', + '/projects/lib2/package.json': '', + '/projects/lib2/project.json': '', + }); + }); it('should rename Nx ignored files in a folder', async () => { vol.fromJSON( { @@ -22,12 +48,11 @@ describe('restoreNxIgnoredFiles', () => { await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); - expect(vol.existsSync('/nx.json')).toBe(true); - expect(vol.existsSync('/_nx.json')).toBe(false); - expect(vol.existsSync('/package.json')).toBe(true); - expect(vol.existsSync('/_package.json')).toBe(false); - expect(vol.existsSync('/project.json')).toBe(true); - expect(vol.existsSync('/_project.json')).toBe(false); + expect(vol.toJSON()).toStrictEqual({ + '/nx.json': '', + '/package.json': '', + '/project.json': '', + }); }); it('should throw if target folder does not exist', async () => { @@ -41,25 +66,20 @@ describe('restoreNxIgnoredFiles', () => { it('should rename Nx ignored files in nested folders', async () => { vol.fromJSON( { - '/workspaces/workspace1/_nx.json': '{}', - '/workspaces/workspace1/_package.json': '{}', - '/workspaces/workspace1/lib1/_project.json': '{}', + '/workspaces/workspace1/_nx.json': '', + '/workspaces/workspace1/_package.json': '', + '/workspaces/workspace1/lib1/_project.json': '', }, MEMFS_VOLUME, ); await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); - expect(vol.existsSync('/workspaces/workspace1/nx.json')).toBe(true); - expect(vol.existsSync('/workspaces/workspace1/_nx.json')).toBe(false); - expect(vol.existsSync('/workspaces/workspace1/package.json')).toBe(true); - expect(vol.existsSync('/workspaces/workspace1/_package.json')).toBe(false); - expect(vol.existsSync('/workspaces/workspace1/lib1/project.json')).toBe( - true, - ); - expect(vol.existsSync('/workspaces/workspace1/lib1/_project.json')).toBe( - false, - ); + expect(vol.toJSON()).toStrictEqual({ + '/workspaces/workspace1/nx.json': '', + '/workspaces/workspace1/package.json': '', + '/workspaces/workspace1/lib1/project.json': '', + }); }); }); From 6c55a2fc7158fcf8a444e418bcbd925c932a0b0d Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 15:18:12 +0100 Subject: [PATCH 15/17] refactor: improve tests --- .../lib/utils/test-folder-setup.unit.test.ts | 84 +++++++------------ 1 file changed, 28 insertions(+), 56 deletions(-) diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts index 65cf97e4e..de4ac9081 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -1,6 +1,5 @@ import { bold } from 'ansis'; import { vol } from 'memfs'; -import * as fsPromises from 'node:fs/promises'; import { describe, expect, it, vi } from 'vitest'; import { MEMFS_VOLUME } from '@code-pushup/test-utils'; import { @@ -39,9 +38,9 @@ describe('restoreNxIgnoredFiles', () => { it('should rename Nx ignored files in a folder', async () => { vol.fromJSON( { - '/_nx.json': '{}', - '/_package.json': '{}', - '/_project.json': '{}', + '/_nx.json': '', + '/_package.json': '', + '/_project.json': '', }, MEMFS_VOLUME, ); @@ -87,7 +86,7 @@ describe('cleanTestFolder', () => { it('should clean and create a test folder', async () => { vol.fromJSON( { - '/tmp/unit/package.json': '{}', + '/tmp/unit/package.json': '', }, MEMFS_VOLUME, ); @@ -99,77 +98,50 @@ describe('cleanTestFolder', () => { }); describe('teardownTestFolder', () => { - const statSpy = vi.spyOn(fsPromises, 'stat'); - const rmSpy = vi.spyOn(fsPromises, 'rm'); - it('should handle non-existent folder', async () => { vol.fromJSON({}, MEMFS_VOLUME); - statSpy.mockRejectedValue(new Error('ENOENT: no such file or directory')); - await expect(teardownTestFolder('/tmp/unit')).resolves.not.toThrow(); + + expect(vol.toJSON()).toStrictEqual({}); }); it('should delete existing directory', async () => { - statSpy.mockResolvedValue({ - isDirectory: () => true, - } as Awaited>); - rmSpy.mockResolvedValue(undefined); + vol.fromJSON( + { + '/tmp/unit/package.json': '', + '/tmp/unit/src/index.ts': '', + '/tmp/unit/README.md': '', + }, + MEMFS_VOLUME, + ); await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); - expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); - expect(rmSpy).toHaveBeenCalledWith('/tmp/unit', { - recursive: true, - force: true, - maxRetries: 2, - retryDelay: 100, + // memfs represents empty directories as null, so /tmp remains as null after deletion + expect(vol.toJSON()).toStrictEqual({ + '/tmp': null, }); }); it('should warn when path is a file instead of directory', async () => { - statSpy.mockResolvedValue({ - isDirectory: () => false, - } as Awaited>); - rmSpy.mockResolvedValue(undefined); + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}); + vol.fromJSON( + { + '/tmp/unit/package.json': '', + }, + MEMFS_VOLUME, + ); await expect(teardownTestFolder('/tmp/unit/package.json')).resolves.toEqual( undefined, ); - expect(statSpy).toHaveBeenCalledWith('/tmp/unit/package.json'); - expect(console.warn).toHaveBeenCalledWith( - `⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`, - ); - }); - - it('should ignore stat failure', async () => { - statSpy.mockResolvedValue({ - isDirectory: () => true, - } as Awaited>); - - await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); - - expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); - }); - - it('should handle deletion failure', async () => { - statSpy.mockResolvedValue({ - isDirectory: () => true, - } as Awaited>); - rmSpy.mockRejectedValue(new Error('Deletion failed')); - - await expect(teardownTestFolder('/tmp/unit')).resolves.toEqual(undefined); - - expect(statSpy).toHaveBeenCalledWith('/tmp/unit'); - expect(rmSpy).toHaveBeenCalledWith('/tmp/unit', { - recursive: true, - force: true, - maxRetries: 2, - retryDelay: 100, + expect(vol.toJSON()).toStrictEqual({ + '/tmp/unit': null, }); - expect(console.warn).toHaveBeenCalledWith( - `⚠️ Failed to delete test artefact ${bold('/tmp/unit')} so the folder is still in the file system!\nIt may require a deletion before running e2e tests again.`, + expect(warnSpy).toHaveBeenCalledWith( + `⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`, ); }); }); From 13b84bad3c9ad4bb1b70af9fc84de2845bc37a50 Mon Sep 17 00:00:00 2001 From: John Doe Date: Mon, 10 Nov 2025 15:21:09 +0100 Subject: [PATCH 16/17] refactor: improve tests 2 --- .../test-utils/src/lib/utils/test-folder-setup.unit.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts index de4ac9081..ba9a70ad1 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -93,7 +93,9 @@ describe('cleanTestFolder', () => { await expect(cleanTestFolder('/tmp/unit')).resolves.not.toThrow(); - expect(vol.existsSync('/tmp/unit')).toBe(true); + expect(vol.toJSON()).toStrictEqual({ + '/tmp/unit': null, + }); }); }); From 6dff5a743c8eeadf938147fc6c0388b2a25b356f Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Mon, 10 Nov 2025 15:26:18 +0100 Subject: [PATCH 17/17] Update testing/test-utils/src/lib/utils/test-folder-setup.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> --- testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts index ba9a70ad1..a205d23b5 100644 --- a/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -35,6 +35,7 @@ describe('restoreNxIgnoredFiles', () => { '/projects/lib2/project.json': '', }); }); + it('should rename Nx ignored files in a folder', async () => { vol.fromJSON( {