diff --git a/config/jest/babelTransform.js b/config/jest/babelTransform.js deleted file mode 100644 index 335131f59..000000000 --- a/config/jest/babelTransform.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; - -const babelJest = require('babel-jest').default; - -const hasJsxRuntime = (() => { - if (process.env.DISABLE_NEW_JSX_TRANSFORM === 'true') { - return false; - } - - try { - require.resolve('react/jsx-runtime'); - return true; - } catch (e) { - return false; - } -})(); - -module.exports = babelJest.createTransformer({ - presets: [ - [ - require.resolve('babel-preset-react-app'), - { - runtime: hasJsxRuntime ? 'automatic' : 'classic', - }, - ], - ], - "plugins": [ - [ - "formatjs", - { - "idInterpolationPattern": "[sha512:contenthash:base64:6]", - "ast": true - } - ] - ], - babelrc: false, - configFile: false, -}); diff --git a/config/jest/cssTransform.js b/config/jest/cssTransform.js deleted file mode 100644 index 37b59a75b..000000000 --- a/config/jest/cssTransform.js +++ /dev/null @@ -1,14 +0,0 @@ -'use strict'; - -// This is a custom Jest transformer turning style imports into empty objects. -// http://facebook.github.io/jest/docs/en/webpack.html - -module.exports = { - process() { - return {code: 'module.exports = {};'}; - }, - getCacheKey() { - // The output is always the same. - return 'cssTransform'; - }, -}; diff --git a/config/jest/fileTransform.js b/config/jest/fileTransform.js deleted file mode 100644 index 0a0709c97..000000000 --- a/config/jest/fileTransform.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict'; - -const path = require('path'); -const camelcase = require('camelcase'); - -// This is a custom Jest transformer turning file imports into filenames. -// http://facebook.github.io/jest/docs/en/webpack.html - -module.exports = { - process(src, filename) { - const assetFilename = JSON.stringify(path.basename(filename)); - - if (filename.match(/\.svg$/)) { - // Based on how SVGR generates a component name: - // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6 - const pascalCaseFilename = camelcase(path.parse(filename).name, { - pascalCase: true, - }); - const componentName = `Svg${pascalCaseFilename}`; - return `const React = require('react'); - module.exports = { - __esModule: true, - default: ${assetFilename}, - ReactComponent: React.forwardRef(function ${componentName}(props, ref) { - return { - $$typeof: Symbol.for('react.element'), - type: 'svg', - ref: ref, - key: null, - props: Object.assign({}, props, { - children: ${assetFilename} - }) - }; - }), - };`; - } - - return {code: `module.exports = ${assetFilename};`}; - }, -}; diff --git a/scripts/test.js b/scripts/test.js deleted file mode 100644 index a38c855c5..000000000 --- a/scripts/test.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -// Do this as the first thing so that any code reading it knows the right env. -process.env.BABEL_ENV = 'test'; -process.env.NODE_ENV = 'test'; -process.env.PUBLIC_URL = ''; - -// Makes the script crash on unhandled rejections instead of silently -// ignoring them. In the future, promise rejections that are not handled will -// terminate the Node.js process with a non-zero exit code. -process.on('unhandledRejection', err => { - throw err; -}); - -// Ensure environment variables are read. -require('../config/env'); - -const jest = require('jest'); -const execSync = require('child_process').execSync; -let argv = process.argv.slice(2); - -function isInGitRepository() { - try { - execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -function isInMercurialRepository() { - try { - execSync('hg --cwd . root', { stdio: 'ignore' }); - return true; - } catch (e) { - return false; - } -} - -// Watch unless on CI or explicitly running all tests -if ( - !process.env.CI && - argv.indexOf('--watchAll') === -1 && - argv.indexOf('--watchAll=false') === -1 -) { - // https://github.com/facebook/create-react-app/issues/5210 - const hasSourceControl = isInGitRepository() || isInMercurialRepository(); - argv.push(hasSourceControl ? '--watch' : '--watchAll'); -} - - -jest.run(argv); diff --git a/src/customJestResolver.js b/src/customJestResolver.js deleted file mode 100644 index c6c82d6ce..000000000 --- a/src/customJestResolver.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// -// Taken from https://github.com/microsoft/accessibility-insights-web/pull/5421/commits/9ad4e618019298d82732d49d00aafb846fb6bac7 - -module.exports = (path, options) => { - // Call the defaultResolver, so we leverage its cache, error handling, etc. - return options.defaultResolver(path, { - ...options, - // Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb) - packageFilter: pkg => { - // This is a workaround for https://github.com/uuidjs/uuid/pull/616 - // - // jest-environment-jsdom 28+ tries to use browser exports instead of default exports, - // but uuid only offers an ESM browser export and not a CommonJS one. Jest does not yet - // support ESM modules natively, so this causes a Jest error related to trying to parse - // "export" syntax. - // - // This workaround prevents Jest from considering uuid's module-based exports at all; - // it falls back to uuid's CommonJS+node "main" property. - // - // Once we're able to migrate our Jest config to ESM and a browser crypto - // implementation is available for the browser+ESM version of uuid to use (eg, via - // https://github.com/jsdom/jsdom/pull/3352 or a similar polyfill), this can go away. - if (pkg.name === 'uuid') { - delete pkg['exports']; - delete pkg['module']; - } - return pkg; - }, - }); -}; diff --git a/src/setupTests.js b/src/setupTests.js deleted file mode 100644 index 1f804e379..000000000 --- a/src/setupTests.js +++ /dev/null @@ -1,15 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; - -import mswServer from 'api-mocks/msw-server'; - -globalThis.IS_REACT_ACT_ENVIRONMENT = true; - -globalThis.ResizeObserver = require('resize-observer-polyfill'); - -beforeAll(() => mswServer.listen()); -afterEach(() => mswServer.resetHandlers()); -afterAll(() => mswServer.close());