Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Test suite doesnt work with dependencies #11

@seanaye

Description

@seanaye

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

  1. Add a project dependency with ESM exports in my case this is idb
  2. Try to run a jest test in which this dependency is imported
  3. Test failure

Specifications

  • Version: 0.4.2
  • Platform: MacOS, Node 16.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions