diff --git a/.nvmrc b/.nvmrc index 5cb297e3e48..9a2a0e219c9 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -16.17 +v20 diff --git a/.puppeteerrc.cjs b/.puppeteerrc.cjs new file mode 100644 index 00000000000..8c0e0bd08b6 --- /dev/null +++ b/.puppeteerrc.cjs @@ -0,0 +1,9 @@ +const {join} = require('path'); + +/** + * @type {import("puppeteer").Configuration} + */ +module.exports = { + // Changes the cache location for Puppeteer. + cacheDirectory: join(__dirname, 'node_modules', '.cache', 'puppeteer'), +}; \ No newline at end of file diff --git a/changelog/dev-upgrade-support-to-node-20 b/changelog/dev-upgrade-support-to-node-20 new file mode 100644 index 00000000000..a0512f89313 --- /dev/null +++ b/changelog/dev-upgrade-support-to-node-20 @@ -0,0 +1,4 @@ +Significance: minor +Type: dev + +Update node to v20 diff --git a/client/additional-methods-setup/upe-preview-methods-selector/test/add-payment-methods-task.test.js b/client/additional-methods-setup/upe-preview-methods-selector/test/add-payment-methods-task.test.js index 2408c60edde..3339e812975 100644 --- a/client/additional-methods-setup/upe-preview-methods-selector/test/add-payment-methods-task.test.js +++ b/client/additional-methods-setup/upe-preview-methods-selector/test/add-payment-methods-task.test.js @@ -270,10 +270,13 @@ describe( 'AddPaymentMethodsTask', () => { userEvent.click( screen.getByText( 'Continue' ) ); + await jest.runAllTimersAsync(); + expect( updateEnabledPaymentMethodsMock ).toHaveBeenCalledWith( [ 'card', 'p24', ] ); + await waitFor( () => expect( setCompletedMock ).toHaveBeenCalledWith( { initialMethods: [ 'card' ] }, @@ -335,6 +338,8 @@ describe( 'AddPaymentMethodsTask', () => { userEvent.click( screen.getByText( 'Continue' ) ); + await jest.runAllTimersAsync(); + // Methods are removed. expect( updateEnabledPaymentMethodsMock ).toHaveBeenCalledWith( [ 'card', diff --git a/client/components/banner-notice/tests/index.test.tsx b/client/components/banner-notice/tests/index.test.tsx index 819a9bf935e..1b669039c35 100644 --- a/client/components/banner-notice/tests/index.test.tsx +++ b/client/components/banner-notice/tests/index.test.tsx @@ -4,7 +4,6 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import user from '@testing-library/user-event'; -import { mocked } from 'ts-jest/utils'; import { speak } from '@wordpress/a11y'; /** @@ -16,7 +15,7 @@ jest.mock( '@wordpress/a11y', () => ( { speak: jest.fn() } ) ); describe( 'BannerNotice', () => { beforeEach( () => { - mocked( speak ).mockClear(); + jest.mocked( speak ).mockClear(); } ); it( 'should match snapshot', () => { diff --git a/client/components/loadable-checkbox/test/__snapshots__/index.test.js.snap b/client/components/loadable-checkbox/test/__snapshots__/index.test.js.snap index b282c022d63..df04b0eba0e 100644 --- a/client/components/loadable-checkbox/test/__snapshots__/index.test.js.snap +++ b/client/components/loadable-checkbox/test/__snapshots__/index.test.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Loadable checkbox renders correctly 1`] = ` -Object { +{ "asFragment": [Function], "baseElement":

{ jest.useFakeTimers(); act( () => { userEvent.click( container.queryByLabelText( 'Foo' ) ); - jest.runTimersToTime( 400 ); + jest.advanceTimersByTime( 400 ); } ); container.rerender( getLoadableCheckbox( false, 1500, 0 ) ); expect( mockOnChangeEvent ).not.toHaveBeenCalled(); act( () => { - jest.runTimersToTime( 1200 ); + jest.advanceTimersByTime( 1200 ); } ); container.rerender( getLoadableCheckbox( false, 1500, 0 ) ); expect( mockOnChangeEvent ).toHaveBeenCalled(); @@ -122,12 +122,12 @@ describe( 'Loadable checkbox', () => { jest.useFakeTimers(); act( () => { userEvent.click( container.queryByLabelText( 'Foo' ) ); - jest.runTimersToTime( 400 ); + jest.advanceTimersByTime( 400 ); } ); container.rerender( getLoadableCheckbox( false, 0, 1500 ) ); expect( mockOnChangeEvent ).not.toHaveBeenCalled(); act( () => { - jest.runTimersToTime( 1200 ); + jest.advanceTimersByTime( 1200 ); } ); container.rerender( getLoadableCheckbox( false, 0, 1500 ) ); expect( mockOnChangeEvent ).toHaveBeenCalledWith( false ); diff --git a/client/components/tooltip/test/index.test.tsx b/client/components/tooltip/test/index.test.tsx index cdbc146dd5f..a24ed25f0fa 100644 --- a/client/components/tooltip/test/index.test.tsx +++ b/client/components/tooltip/test/index.test.tsx @@ -193,6 +193,9 @@ describe( 'ClickTooltip', () => { act( () => { userEvent.click( screen.getByText( 'Trigger element' ) ); + } ); + + act( () => { jest.runAllTimers(); } ); diff --git a/client/connect-account-page/test/index.test.tsx b/client/connect-account-page/test/index.test.tsx index 21af6775c8c..cb176485667 100644 --- a/client/connect-account-page/test/index.test.tsx +++ b/client/connect-account-page/test/index.test.tsx @@ -6,7 +6,6 @@ import React from 'react'; import { render, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import apiFetch from '@wordpress/api-fetch'; -import { mocked } from 'ts-jest/utils'; /** * Internal dependencies @@ -103,7 +102,7 @@ describe( 'ConnectAccountPage', () => { render( ); // mockApiFetch.mockRejectedValueOnce( {} ); - mocked( apiFetch ).mockRejectedValueOnce( new Error() ); + jest.mocked( apiFetch ).mockRejectedValueOnce( new Error() ); userEvent.click( screen.getByRole( 'button', { name: 'Verify business details' } ) diff --git a/client/deposits/filters/test/index.js b/client/deposits/filters/test/index.js index ba69a1ab7fe..04071451934 100644 --- a/client/deposits/filters/test/index.js +++ b/client/deposits/filters/test/index.js @@ -15,10 +15,18 @@ import { DepositsFilters } from '../'; // TODO: this is a bit of a hack as we're mocking an old version of WC, we should relook at this. jest.mock( '@woocommerce/settings', () => ( { ...jest.requireActual( '@woocommerce/settings' ), - getSetting: jest.fn( ( key ) => ( key === 'wcVersion' ? 7.7 : '' ) ), + getSetting: jest.fn( ( key ) => ( key === 'wcVersion' ? 7.8 : '' ) ), } ) ); describe( 'Deposits filters', () => { + beforeAll( () => { + jest.useFakeTimers(); + } ); + + afterAll( () => { + jest.useRealTimers(); + } ); + beforeEach( () => { // the query string is preserved across tests, so we need to reset it updateQueryString( {}, '/', {} ); diff --git a/client/deposits/list/test/__snapshots__/index.tsx.snap b/client/deposits/list/test/__snapshots__/index.tsx.snap index e905e893318..5d6d3d1b96c 100644 --- a/client/deposits/list/test/__snapshots__/index.tsx.snap +++ b/client/deposits/list/test/__snapshots__/index.tsx.snap @@ -161,7 +161,6 @@ exports[`Deposits list renders correctly a single deposit 1`] = ` data-wp-component="CardBody" >