diff --git a/.nxignore b/.nxignore deleted file mode 100644 index ec58c2555..000000000 --- a/.nxignore +++ /dev/null @@ -1,2 +0,0 @@ -# exclude mock Nx monorepos used for testing -mocks 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..829cee7c8 100644 --- a/e2e/ci-e2e/mocks/setup.ts +++ b/e2e/ci-e2e/mocks/setup.ts @@ -7,6 +7,7 @@ import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, initGitRepo, + restoreNxIgnoredFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -28,6 +29,7 @@ export async function setupTestRepo(folder: string) { ); await cp(fixturesDir, baseDir, { recursive: true }); + await restoreNxIgnoredFiles(baseDir); 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..c0c2688f1 100644 --- a/e2e/cli-e2e/tests/collect.e2e.test.ts +++ b/e2e/cli-e2e/tests/collect.e2e.test.ts @@ -5,6 +5,7 @@ import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { @@ -36,6 +37,7 @@ describe('CLI collect', () => { beforeAll(async () => { await cp(fixtureDummyDir, dummyDir, { recursive: true }); + 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 4108d9b9e..3869581f2 100644 --- a/e2e/cli-e2e/tests/compare.e2e.test.ts +++ b/e2e/cli-e2e/tests/compare.e2e.test.ts @@ -6,6 +6,7 @@ import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile, readTextFile } from '@code-pushup/utils'; @@ -30,6 +31,7 @@ describe('CLI compare', () => { beforeAll(async () => { await cp(fixtureDummyDir, existingDir, { recursive: true }); + await restoreNxIgnoredFiles(existingDir); }); 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-coverage-e2e/tests/collect.e2e.test.ts b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts index fd70eac00..974c258c5 100644 --- a/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-coverage-e2e/tests/collect.e2e.test.ts @@ -9,6 +9,7 @@ import { TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -24,6 +25,7 @@ describe('PLUGIN collect report with coverage-plugin NPM package', () => { beforeAll(async () => { await cp(fixtureDir, testFileDir, { recursive: true }); + 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 bbfada16a..93ae1e4f9 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -7,6 +7,7 @@ import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, omitVariableReportData, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -39,10 +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 restoreNxIgnoredFiles(artifactsConfigDir); }); 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..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 @@ -10,6 +10,7 @@ import { nxTargetProject } from '@code-pushup/test-nx-utils'; import { E2E_ENVIRONMENTS_DIR, TEST_OUTPUT_DIR, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -32,6 +33,7 @@ describe('plugin-js-packages', () => { beforeAll(async () => { await cp(fixturesNPMDir, npmRepoDir, { recursive: true }); + 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 dc94cdfbe..5f38a5422 100644 --- a/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-jsdocs-e2e/tests/collect.e2e.test.ts @@ -9,6 +9,7 @@ import { TEST_OUTPUT_DIR, initGitRepo, omitVariableReportData, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -36,6 +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 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 e1c255e70..63337fa90 100644 --- a/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-lighthouse-e2e/tests/collect.e2e.test.ts @@ -8,6 +8,7 @@ import { TEST_OUTPUT_DIR, omitVariableReportData, removeColorCodes, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -25,6 +26,7 @@ describe('PLUGIN collect report with lighthouse-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, testFileDir, { recursive: true }); + 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 1d3766c37..c1e5af653 100644 --- a/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-typescript-e2e/tests/collect.e2e.test.ts @@ -9,6 +9,7 @@ import { omitVariableReportData, osAgnosticAuditOutputs, osAgnosticPath, + restoreNxIgnoredFiles, teardownTestFolder, } from '@code-pushup/test-utils'; import { executeProcess, readJsonFile } from '@code-pushup/utils'; @@ -50,6 +51,7 @@ describe('PLUGIN collect report with typescript-plugin NPM package', () => { beforeAll(async () => { await cp(fixturesDir, envRoot, { recursive: true }); + await restoreNxIgnoredFiles(envRoot); }); 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..973a97044 100644 --- a/packages/ci/src/lib/run.int.test.ts +++ b/packages/ci/src/lib/run.int.test.ts @@ -23,6 +23,7 @@ import { import { cleanTestFolder, initGitRepo, + restoreNxIgnoredFiles, simulateGitFetch, teardownTestFolder, } from '@code-pushup/test-utils'; @@ -624,6 +625,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', tool); await cp(monorepoDir, workDir, { recursive: true }); + await restoreNxIgnoredFiles(workDir); await git.add('.'); await git.commit(`Create packages in ${tool} monorepo`); setup?.(); @@ -1137,6 +1139,7 @@ describe('runInCI', () => { beforeEach(async () => { const monorepoDir = path.join(fixturesDir, 'monorepos', 'custom'); await cp(monorepoDir, workDir, { recursive: true }); + await restoreNxIgnoredFiles(workDir); 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/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts index 02273d462..34ef4628f 100644 --- a/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts +++ b/packages/plugin-eslint/src/lib/eslint-plugin.int.test.ts @@ -1,33 +1,51 @@ 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, + teardownTestFolder, +} 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-monorepo'), + path.join(tmpDir, 'nx-monorepo'), + { 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', @@ -40,7 +58,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-monorepo')); const plugin = await eslintPlugin({ eslintrc: './packages/nx-plugin/eslint.config.js', patterns: ['packages/nx-plugin/**/*.ts', 'packages/nx-plugin/**/*.json'], @@ -62,7 +80,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-monorepo')); const plugin = await eslintPlugin( { eslintrc: './packages/nx-plugin/eslint.config.js', @@ -140,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 6526243d7..9214b8999 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,12 @@ +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, + teardownTestFolder, +} from '@code-pushup/test-utils'; import type { ESLintTarget } from '../config.js'; import type { RuleData } from './parse.js'; import { listRules } from './rules.js'; @@ -14,6 +20,7 @@ describe('listRules', () => { 'mocks', 'fixtures', ); + const tmpDir = path.join(process.cwd(), 'tmp', 'int', 'plugin-eslint'); let cwdSpy: MockInstance<[], string>; @@ -21,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); }); @@ -89,13 +101,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..efa8db941 100644 --- a/packages/plugin-eslint/src/lib/nx.int.test.ts +++ b/packages/plugin-eslint/src/lib/nx.int.test.ts @@ -1,7 +1,12 @@ +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, + 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'; @@ -14,17 +19,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 @@ -34,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 () => { 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..6e7e47518 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,35 @@ 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: string[] = [ + '_package.json', + '_nx.json', + '_project.json', +]; + +/** + * 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 + */ +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))); + } + } +} 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..a205d23b5 --- /dev/null +++ b/testing/test-utils/src/lib/utils/test-folder-setup.unit.test.ts @@ -0,0 +1,150 @@ +import { bold } from 'ansis'; +import { vol } from 'memfs'; +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 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( + { + '/_nx.json': '', + '/_package.json': '', + '/_project.json': '', + }, + MEMFS_VOLUME, + ); + + await expect(restoreNxIgnoredFiles('/')).resolves.not.toThrow(); + + expect(vol.toJSON()).toStrictEqual({ + '/nx.json': '', + '/package.json': '', + '/project.json': '', + }); + }); + + 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.toJSON()).toStrictEqual({ + '/workspaces/workspace1/nx.json': '', + '/workspaces/workspace1/package.json': '', + '/workspaces/workspace1/lib1/project.json': '', + }); + }); +}); + +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.toJSON()).toStrictEqual({ + '/tmp/unit': null, + }); + }); +}); + +describe('teardownTestFolder', () => { + it('should handle non-existent folder', async () => { + vol.fromJSON({}, MEMFS_VOLUME); + + await expect(teardownTestFolder('/tmp/unit')).resolves.not.toThrow(); + + expect(vol.toJSON()).toStrictEqual({}); + }); + + it('should delete existing directory', async () => { + 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); + + // 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 () => { + 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(vol.toJSON()).toStrictEqual({ + '/tmp/unit': null, + }); + expect(warnSpy).toHaveBeenCalledWith( + `⚠️ You are trying to delete a file instead of a directory - ${bold('/tmp/unit/package.json')}.`, + ); + }); +});