kulshekhar / ts-jest

A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.

Home Page:https://kulshekhar.github.io/ts-jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug]: isolatedModules is not a replacement of transpileOnly

unional opened this issue · comments

Version

29.0.3

Steps to reproduce

Don't have a minimal repro, as this is about how the flag works.

You can see a test failure here:
https://github.com/justland/just-web/actions/runs/3668482089/jobs/6201650192

@just-web/events:coverage:     SyntaxError: The requested module '@unional/events-plus' does not provide an export named 'JustEventDuo'

Basically in that code, I have this line:

export { justEvent, JustEventDuo, JustEventEmpty, JustEventUno } from '@unional/events-plus'

If I add isolatedModules to tsconfig.json, I'll get this error from tsc:

ts/index.ts:5:35 - error TS1205: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

5 export { justEvent, JustEventDuo, JustEventEmpty, JustEventUno } from '@unional/events-plus'

That means isolatedModules should not be used as a replacement of transpileOnly, which was removed a while back.

Expected behavior

The test should run.

Actual behavior

Failed as above

Debug log

no log needed

Additional context

IMO we should re-introduce transpileOnly setting.

Environment

System:
    OS: Windows 10 10.0.22621
    CPU: (16) x64 AMD Ryzen 7 5800X 8-Core Processor
  Binaries:
    Node: 18.7.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    jest: ^29.3.1 => 29.3.1
commented

You are mistaking between 2 isolatedModules options, see improvement issue here #3750

Um, but the problem is the same.
If I remove isolatedModules from ts-jest config, the test pass.
If I break the export { ... } '@unional/events-plus' line into two, with one as export type {...}, the test pass too.

So it seems to me that the ts-jest isolatedModules has the same behavior and restriction.

I have made this a repro: https://github.com/justland/just-web/tree/ts-jest-isolated-modules

git clone justland/just-web
git checkout ts-jest-isolated-modules
pnpm i
pnpm events test

Here is the jest.config.mjs:

/** @type {import('jest').Config} */
export default {
  displayName: 'events',
  extensionsToTreatAsEsm: ['.ts'],
  moduleNameMapper: {
    '^(\\.{1,2}/.*)\\.js$': '$1',
  },
  roots: ['<rootDir>/ts'],
  testMatch: ['**/?(*.)+(spec|test|integrate|accept|system|unit).[jt]s?(x)'],
  transform: {
    '^.+\\.m?[t]sx?$': ['ts-jest', {
      isolatedModules: true,
      useESM: true
    }],
  }
}

You will see the test fails.
If you comment out isolatedModules: true,, the test will pass