From cd3a6bd9922bc67ec554470d32d4d3522d16442f Mon Sep 17 00:00:00 2001 From: Javier Pedemonte Date: Tue, 23 Jul 2024 14:31:05 -0500 Subject: [PATCH] test: polyfill missing method --- examples/discovery-search-app/package.json | 2 ++ examples/discovery-search-app/src/setupTests.js | 6 ++++++ packages/discovery-react-components/.storybook/main.ts | 6 +++++- packages/discovery-react-components/package.json | 7 ++----- packages/discovery-react-components/src/setupTests.ts | 6 ++++++ yarn.lock | 9 +++++---- 6 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 examples/discovery-search-app/src/setupTests.js diff --git a/examples/discovery-search-app/package.json b/examples/discovery-search-app/package.json index 335e4a517..b075e1d75 100644 --- a/examples/discovery-search-app/package.json +++ b/examples/discovery-search-app/package.json @@ -42,12 +42,14 @@ "devDependencies": { "@testing-library/cypress": "^7.0.7", "@types/proper-url-join": "^2.1.4", + "core-js": "^3.37.1", "cross-env": "^7.0.3", "cypress": "^13.6.3", "react-scripts": "^5.0.1", "start-server-and-test": "^2.0.3" }, "jest": { + "displayName": "Search app (unit)", "moduleNameMapper": { "^axios$": "axios/dist/node/axios.cjs" } diff --git a/examples/discovery-search-app/src/setupTests.js b/examples/discovery-search-app/src/setupTests.js new file mode 100644 index 000000000..9dbd14ee5 --- /dev/null +++ b/examples/discovery-search-app/src/setupTests.js @@ -0,0 +1,6 @@ +/** + * Set up `jest` when run from `react-scripts` + */ + +// polyfill for `Promise.withResolvers()` +import 'core-js/proposals/promise-with-resolvers'; diff --git a/packages/discovery-react-components/.storybook/main.ts b/packages/discovery-react-components/.storybook/main.ts index 068c1890f..c0ba6bd2f 100644 --- a/packages/discovery-react-components/.storybook/main.ts +++ b/packages/discovery-react-components/.storybook/main.ts @@ -1,4 +1,5 @@ import { StorybookConfig } from '@storybook/react-vite'; +import path from 'node:path'; import { mergeConfig } from 'vite'; import { nodePolyfills } from 'vite-plugin-node-polyfills'; @@ -23,7 +24,10 @@ const config: StorybookConfig = { disableTelemetry: true }, - staticDirs: ['../../../node_modules/pdfjs-dist/build/'], + staticDirs: [ + // should resolve to '.../pdfjs-dist/build/' + path.dirname(require.resolve('pdfjs-dist')) + ], framework: '@storybook/react-vite', diff --git a/packages/discovery-react-components/package.json b/packages/discovery-react-components/package.json index 27bbe6727..45c38ba3e 100644 --- a/packages/discovery-react-components/package.json +++ b/packages/discovery-react-components/package.json @@ -97,7 +97,7 @@ }, "jest": { "resetMocks": false, - "displayName": "Disco React Components (Unit)", + "displayName": "Disco React Components (unit)", "transformIgnorePatterns": [ "/!node_modules\\/react-virtualized/" ], @@ -109,9 +109,6 @@ "!src/**/__fixtures__/**", "!src/**/__stories__/**", "!src/**/*.stories.*" - ], - "moduleNameMapper": { - "^pdfjs-dist$": "pdfjs-dist/legacy/build/pdf.mjs" - } + ] } } diff --git a/packages/discovery-react-components/src/setupTests.ts b/packages/discovery-react-components/src/setupTests.ts index 191b5ba7a..a03f74c6a 100644 --- a/packages/discovery-react-components/src/setupTests.ts +++ b/packages/discovery-react-components/src/setupTests.ts @@ -1,4 +1,10 @@ +/** + * Set up `jest` when run from `react-scripts` + */ + import '@testing-library/jest-dom/extend-expect'; +// polyfill for `Promise.withResolvers()` +import 'core-js/proposals/promise-with-resolvers'; import setPdfJsGlobalWorkerOptions from 'utils/setPdfJsGlobalWorkerOptions'; // Set pdf.js worker for all tests diff --git a/yarn.lock b/yarn.lock index 5def2ce9d..60734696b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10130,10 +10130,10 @@ __metadata: languageName: node linkType: hard -"core-js@npm:^3.19.2, core-js@npm:^3.29.0": - version: 3.33.3 - resolution: "core-js@npm:3.33.3" - checksum: 10c0/08abdc9470c8228b9d09f61e62ab312738681202c4c34e9638889125b304b235f34c4fe22e9d41c20906ac0fcc807dca57c5ff7d6b90021bf64e8fe23461d9ab +"core-js@npm:^3.19.2, core-js@npm:^3.29.0, core-js@npm:^3.37.1": + version: 3.37.1 + resolution: "core-js@npm:3.37.1" + checksum: 10c0/440eb51a7a39128a320225fe349f870a3641b96c9ecd26470227db730ef8c161ea298eaea621db66ec0ff622a85299efb4e23afebf889c0a1748616102307675 languageName: node linkType: hard @@ -11319,6 +11319,7 @@ __metadata: carbon-components-react: "npm:7.59.24" carbon-icons: "npm:^7.0.7" classnames: "npm:^2.5.1" + core-js: "npm:^3.37.1" cors: "npm:^2.8.5" cross-env: "npm:^7.0.3" cypress: "npm:^13.6.3"