Skip to content

Commit

Permalink
fix hashing import
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 22, 2022
1 parent 63f3f39 commit 71f3754
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 134 deletions.
2 changes: 1 addition & 1 deletion exchanges/auth/src/authExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
Operation,
OperationResult,
} from '@urql/core';
import { queryOperation } from '@urql/core/test-utils';
import { queryOperation } from '../../../packages/core/src/test-utils';

const makeExchangeArgs = () => {
const operations: Operation[] = [];
Expand Down
16 changes: 9 additions & 7 deletions exchanges/context/src/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ it(`calls getContext`, () => {
expect(result).toHaveBeenCalledTimes(1);
});

it(`calls getContext async`, done => {
it(`calls getContext async`, async () => {
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
Expand Down Expand Up @@ -108,10 +108,12 @@ it(`calls getContext async`, done => {

next(op);

setTimeout(() => {
expect(response).toHaveBeenCalledTimes(1);
expect(response.mock.calls[0][0].context.headers).toEqual(headers);
expect(result).toHaveBeenCalledTimes(1);
done();
}, 10);
await new Promise(res => {
setTimeout(() => {
expect(response).toHaveBeenCalledTimes(1);
expect(response.mock.calls[0][0].context.headers).toEqual(headers);
expect(result).toHaveBeenCalledTimes(1);
res();
}, 10);
});
});
2 changes: 1 addition & 1 deletion exchanges/execute/src/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
context,
queryOperation,
subscriptionOperation,
} from '@urql/core/src/test-utils';
} from '../../../packages/core/src/test-utils';
import {
makeErrorResult,
makeOperation,
Expand Down
46 changes: 25 additions & 21 deletions exchanges/request-policy/src/requestPolicyExchange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ beforeEach(() => {
({ source: ops$, next } = makeSubject<Operation>());
});

it(`upgrades to cache-and-network`, done => {
it(`upgrades to cache-and-network`, async () => {
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
Expand Down Expand Up @@ -78,18 +78,20 @@ it(`upgrades to cache-and-network`, done => {
);
expect(result).toHaveBeenCalledTimes(1);

setTimeout(() => {
next(op);
expect(response).toHaveBeenCalledTimes(2);
expect(response.mock.calls[1][0].context.requestPolicy).toEqual(
'cache-and-network'
);
expect(result).toHaveBeenCalledTimes(2);
done();
}, 10);
await new Promise(res => {
setTimeout(() => {
next(op);
expect(response).toHaveBeenCalledTimes(2);
expect(response.mock.calls[1][0].context.requestPolicy).toEqual(
'cache-and-network'
);
expect(result).toHaveBeenCalledTimes(2);
res();
}, 10);
});
});

it(`doesn't upgrade when shouldUpgrade returns false`, done => {
it(`doesn't upgrade when shouldUpgrade returns false`, async () => {
const response = vi.fn(
(forwardOp: Operation): OperationResult => {
return {
Expand Down Expand Up @@ -123,14 +125,16 @@ it(`doesn't upgrade when shouldUpgrade returns false`, done => {
);
expect(result).toHaveBeenCalledTimes(1);

setTimeout(() => {
next(op);
expect(response).toHaveBeenCalledTimes(2);
expect(response.mock.calls[1][0].context.requestPolicy).toEqual(
'cache-first'
);
expect(result).toHaveBeenCalledTimes(2);
expect(shouldUpgrade).toBeCalledTimes(2);
done();
}, 10);
await new Promise(res => {
setTimeout(() => {
next(op);
expect(response).toHaveBeenCalledTimes(2);
expect(response.mock.calls[1][0].context.requestPolicy).toEqual(
'cache-first'
);
expect(result).toHaveBeenCalledTimes(2);
expect(shouldUpgrade).toBeCalledTimes(2);
res();
}, 10);
});
});
11 changes: 7 additions & 4 deletions packages/core/src/utils/request.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
vi.mock('./hash', async () => ({
hash: await vi.importActual('./hash').hash,
phash: (x: number) => x,
}));
vi.mock('./hash', async () => {
const hash = await vi.importActual('./hash');
return {
...hash,
phash: (x: number) => x,
};
});

import { parse, print } from 'graphql';
import { gql } from '../gql';
Expand Down
13 changes: 8 additions & 5 deletions packages/preact-urql/src/components/Mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('Mutation', () => {
cleanup();
});

it('Should execute the mutation', done => {
it('Should execute the mutation', async () => {
// eslint-disable-next-line
let execute = () => {},
props = {};
Expand Down Expand Up @@ -60,9 +60,12 @@ describe('Mutation', () => {
fetching: true,
error: undefined,
});
setTimeout(() => {
expect(props).toStrictEqual({ data: 1, fetching: false, error: 2 });
done();
}, 400);

await new Promise(res => {
setTimeout(() => {
expect(props).toStrictEqual({ data: 1, fetching: false, error: 2 });
res();
}, 400);
});
});
});
13 changes: 8 additions & 5 deletions packages/preact-urql/src/components/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Query', () => {
cleanup();
});

it('Should execute the query', done => {
it('Should execute the query', async () => {
let props = {};
const Test = () => h('p', {}, 'hi');
const App = () => {
Expand All @@ -50,9 +50,12 @@ describe('Query', () => {
fetching: true,
error: undefined,
});
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: false, error: 1 });
done();
}, 250);

await new Promise(res => {
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: false, error: 1 });
res();
}, 250);
});
});
});
13 changes: 8 additions & 5 deletions packages/preact-urql/src/components/Subscription.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Subscription', () => {
cleanup();
});

it('Should execute the subscription', done => {
it('Should execute the subscription', async () => {
let props = {};
const Test = () => h('p', {}, 'hi');
const App = () => {
Expand All @@ -46,9 +46,12 @@ describe('Subscription', () => {
fetching: true,
error: undefined,
});
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: true, error: 1 });
done();
}, 300);

await new Promise(res => {
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: true, error: 1 });
res();
}, 300);
});
});
});
96 changes: 52 additions & 44 deletions packages/preact-urql/src/hooks/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('useQuery', () => {
expect(state).toHaveProperty('fetching', true);
});

it('forwards data response', done => {
it('forwards data response', async () => {
const { rerender } = render(
h(Provider, {
value: client as any,
Expand All @@ -110,19 +110,21 @@ describe('useQuery', () => {
})
);

setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('data', 0);
done();
}, 400);
await new Promise(res => {
setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('data', 0);
res();
}, 400);
});
});

it('forwards error response', done => {
it('forwards error response', async () => {
const { rerender } = render(
h(Provider, {
value: client as any,
Expand All @@ -137,19 +139,21 @@ describe('useQuery', () => {
})
);

setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('error', 1);
done();
}, 400);
await new Promise(res => {
setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('error', 1);
res();
}, 400);
});
});

it('forwards extensions response', done => {
it('forwards extensions response', async () => {
const { rerender } = render(
h(Provider, {
value: client as any,
Expand All @@ -167,20 +171,22 @@ describe('useQuery', () => {
})
);

setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
await new Promise(res => {
setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);

expect(state).toHaveProperty('extensions', { i: 1 });
done();
}, 400);
expect(state).toHaveProperty('extensions', { i: 1 });
res();
}, 400);
});
});

it('sets fetching to false', done => {
it('sets fetching to false', async () => {
const { rerender } = render(
h(Provider, {
value: client as any,
Expand All @@ -195,16 +201,18 @@ describe('useQuery', () => {
})
);

setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('fetching', false);
done();
}, 400);
await new Promise(res => {
setTimeout(() => {
rerender(
h(Provider, {
value: client as any,
children: [h(QueryUser, { ...props })],
})
);
expect(state).toHaveProperty('fetching', false);
res();
}, 400);
});
});

describe('on change', () => {
Expand Down
12 changes: 7 additions & 5 deletions packages/react-urql/src/components/Mutation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Mutation', () => {
cleanup();
});

it('Should execute the mutation', done => {
it('Should execute the mutation', async () => {
let execute = () => {
/* noop */
},
Expand Down Expand Up @@ -65,9 +65,11 @@ describe('Mutation', () => {
fetching: true,
error: undefined,
});
setTimeout(() => {
expect(props).toStrictEqual({ data: 1, fetching: false, error: 2 });
done();
}, 400);
await new Promise(res => {
setTimeout(() => {
expect(props).toStrictEqual({ data: 1, fetching: false, error: 2 });
res();
}, 400);
});
});
});
12 changes: 7 additions & 5 deletions packages/react-urql/src/components/Query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Query', () => {
cleanup();
});

it('Should execute the query', done => {
it('Should execute the query', async () => {
let props = {};
const Test = () => <p>Hi</p>;
const App = () => {
Expand All @@ -54,9 +54,11 @@ describe('Query', () => {
fetching: true,
error: undefined,
});
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: false, error: 1 });
done();
}, 200);
await new Promise(res => {
setTimeout(() => {
expect(props).toStrictEqual({ data: 0, fetching: false, error: 1 });
res();
}, 200);
});
});
});
Loading

0 comments on commit 71f3754

Please sign in to comment.