Mirror: The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.

chore: change `global` -> `globalThis` in tests (#3590)

+1 -1
exchanges/execute/src/execute.test.ts
···
const expectedQueryOperationName = 'getUser';
const expectedSubscribeOperationName = 'subscribeToUser';
-
const fetchMock = (global as any).fetch as Mock;
+
const fetchMock = (globalThis as any).fetch as Mock;
const mockHttpResponseData = { key: 'value' };
beforeEach(() => {
+2 -2
exchanges/graphcache/src/offlineExchange.test.ts
···
describe('offline', () => {
beforeAll(() => {
vi.resetAllMocks();
-
global.navigator = { onLine: true } as any;
+
globalThis.navigator = { onLine: true } as any;
});
it('should intercept errored mutations', () => {
-
const onlineSpy = vi.spyOn(navigator, 'onLine', 'get');
+
const onlineSpy = vi.spyOn(globalThis.navigator, 'onLine', 'get');
const client = createClient({
url: 'http://0.0.0.0',
+1 -1
packages/core/src/exchanges/debug.test.ts
···
});
it('forwards query operations correctly', async () => {
-
vi.spyOn(global.console, 'log').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'log').mockImplementation(() => {
/** Do NOthing */
});
const { source: ops$, next, complete } = input;
+3 -3
packages/core/src/exchanges/fetch.test.ts
···
import { OperationResult } from '../types';
import { fetchExchange } from './fetch';
-
const fetch = (global as any).fetch as Mock;
+
const fetch = (globalThis as any).fetch as Mock;
const abort = vi.fn();
const abortError = new Error();
abortError.name = 'AbortError';
beforeAll(() => {
-
(global as any).AbortController = function AbortController() {
+
(globalThis as any).AbortController = function AbortController() {
this.signal = undefined;
this.abort = abort;
};
···
});
afterAll(() => {
-
(global as any).AbortController = undefined;
+
(globalThis as any).AbortController = undefined;
});
const response = JSON.stringify({
+3 -3
packages/core/src/internal/fetchSource.test.ts
···
import { OperationResult, Operation } from '../types';
import { makeOperation } from '../utils';
-
const fetch = (global as any).fetch as Mock;
+
const fetch = (globalThis as any).fetch as Mock;
const abort = vi.fn();
beforeAll(() => {
-
(global as any).AbortController = function AbortController() {
+
(globalThis as any).AbortController = function AbortController() {
this.signal = undefined;
this.abort = abort;
};
···
});
afterAll(() => {
-
(global as any).AbortController = undefined;
+
(globalThis as any).AbortController = undefined;
});
const response = JSON.stringify({
+3 -3
packages/core/src/utils/variables.test.ts
···
});
it('stringifies plain objects from foreign JS contexts correctly', () => {
-
const global: typeof globalThis = new Script(
+
const scriptGlobal: typeof globalThis = new Script(
'exports = globalThis'
).runInNewContext({}).exports;
-
const plain = new global.Function('return { test: true }')();
+
const plain = new scriptGlobal.Function('return { test: true }')();
expect(stringifyVariables(plain)).toBe('{"test":true}');
-
const data = new global.Function('return new (class Test {})')();
+
const data = new scriptGlobal.Function('return new (class Test {})')();
expect(stringifyVariables(data)).toMatch(/^{"__key":"\w+"}$/);
});
});
+1 -1
packages/preact-urql/src/components/Mutation.test.tsx
···
beforeEach(() => {
vi.useFakeTimers();
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/preact-urql/src/components/Query.test.tsx
···
describe('Query', () => {
beforeEach(() => {
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/preact-urql/src/components/Subscription.test.tsx
···
describe('Subscription', () => {
beforeEach(() => {
vi.useFakeTimers();
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/preact-urql/src/hooks/useMutation.test.tsx
···
};
beforeAll(() => {
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/preact-urql/src/hooks/useQuery.test.tsx
···
beforeEach(() => {
vi.useFakeTimers();
-
vi.spyOn(global.console, 'error');
+
vi.spyOn(globalThis.console, 'error');
});
describe('useQuery', () => {
+1 -1
packages/preact-urql/src/hooks/useSubscription.test.tsx
···
};
beforeAll(() => {
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/react-urql/src/components/Mutation.test.tsx
···
beforeEach(() => {
vi.useFakeTimers();
// TODO: Fix use of act()
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/react-urql/src/components/Query.test.tsx
···
describe('Query', () => {
beforeEach(() => {
// TODO: Fix use of act()
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/react-urql/src/hooks/useMutation.test.tsx
···
beforeEach(() => {
vi.useFakeTimers();
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
+1 -1
packages/react-urql/src/hooks/useQuery.spec.ts
···
describe('useQuery', () => {
beforeAll(() => {
// TODO: Fix use of act()
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
+1 -1
packages/react-urql/src/hooks/useQuery.test.tsx
···
beforeEach(() => {
vi.useFakeTimers();
// TODO: Fix use of act()
-
vi.spyOn(global.console, 'error').mockImplementation(() => {
+
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothings
});
+3 -3
scripts/vitest/setup.js
···
// This script is run before each `.test.ts` file.
import { vi } from 'vitest';
-
global.AbortController = undefined;
-
global.fetch = vi.fn();
+
globalThis.AbortController = undefined;
+
globalThis.fetch = vi.fn();
process.on('unhandledRejection', error => {
throw error;
});
const originalConsole = console;
-
global.console = {
+
globalThis.console = {
...originalConsole,
warn: (vi.SpyInstance = () => {
/* noop */