45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
/**
|
|
* Jest for the Doormile console.
|
|
*
|
|
* Babel is configured INLINE rather than through a babel.config file at the
|
|
* repo root on purpose: @vitejs/plugin-react picks up root Babel config, so a
|
|
* babel.config.cjs added for tests would silently change how production
|
|
* bundles are compiled. Test tooling must not be able to move the build.
|
|
*/
|
|
const babelOptions = {
|
|
babelrc: false,
|
|
configFile: false,
|
|
presets: [
|
|
['@babel/preset-env', { targets: { node: 'current' } }],
|
|
['@babel/preset-react', { runtime: 'automatic' }],
|
|
],
|
|
plugins: [require.resolve('./tests/setup/babel-plugin-import-meta.cjs')],
|
|
};
|
|
|
|
module.exports = {
|
|
testEnvironment: 'jsdom',
|
|
roots: ['<rootDir>/tests'],
|
|
testMatch: ['**/*.test.js', '**/*.test.jsx'],
|
|
setupFilesAfterEnv: ['<rootDir>/tests/setup/jest.setup.cjs'],
|
|
clearMocks: true,
|
|
restoreMocks: true,
|
|
transform: {
|
|
'^.+\.[jt]sx?$': ['babel-jest', babelOptions],
|
|
},
|
|
moduleNameMapper: {
|
|
'\.(css|less|scss|sass)$': '<rootDir>/tests/setup/styleMock.cjs',
|
|
'\.(png|jpe?g|gif|svg|webp|woff2?|ttf|eot)$': '<rootDir>/tests/setup/fileMock.cjs',
|
|
'^@/(.*)$': '<rootDir>/src/$1',
|
|
// Vite resolves these bare specifiers from src/ (jsconfig baseUrl).
|
|
// Jest needs telling, or any test importing a file that uses them fails
|
|
// to resolve rather than failing an assertion.
|
|
'^(components|pages|utils|themes|assets|lib|api)/(.*)$': '<rootDir>/src/$1/$2',
|
|
},
|
|
collectCoverageFrom: [
|
|
'src/api/doormile/**/*.js',
|
|
'src/lib/**/*.js',
|
|
'src/utils/**/*.js',
|
|
'!src/**/*.md',
|
|
],
|
|
};
|