From 63f3f395f09a37be417edb31c687cd7729b84499 Mon Sep 17 00:00:00 2001 From: jdecroock Date: Tue, 22 Nov 2022 17:45:58 +0100 Subject: [PATCH] use importActual --- exchanges/execute/src/execute.test.ts | 7 +++---- packages/core/src/utils/request.test.ts | 11 +++++------ .../react-urql/src/components/Mutation.test.tsx | 5 ++--- .../react-urql/src/components/Query.test.tsx | 5 ++--- .../react-urql/src/hooks/useMutation.test.tsx | 5 ++--- packages/react-urql/src/hooks/useQuery.test.tsx | 5 ++--- .../src/hooks/useSubscription.test.tsx | 3 +-- .../storage-rn/src/makeAsyncStorage.test.ts | 17 +++++++++++++---- packages/vue-urql/src/useMutation.test.ts | 15 +++++++++------ packages/vue-urql/src/useQuery.test.ts | 2 +- packages/vue-urql/src/useSubscription.test.ts | 2 +- 11 files changed, 41 insertions(+), 36 deletions(-) diff --git a/exchanges/execute/src/execute.test.ts b/exchanges/execute/src/execute.test.ts index 454cd020f5..b63cb69088 100644 --- a/exchanges/execute/src/execute.test.ts +++ b/exchanges/execute/src/execute.test.ts @@ -1,6 +1,5 @@ -vi.mock('graphql', () => { - // eslint-disable-next-line - const graphql = require('graphql'); +vi.mock('graphql', async () => { + const graphql = await vi.importActual('graphql'); return { __esModule: true, @@ -27,7 +26,7 @@ import { context, queryOperation, subscriptionOperation, -} from '@urql/core/test-utils'; +} from '@urql/core/src/test-utils'; import { makeErrorResult, makeOperation, diff --git a/packages/core/src/utils/request.test.ts b/packages/core/src/utils/request.test.ts index b90c385413..8da185ee25 100644 --- a/packages/core/src/utils/request.test.ts +++ b/packages/core/src/utils/request.test.ts @@ -1,13 +1,12 @@ +vi.mock('./hash', async () => ({ + hash: await vi.importActual('./hash').hash, + phash: (x: number) => x, +})); + import { parse, print } from 'graphql'; import { gql } from '../gql'; import { createRequest, stringifyDocument } from './request'; -vi.mock('./hash', () => ({ - // eslint-disable-next-line - hash: require('./hash').hash, - phash: (x: number) => x, -})); - it('should hash identical queries identically', () => { const reqA = createRequest('{ test }'); const reqB = createRequest('{ test }'); diff --git a/packages/react-urql/src/components/Mutation.test.tsx b/packages/react-urql/src/components/Mutation.test.tsx index ce99854a3e..81911454ff 100644 --- a/packages/react-urql/src/components/Mutation.test.tsx +++ b/packages/react-urql/src/components/Mutation.test.tsx @@ -1,8 +1,7 @@ /* eslint-disable react-hooks/rules-of-hooks */ -vi.mock('../context', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { delay, fromValue, pipe } = require('wonka'); +vi.mock('../context', async () => { + const { delay, fromValue, pipe } = await vi.importActual('wonka'); const mock = { executeMutation: vi.fn(() => pipe(fromValue({ data: 1, error: 2 }), delay(200)) diff --git a/packages/react-urql/src/components/Query.test.tsx b/packages/react-urql/src/components/Query.test.tsx index 94931dffe9..7bbc3e9643 100644 --- a/packages/react-urql/src/components/Query.test.tsx +++ b/packages/react-urql/src/components/Query.test.tsx @@ -1,6 +1,5 @@ -vi.mock('../context', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { map, interval, pipe } = require('wonka'); +vi.mock('../context', async () => { + const { map, interval, pipe } = await vi.importActual('wonka'); const mock = { executeQuery: vi.fn(() => pipe( diff --git a/packages/react-urql/src/hooks/useMutation.test.tsx b/packages/react-urql/src/hooks/useMutation.test.tsx index 3484d0d3e1..596e5d8457 100644 --- a/packages/react-urql/src/hooks/useMutation.test.tsx +++ b/packages/react-urql/src/hooks/useMutation.test.tsx @@ -1,9 +1,8 @@ /* eslint-disable react-hooks/rules-of-hooks */ // Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011 -vi.mock('../context', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { delay, fromValue, pipe } = require('wonka'); +vi.mock('../context', async () => { + const { delay, fromValue, pipe } = await vi.importActual('wonka'); const mock = { executeMutation: vi.fn(() => pipe(fromValue({ data: 1, error: 2, extensions: { i: 1 } }), delay(200)) diff --git a/packages/react-urql/src/hooks/useQuery.test.tsx b/packages/react-urql/src/hooks/useQuery.test.tsx index 3214342b79..ed67e92b32 100644 --- a/packages/react-urql/src/hooks/useQuery.test.tsx +++ b/packages/react-urql/src/hooks/useQuery.test.tsx @@ -1,9 +1,8 @@ /* eslint-disable react-hooks/rules-of-hooks */ // Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011 -vi.mock('../context', () => { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { map, interval, pipe } = require('wonka'); +vi.mock('../context', async () => { + const { map, interval, pipe } = await vi.importActual('wonka'); const mock = { executeQuery: vi.fn(() => pipe( diff --git a/packages/react-urql/src/hooks/useSubscription.test.tsx b/packages/react-urql/src/hooks/useSubscription.test.tsx index 5536856595..2d115d56f8 100644 --- a/packages/react-urql/src/hooks/useSubscription.test.tsx +++ b/packages/react-urql/src/hooks/useSubscription.test.tsx @@ -3,8 +3,7 @@ // Note: Testing for hooks is not yet supported in Enzyme - https://github.com/airbnb/enzyme/issues/2011 vi.mock('../context', () => { const d = { data: 1234, error: 5678 }; - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { merge, fromValue, never } = require('wonka'); + const { merge, fromValue, never } = vi.importActual('wonka'); const mock = { executeSubscription: vi.fn(() => merge([fromValue(d), never])), }; diff --git a/packages/storage-rn/src/makeAsyncStorage.test.ts b/packages/storage-rn/src/makeAsyncStorage.test.ts index 32a5378e09..6044663138 100644 --- a/packages/storage-rn/src/makeAsyncStorage.test.ts +++ b/packages/storage-rn/src/makeAsyncStorage.test.ts @@ -1,18 +1,27 @@ -import AsyncStorage from '@react-native-async-storage/async-storage'; -import NetInfo from '@react-native-community/netinfo'; -import { makeAsyncStorage } from './makeAsyncStorage'; - vi.mock('@react-native-community/netinfo', () => ({ addEventListener: () => 'addEventListener', + default: { + addEventListener: () => 'addEventListener', + }, })); vi.mock('@react-native-async-storage/async-storage', () => ({ + default: { + setItem: () => 'setItem', + getItem: () => 'getItem', + getAllKeys: () => 'getAllKeys', + removeItem: () => 'removeItem', + }, setItem: () => 'setItem', getItem: () => 'getItem', getAllKeys: () => 'getAllKeys', removeItem: () => 'removeItem', })); +import AsyncStorage from '@react-native-async-storage/async-storage'; +import NetInfo from '@react-native-community/netinfo'; +import { makeAsyncStorage } from './makeAsyncStorage'; + const request = [ { query: 'something something', diff --git a/packages/vue-urql/src/useMutation.test.ts b/packages/vue-urql/src/useMutation.test.ts index fce0e1f6b5..987501d710 100644 --- a/packages/vue-urql/src/useMutation.test.ts +++ b/packages/vue-urql/src/useMutation.test.ts @@ -1,10 +1,13 @@ -import { reactive, ref } from 'vue'; +import { reactive } from 'vue'; -vi.mock('./useClient.ts', () => ({ - __esModule: true, - ...require('./useClient.ts'), - useClient: () => ref(client), -})); +vi.mock('./useClient.ts', async () => { + const { ref } = await vi.importActual('vue'); + return { + __esModule: true, + ...(await vi.importActual('./useClient.ts')), + useClient: () => ref(client), + }; +}); import { makeSubject } from 'wonka'; import { createClient, gql } from '@urql/core'; diff --git a/packages/vue-urql/src/useQuery.test.ts b/packages/vue-urql/src/useQuery.test.ts index e960e7e611..58b371b043 100644 --- a/packages/vue-urql/src/useQuery.test.ts +++ b/packages/vue-urql/src/useQuery.test.ts @@ -2,7 +2,7 @@ import { nextTick, reactive, ref } from 'vue'; vi.mock('./useClient.ts', () => ({ __esModule: true, - ...require('./useClient.ts'), + ...(await vi.importActual('./useClient.ts')), useClient: () => ref(client), })); diff --git a/packages/vue-urql/src/useSubscription.test.ts b/packages/vue-urql/src/useSubscription.test.ts index 714958f338..ff23a13714 100644 --- a/packages/vue-urql/src/useSubscription.test.ts +++ b/packages/vue-urql/src/useSubscription.test.ts @@ -2,7 +2,7 @@ import { nextTick, reactive, ref } from 'vue'; vi.mock('./useClient.ts', () => ({ __esModule: true, - ...require('./useClient.ts'), + ...(await vi.importActual('./useClient.ts')), useClient: () => ref(client), }));