diff --git a/eslint.config.js b/eslint.config.js index 7397d95d0..63b9cc76a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -139,6 +139,7 @@ export default tseslint.config( { ignores: [ '**/*.mock.*', + '**/*.setup-file.*', '**/code-pushup.config.ts', '**/mocks/fixtures/**', '**/__snapshots__/**', diff --git a/examples/plugins/src/lighthouse/mock/fixtures/lhr.ts b/examples/plugins/src/lighthouse/mocks/fixtures/lhr.ts similarity index 100% rename from examples/plugins/src/lighthouse/mock/fixtures/lhr.ts rename to examples/plugins/src/lighthouse/mocks/fixtures/lhr.ts diff --git a/nx.json b/nx.json index 7e7265dfe..c77d9dff8 100644 --- a/nx.json +++ b/nx.json @@ -14,9 +14,8 @@ "!{workspaceRoot}/**/.code-pushup/**/*", "!{projectRoot}/code-pushup.config.?(m)[jt]s", "!{projectRoot}/code-pushup.config.bundled_*.mjs", - "!{projectRoot}/@(test|mocks|mock)/**/*", + "!{projectRoot}/@(test|mocks)/**/*", "!{projectRoot}/**/?(*.)test.[jt]s?(x)?(.snap)", - "!{projectRoot}/**/?(*.)mocks.[jt]s?(x)", "!{projectRoot}/**/?(*.)mock.[jt]s?(x)", "!{projectRoot}/vitest.@(unit|int|e2e).config.[jt]s", "!{projectRoot}/dist/**/*", diff --git a/packages/nx-plugin/mock/fixtures/env.ts b/packages/nx-plugin/mocks/fixtures/env.ts similarity index 100% rename from packages/nx-plugin/mock/fixtures/env.ts rename to packages/nx-plugin/mocks/fixtures/env.ts diff --git a/packages/nx-plugin/mock/utils/executor.ts b/packages/nx-plugin/mocks/utils/executor.ts similarity index 100% rename from packages/nx-plugin/mock/utils/executor.ts rename to packages/nx-plugin/mocks/utils/executor.ts diff --git a/packages/nx-plugin/src/executors/cli/utils.int.test.ts b/packages/nx-plugin/src/executors/cli/utils.int.test.ts index cecff0afc..6a15be36b 100644 --- a/packages/nx-plugin/src/executors/cli/utils.int.test.ts +++ b/packages/nx-plugin/src/executors/cli/utils.int.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest'; import type { UploadConfig } from '@code-pushup/models'; -import { normalizedExecutorContext } from '../../../mock/utils/executor.js'; +import { normalizedExecutorContext } from '../../../mocks/utils/executor.js'; import * as config from '../internal/config.js'; import { parseCliExecutorOptions } from './utils.js'; diff --git a/packages/nx-plugin/src/executors/internal/config.int.test.ts b/packages/nx-plugin/src/executors/internal/config.int.test.ts index 54b2e32dc..79a27da14 100644 --- a/packages/nx-plugin/src/executors/internal/config.int.test.ts +++ b/packages/nx-plugin/src/executors/internal/config.int.test.ts @@ -1,5 +1,5 @@ import { describe, expect } from 'vitest'; -import { ENV } from '../../../mock/fixtures/env.js'; +import { ENV } from '../../../mocks/fixtures/env.js'; import { uploadConfig } from './config.js'; import * as env from './env.js'; diff --git a/packages/nx-plugin/src/executors/internal/config.unit.test.ts b/packages/nx-plugin/src/executors/internal/config.unit.test.ts index c9d948bdd..a44590c70 100644 --- a/packages/nx-plugin/src/executors/internal/config.unit.test.ts +++ b/packages/nx-plugin/src/executors/internal/config.unit.test.ts @@ -1,6 +1,6 @@ import { type MockInstance, describe, expect } from 'vitest'; import { osAgnosticPath } from '@code-pushup/test-utils'; -import { ENV } from '../../../mock/fixtures/env.js'; +import { ENV } from '../../../mocks/fixtures/env.js'; import { globalConfig, persistConfig, uploadConfig } from './config.js'; describe('globalConfig', () => { diff --git a/packages/nx-plugin/tsconfig.test.json b/packages/nx-plugin/tsconfig.test.json index 7bbd41b93..54cacd82f 100644 --- a/packages/nx-plugin/tsconfig.test.json +++ b/packages/nx-plugin/tsconfig.test.json @@ -7,7 +7,7 @@ "include": [ "vitest.unit.config.ts", "vitest.int.config.ts", - "mock/**/*.ts", + "mocks/**/*.ts", "src/**/*.test.ts", "src/**/*.test.tsx", "src/**/*.test.js", diff --git a/packages/plugin-lighthouse/CONTRIBUTING.md b/packages/plugin-lighthouse/CONTRIBUTING.md index 6ab94e123..0b1d215ec 100644 --- a/packages/plugin-lighthouse/CONTRIBUTING.md +++ b/packages/plugin-lighthouse/CONTRIBUTING.md @@ -15,7 +15,7 @@ To test lighthouse properly we work with a predefined testing setup. On some OS there could be a problem finding the path to Chrome. -We try to detect it automatically in the [`chrome-path.mock.ts` script](../../testing/test-setup/src/lib/chrome-path.mock.ts). +We try to detect it automatically in the [`chrome-path.setup-file.ts` script](../../testing/test-setup/src/lib/chrome-path.setup-file.ts). There we use `getChromePath` and have `chromium` installed as NPM package, so detecting the path should not cause any problem. However, if no chrome path is detected automatically the error looks like this: @@ -46,7 +46,7 @@ In the CI you can set a static path if needed over the env variable like this: # ... ``` -We consider this path in our `beforeAll` hook in a [`chrome-path.mock.ts` script](../../testing/test-setup/src/lib/chrome-path.mock.ts). +We consider this path in our `beforeAll` hook in a [`chrome-path.setup-file.ts` script](../../testing/test-setup/src/lib/chrome-path.setup-file.ts). ### Testing chrome flags @@ -66,15 +66,15 @@ For a full list of available flags check out [this document](https://peter.sh/ex ### Chrome User Data -To bootstrap Chrome with a predefined for setting we have to provide a couple of config files that we located under `/mock/chromium-user-data`. +To bootstrap Chrome with a predefined for setting we have to provide a couple of config files that we located under `/mocks/chromium-user-data`. When executing Lighthouse we provide the path to this folder over the `Flag` object. To generate initialise or edit the file structure under `chromium-user-data` do the following steps: -1. Spin up Chrome by running `npx chrome-debug --user-data-dir=./packages/plugin-lighthouse/mock/chromium-user-data` +1. Spin up Chrome by running `npx chrome-debug --user-data-dir=./packages/plugin-lighthouse/mocks/chromium-user-data` chrome-blank-screen -2. If you do this the first time you should already see content under `/mock/chromium-user-data` +2. If you do this the first time you should already see content under `/mocks/chromium-user-data` 3. Edit the configuration over the Chrome UI. E.g. adding a profile 4. Close chromium and open it again, and you should see chromium bootstraps as the configured user chrome-blank-screen-pre-configured diff --git a/testing/test-setup-config/src/lib/vitest-config-factory.unit.test.ts b/testing/test-setup-config/src/lib/vitest-config-factory.unit.test.ts index a92a3e4bf..84293c3e1 100644 --- a/testing/test-setup-config/src/lib/vitest-config-factory.unit.test.ts +++ b/testing/test-setup-config/src/lib/vitest-config-factory.unit.test.ts @@ -32,8 +32,8 @@ describe('createVitestConfig', () => { ], globalSetup: ['../../global-setup.ts'], setupFiles: expect.arrayContaining([ - '../../testing/test-setup/src/lib/reset.mocks.ts', - '../../testing/test-setup/src/lib/fs.mock.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', + '../../testing/test-setup/src/lib/fs.setup-file.ts', ]), coverage: expect.objectContaining({ reporter: ['text', 'lcov'], @@ -70,19 +70,19 @@ describe('createVitestConfig', () => { const setupFiles = config.test!.setupFiles; expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/reset.mocks.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', ); expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/fs.mock.ts', + '../../testing/test-setup/src/lib/fs.setup-file.ts', ); expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/git.mock.ts', + '../../testing/test-setup/src/lib/git.setup-file.ts', ); expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/portal-client.mock.ts', + '../../testing/test-setup/src/lib/portal-client.setup-file.ts', ); expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/logger.mock.ts', + '../../testing/test-setup/src/lib/logger.setup-file.ts', ); expect(setupFiles).toContain( '../../testing/test-setup/src/lib/extend/markdown-table.matcher.ts', @@ -141,16 +141,16 @@ describe('createVitestConfig', () => { const setupFiles = config.test!.setupFiles; expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/logger.mock.ts', + '../../testing/test-setup/src/lib/logger.setup-file.ts', ); expect(setupFiles).not.toContain( - '../../testing/test-setup/src/lib/fs.mock.ts', + '../../testing/test-setup/src/lib/fs.setup-file.ts', ); expect(setupFiles).not.toContain( - '../../testing/test-setup/src/lib/cliui.mock.ts', + '../../testing/test-setup/src/lib/cliui.setup-file.ts', ); expect(setupFiles).not.toContain( - '../../testing/test-setup/src/lib/git.mock.ts', + '../../testing/test-setup/src/lib/git.setup-file.ts', ); expect(setupFiles).toContain( '../../testing/test-setup/src/lib/extend/path.matcher.ts', @@ -186,14 +186,14 @@ describe('createVitestConfig', () => { const setupFiles = config.test!.setupFiles; // Should only include reset mocks expect(setupFiles).toContain( - '../../testing/test-setup/src/lib/reset.mocks.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', ); // Should NOT include fs, git, etc. expect(setupFiles).not.toContain( - '../../testing/test-setup/src/lib/git.mock.ts', + '../../testing/test-setup/src/lib/git.setup-file.ts', ); expect(setupFiles).not.toContain( - '../../testing/test-setup/src/lib/fs.mock.ts', + '../../testing/test-setup/src/lib/fs.setup-file.ts', ); // Should include all matchers expect(setupFiles).toContain( diff --git a/testing/test-setup-config/src/lib/vitest-setup-files.ts b/testing/test-setup-config/src/lib/vitest-setup-files.ts index ccc34bbea..62e352b35 100644 --- a/testing/test-setup-config/src/lib/vitest-setup-files.ts +++ b/testing/test-setup-config/src/lib/vitest-setup-files.ts @@ -20,12 +20,12 @@ const CUSTOM_MATCHERS = [ * which is why they use `../../` to navigate to the workspace root first. */ const UNIT_TEST_SETUP_FILES = [ - '../../testing/test-setup/src/lib/reset.mocks.ts', - '../../testing/test-setup/src/lib/fs.mock.ts', - '../../testing/test-setup/src/lib/logger.mock.ts', - '../../testing/test-setup/src/lib/git.mock.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', + '../../testing/test-setup/src/lib/fs.setup-file.ts', + '../../testing/test-setup/src/lib/logger.setup-file.ts', + '../../testing/test-setup/src/lib/git.setup-file.ts', '../../testing/test-setup/src/lib/performance.setup-file.ts', - '../../testing/test-setup/src/lib/portal-client.mock.ts', + '../../testing/test-setup/src/lib/portal-client.setup-file.ts', '../../testing/test-setup/src/lib/process.setup-file.ts', ...CUSTOM_MATCHERS, ] as const; @@ -38,9 +38,9 @@ const UNIT_TEST_SETUP_FILES = [ */ const INT_TEST_SETUP_FILES = [ - '../../testing/test-setup/src/lib/reset.mocks.ts', - '../../testing/test-setup/src/lib/logger.mock.ts', - '../../testing/test-setup/src/lib/chrome-path.mock.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', + '../../testing/test-setup/src/lib/logger.setup-file.ts', + '../../testing/test-setup/src/lib/chrome-path.setup-file.ts', ...CUSTOM_MATCHERS, ] as const; @@ -51,7 +51,7 @@ const INT_TEST_SETUP_FILES = [ * which is why they use `../../` to navigate to the workspace root first. */ const E2E_TEST_SETUP_FILES = [ - '../../testing/test-setup/src/lib/reset.mocks.ts', + '../../testing/test-setup/src/lib/reset.setup-file.ts', ...CUSTOM_MATCHERS, ] as const; diff --git a/testing/test-setup/README.md b/testing/test-setup/README.md index c3b1e60e0..1c3d1b956 100644 --- a/testing/test-setup/README.md +++ b/testing/test-setup/README.md @@ -13,11 +13,11 @@ See [`@code-pushup/test-setup-config` docs](../test-setup-config/README.md) on h In this library you can find all files that can be used in `setupFiles` property of `vitest.config.(unit|int|e2e).ts` files. Currently include: - [console](./src/lib/console.mock.ts) mocking -- [file system](./src/lib/fs.mock.ts) mocking -- [`portal-client`](./src/lib/portal-client.mock.ts) mocking -- [git](./src/lib/git.mock.ts) mocking +- [file system](./src/lib/fs.setup-file.ts) mocking +- [`portal-client`](./src/lib/portal-client.setup-file.ts) mocking +- [git](./src/lib/git.setup-file.ts) mocking Additionally, you may find helper functions for: - setting up and tearing down a [testing folder](./src/lib/test-folder.setup.ts) -- [resetting](./src/lib/reset.mocks.ts) mocks +- [resetting](./src/lib/reset.setup-file.ts) mocks diff --git a/testing/test-setup/src/lib/chrome-path.mock.ts b/testing/test-setup/src/lib/chrome-path.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/chrome-path.mock.ts rename to testing/test-setup/src/lib/chrome-path.setup-file.ts diff --git a/testing/test-setup/src/lib/fs.mock.ts b/testing/test-setup/src/lib/fs.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/fs.mock.ts rename to testing/test-setup/src/lib/fs.setup-file.ts diff --git a/testing/test-setup/src/lib/git.mock.ts b/testing/test-setup/src/lib/git.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/git.mock.ts rename to testing/test-setup/src/lib/git.setup-file.ts diff --git a/testing/test-setup/src/lib/logger.mock.ts b/testing/test-setup/src/lib/logger.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/logger.mock.ts rename to testing/test-setup/src/lib/logger.setup-file.ts diff --git a/testing/test-setup/src/lib/portal-client.mock.ts b/testing/test-setup/src/lib/portal-client.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/portal-client.mock.ts rename to testing/test-setup/src/lib/portal-client.setup-file.ts diff --git a/testing/test-setup/src/lib/reset.mocks.ts b/testing/test-setup/src/lib/reset.setup-file.ts similarity index 100% rename from testing/test-setup/src/lib/reset.mocks.ts rename to testing/test-setup/src/lib/reset.setup-file.ts