swc-project / swc-node

Faster ts-node without typecheck
MIT License
1.78k stars 75 forks source link

Setting up `swc-node/jest` with pnpm #731

Closed MattSilvaa closed 5 months ago

MattSilvaa commented 1 year ago

Hello! I am having difficulties running my jest unit tests when transforming them with swc-node/jest. Is there something obvious that I am doing wrong? Any help is appreciated, thanks!

jest.config.js

module.exports = {
  cacheDirectory: '<rootDir>/jc',
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
  setupFilesAfterEnv: ['jest-specific-snapshot', '<rootDir>/test/setup.ts'],
  testMatch: ['<rootDir>/test/**/*.jest.ts'],
  transform: {
    '^.+\\.(t|j)sx?$': ['@swc-node/jest'],
  },
  verbose: true
}

Error message:

Test suite failed to run

    failed to process input file

    Caused by:
        0: failed to open input source map file
        1: No such file or directory (os error 2)

      at Compiler.transformSync (node_modules/.pnpm/@swc+core@1.3.22/node_modules/@swc/core/index.js:241:29)
      at transformSync (node_modules/.pnpm/@swc+core@1.3.22/node_modules/@swc/core/index.js:348:21)
      at transformJest (node_modules/.pnpm/@swc-node+core@1.10.5_@swc+core@1.3.22/node_modules/@swc-node/core/index.ts:81:26)
      at Object.process (node_modules/.pnpm/@swc-node+jest@1.5.5_@swc+core@1.3.22_typescript@4.3.5/node_modules/@swc-node/jest/index.ts:33:27)
      at ScriptTransformer.transformSource (node_modules/.pnpm/@jest+transform@29.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:542:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/.pnpm/@jest+transform@29.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:671:40)
      at ScriptTransformer.transform (node_modules/.pnpm/@jest+transform@29.6.2/node_modules/@jest/transform/build/ScriptTransformer.js:723:19)

Problem seems to be that it can't find transformJest and Object.process because it's looking for the index file in the wrong location.