Skip to content

Supertest: Jest encountered an unexpected token #391

@donaldp

Description

@donaldp

formidablejs/framework version: 0.28.4

Details

Getting an import error when running tests. Happens on both yarn and bun

Expected Behavior

Tests should pass

Actual Behavior

Tests are failing due to import issue

Possible Fix

Additional Info

Your Environment

  • Environment name and version: macOS 26, bun 1.3.1
  • Operating System and version: macOS 26,
  • Useful link to screenshot or any other information:

Steps to Reproduce

bun create formidable@latest bun-app
cd bun-app
bun run build
bun run test

Stack Trace

$ jest --roots test
 FAIL  test/app.e2e.test.ts
  ● Test suite failed to run

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
     • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
     • 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/configuration
    For information about custom transformations, see:
    https://jestjs.io/docs/code-transformation

    Details:

    /Users/donald/code/bun-app/node_modules/@paralleldrive/cuid2/index.js:1
    import { createId, init, getConstants, isCuid } from "./src/index.js";
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | const formidable = require('../.formidable/build').default
    > 2 | const supertest = require('supertest')
        |                   ^
      3 |
      4 | describe('Application (e2e)', () => {
      5 |       let app

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1318:40)
      at Object.<anonymous> (node_modules/formidable/dist/index.cjs:8:13)
      at Object.require (node_modules/superagent/src/node/index.js:16:20)
      at Object.<anonymous> (node_modules/supertest/lib/test.js:12:21)
      at Object.<anonymous> (node_modules/supertest/index.js:13:14)
      at Object.<anonymous> (test/app.e2e.test.ts:2:19)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        3.965 s
Ran all test suites.
error: script "test" exited with code 1

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions