Skip to content

Commit c68699c

Browse files
ciampomanzoorwanijk
authored andcommitted
Tests: Migrate internal linting to Vitest and remove unused Jest dependencies (WordPress#83502)
* Tests: Switch internal linting to the Vitest baseline * Tests: Simplify internal lint verification * E2E Tests: Remove unused Jest peer dependency (WordPress#83505) * E2E Tests: Remove unused Jest peer dependency * E2E Tests: Link Jest peer cleanup changelog * Tests: Address Vitest lint migration feedback --- Co-authored-by: ciampo <mciampini@git.wordpress.org> Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
1 parent e68b6a2 commit c68699c

14 files changed

Lines changed: 323 additions & 46 deletions

File tree

‎package-lock.json‎

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/block-editor/src/components/global-styles/test/dimensions-panel.jsdom.test.jsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,7 @@ function expectLocalOverride() {
158158

159159
// Asserts the placeholder treatment for a control. A control can inherit a
160160
// value while showing no placeholder when the inherited sides differ
161-
// (BoxControl cannot render a per-side placeholder). Kept as a helper so the
162-
// branch isn't a conditional `expect` in the test body (which
163-
// `jest/no-conditional-expect` disallows).
161+
// (BoxControl cannot render a per-side placeholder).
164162
function expectPlaceholderState( el, placeholder ) {
165163
if ( placeholder ) {
166164
expect( el ).toHaveAttribute( 'placeholder', placeholder );

‎packages/core-data/src/entity-types/test/types.jsdom.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
/* eslint-disable no-unused-expressions -- the assertions below are expression statements. */
1616
/* eslint-disable @typescript-eslint/no-unused-vars -- the values exist only so their inferred types can be asserted. */
17-
/* eslint-disable jest/expect-expect -- these tests contain compile-time assertions only. */
17+
/* eslint-disable vitest/expect-expect -- these tests contain compile-time assertions only. */
1818
import { dispatch, select, resolveSelect } from '@wordpress/data';
1919
import { describe, it } from 'vitest';
2020
import { store as coreStore } from '../../index';
@@ -895,6 +895,6 @@ describe( 'Entity record types', () => {
895895
} );
896896
} );
897897

898-
/* eslint-enable jest/expect-expect */
898+
/* eslint-enable vitest/expect-expect */
899899
/* eslint-enable no-unused-expressions */
900900
/* eslint-enable @typescript-eslint/no-unused-vars */

‎packages/e2e-tests/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Enhancements
6+
7+
- Remove the unused Jest peer dependency from the fixture package ([#83502](https://github.com/WordPress/gutenberg/pull/83502)).
8+
59
## 9.21.0 (2026-09-23)
610

711
## 9.20.0 (2026-09-10)

‎packages/e2e-tests/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"y-websocket": "^3.0.0"
3131
},
3232
"peerDependencies": {
33-
"jest": ">=29",
3433
"react": "^18 || ^19",
3534
"react-dom": "^18 || ^19"
3635
},

‎packages/interface/src/test/types.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type FillPropsOnClick = NonNullable<
2222
>[ 'onClick' ];
2323

2424
describe( 'Interface types', () => {
25-
// eslint-disable-next-line jest/expect-expect -- compile-time assertions only.
25+
// eslint-disable-next-line vitest/expect-expect -- compile-time assertions only.
2626
it( 'types the selector return values', () => {
2727
true satisfies Expect<
2828
ReturnType< Selectors[ 'isComplementaryAreaLoading' ] >,
@@ -34,7 +34,7 @@ describe( 'Interface types', () => {
3434
>;
3535
} );
3636

37-
// eslint-disable-next-line jest/expect-expect -- compile-time assertions only.
37+
// eslint-disable-next-line vitest/expect-expect -- compile-time assertions only.
3838
it( 'accepts typed and inline click handlers', () => {
3939
const onButtonClick = ( event: MouseEvent< HTMLButtonElement > ) =>
4040
event.currentTarget;

‎test/unit/config/console-test-cases.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ export default function consoleTests() {
178178
cleanup = () => console[ methodName ]( 'Cleanup message.' );
179179
} );
180180

181+
// The unasserted console call must fail the test even after resetting mocks.
182+
// eslint-disable-next-line vitest/expect-expect
181183
test.fails(
182184
'does not let afterEach reset hide an unexpected call',
183185
() => {

‎test/unit/scripts/test/vitest-policy-rules.test.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,27 @@ describe( 'Vitest policy rules', () => {
418418
}
419419
} );
420420

421+
it( 'rejects ES module exports from test suites', () => {
422+
for ( const source of [
423+
'export const value = true;',
424+
'export default true;',
425+
"export * from './helpers';",
426+
] ) {
427+
expectViolation(
428+
`import { test } from 'vitest'; ${ source }`,
429+
'Do not export from a test file',
430+
{ project: 'node', isVitestTest: true }
431+
);
432+
}
433+
} );
434+
435+
it( 'allows ES module exports from shared test helpers', () => {
436+
expectValid(
437+
"import { test, expect } from 'vitest'; export function suite() { test( 'example', () => { expect( true ).toBe( true ); } ); }",
438+
{ project: 'node' }
439+
);
440+
} );
441+
421442
it( 'allows properties on local module-like objects', () => {
422443
expectValid(
423444
'const module = { exports: {} };\nmodule.exports.value = true;\nconst exports = {};\nexports.value = true;',

‎test/unit/scripts/validate-test-routing.mjs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,12 @@ const vitestTests = new Set(
145145
);
146146

147147
// Retain only the public Jest adapter, legacy E2E/reporting packages, and the
148-
// active lint rules that support Vitest and legacy consumers.
148+
// runner-neutral jest-dom rules and Jest lint rules for legacy consumers.
149149
const retainedJestInfrastructure = [
150-
'dependency:packages/e2e-tests/package.json:peerDependencies.jest',
151150
'dependency:packages/eslint-plugin/package.json:dependencies.eslint-plugin-jest',
152151
'dependency:packages/report-flaky-tests/package.json:dependencies.@jest/test-result',
153152
'dependency:packages/report-flaky-tests/package.json:dependencies.jest-message-util',
154153
'dependency:packages/scripts/package.json:peerDependencies.jest',
155-
'dependency:tools/eslint/package.json:dependencies.eslint-plugin-jest',
156154
'dependency:tools/eslint/package.json:dependencies.eslint-plugin-jest-dom',
157155
];
158156
const infrastructureFiles = globSync(

‎test/unit/scripts/vitest-policy-rules.mjs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,23 @@ export function validateVitestPolicy( {
22482248
report( 'commonjs-import', 'CommonJS import', node );
22492249
}
22502250

2251+
// Preserve jest/no-export for suites. Vitest has no equivalent rule;
2252+
// shared helpers and setup modules must remain able to export.
2253+
if (
2254+
isVitestTest &&
2255+
[
2256+
'ExportNamedDeclaration',
2257+
'ExportDefaultDeclaration',
2258+
'ExportAllDeclaration',
2259+
].includes( node.type )
2260+
) {
2261+
report(
2262+
'test-export',
2263+
'Do not export from a test file. Move shared helpers to a separate module',
2264+
node
2265+
);
2266+
}
2267+
22512268
if (
22522269
node.type === 'TSExportAssignment' ||
22532270
( node.type === 'AssignmentExpression' &&

0 commit comments

Comments
 (0)