go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/jest.config.ts (about) 1 // Copyright 2023 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import type { Config } from 'jest'; 16 17 const config: Config = { 18 // Use `js-with-babel` instead of `js-with-ts` because 19 // 1. `js-with-babel` is significantly faster than `js-with-ts`. This is 20 // likely because babel transpiles each file individually while tsc compiles 21 // the entire project as a whole. 22 // 2. The production build is also transpiled by babel. Using the same 23 // transpiler helps ensuring the code under test behaves similar to the code 24 // in production. Ideally, we should build testing code with the same 25 // toolchain as we build production code (i.e. Vite). However, there's no 26 // plugin supporting that yet. 27 preset: 'ts-jest/presets/js-with-babel', 28 testEnvironment: 'jsdom', 29 // Match all JS/TS files under `**/__tests__/**` and all JS/TS files with 30 // extension `.test` before the JS/TS extension. Unlike the default patterns, 31 // `test.ts` is not treated as a test file since `test` in `test.ts` is not an 32 // extension. 33 testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/*.test.[jt]s?(x)'], 34 // Some modules use `es6` modules, which is not compatible with jest, so we 35 // need to transform them. 36 transformIgnorePatterns: ['/node_modules/?!(lodash-es|lit)'], 37 globalSetup: './src/testing_tools/global_setup.ts', 38 setupFilesAfterEnv: ['./src/testing_tools/setup_after_env.ts'], 39 moduleNameMapper: { 40 '\\.(css|less)$': 'identity-obj-proxy', 41 '\\.(svg|md)($|\\?)': '<rootDir>/src/testing_tools/asset_module_stub', 42 // Support custom path mapping declared in tsconfig.json. 43 '^@/(.*)': '<rootDir>/src/$1', 44 '^@root/(.*)': '<rootDir>/$1', 45 }, 46 }; 47 48 export default config;