Skip to content

Commit

Permalink
chore: change global -> globalThis in tests (#3590)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored May 18, 2024
1 parent 88bed21 commit 3ffe6fd
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion exchanges/execute/src/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const exchangeArgs = {
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(() => {
Expand Down
4 changes: 2 additions & 2 deletions exchanges/graphcache/src/offlineExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ describe('storage', () => {
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',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/exchanges/debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ beforeEach(() => {
});

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;
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/exchanges/fetch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import { queryOperation } from '../test-utils';
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;
};
Expand All @@ -36,7 +36,7 @@ afterEach(() => {
});

afterAll(() => {
(global as any).AbortController = undefined;
(globalThis as any).AbortController = undefined;
});

const response = JSON.stringify({
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/internal/fetchSource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import { gql } from '../gql';
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;
};
Expand All @@ -32,7 +32,7 @@ beforeEach(() => {
});

afterAll(() => {
(global as any).AbortController = undefined;
(globalThis as any).AbortController = undefined;
});

const response = JSON.stringify({
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/utils/variables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('stringifyVariables', () => {
});

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+"}$/);
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/components/Mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Mutation', () => {
beforeEach(() => {
vi.useFakeTimers();

vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/components/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const client = {

describe('Query', () => {
beforeEach(() => {
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/components/Subscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const client = {
describe('Subscription', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/hooks/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MutationUser: FC<typeof props> = ({ query }) => {
};

beforeAll(() => {
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/hooks/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const QueryUser: FC<UseQueryArgs<{ myVar: number }>> = ({

beforeEach(() => {
vi.useFakeTimers();
vi.spyOn(global.console, 'error');
vi.spyOn(globalThis.console, 'error');
});

describe('useQuery', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/preact-urql/src/hooks/useSubscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const SubscriptionUser: FC<{
};

beforeAll(() => {
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-urql/src/components/Mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Mutation', () => {
beforeEach(() => {
vi.useFakeTimers();
// TODO: Fix use of act()
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-urql/src/components/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const variables = {
describe('Query', () => {
beforeEach(() => {
// TODO: Fix use of act()
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-urql/src/hooks/useMutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const MutationUser = ({ query }: { query: any }) => {
beforeEach(() => {
vi.useFakeTimers();

vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});

Expand Down
2 changes: 1 addition & 1 deletion packages/react-urql/src/hooks/useQuery.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const mockVariables = {
describe('useQuery', () => {
beforeAll(() => {
// TODO: Fix use of act()
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothing
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/react-urql/src/hooks/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const QueryUser = ({
beforeEach(() => {
vi.useFakeTimers();
// TODO: Fix use of act()
vi.spyOn(global.console, 'error').mockImplementation(() => {
vi.spyOn(globalThis.console, 'error').mockImplementation(() => {
// do nothings
});

Expand Down
6 changes: 3 additions & 3 deletions scripts/vitest/setup.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// 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 */
Expand Down

0 comments on commit 3ffe6fd

Please sign in to comment.