Skip to content

Commit 471da20

Browse files
Bump Vitest to v4 to unblock @storybook/addon-vitest (#4260)
## Background #4257 is adding a Storybook a11y CI gate to `@graphiql/react`, currently via `@storybook/test-runner` + `axe-playwright`. The paved path Storybook recommends is `@storybook/addon-vitest`, which folds stories into the existing Vitest suite and avoids a separate workflow file, test-runner config, and JSON baseline. That addon requires Vitest ≥ 3; we're on `^2.1.9` workspace-wide, so this upgrade is a prerequisite for taking the cleaner approach in #4257 rather than landing cruft we'd immediately want to rip out. ## What this enables Switching #4257 to: - `@storybook/addon-vitest` + `@storybook/addon-a11y` - Browser-mode Vitest project for stories (Playwright Chromium, like the test-runner uses today) - Per-story `parameters.a11y.test: 'error' | 'todo' | 'off'` — no JSON baseline file - No new workflow, no `.storybook/test-runner.ts`, no `a11y-baseline.json`, no `@storybook/test-runner` / `axe-playwright` devDeps ## Changes Workspace-wide bump to Vitest v4 and its companion peer-deps. A few mocks needed light fixups for v4's stricter `new` semantics.
1 parent fd92d04 commit 471da20

14 files changed

Lines changed: 240 additions & 252 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"turbo": "^2.5.2",
114114
"typedoc": "^0.28.19",
115115
"typescript": "^5.8.0",
116-
"vitest": "^2.1.9",
116+
"vitest": "^4.1.6",
117117
"wgutils": "^1.2.5",
118118
"wsrun": "^5.2.4"
119119
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../graphiql/__mocks__/zustand.mts

packages/graphiql-plugin-doc-explorer/__mocks__/zustand.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../graphiql/__mocks__/zustand.mts

packages/graphiql-plugin-history/__mocks__/zustand.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/graphiql-plugin-history/vitest.config.mts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,15 @@ export default defineConfig({
1616
),
1717
},
1818
],
19+
// `GraphiQLProvider` kicks off Monaco dynamic imports that may settle
20+
// after these quick tests tear down; ignore those teardown errors.
21+
onUnhandledError(error) {
22+
if (
23+
error.name === 'EnvironmentTeardownError' &&
24+
/monaco-editor|monaco-graphql/.test(error.message)
25+
) {
26+
return false;
27+
}
28+
},
1929
},
2030
});

packages/graphiql/__mocks__/monaco-editor.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ if (!navigator.clipboard) {
2525
*/
2626
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2727
if (!window.ResizeObserver) {
28+
class ResizeObserverMock {
29+
observe() {}
30+
unobserve() {}
31+
disconnect() {}
32+
}
2833
Object.defineProperty(window, 'ResizeObserver', {
2934
writable: false,
30-
value: vi.fn().mockReturnValue({
31-
observe() {},
32-
disconnect() {},
33-
}),
35+
value: ResizeObserverMock,
3436
});
3537
}
3638

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
* @see https://zustand.docs.pmnd.rs/guides/testing#vitest
66
*/
77

8-
import { afterEach } from 'vitest';
8+
import { afterEach, vi } from 'vitest';
99
import { act } from '@testing-library/react';
10-
import {
11-
create as originalCreate,
12-
createStore as originalCreateStore,
13-
useStore,
14-
StateCreator,
15-
} from 'zustand';
10+
import type { StateCreator } from 'zustand';
11+
import type * as ZustandExports from 'zustand';
1612

17-
// Originally zustand docs suggest to use `export * from 'zustand'`, but I had issues with it.
18-
// It conflicts with locale export of `create` and `createStore` functions
19-
export { useStore };
13+
// A static `import ... from 'zustand'` resolves back to this mock and recurses.
14+
const {
15+
create: originalCreate,
16+
createStore: originalCreateStore,
17+
useStore: originalUseStore,
18+
} = await vi.importActual<typeof ZustandExports>('zustand');
19+
20+
export const useStore = originalUseStore;
2021

2122
// a variable to hold reset functions for all stores declared in the app
2223
export const storeResetFns = new Set<() => void>();
2324

24-
const createUncurried = <T>(stateCreator: StateCreator<T>) => {
25+
const createUncurried = <T,>(stateCreator: StateCreator<T>) => {
2526
const store = originalCreate(stateCreator);
2627
const initialState = store.getInitialState();
2728
storeResetFns.add(() => {
@@ -31,7 +32,7 @@ const createUncurried = <T>(stateCreator: StateCreator<T>) => {
3132
};
3233

3334
// when creating a store, we get its initial state, create a reset function and add it in the set
34-
export const create = (<T>(stateCreator: StateCreator<T>) => {
35+
export const create = (<T,>(stateCreator: StateCreator<T>) => {
3536
console.log('zustand create mock');
3637

3738
// to support a curried version of create
@@ -51,7 +52,7 @@ function createStoreUncurried<T>(stateCreator: StateCreator<T>) {
5152
}
5253

5354
// When creating a store, we get its initial state, create a reset function and add it in the set
54-
export const createStore = (<T>(stateCreator: StateCreator<T>) => {
55+
export const createStore = (<T,>(stateCreator: StateCreator<T>) => {
5556
console.log('zustand createStore mock');
5657

5758
// to support a curried version of createStore

packages/graphiql/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@testing-library/jest-dom": "^6.6.3",
6767
"@testing-library/react": "^16.3.0",
6868
"@vitejs/plugin-react": "^4.4.1",
69-
"@vitest/web-worker": "3.1.4",
69+
"@vitest/web-worker": "^4.1.6",
7070
"babel-plugin-react-compiler": "19.1.0-rc.1",
7171
"cross-env": "^7.0.2",
7272
"cypress": "^13.13.2",
@@ -78,7 +78,7 @@
7878
"typescript": "^5.8.0",
7979
"vite": "^6.3.4",
8080
"vite-plugin-dts": "^4.5.3",
81-
"vitest-canvas-mock": "0.3.3"
81+
"vitest-canvas-mock": "^1.1.4"
8282
},
8383
"browser": {
8484
"//": "esm.sh polyfills `process`, we don't need it",

packages/graphiql/src/GraphiQL.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ describe('GraphiQL', () => {
421421

422422
const callback = async () => {
423423
try {
424-
await findByText('Persist headers');
424+
// Expecting non-existence; short-circuit instead of waiting the default.
425+
await findByText('Persist headers', undefined, { timeout: 1000 });
425426
} catch {
426427
// eslint-disable-next-line no-throw-literal
427428
throw 'failed';

0 commit comments

Comments
 (0)