diff --git a/jest.config.js b/jest.config.js index a7ae298..b71131b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,25 +1,17 @@ const { join } = require('path'); +const config = require('@folio/jest-config-stripes'); -/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ +/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ module.exports = { - testEnvironment: 'jsdom', + ...config, - preset: 'ts-jest', - transform: { - '^.+\\.(t|j)sx?$': 'ts-jest', - }, - transformIgnorePatterns: ['node_modules/(?!@folio|ky)'], coverageProvider: 'v8', moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'], testMatch: ['**/src/**/?(*.)test.{js,jsx,ts,tsx}'], - testPathIgnorePatterns: ['/node_modules/', 'src/typings/'], - - reporters: ['default', 'jest-junit'], coverageReporters: ['lcov', 'text'], - coverageDirectory: './artifacts/coverage-jest/', collectCoverageFrom: [ '/index.ts', '/src/**/*.{ts,tsx}', @@ -29,9 +21,15 @@ module.exports = { '!**/node_modules/**', ], - setupFiles: [join(__dirname, './src/test/setupTests.ts')], + setupFiles: [...config.setupFiles, join(__dirname, './src/test/setupTests.ts')], setupFilesAfterEnv: [join(__dirname, './src/test/jest.setup.ts')], + preset: 'ts-jest', + transform: { + '^.+\\.(ts|tsx)?$': 'ts-jest', + ...config.transform, + }, + moduleNameMapper: { '^.+\\.(css|svg)$': 'identity-obj-proxy', @@ -41,10 +39,4 @@ module.exports = { slowTestThreshold: 10, testTimeout: 20000, - - globals: { - 'ts-jest': { - tsconfig: 'src/tsconfig.json', - }, - }, }; \ No newline at end of file diff --git a/package.json b/package.json index b2981e5..fee8a43 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ }, "devDependencies": { "@folio/eslint-config-stripes": "^7.0.0", + "@folio/jest-config-stripes": "^2.0.0", "@folio/stripes": "^9.0.0", "@folio/stripes-cli": "^3.0.0", "@formatjs/cli": "^4.2.21", @@ -35,10 +36,6 @@ "eslint-plugin-jest": "^23.0.4", "eslint-import-resolver-webpack": "^0.13.2", "identity-obj-proxy": "^3.0.0", - "jest": "^28.0.0", - "jest-css-modules": "^2.1.0", - "jest-environment-jsdom": "^29.6.1", - "jest-junit": "^16.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-final-form": "^6.5.9", diff --git a/src/test/jest.setup.ts b/src/test/jest.setup.ts index 7b0828b..12527a7 100644 --- a/src/test/jest.setup.ts +++ b/src/test/jest.setup.ts @@ -1 +1 @@ -import '@testing-library/jest-dom'; +import '@folio/jest-config-stripes/testing-library/jest-dom'; diff --git a/src/test/util/expectRender.ts b/src/test/util/expectRender.ts index 0006280..de3df2e 100644 --- a/src/test/util/expectRender.ts +++ b/src/test/util/expectRender.ts @@ -1,9 +1,7 @@ -import { render } from '@testing-library/react'; +import { render } from '@folio/jest-config-stripes/testing-library/react'; import { ReactNode } from 'react'; import withIntlConfiguration from './withIntlConfiguration'; -export default function expectRender( - error: ReactNode -): jest.JestMatchers { +export default function expectRender(error: ReactNode): jest.JestMatchers { return expect(render(withIntlConfiguration(error)).container.textContent); } diff --git a/src/test/util/getIntl.tsx b/src/test/util/getIntl.tsx index c11852c..0474fa8 100644 --- a/src/test/util/getIntl.tsx +++ b/src/test/util/getIntl.tsx @@ -1,4 +1,4 @@ -import { cleanup, render } from '@testing-library/react'; +import { cleanup, render } from '@folio/jest-config-stripes/testing-library/react'; import React from 'react'; import { IntlContext, IntlShape } from 'react-intl'; import withIntlConfiguration from './withIntlConfiguration'; diff --git a/src/typings.d.ts b/src/typings.d.ts index 35306c6..1cae7c8 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -1 +1,12 @@ +/* eslint-disable import/no-extraneous-dependencies */ declare module '*.css'; + +// see STTYPES-9 to understand why this is necessary +declare module '@folio/jest-config-stripes/testing-library/react' { + export { default } from '@testing-library/react'; + export * from '@testing-library/react'; +} +declare module '@folio/jest-config-stripes/testing-library/user-event' { + export { default } from '@testing-library/user-event'; + export * from '@testing-library/user-event'; +} diff --git a/src/views/MainPage.test.tsx b/src/views/MainPage.test.tsx index 7519f80..7bf4cfe 100644 --- a/src/views/MainPage.test.tsx +++ b/src/views/MainPage.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen } from '@folio/jest-config-stripes/testing-library/react'; import React from 'react'; import MainPage from './MainPage'; diff --git a/src/tsconfig.json b/tsconfig.json similarity index 100% rename from src/tsconfig.json rename to tsconfig.json