@gitlab/frontend-tests 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,6 +51,8 @@ This package holds the framework core of GitLab's frontend integration tests. Th
51
51
 
52
52
  `@gitlab/frontend-tests/integration/jest-config` exports `createFrontendIntegrationConfig(config)` and `MSW_ESM_DEPENDENCIES`.
53
53
 
54
+ `@gitlab/frontend-tests/integration/setup-budget` and `@gitlab/frontend-tests/integration/setup-budget-lint` are described in [Wait budgets](#wait-budgets).
55
+
54
56
  ### Jest configuration
55
57
 
56
58
  Pass an existing Jest config to the factory. It returns a copy with the integration overrides applied.
@@ -77,6 +79,68 @@ It does not touch `setupFilesAfterEnv`, module aliases or the test environment.
77
79
 
78
80
  `msw` v2 is a peer dependency, and `@jest/types` is an optional peer that only TypeScript consumers of `jest-config` need. `@whatwg-node/fetch` is the only regular dependency; `lodash-es` is bundled.
79
81
 
82
+ ### Wait budgets
83
+
84
+ `setupBeforeEach` gives booting the app a longer wait budget than the rest of the spec, without a flag threaded through helpers. Call `installSetupBudget` from a `setupFilesAfterEnv` file:
85
+
86
+ ```js
87
+ import { installSetupBudget } from '@gitlab/frontend-tests/integration/setup-budget';
88
+
89
+ installSetupBudget({ timeout: 3000 });
90
+ ```
91
+
92
+ Both options are optional:
93
+
94
+ - `timeout`: ceiling for regular waits. Defaults to 3000.
95
+ - `setupTimeout`: ceiling for waits inside `setupBeforeEach`. Defaults to 15000 in CI and 6000 locally. It must stay under the `testTimeout` that `createFrontendIntegrationConfig` sets (20000 in CI, 7000 locally), or `installSetupBudget` throws. A consumer that overrides `testTimeout` is not checked.
96
+
97
+ `installSetupBudget` installs a `@testing-library/dom` `asyncWrapper` and exposes `setupBeforeEach` as a global. `setupBeforeEach(fn)` registers a regular `beforeEach`. Every wait that runs while `fn` runs, including waits inside helpers it calls, gets `setupTimeout`. Every other wait gets `timeout`. Hooks run in declaration order, so a `beforeEach` declared above `setupBeforeEach` in the same block runs on `timeout`. An explicit `timeout` passed to a wait still wins, but the slow-wait log measures it against the budget. `installSetupBudget` chains to an `asyncWrapper` installed before it. TypeScript specs get the `setupBeforeEach` global type from the import of `installSetupBudget`.
98
+
99
+ ```js
100
+ describe('when the item has labels', () => {
101
+ setupBeforeEach(async () => {
102
+ mountApp();
103
+ await waitForElement(findList);
104
+ });
105
+
106
+ describe('when a label is removed', () => {
107
+ beforeEach(() => removeLabel()); // regular budget
108
+
109
+ it('updates the list', async () => {
110
+ await waitForElement(findEmptyState); // regular budget
111
+ });
112
+ });
113
+ });
114
+ ```
115
+
116
+ A wait that uses two thirds of its allowed run time is logged with `console.log` as `[integration] slow wait` or `[integration] slow setup wait`. When `JEST_INTEGRATION_SLOW_WAITS_FILE` is set, each slow wait is also appended to that file as one JSON line: `{ file, test, elapsedMs, ceilingMs, phase }`, where `phase` is `setup` or `test` (`WAIT_PHASE`).
117
+
118
+ `@gitlab/frontend-tests/integration/setup-budget-lint` exports `SETUP_BUDGET_RESTRICTED_SYNTAX` and `SETUP_BUDGET_GLOBALS` for ESLint flat config. ESLint keeps one `no-restricted-syntax` setting per file match, so spread the entries into the existing list:
119
+
120
+ ```js
121
+ import {
122
+ SETUP_BUDGET_GLOBALS,
123
+ SETUP_BUDGET_RESTRICTED_SYNTAX,
124
+ } from '@gitlab/frontend-tests/integration/setup-budget-lint';
125
+
126
+ export default [
127
+ {
128
+ files: ['spec/integration/**/*_spec.js'],
129
+ languageOptions: { globals: SETUP_BUDGET_GLOBALS },
130
+ rules: { 'no-restricted-syntax': ['error', ...SETUP_BUDGET_RESTRICTED_SYNTAX] },
131
+ },
132
+ ];
133
+ ```
134
+
135
+ The rules:
136
+
137
+ - Each test gets at most one `setupBeforeEach`. A `setupBeforeEach` inside a `describe` that already has one higher up is an error, and so are two in the same block.
138
+ - Waits do not set their own `timeout`. If a wait really cannot be faster, disable the rule on that line and say why.
139
+
140
+ The lint entries live in their own subpath so an ESLint config does not load the test runtime.
141
+
142
+ `@testing-library/dom` is an optional peer dependency that only `setup-budget` needs. The budget is not exported from `@gitlab/frontend-tests/integration`, so consumers that only use fixtures and the server do not need it.
143
+
80
144
  ### Gotchas
81
145
 
82
146
  - Load the polyfills through `setupFiles`, not `setupFilesAfterEnv`. `msw/node` reads these globals while its module body evaluates, so they must exist before it loads. Keep the text-encoding entry before the main one: `@whatwg-node/fetch` needs `TextDecoder` at load time, and bundlers hoist imports, so a single file cannot guarantee the order.
@@ -2,6 +2,7 @@
2
2
 
3
3
  // `msw` dependencies that ship ESM only, so Jest has to transform them.
4
4
  const MSW_ESM_DEPENDENCIES = ['rettime', 'until-async', '@open-draft/.*'];
5
+ const integrationTestTimeout = () => (process.env.CI ? 20000 : 7000);
5
6
  // Order matters: `@whatwg-node/fetch` needs TextEncoder/TextDecoder at load time.
6
7
  const POLYFILLS_SETUP_FILES = [
7
8
  '@gitlab/frontend-tests/integration/polyfills/text-encoding',
@@ -22,10 +23,11 @@ function createFrontendIntegrationConfig(config = {}) {
22
23
  testPathIgnorePatterns: [],
23
24
  setupFiles: [...setupFiles, ...POLYFILLS_SETUP_FILES],
24
25
  fakeTimers: { enableGlobally: false },
25
- testTimeout: process.env.CI ? 20000 : 7000,
26
+ testTimeout: integrationTestTimeout(),
26
27
  };
27
28
  }
28
29
 
29
30
  exports.MSW_ESM_DEPENDENCIES = MSW_ESM_DEPENDENCIES;
30
31
  exports.POLYFILLS_SETUP_FILES = POLYFILLS_SETUP_FILES;
31
32
  exports.createFrontendIntegrationConfig = createFrontendIntegrationConfig;
33
+ exports.integrationTestTimeout = integrationTestTimeout;
@@ -1,5 +1,6 @@
1
1
  import type { Config } from '@jest/types';
2
2
  export declare const MSW_ESM_DEPENDENCIES: string[];
3
+ export declare const integrationTestTimeout: () => 20000 | 7000;
3
4
  export declare const POLYFILLS_SETUP_FILES: string[];
4
5
  /**
5
6
  * Turns a consumer's Jest config into one that can run MSW integration specs. It
@@ -1,5 +1,6 @@
1
1
  import type { Config } from '@jest/types';
2
2
  export declare const MSW_ESM_DEPENDENCIES: string[];
3
+ export declare const integrationTestTimeout: () => 20000 | 7000;
3
4
  export declare const POLYFILLS_SETUP_FILES: string[];
4
5
  /**
5
6
  * Turns a consumer's Jest config into one that can run MSW integration specs. It
@@ -1,5 +1,6 @@
1
1
  // `msw` dependencies that ship ESM only, so Jest has to transform them.
2
2
  const MSW_ESM_DEPENDENCIES = ['rettime', 'until-async', '@open-draft/.*'];
3
+ const integrationTestTimeout = () => (process.env.CI ? 20000 : 7000);
3
4
  // Order matters: `@whatwg-node/fetch` needs TextEncoder/TextDecoder at load time.
4
5
  const POLYFILLS_SETUP_FILES = [
5
6
  '@gitlab/frontend-tests/integration/polyfills/text-encoding',
@@ -20,8 +21,8 @@ function createFrontendIntegrationConfig(config = {}) {
20
21
  testPathIgnorePatterns: [],
21
22
  setupFiles: [...setupFiles, ...POLYFILLS_SETUP_FILES],
22
23
  fakeTimers: { enableGlobally: false },
23
- testTimeout: process.env.CI ? 20000 : 7000,
24
+ testTimeout: integrationTestTimeout(),
24
25
  };
25
26
  }
26
27
 
27
- export { MSW_ESM_DEPENDENCIES, POLYFILLS_SETUP_FILES, createFrontendIntegrationConfig };
28
+ export { MSW_ESM_DEPENDENCIES, POLYFILLS_SETUP_FILES, createFrontendIntegrationConfig, integrationTestTimeout };
@@ -0,0 +1,88 @@
1
+ 'use strict';
2
+
3
+ var node_fs = require('node:fs');
4
+ var dom = require('@testing-library/dom');
5
+ var integration_jest_config = require('./jest_config.cjs');
6
+
7
+ /** The `phase` of a slow wait in the log and the slow-waits file. */
8
+ const WAIT_PHASE = { SETUP: 'setup', TEST: 'test' };
9
+ // A wait that uses this share of its ceiling passes locally and flakes on a starved CI runner.
10
+ const SLOW_SHARE = 2 / 3;
11
+ let budget = { timeout: 3000, setupTimeout: process.env.CI ? 15000 : 6000 };
12
+ let settingUp = false;
13
+ let innerWrapper = (cb) => cb();
14
+ /**
15
+ * A `beforeEach` whose waits, including those inside helpers it awaits, get the setup
16
+ * budget. Use it once per test path, to boot the app. Hooks run in declaration order, so
17
+ * a `beforeEach` declared above it in the same block runs on the regular budget.
18
+ */
19
+ function setupBeforeEach(fn, hookTimeout) {
20
+ beforeEach(async () => {
21
+ settingUp = true;
22
+ try {
23
+ await fn();
24
+ }
25
+ finally {
26
+ settingUp = false;
27
+ }
28
+ }, hookTimeout);
29
+ }
30
+ function logSlowWait(elapsedMs, ceilingMs, phase) {
31
+ const { testPath, currentTestName } = expect.getState();
32
+ const isSetup = phase === WAIT_PHASE.SETUP;
33
+ const advice = isSetup
34
+ ? 'Setup is close to its budget; find what makes it slow.'
35
+ : 'Move the setup into setupBeforeEach, or split the wait.';
36
+ // `console.log`, not `warn`: consumers' console watchers often turn `warn` into a failure.
37
+ // eslint-disable-next-line no-console
38
+ console.log(`[integration] slow ${isSetup ? 'setup ' : ''}wait: ${elapsedMs}ms in "${currentTestName}" (ceiling ${ceilingMs}ms). ${advice}`);
39
+ // One JSON line per wait, so a reporter can list them; appends stay atomic across workers.
40
+ if (process.env.JEST_INTEGRATION_SLOW_WAITS_FILE) {
41
+ node_fs.appendFileSync(process.env.JEST_INTEGRATION_SLOW_WAITS_FILE, `${JSON.stringify({ file: testPath, test: currentTestName, elapsedMs, ceilingMs, phase })}\n`);
42
+ }
43
+ }
44
+ // Installed as @testing-library's `asyncWrapper`. `waitFor` reads `asyncUtilTimeout` inside
45
+ // it, so setting the timeout here picks the budget for each wait.
46
+ async function setupBudgetAsyncWrapper(callback) {
47
+ const phase = settingUp ? WAIT_PHASE.SETUP : WAIT_PHASE.TEST;
48
+ const ceilingMs = settingUp ? budget.setupTimeout : budget.timeout;
49
+ dom.configure({ asyncUtilTimeout: ceilingMs });
50
+ const start = performance.now();
51
+ try {
52
+ return (await innerWrapper(callback));
53
+ }
54
+ finally {
55
+ // ponytail: an explicit `timeout` on the wait is invisible here, so it is logged against the budget.
56
+ const elapsedMs = Math.round(performance.now() - start);
57
+ if (elapsedMs > ceilingMs * SLOW_SHARE)
58
+ logSlowWait(elapsedMs, ceilingMs, phase);
59
+ }
60
+ }
61
+ /**
62
+ * Call from a `setupFilesAfterEnv` file. Sets the wait budgets, installs the wrapper and
63
+ * exposes `setupBeforeEach` as a global.
64
+ */
65
+ function installSetupBudget(options = {}) {
66
+ const next = {
67
+ timeout: options.timeout ?? budget.timeout,
68
+ setupTimeout: options.setupTimeout ?? budget.setupTimeout,
69
+ };
70
+ // Compares with the `testTimeout` from `createFrontendIntegrationConfig`. A consumer that
71
+ // sets its own `testTimeout` after the factory is not checked.
72
+ const hookTimeout = integration_jest_config.integrationTestTimeout();
73
+ if (next.setupTimeout >= hookTimeout) {
74
+ throw new Error(`setupTimeout (${next.setupTimeout}ms) must stay under the hook timeout (${hookTimeout}ms).`);
75
+ }
76
+ budget = next;
77
+ // Chain to a wrapper the consumer installed earlier, such as an `act()` wrapper.
78
+ const { asyncWrapper } = dom.getConfig();
79
+ if (asyncWrapper !== setupBudgetAsyncWrapper)
80
+ innerWrapper = asyncWrapper;
81
+ dom.configure({ asyncUtilTimeout: budget.timeout, asyncWrapper: setupBudgetAsyncWrapper });
82
+ Object.assign(globalThis, { setupBeforeEach });
83
+ }
84
+
85
+ exports.WAIT_PHASE = WAIT_PHASE;
86
+ exports.installSetupBudget = installSetupBudget;
87
+ exports.setupBeforeEach = setupBeforeEach;
88
+ exports.setupBudgetAsyncWrapper = setupBudgetAsyncWrapper;
@@ -0,0 +1,28 @@
1
+ export interface SetupBudgetOptions {
2
+ /** Ceiling for waits outside `setupBeforeEach`. */
3
+ timeout?: number;
4
+ /** Ceiling for waits inside `setupBeforeEach`. Must stay under the hook timeout. */
5
+ setupTimeout?: number;
6
+ }
7
+ type Hook = () => unknown;
8
+ /** The `phase` of a slow wait in the log and the slow-waits file. */
9
+ export declare const WAIT_PHASE: {
10
+ readonly SETUP: "setup";
11
+ readonly TEST: "test";
12
+ };
13
+ declare global {
14
+ var setupBeforeEach: (fn: Hook, hookTimeout?: number) => void;
15
+ }
16
+ /**
17
+ * A `beforeEach` whose waits, including those inside helpers it awaits, get the setup
18
+ * budget. Use it once per test path, to boot the app. Hooks run in declaration order, so
19
+ * a `beforeEach` declared above it in the same block runs on the regular budget.
20
+ */
21
+ export declare function setupBeforeEach(fn: Hook, hookTimeout?: number): void;
22
+ export declare function setupBudgetAsyncWrapper<T>(callback: () => Promise<T>): Promise<T>;
23
+ /**
24
+ * Call from a `setupFilesAfterEnv` file. Sets the wait budgets, installs the wrapper and
25
+ * exposes `setupBeforeEach` as a global.
26
+ */
27
+ export declare function installSetupBudget(options?: SetupBudgetOptions): void;
28
+ export {};
@@ -0,0 +1,28 @@
1
+ export interface SetupBudgetOptions {
2
+ /** Ceiling for waits outside `setupBeforeEach`. */
3
+ timeout?: number;
4
+ /** Ceiling for waits inside `setupBeforeEach`. Must stay under the hook timeout. */
5
+ setupTimeout?: number;
6
+ }
7
+ type Hook = () => unknown;
8
+ /** The `phase` of a slow wait in the log and the slow-waits file. */
9
+ export declare const WAIT_PHASE: {
10
+ readonly SETUP: "setup";
11
+ readonly TEST: "test";
12
+ };
13
+ declare global {
14
+ var setupBeforeEach: (fn: Hook, hookTimeout?: number) => void;
15
+ }
16
+ /**
17
+ * A `beforeEach` whose waits, including those inside helpers it awaits, get the setup
18
+ * budget. Use it once per test path, to boot the app. Hooks run in declaration order, so
19
+ * a `beforeEach` declared above it in the same block runs on the regular budget.
20
+ */
21
+ export declare function setupBeforeEach(fn: Hook, hookTimeout?: number): void;
22
+ export declare function setupBudgetAsyncWrapper<T>(callback: () => Promise<T>): Promise<T>;
23
+ /**
24
+ * Call from a `setupFilesAfterEnv` file. Sets the wait budgets, installs the wrapper and
25
+ * exposes `setupBeforeEach` as a global.
26
+ */
27
+ export declare function installSetupBudget(options?: SetupBudgetOptions): void;
28
+ export {};
@@ -0,0 +1,83 @@
1
+ import { appendFileSync } from 'node:fs';
2
+ import { getConfig, configure } from '@testing-library/dom';
3
+ import { integrationTestTimeout } from './jest_config.js';
4
+
5
+ /** The `phase` of a slow wait in the log and the slow-waits file. */
6
+ const WAIT_PHASE = { SETUP: 'setup', TEST: 'test' };
7
+ // A wait that uses this share of its ceiling passes locally and flakes on a starved CI runner.
8
+ const SLOW_SHARE = 2 / 3;
9
+ let budget = { timeout: 3000, setupTimeout: process.env.CI ? 15000 : 6000 };
10
+ let settingUp = false;
11
+ let innerWrapper = (cb) => cb();
12
+ /**
13
+ * A `beforeEach` whose waits, including those inside helpers it awaits, get the setup
14
+ * budget. Use it once per test path, to boot the app. Hooks run in declaration order, so
15
+ * a `beforeEach` declared above it in the same block runs on the regular budget.
16
+ */
17
+ function setupBeforeEach(fn, hookTimeout) {
18
+ beforeEach(async () => {
19
+ settingUp = true;
20
+ try {
21
+ await fn();
22
+ }
23
+ finally {
24
+ settingUp = false;
25
+ }
26
+ }, hookTimeout);
27
+ }
28
+ function logSlowWait(elapsedMs, ceilingMs, phase) {
29
+ const { testPath, currentTestName } = expect.getState();
30
+ const isSetup = phase === WAIT_PHASE.SETUP;
31
+ const advice = isSetup
32
+ ? 'Setup is close to its budget; find what makes it slow.'
33
+ : 'Move the setup into setupBeforeEach, or split the wait.';
34
+ // `console.log`, not `warn`: consumers' console watchers often turn `warn` into a failure.
35
+ // eslint-disable-next-line no-console
36
+ console.log(`[integration] slow ${isSetup ? 'setup ' : ''}wait: ${elapsedMs}ms in "${currentTestName}" (ceiling ${ceilingMs}ms). ${advice}`);
37
+ // One JSON line per wait, so a reporter can list them; appends stay atomic across workers.
38
+ if (process.env.JEST_INTEGRATION_SLOW_WAITS_FILE) {
39
+ appendFileSync(process.env.JEST_INTEGRATION_SLOW_WAITS_FILE, `${JSON.stringify({ file: testPath, test: currentTestName, elapsedMs, ceilingMs, phase })}\n`);
40
+ }
41
+ }
42
+ // Installed as @testing-library's `asyncWrapper`. `waitFor` reads `asyncUtilTimeout` inside
43
+ // it, so setting the timeout here picks the budget for each wait.
44
+ async function setupBudgetAsyncWrapper(callback) {
45
+ const phase = settingUp ? WAIT_PHASE.SETUP : WAIT_PHASE.TEST;
46
+ const ceilingMs = settingUp ? budget.setupTimeout : budget.timeout;
47
+ configure({ asyncUtilTimeout: ceilingMs });
48
+ const start = performance.now();
49
+ try {
50
+ return (await innerWrapper(callback));
51
+ }
52
+ finally {
53
+ // ponytail: an explicit `timeout` on the wait is invisible here, so it is logged against the budget.
54
+ const elapsedMs = Math.round(performance.now() - start);
55
+ if (elapsedMs > ceilingMs * SLOW_SHARE)
56
+ logSlowWait(elapsedMs, ceilingMs, phase);
57
+ }
58
+ }
59
+ /**
60
+ * Call from a `setupFilesAfterEnv` file. Sets the wait budgets, installs the wrapper and
61
+ * exposes `setupBeforeEach` as a global.
62
+ */
63
+ function installSetupBudget(options = {}) {
64
+ const next = {
65
+ timeout: options.timeout ?? budget.timeout,
66
+ setupTimeout: options.setupTimeout ?? budget.setupTimeout,
67
+ };
68
+ // Compares with the `testTimeout` from `createFrontendIntegrationConfig`. A consumer that
69
+ // sets its own `testTimeout` after the factory is not checked.
70
+ const hookTimeout = integrationTestTimeout();
71
+ if (next.setupTimeout >= hookTimeout) {
72
+ throw new Error(`setupTimeout (${next.setupTimeout}ms) must stay under the hook timeout (${hookTimeout}ms).`);
73
+ }
74
+ budget = next;
75
+ // Chain to a wrapper the consumer installed earlier, such as an `act()` wrapper.
76
+ const { asyncWrapper } = getConfig();
77
+ if (asyncWrapper !== setupBudgetAsyncWrapper)
78
+ innerWrapper = asyncWrapper;
79
+ configure({ asyncUtilTimeout: budget.timeout, asyncWrapper: setupBudgetAsyncWrapper });
80
+ Object.assign(globalThis, { setupBeforeEach });
81
+ }
82
+
83
+ export { WAIT_PHASE, installSetupBudget, setupBeforeEach, setupBudgetAsyncWrapper };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ // `no-restricted-syntax` entries for specs that use `setupBeforeEach`. ESLint keeps one
4
+ // `no-restricted-syntax` setting per file match, so consumers spread these into theirs.
5
+ const NAME = '/^[fx]?describe$/';
6
+ // `describe(...)`, `describe.only(...)`, `describe.each(table)(...)` and describe.each`table`(...).
7
+ const DESCRIBE = `:matches(CallExpression[callee.name=${NAME}], CallExpression[callee.object.name=${NAME}], CallExpression[callee.callee.object.name=${NAME}], CallExpression[callee.tag.object.name=${NAME}])`;
8
+ const SETUP = "CallExpression[callee.name='setupBeforeEach']";
9
+ const SETUP_STATEMENT = `ExpressionStatement:has(> ${SETUP})`;
10
+ const SETUP_BUDGET_RESTRICTED_SYNTAX = [
11
+ {
12
+ // Each test boots on the setup budget once: no setupBeforeEach below another one.
13
+ selector: `:matches(Program, BlockStatement):has(> ${SETUP_STATEMENT}) ${DESCRIBE} ${SETUP}`,
14
+ message: 'A setupBeforeEach higher up already boots these tests. Use beforeEach here; it gets the regular wait budget.',
15
+ },
16
+ {
17
+ selector: `${SETUP_STATEMENT} ~ ${SETUP_STATEMENT}`,
18
+ message: 'Use setupBeforeEach once per block. Put all setup in it.',
19
+ },
20
+ {
21
+ selector: "CallExpression:matches([callee.name=/^(waitFor|findBy|findAllBy)/], [callee.property.name=/^(findBy|findAllBy)/]) > ObjectExpression > Property[key.name='timeout']",
22
+ message: 'Find out why this wait is slow first; most slow waits are avoidable. If it is not, disable this line with a reason.',
23
+ },
24
+ ];
25
+ const SETUP_BUDGET_GLOBALS = { setupBeforeEach: 'readonly' };
26
+
27
+ exports.SETUP_BUDGET_GLOBALS = SETUP_BUDGET_GLOBALS;
28
+ exports.SETUP_BUDGET_RESTRICTED_SYNTAX = SETUP_BUDGET_RESTRICTED_SYNTAX;
@@ -0,0 +1,7 @@
1
+ export declare const SETUP_BUDGET_RESTRICTED_SYNTAX: {
2
+ selector: string;
3
+ message: string;
4
+ }[];
5
+ export declare const SETUP_BUDGET_GLOBALS: {
6
+ readonly setupBeforeEach: "readonly";
7
+ };
@@ -0,0 +1,7 @@
1
+ export declare const SETUP_BUDGET_RESTRICTED_SYNTAX: {
2
+ selector: string;
3
+ message: string;
4
+ }[];
5
+ export declare const SETUP_BUDGET_GLOBALS: {
6
+ readonly setupBeforeEach: "readonly";
7
+ };
@@ -0,0 +1,25 @@
1
+ // `no-restricted-syntax` entries for specs that use `setupBeforeEach`. ESLint keeps one
2
+ // `no-restricted-syntax` setting per file match, so consumers spread these into theirs.
3
+ const NAME = '/^[fx]?describe$/';
4
+ // `describe(...)`, `describe.only(...)`, `describe.each(table)(...)` and describe.each`table`(...).
5
+ const DESCRIBE = `:matches(CallExpression[callee.name=${NAME}], CallExpression[callee.object.name=${NAME}], CallExpression[callee.callee.object.name=${NAME}], CallExpression[callee.tag.object.name=${NAME}])`;
6
+ const SETUP = "CallExpression[callee.name='setupBeforeEach']";
7
+ const SETUP_STATEMENT = `ExpressionStatement:has(> ${SETUP})`;
8
+ const SETUP_BUDGET_RESTRICTED_SYNTAX = [
9
+ {
10
+ // Each test boots on the setup budget once: no setupBeforeEach below another one.
11
+ selector: `:matches(Program, BlockStatement):has(> ${SETUP_STATEMENT}) ${DESCRIBE} ${SETUP}`,
12
+ message: 'A setupBeforeEach higher up already boots these tests. Use beforeEach here; it gets the regular wait budget.',
13
+ },
14
+ {
15
+ selector: `${SETUP_STATEMENT} ~ ${SETUP_STATEMENT}`,
16
+ message: 'Use setupBeforeEach once per block. Put all setup in it.',
17
+ },
18
+ {
19
+ selector: "CallExpression:matches([callee.name=/^(waitFor|findBy|findAllBy)/], [callee.property.name=/^(findBy|findAllBy)/]) > ObjectExpression > Property[key.name='timeout']",
20
+ message: 'Find out why this wait is slow first; most slow waits are avoidable. If it is not, disable this line with a reason.',
21
+ },
22
+ ];
23
+ const SETUP_BUDGET_GLOBALS = { setupBeforeEach: 'readonly' };
24
+
25
+ export { SETUP_BUDGET_GLOBALS, SETUP_BUDGET_RESTRICTED_SYNTAX };
@@ -0,0 +1,2 @@
1
+ // Resolver stub for tools that ignore `exports` (webpack 4). Node and Jest use `exports`.
2
+ export * from '../dist/integration/setup_budget_lint.js';
@@ -0,0 +1,2 @@
1
+ // Resolver stub for tools that ignore `exports` (webpack 4). Node and Jest use `exports`.
2
+ export * from '../dist/integration/setup_budget.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/frontend-tests",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "Reusable test infrastructure for GitLab frontend packages",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -20,6 +20,12 @@
20
20
  ],
21
21
  "integration/polyfills/text-encoding": [
22
22
  "./dist/integration/polyfills_text_encoding.d.ts"
23
+ ],
24
+ "integration/setup-budget": [
25
+ "./dist/integration/setup_budget.d.ts"
26
+ ],
27
+ "integration/setup-budget-lint": [
28
+ "./dist/integration/setup_budget_lint.d.ts"
23
29
  ]
24
30
  }
25
31
  },
@@ -74,6 +80,26 @@
74
80
  "default": "./dist/integration/jest_config.cjs"
75
81
  }
76
82
  },
83
+ "./integration/setup-budget": {
84
+ "import": {
85
+ "types": "./dist/integration/setup_budget.d.ts",
86
+ "default": "./dist/integration/setup_budget.js"
87
+ },
88
+ "require": {
89
+ "types": "./dist/integration/setup_budget.d.cts",
90
+ "default": "./dist/integration/setup_budget.cjs"
91
+ }
92
+ },
93
+ "./integration/setup-budget-lint": {
94
+ "import": {
95
+ "types": "./dist/integration/setup_budget_lint.d.ts",
96
+ "default": "./dist/integration/setup_budget_lint.js"
97
+ },
98
+ "require": {
99
+ "types": "./dist/integration/setup_budget_lint.d.cts",
100
+ "default": "./dist/integration/setup_budget_lint.cjs"
101
+ }
102
+ },
77
103
  "./*": {
78
104
  "import": {
79
105
  "types": "./dist/*.d.ts",
@@ -95,11 +121,15 @@
95
121
  },
96
122
  "peerDependencies": {
97
123
  "@jest/types": ">=29",
124
+ "@testing-library/dom": ">=9",
98
125
  "msw": "^2.0.0"
99
126
  },
100
127
  "peerDependenciesMeta": {
101
128
  "@jest/types": {
102
129
  "optional": true
130
+ },
131
+ "@testing-library/dom": {
132
+ "optional": true
103
133
  }
104
134
  },
105
135
  "devDependencies": {
@@ -109,6 +139,7 @@
109
139
  "@rollup/plugin-node-resolve": "^16.0.3",
110
140
  "@rollup/plugin-typescript": "^12.3.0",
111
141
  "@rstest/core": "^0.12.5",
142
+ "@testing-library/dom": "^10.4.2",
112
143
  "@types/lodash-es": "^4.17.12",
113
144
  "@types/node": "^20",
114
145
  "eslint": "^9.0.0",