Skip to content

Commit

Permalink
Upgrade to Jest 30 (#1914)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Mar 26, 2024
1 parent 50fe84e commit 4fbec68
Show file tree
Hide file tree
Showing 16 changed files with 636 additions and 691 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"eslint-plugin-simple-import-sort": "^10.0.0",
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^3.2.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest": "^30.0.0-alpha.3",
"jest-environment-jsdom": "^30.0.0-alpha.3",
"jest-runner-eslint": "^2.2.0",
"jest-runner-prettier": "^1.0.0",
"jest-watch-master": "^1.0.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/addresses/src/__tests__/address-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jest.mock('@solana/codecs-strings', () => ({
getBase58Decoder: jest.fn(),
getBase58Encoder: jest.fn(),
}));
// HACK: Pierce the veil of `jest.isolateModules` so that the modules inside get the same version of
// `@solana/errors` that is imported above.
jest.mock('@solana/errors', () => jest.requireActual('@solana/errors'));

// real implementations
const originalBase58Module = jest.requireActual('@solana/codecs-strings');
Expand Down
4 changes: 4 additions & 0 deletions packages/assertions/src/__tests__/subtle-crypto-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import {
assertVerificationCapabilityIsAvailable,
} from '../subtle-crypto';

// HACK: Pierce the veil of `jest.isolateModules` so that the modules inside get the same version of
// `@solana/errors` that is imported above.
jest.mock('@solana/errors', () => jest.requireActual('@solana/errors'));

describe('assertDigestCapabilityIsAvailable()', () => {
describe('when `SubtleCrypto::digest` is available', () => {
it('does not throw', () => {
Expand Down
144 changes: 36 additions & 108 deletions packages/rpc-graphql/src/loaders/__tests__/account-loader-test.ts

Large diffs are not rendered by default.

72 changes: 18 additions & 54 deletions packages/rpc-graphql/src/loaders/__tests__/block-loader-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
});
it('cache resets on new tick', async () => {
Expand All @@ -66,9 +64,7 @@ describe('account loader', () => {
// Call the query twice
rpcGraphQL.query(source, { slot });
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(2);
});
});
Expand All @@ -90,9 +86,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -113,9 +107,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -139,9 +131,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(2);
expect(rpc.getBlock).toHaveBeenCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -166,9 +156,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -188,9 +176,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -211,9 +197,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -236,9 +220,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -260,9 +242,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -284,9 +264,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand Down Expand Up @@ -314,9 +292,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand Down Expand Up @@ -350,9 +326,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand Down Expand Up @@ -387,9 +361,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(2);
expect(rpc.getBlock).toHaveBeenCalledWith(slot, {
commitment: 'confirmed',
Expand Down Expand Up @@ -417,9 +389,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(2);
expect(rpc.getBlock).toHaveBeenCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -446,9 +416,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -468,9 +436,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(1);
expect(rpc.getBlock).toHaveBeenLastCalledWith(slot, {
commitment: 'confirmed',
Expand All @@ -494,9 +460,7 @@ describe('account loader', () => {
}
`;
rpcGraphQL.query(source, { slot });
// FIXME: Prefer async version of this timer runner. See https://github.com/jestjs/jest/issues/14549
await Promise.resolve();
jest.runAllTimers();
await jest.runAllTimersAsync();
expect(rpc.getBlock).toHaveBeenCalledTimes(3);
expect(rpc.getBlock).toHaveBeenCalledWith(slot, {
commitment: 'confirmed',
Expand Down
Loading

0 comments on commit 4fbec68

Please sign in to comment.