Skip to content

Commit d1f3958

Browse files
Copilotshati-patel
andcommitted
Clean up and document ESM compatibility solution
Co-authored-by: shati-patel <42641846+shati-patel@users.noreply.github.com>
1 parent 1c820c9 commit d1f3958

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

jest-resolver.cjs

Lines changed: 0 additions & 22 deletions
This file was deleted.

jest.config.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ const config: Config = {
8181
moduleFileExtensions: ["js", "mjs", "cjs", "jsx", "ts", "tsx", "json", "node"],
8282

8383
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84+
// NOTE: @actions/* packages v3.x are ESM-only. We need to explicitly map them to their
85+
// transpiled .js files in node_modules so Jest can resolve and transform them correctly.
86+
// This allows the test suite to import these ESM packages in a CommonJS environment.
8487
moduleNameMapper: {
8588
"^(\\.{1,2}/.*)\\.js$": "$1",
8689
"^@actions/core$": "<rootDir>/node_modules/@actions/core/lib/core.js",
@@ -108,9 +111,6 @@ const config: Config = {
108111
// Run tests from one or more projects
109112
// projects: undefined,
110113

111-
// A path to a custom resolver
112-
resolver: "<rootDir>/jest-resolver.cjs",
113-
114114
// Use this configuration option to add custom reporters to Jest
115115
// reporters: undefined,
116116

@@ -206,6 +206,8 @@ const config: Config = {
206206
},
207207

208208
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
209+
// NOTE: @actions/* packages need to be transformed because they are ESM modules.
210+
// We exclude them from the ignore pattern so they will be transformed by @swc/jest.
209211
transformIgnorePatterns: [
210212
// These use ES modules, so need to be transformed
211213
"node_modules/(?!(?:@octokit/.+|@actions/.+|before-after-hook|universal-user-agent)/.*)",

0 commit comments

Comments
 (0)