Skip to content
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"turbo": "^2.5.2",
"typedoc": "^0.28.19",
"typescript": "^5.8.0",
"vitest": "^2.1.9",
"vitest": "^4.1.6",
"wgutils": "^1.2.5",
"wsrun": "^5.2.4"
},
Expand Down
1 change: 0 additions & 1 deletion packages/graphiql-plugin-doc-explorer/__mocks__/zustand.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/graphiql-plugin-history/__mocks__/zustand.mts
1 change: 0 additions & 1 deletion packages/graphiql-plugin-history/__mocks__/zustand.ts

This file was deleted.

10 changes: 10 additions & 0 deletions packages/graphiql-plugin-history/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ export default defineConfig({
),
},
],
// `GraphiQLProvider` kicks off Monaco dynamic imports that may settle
// after these quick tests tear down; ignore those teardown errors.
onUnhandledError(error) {
if (
error.name === 'EnvironmentTeardownError' &&
/monaco-editor|monaco-graphql/.test(error.message)
) {
return false;
}
},
},
});
10 changes: 6 additions & 4 deletions packages/graphiql/__mocks__/monaco-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ if (!navigator.clipboard) {
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!window.ResizeObserver) {
class ResizeObserverMock {
observe() {}
unobserve() {}
disconnect() {}
}
Object.defineProperty(window, 'ResizeObserver', {
writable: false,
value: vi.fn().mockReturnValue({
observe() {},
disconnect() {},
}),
value: ResizeObserverMock,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
* @see https://zustand.docs.pmnd.rs/guides/testing#vitest
*/

import { afterEach } from 'vitest';
import { afterEach, vi } from 'vitest';
import { act } from '@testing-library/react';
import {
create as originalCreate,
createStore as originalCreateStore,
useStore,
StateCreator,
} from 'zustand';
import type { StateCreator } from 'zustand';
import type * as ZustandExports from 'zustand';

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

export const useStore = originalUseStore;

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

const createUncurried = <T>(stateCreator: StateCreator<T>) => {
const createUncurried = <T,>(stateCreator: StateCreator<T>) => {
const store = originalCreate(stateCreator);
const initialState = store.getInitialState();
storeResetFns.add(() => {
Expand All @@ -31,7 +32,7 @@ const createUncurried = <T>(stateCreator: StateCreator<T>) => {
};

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

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

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

// to support a curried version of createStore
Expand Down
4 changes: 2 additions & 2 deletions packages/graphiql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.3.0",
"@vitejs/plugin-react": "^4.4.1",
"@vitest/web-worker": "3.1.4",
"@vitest/web-worker": "^4.1.6",
"babel-plugin-react-compiler": "19.1.0-rc.1",
"cross-env": "^7.0.2",
"cypress": "^13.13.2",
Expand All @@ -78,7 +78,7 @@
"typescript": "^5.8.0",
"vite": "^6.3.4",
"vite-plugin-dts": "^4.5.3",
"vitest-canvas-mock": "0.3.3"
"vitest-canvas-mock": "^1.1.4"
},
"browser": {
"//": "esm.sh polyfills `process`, we don't need it",
Expand Down
3 changes: 2 additions & 1 deletion packages/graphiql/src/GraphiQL.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,8 @@ describe('GraphiQL', () => {

const callback = async () => {
try {
await findByText('Persist headers');
// Expecting non-existence; short-circuit instead of waiting the default.
await findByText('Persist headers', undefined, { timeout: 1000 });
} catch {
// eslint-disable-next-line no-throw-literal
throw 'failed';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import {
import { parseDocument } from '../parseDocument';

vi.mock('../Logger', () => {
const makeNoop = () => ({
error: vi.fn(),
warn: vi.fn(),
info: vi.fn(),
log: vi.fn(),
level: 0,
});
class NoopLogger {
error = vi.fn();
warn = vi.fn();
info = vi.fn();
log = vi.fn();
level = 0;
}
return {
Logger: vi.fn().mockImplementation(makeNoop),
NoopLogger: vi.fn().mockImplementation(makeNoop),
Logger: NoopLogger,
NoopLogger,
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import { Position, Range } from 'graphql-language-service';
import { findGraphQLTags as baseFindGraphQLTags } from '../findGraphQLTags';

vi.mock('../Logger', () => {
const makeNoop = () => ({
error: vi.fn(),
warn: vi.fn(),
info: vi.fn(),
log: vi.fn(),
level: 0,
});
class NoopLogger {
error = vi.fn();
warn = vi.fn();
info = vi.fn();
log = vi.fn();
level = 0;
}
return {
Logger: vi.fn().mockImplementation(makeNoop),
NoopLogger: vi.fn().mockImplementation(makeNoop),
Logger: NoopLogger,
NoopLogger,
};
});

Expand Down
6 changes: 1 addition & 5 deletions packages/graphql-language-service-server/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ export default defineConfig({
testTimeout: 5000,
clearMocks: true,
pool: 'threads',
poolOptions: {
threads: {
singleThread: true,
},
},
fileParallelism: false,
include: ['src/**/*.{test,spec}.ts'],
exclude: ['**/node_modules/**', '**/dist/**', '**/esm/**'],
// Required for the source alias below; tells vite to bundle this
Expand Down
Loading
Loading