Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/update to jest 29 in suite #8726

Merged
merged 3 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/suite/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ module.exports = {
},
verbose: false,
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
testEnvironment: 'jsdom',
fakeTimers: {
enableGlobally: false,
// https://jestjs.io/docs/28.x/upgrading-to-jest28#faketimers
legacyFakeTimers: true,
},
};
5 changes: 3 additions & 2 deletions packages/suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"translations:list-duplicates": "yarn tsx ../suite-data/src/translations/list-duplicates.ts",
"translations:list-unused": "yarn tsx ../suite-data/src/translations/list-unused.ts",
"type-check": "tsc --build tsconfig.json",
"test:unit": "jest",
"test:unit": "jest --version && jest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why add --version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because I am interested in this information as long as there are multiple versions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not update all of them in this PR? :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do it if you have time, will be appreciated

"test-unit:watch": "jest -o --watch"
},
"dependencies": {
Expand Down Expand Up @@ -131,8 +131,9 @@
"@types/ua-parser-js": "^0.7.36",
"@types/uuid": "^9.0.1",
"@types/zxcvbn": "^4.4.1",
"jest": "^26.6.3",
"jest": "^29.5.0",
"jest-canvas-mock": "^2.5.1",
"jest-environment-jsdom": "^29.5.0",
"jest-watch-typeahead": "0.6.5",
"prettier": "2.8.8",
"react-test-renderer": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { combineReducers, createReducer } from '@reduxjs/toolkit';
import { configureMockStore, testMocks } from '@suite-common/test-utils';
import { promiseAllSequence } from '@trezor/utils';

import { db } from 'src/storage';
import { accountsReducer } from 'src/reducers/wallet';
import { coinjoinReducer } from 'src/reducers/wallet/coinjoinReducer';
import selectedAccountReducer from 'src/reducers/wallet/selectedAccountReducer';
Expand Down Expand Up @@ -87,6 +88,9 @@ describe('coinjoinClientActions', () => {
afterEach(() => {
jest.clearAllMocks();
});
beforeAll(async () => {
await db.getDB();
});

fixtures.onCoinjoinRoundChanged.forEach(f => {
it(`onCoinjoinRoundChanged: ${f.description}`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('Discovery Actions', () => {

// Detailed info about this test could be found in fixtures
interruptionFixtures.forEach(f => {
it(`Start/stop/change networks/start: ${f.description}`, async done => {
it(`Start/stop/change networks/start: ${f.description}`, async () => {
require('@trezor/connect').setTestFixtures(f);
const store = initStore();
// additional action listener for triggering "discovery.stop" action
Expand Down Expand Up @@ -274,12 +274,12 @@ describe('Discovery Actions', () => {
expect(complete.type).toEqual(DISCOVERY.COMPLETE);
const discovery = store.getState().wallet.discovery[0];
expect(discovery.loaded).toEqual(store.getState().wallet.accounts.length);
done(expect(discovery.total).toEqual(discovery.loaded));
expect(discovery.total).toEqual(discovery.loaded);
});
});

changeNetworksFixtures.forEach(f => {
it(`Change network: ${f.description}`, async done => {
it(`Change network: ${f.description}`, async () => {
require('@trezor/connect').setTestFixtures(f);
const state = getInitialState();
const store = initStore(state);
Expand Down Expand Up @@ -313,7 +313,7 @@ describe('Discovery Actions', () => {
// length of accounts in reducer are equal discovery.loaded
expect(discovery.loaded).toEqual(accounts.length);
// 100% progress
done(expect(discovery.total).toEqual(discovery.loaded));
expect(discovery.total).toEqual(discovery.loaded);
});
});

Expand Down Expand Up @@ -446,7 +446,7 @@ describe('Discovery Actions', () => {
await store.dispatch(discoveryActions.restart());
});

it(`TrezorConnect responded with success but discovery was removed`, async done => {
it(`TrezorConnect responded with success but discovery was removed`, async () => {
const f = new Promise(resolve => {
setTimeout(() => resolve({ success: true }), 100);
});
Expand All @@ -465,10 +465,10 @@ describe('Discovery Actions', () => {
store.dispatch(discoveryActions.create('device-state', SUITE_DEVICE));
await store.dispatch(discoveryActions.start());
const action = store.getActions().pop();
done(expect(action.type).toEqual(DISCOVERY.REMOVE));
expect(action.type).toEqual(DISCOVERY.REMOVE);
});

it(`TrezorConnect responded with success but discovery is not running`, async done => {
it(`TrezorConnect responded with success but discovery is not running`, async () => {
const f = new Promise(resolve => {
setTimeout(() => resolve({ success: true }), 100);
});
Expand All @@ -492,7 +492,7 @@ describe('Discovery Actions', () => {
store.dispatch(discoveryActions.create('device-state', SUITE_DEVICE));
await store.dispatch(discoveryActions.start());
const action = store.getActions().pop();
done(expect(action.type).toEqual(notificationsActions.addToast.type));
expect(action.type).toEqual(notificationsActions.addToast.type);
});

it('Discovery completed but device is not connected anymore', async () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/suite/src/hooks/wallet/__tests__/useRbfForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ describe('useRbfForm hook', () => {
afterAll(async () => {
await TrezorConnect.dispose();
});
beforeEach(() => {
jest.setTimeout(30000); // action sequences takes time
});
afterEach(() => {
jest.clearAllMocks();
});
Expand Down
53 changes: 27 additions & 26 deletions packages/suite/src/hooks/wallet/__tests__/useSendForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,6 @@ const actionCallback = (
};

describe('useSendForm hook', () => {
beforeEach(() => {
dahaca marked this conversation as resolved.
Show resolved Hide resolved
jest.setTimeout(30000); // action sequences takes time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe leaving this one to avoid flakiness. I had this test failing few times locally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forcepushed

});
afterEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -251,33 +248,37 @@ describe('useSendForm hook', () => {

unmount();
});
});
}, 30000);

fixtures.setMax.forEach(f => {
it(f.description, async () => {
TrezorConnect.setTestFixtures(f.connect);
const store = initStore(getInitialState(f.store));
const callback: TestCallback = {};
const { unmount } = renderWithProviders(
store,
<SendIndex>
<Component callback={callback} />
</SendIndex>,
);
it(
f.description,
async () => {
TrezorConnect.setTestFixtures(f.connect);
const store = initStore(getInitialState(f.store));
const callback: TestCallback = {};
const { unmount } = renderWithProviders(
store,
<SendIndex>
<Component callback={callback} />
</SendIndex>,
);

// wait for first render
await waitForLoader();
// wait for first render
await waitForLoader();

// execute user actions sequence
if (f.actions) {
await actionSequence(f.actions, a => actionCallback(callback, a));
}
// execute user actions sequence
if (f.actions) {
await actionSequence(f.actions, a => actionCallback(callback, a));
}

// validate finalResult
actionCallback(callback, { result: f.finalResult });
// validate finalResult
actionCallback(callback, { result: f.finalResult });

unmount();
});
unmount();
},
30000,
);
});

fixtures.composeDebouncedTransaction.forEach(f => {
Expand Down Expand Up @@ -340,7 +341,7 @@ describe('useSendForm hook', () => {
});

fixtures.feeChange.forEach(f => {
it(f.description, async () => {
it(`changeFee: ${f.description}`, async () => {
TrezorConnect.setTestFixtures(f.connect);
const store = initStore(getInitialState(f.store));
const callback: TestCallback = {};
Expand All @@ -361,7 +362,7 @@ describe('useSendForm hook', () => {
actionCallback(callback, { result: f.finalResult });

unmount();
});
}, 30000);
});

fixtures.amountUnitChange.forEach(f => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ describe('pollingMiddleware', () => {
jest.runOnlyPendingTimers();

expect(store.getActions()).toEqual([{ type: POLLING.REQUEST, key: 'fake' }]);
// todo:
// this assertion fails without
// legacyFakeTimers: true,
// (see jest.config.js)
// https://jestjs.io/docs/28.x/upgrading-to-jest28#faketimers
expect(setTimeout).toHaveBeenCalledTimes(1);
});

Expand Down
6 changes: 4 additions & 2 deletions packages/suite/src/support/tests/svgTransform.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// https://stackoverflow.com/questions/46791263/jest-test-fail-syntaxerror-unexpected-token
module.exports = {
process() {
return 'module.exports = {};';
return {
code: 'module.exports = {};',
};
},

getCacheKey() {
// The output is always the same.
return 'svgTransform';
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8333,8 +8333,9 @@ __metadata:
history: ^4.10.1
idb: ^7.1.1
immer: 9.0.21
jest: ^26.6.3
jest: ^29.5.0
jest-canvas-mock: ^2.5.1
jest-environment-jsdom: ^29.5.0
jest-watch-typeahead: 0.6.5
jws: ^4.0.0
lottie-react: ^2.4.0
Expand Down
Loading