This repository was archived by the owner on Aug 6, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 103
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
Test suite doesnt work with dependencies #11
Copy link
Copy link
Open
Description
Expected Behavior
Simple jest tests should work when there are project dependencies that use ESM syntax.
Actual Behavior
If any added dependency has ESM exports, jest tests will fail and complain about unexpected tokens
FAIL src/utils.test.ts
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/Users/seanaye/dev/coparse/filesystem/node_modules/idb/with-async-ittr.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './build/esm/index.js';
^^^^^^
SyntaxError: Unexpected token 'export'
1 | import { FileHandle, FileSource, FileSystemFile, LegacyFile } from "./file";
> 2 | import { DBSchema, IDBPDatabase, openDB } from "idb/with-async-ittr.js";
I have tried all of the things suggested by the error message but nothing works.
Steps to Reproduce the Problem
- Add a project dependency with ESM exports in my case this is
idb - Try to run a jest test in which this dependency is imported
- Test failure
Specifications
- Version: 0.4.2
- Platform: MacOS, Node 16.1
laustdeleuran and sandereversstaffanselander
Metadata
Metadata
Assignees
Labels
No labels