Skip to content

Commit

Permalink
wip: test
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Nov 30, 2024
1 parent a3f150c commit 7d8f0b1
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
import type { Config } from 'jest';
import { createJsWithTsPreset } from 'ts-jest';

const compileModules = [
'@babel',
'.pnpm',
// Transform esm to cjs
'internmap',
'd3-*',
'lodash-es',
];

const ignoreList: string[] = [];
const esm = ['internmap', 'd3-*'].join('|');

// cnpm use `_` as prefix
['', '_'].forEach((prefix) => {
compileModules.forEach((module) => {
ignoreList.push(`${prefix}${module}`);
});
});

const transformIgnorePatterns = [
// Ignore modules without es dir.
// Update: @babel/runtime should also be transformed
`<rootDir>/node_modules/(?!(${esm}))`,
`<rootDir>/node_modules/.pnpm/(?!(${esm}))`,
// `[/\\\\]node_modules[/\\\\](?!${ignoreList.join('|')})[^/\\\\]+?[/\\\\](?!(es)[/\\\\])`,
];

const config: Config = {
preset: 'ts-jest',
...createJsWithTsPreset({
tsconfig: {
target: 'ESNext',
allowJs: true,
},
}),
testEnvironment: 'jsdom',
collectCoverage: false,
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
testRegex: '(/__tests__/.*\\.(test|spec))\\.ts$',
collectCoverageFrom: ['src/**/*.ts'],
// Transform esm to cjs.
transformIgnorePatterns: [
`<rootDir>/node_modules/(?!(${esm}))`,
`<rootDir>/node_modules/.pnpm/(?!(${esm}))`,
],
transformIgnorePatterns,
};

export default config;

0 comments on commit 7d8f0b1

Please sign in to comment.