Skip to content

Commit 1eba293

Browse files
committed
refactor esm packages
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent aaeaa27 commit 1eba293

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

jest.config.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
import type { Config } from 'jest';
22

3+
const esmPackages = [
4+
'@primer/react',
5+
'@primer/primitives',
6+
'@primer/octicons-react',
7+
'@lit-labs/react',
8+
'lit',
9+
'@github/relative-time-element',
10+
'@github/tab-container-element',
11+
'@octokit/oauth-methods',
12+
'@octokit/oauth-authorization-url',
13+
'@octokit/request',
14+
'@octokit/request-error',
15+
'@octokit/endpoint',
16+
'@octokit/core',
17+
'@octokit/plugin-paginate-rest',
18+
'@octokit/plugin-rest-endpoint-methods',
19+
'universal-user-agent',
20+
];
21+
22+
const escapeForRegExp = (s: string) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
23+
24+
const transformIgnorePattern = `node_modules/(?!(?:${esmPackages.map(escapeForRegExp).join('|')})/)`;
25+
326
const config: Config = {
427
preset: 'ts-jest',
528
globalSetup: '<rootDir>/src/renderer/__helpers__/jest.setup.env.ts',
@@ -13,12 +36,8 @@ const config: Config = {
1336
'^.+\\.(js|mjs)$': 'babel-jest',
1437
},
1538
// Allow transforming specific ESM packages in node_modules that ship untranspiled ESM.
16-
// @primer/* libraries rely on lit and @lit-labs/react internally for some components.
17-
// @octokit/* libraries rely on universal-user-agent internally.
18-
// We also include GitHub web components that ship ESM-only builds.
19-
transformIgnorePatterns: [
20-
'node_modules/(?!(?:@primer/react|@primer/primitives|@primer/octicons-react|@lit-labs/react|lit|@github/relative-time-element|@github/tab-container-element|@octokit/oauth-methods|@octokit/oauth-authorization-url|@octokit/request|@octokit/request-error|@octokit/endpoint|@octokit/core|@octokit/plugin-paginate-rest|@octokit/plugin-rest-endpoint-methods|universal-user-agent)/)',
21-
],
39+
// Packages are listed above in `esmPackages` for easier maintenance.
40+
transformIgnorePatterns: [transformIgnorePattern],
2241
moduleNameMapper: {
2342
// GitHub Primer Design System - CSS in JS
2443
'\\.css$': 'identity-obj-proxy',

0 commit comments

Comments
 (0)