Skip to content

Commit

Permalink
initial pass of migrating to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 22, 2022
1 parent 1504a44 commit ee50a73
Show file tree
Hide file tree
Showing 69 changed files with 1,563 additions and 2,463 deletions.
12 changes: 6 additions & 6 deletions exchanges/auth/src/authExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { queryOperation } from '@urql/core/test-utils';

const makeExchangeArgs = () => {
const operations: Operation[] = [];
const result = jest.fn(
const result = vi.fn(
(operation: Operation): OperationResult => ({ operation })
);

Expand Down Expand Up @@ -146,7 +146,7 @@ it('adds the same token to subsequent operations', async () => {
const { exchangeArgs } = makeExchangeArgs();
const { source, next } = makeSubject<any>();

const result = jest.fn();
const result = vi.fn();
const auth$ = pipe(
source,
authExchange({
Expand Down Expand Up @@ -200,9 +200,9 @@ it('triggers authentication when an operation did error', async () => {
let initialAuth;
let afterErrorAuth;

const didAuthError = jest.fn().mockReturnValueOnce(true);
const didAuthError = vi.fn().mockReturnValueOnce(true);

const getAuth = jest
const getAuth = vi
.fn()
.mockImplementationOnce(() => {
initialAuth = Promise.resolve({ token: 'initial-token' });
Expand Down Expand Up @@ -265,12 +265,12 @@ it('triggers authentication when an operation will error', async () => {
let initialAuth;
let afterErrorAuth;

const willAuthError = jest
const willAuthError = vi
.fn()
.mockReturnValueOnce(true)
.mockReturnValue(false);

const getAuth = jest
const getAuth = vi
.fn()
.mockImplementationOnce(() => {
initialAuth = Promise.resolve({ token: 'initial-token' });
Expand Down
10 changes: 5 additions & 5 deletions exchanges/context/src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const queryOneData = {
},
};

const dispatchDebug = jest.fn();
const dispatchDebug = vi.fn();
let client, op, ops$, next;
beforeEach(() => {
client = createClient({ url: 'http://0.0.0.0' });
Expand All @@ -41,7 +41,7 @@ beforeEach(() => {
});

it(`calls getContext`, () => {
const response = jest.fn(
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
operation: forwardOp,
Expand All @@ -50,7 +50,7 @@ it(`calls getContext`, () => {
}
);

const result = jest.fn();
const result = vi.fn();
const forward: ExchangeIO = ops$ => {
return pipe(ops$, map(response));
};
Expand All @@ -76,7 +76,7 @@ it(`calls getContext`, () => {
});

it(`calls getContext async`, done => {
const response = jest.fn(
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
operation: forwardOp,
Expand All @@ -85,7 +85,7 @@ it(`calls getContext async`, done => {
}
);

const result = jest.fn();
const result = vi.fn();
const forward: ExchangeIO = ops$ => {
return pipe(ops$, map(response));
};
Expand Down
19 changes: 10 additions & 9 deletions exchanges/execute/src/execute.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
jest.mock('graphql', () => {
const graphql = jest.requireActual('graphql');
vi.mock('graphql', () => {
// eslint-disable-next-line
const graphql = require('graphql');

return {
__esModule: true,
...graphql,
print: jest.fn(() => '{ placeholder }'),
execute: jest.fn(() => ({ key: 'value' })),
subscribe: jest.fn(),
print: vi.fn(() => '{ placeholder }'),
execute: vi.fn(() => ({ key: 'value' })),
subscribe: vi.fn(),
};
});

Expand Down Expand Up @@ -48,11 +49,11 @@ const expectedSubscribeOperationName = getOperationName(
subscriptionOperation.query
);

const fetchMock = (global as any).fetch as jest.Mock;
const fetchMock = (global as any).fetch as vi.Mock;
const mockHttpResponseData = { key: 'value' };

beforeEach(() => {
jest.clearAllMocks();
vi.clearAllMocks();
mocked(print).mockImplementation(a => a as any);
mocked(execute).mockResolvedValue({ data: mockHttpResponseData });
mocked(subscribe).mockImplementation(async function* x(this: any) {
Expand Down Expand Up @@ -167,15 +168,15 @@ describe('on operation', () => {

fetchMock.mockResolvedValue({
status: 200,
text: jest
text: vi
.fn()
.mockResolvedValue(JSON.stringify({ data: mockHttpResponseData })),
});

const responseFromFetchExchange = await pipe(
fromValue(queryOperation),
fetchExchange({
dispatchDebug: jest.fn(),
dispatchDebug: vi.fn(),
forward: () => empty as Source<OperationResult>,
client: {} as Client,
}),
Expand Down
Loading

0 comments on commit ee50a73

Please sign in to comment.