From 9f1831c23ef29289cd12b2df12a19311a87f1c85 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Tue, 31 Aug 2021 10:52:06 +0200 Subject: [PATCH] test(jest): opt-in to shorter snapshot format (#4843) * test(jest): opt-in to shorter snapshot format https://github.com/facebook/jest/pull/11654 ...waiting for the release of jest * remove usage of setImmediate (doesn't exist in browser) * make sessionStorage mock writable * update jest to latest * final update & snapshot changes * simplify lockfile * Update src/lib/__tests__/InstantSearch-test.tsx * simpler without fake timerz --- jest.config.js | 4 +- package.json | 13 +- scripts/jest/matchers/toWarnDev.ts | 4 +- src/__tests__/index-es-test.ts | 2 +- src/__tests__/index-test.ts | 2 +- .../ClearRefinements-test.tsx.snap | 12 +- .../__snapshots__/Hits-test.tsx.snap | 20 +- .../__snapshots__/MenuSelect-test.tsx.snap | 34 +- .../__snapshots__/Pagination-test.tsx.snap | 166 +- .../__snapshots__/RangeInput-test.tsx.snap | 140 +- .../RefinementListItem-test.tsx.snap | 8 +- .../__snapshots__/SearchBox-test.tsx.snap | 28 +- .../__snapshots__/Selector-test.tsx.snap | 4 +- .../__snapshots__/Slider-test.tsx.snap | 18 +- src/components/Stats/__tests__/Stats-test.tsx | 6 +- .../__snapshots__/Template-test.tsx.snap | 12 +- .../__tests__/connectDynamicWidgets-test.ts | 34 +- .../__tests__/connectGeoSearch-test.ts | 14 +- .../__tests__/connectHitsPerPage-test.ts | 18 +- .../__tests__/connectRefinementList-test.ts | 5 +- .../InstantSearch-integration-test.ts | 6 +- src/lib/__tests__/InstantSearch-test.tsx | 93 +- src/lib/__tests__/RoutingManager-test.ts | 48 +- .../__tests__/sessionStorage.ts | 1 + src/lib/routers/__tests__/history.test.ts | 6 +- .../__tests__/createMetadataMiddleware.ts | 28 +- src/widgets/answers/__tests__/answers-test.ts | 7 +- .../__snapshots__/breadcrumb-test.ts.snap | 18 +- .../clear-refinements-test.ts.snap | 48 +- .../__tests__/clear-refinements-test.ts | 4 +- .../current-refinements-test.ts.snap | 86 +- .../__tests__/dynamic-widgets-test.ts | 4 +- .../__snapshots__/geo-search-test.ts.snap | 20 +- .../hierarchical-menu-test.ts.snap | 102 +- .../__snapshots__/hits-per-page-test.ts.snap | 12 +- .../hits/__tests__/hits-integration-test.ts | 10 +- src/widgets/hits/__tests__/hits-test.ts | 150 +- src/widgets/index/__tests__/index-test.ts | 14 +- .../__snapshots__/infinite-hits-test.ts.snap | 174 +- .../infinite-hits-integration-test.ts | 30 +- .../__tests__/infinite-hits-test.ts | 40 +- .../__snapshots__/menu-select-test.ts.snap | 36 +- .../__tests__/__snapshots__/menu-test.ts.snap | 36 +- .../__snapshots__/numeric-menu-test.ts.snap | 48 +- .../__snapshots__/pagination-test.ts.snap | 16 +- .../__snapshots__/range-input-test.ts.snap | 84 +- .../__snapshots__/range-slider-test.ts.snap | 36 +- .../__snapshots__/rating-menu-test.ts.snap | 28 +- .../refinement-list-test.ts.snap | 28 +- .../__snapshots__/search-box-test.ts.snap | 20 +- src/widgets/sort-by/__tests__/sort-by-test.ts | 12 +- src/widgets/stats/__tests__/stats-test.ts | 24 +- .../toggle-refinement-test.ts.snap | 144 +- .../__snapshots__/voice-search-test.ts.snap | 26 +- test/utils/runAllMicroTasks.ts | 2 - yarn.lock | 1550 ++++++++++------- 56 files changed, 1945 insertions(+), 1590 deletions(-) delete mode 100644 test/utils/runAllMicroTasks.ts diff --git a/jest.config.js b/jest.config.js index b35a492dde..840b76a755 100644 --- a/jest.config.js +++ b/jest.config.js @@ -25,7 +25,9 @@ module.exports = { globals: { __DEV__: true, }, - + snapshotFormat: { + printBasicPrototype: false, + }, // reporter for circleci reporters: [ 'default', diff --git a/package.json b/package.json index a9200ed2bd..c3a84181e4 100644 --- a/package.json +++ b/package.json @@ -80,8 +80,7 @@ "@testing-library/preact": "1.0.2", "@types/classnames": "^2.2.7", "@types/enzyme": "^3.1.15", - "@types/jest": "^26.0.22", - "@types/jest-diff": "^24.3.0", + "@types/jest": "^27.0.1", "@types/jsdom": "^16.2.13", "@types/scriptjs": "^0.0.2", "@types/storybook__addon-actions": "^3.4.2", @@ -98,7 +97,7 @@ "algoliasearch": "4.10.3", "algoliasearch-v3": "npm:algoliasearch@3.35.1", "babel-eslint": "10.0.3", - "babel-jest": "26.6.3", + "babel-jest": "27.1.0", "babel-loader": "8.0.6", "babel-plugin-inline-replace-variables": "1.3.1", "babel-plugin-polyfill-es-shims": "0.0.7", @@ -120,12 +119,12 @@ "eslint-plugin-react": "7.18.0", "eslint-plugin-react-hooks": "2.3.0", "instantsearch-e2e-tests": "algolia/instantsearch-e2e-tests#1.3.0", - "jest": "26.6.3", - "jest-diff": "26.6.2", - "jest-environment-jsdom": "26.6.2", + "jest": "27.1.0", + "jest-diff": "27.1.0", + "jest-environment-jsdom": "27.1.0", "jest-environment-jsdom-global": "2.0.4", "jest-junit": "12.2.0", - "jest-watch-typeahead": "0.6.2", + "jest-watch-typeahead": "0.6.4", "jscodeshift": "0.7.0", "jsdom-global": "3.0.2", "places.js": "1.17.1", diff --git a/scripts/jest/matchers/toWarnDev.ts b/scripts/jest/matchers/toWarnDev.ts index c5dd72bf0f..739fa527da 100644 --- a/scripts/jest/matchers/toWarnDev.ts +++ b/scripts/jest/matchers/toWarnDev.ts @@ -1,6 +1,6 @@ /* eslint-disable no-console */ -import jestDiff from 'jest-diff'; +import { diff } from 'jest-diff'; declare global { // eslint-disable-next-line @typescript-eslint/no-namespace @@ -56,7 +56,7 @@ const matcher: jest.ExpectExtendMap = { Difference: -${jestDiff(expectedMessage, actualWarning)}`, +${diff(expectedMessage, actualWarning)}`, }; } diff --git a/src/__tests__/index-es-test.ts b/src/__tests__/index-es-test.ts index f11abea482..16127c057e 100644 --- a/src/__tests__/index-es-test.ts +++ b/src/__tests__/index-es-test.ts @@ -31,7 +31,7 @@ describe('instantsearch()', () => { it('includes the helper functions', () => { expect(Object.keys(instantsearch)).toMatchInlineSnapshot(` - Array [ + [ "version", "createInfiniteHitsSessionStorageCache", "highlight", diff --git a/src/__tests__/index-test.ts b/src/__tests__/index-test.ts index 91ef76077b..5a16a04b1f 100644 --- a/src/__tests__/index-test.ts +++ b/src/__tests__/index-test.ts @@ -21,7 +21,7 @@ describe('instantsearch()', () => { it('includes the API and the helper functions', () => { expect(Object.keys(instantsearch)).toMatchInlineSnapshot(` - Array [ + [ "version", "connectors", "widgets", diff --git a/src/components/ClearRefinements/__tests__/__snapshots__/ClearRefinements-test.tsx.snap b/src/components/ClearRefinements/__tests__/__snapshots__/ClearRefinements-test.tsx.snap index 22e03d4010..0b16d58f41 100644 --- a/src/components/ClearRefinements/__tests__/__snapshots__/ClearRefinements-test.tsx.snap +++ b/src/components/ClearRefinements/__tests__/__snapshots__/ClearRefinements-test.tsx.snap @@ -1,15 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ClearRefinements should render 1`] = ` -Array [ +[
- Array [ + [