Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default tseslint.config(
{
ignores: [
'**/*.mock.*',
'**/*.setup-file.*',
'**/code-pushup.config.ts',
'**/mocks/fixtures/**',
'**/__snapshots__/**',
Expand Down
3 changes: 1 addition & 2 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/**/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-plugin/src/executors/cli/utils.int.test.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-plugin/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-lighthouse/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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 `<project-root>/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 `<project-root>/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`
<img width="1202" alt="chrome-blank-screen" src="./docs/images/chrome-blank-screen.png">

2. If you do this the first time you should already see content under `<project-root>/mock/chromium-user-data`
2. If you do this the first time you should already see content under `<project-root>/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
<img width="1202" alt="chrome-blank-screen-pre-configured" src="./docs/images/chrome-blank-screen-pre-configure.png">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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(
Expand Down
18 changes: 9 additions & 9 deletions testing/test-setup-config/src/lib/vitest-setup-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions testing/test-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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