-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't run unit tests with jest when using esm modules, typescript and undici v5.16.0 #1878
Comments
edit: see #1878 (comment) for a better solution! This is an issue with diff --git a/jest.config.cjs b/jest.config.cjs
index 3841fe0..cb6e7d5 100644
--- a/jest.config.cjs
+++ b/jest.config.cjs
@@ -8,7 +8,7 @@ module.exports = {
},
},
moduleNameMapper: {
- '^(\\.{1,2}/.*)\\.js$': '$1',
+ '^(\\.{1,2}/.*)\\.js$': '$1.js',
},
testMatch: ["**/test/**/*.spec.ts"]
-};
\ No newline at end of file
+};
diff --git a/test/index.spec.ts b/test/index.spec.ts
index 87d3dbb..9068d1f 100644
--- a/test/index.spec.ts
+++ b/test/index.spec.ts
@@ -7,7 +7,7 @@ describe('get request', function () {
afterAll(stopServer);
it('makes get request', async () => {
- const result = await get(BASE_URL);
+ const result = await (await get(BASE_URL)).body.text();
expect(result).toBe('Hello World');
});
}) I would experiment with |
Okay, it seems like ts-jest is at fault for suggesting a bad default for moduleNameWrapper. |
Yeah, ts-jest's suggestion is to just drop the To fix this in my project, I changed my
It's a bit of a hack, but until Jest has full ESM support, it gets the job done. To help future searchers, I should note, I was led to this issue while trying to debug this problem when importing |
upon further diagnosis, the issue earlier wasn't with TS 5, but rather with discord.js 14.8.0 requiring undici. nodejs/undici#1878
Bug Description
When trying to run unit tests with jest for files which use undici an error is thrown.
Reproducible By
You can reproduce this error by cloning this repo. README contains steps to reproduce the bug.
Expected Behavior
Unit tests should complete successfully.
Logs & Screenshots
This is the error shown by jest:
Also notice that if you lower the undici version, let's say to v5.15.0, a different issue will be thrown
Environment
MacOS Monterey
Node v16.14.2
Undici v5.16.0
The text was updated successfully, but these errors were encountered: