Skip to content

@swc-node/jest doesn't pass options from tsconfig to swc properly  #700

Description

@meskill

After upgrading from 1.5.5 to 1.6.2 I get next error related to legacyDecorators:

 FAIL  packages/createApp.test.ts
  ● Test suite failed to run


      × Expression expected
        ╭─[/workspaces/app/createApp.test.ts:11:1]
     11 │   it('Создание и запуск приложения', async () => {
     13 │ 
     14 │     @Module({
        ·     ─
     15 │       providers: [
     16 │         {
     17 │           provide: 'level-3',
        ╰────


    Caused by:
        Syntax Error

      at Compiler.transformSync (node_modules/@swc/core/index.js:241:29)
      at transformSync (node_modules/@swc/core/index.js:348:21)
      at transformJest (node_modules/@swc-node/core/index.ts:74:2)
      at Object.process (node_modules/@swc-node/jest/index.ts:33:27)
      at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:519:31)
      at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:648:40)
      at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:700:19)

The source problem of the issue:

  1. This code converts @swc-node/jest options to swc options
  2. This code provides options from the tsconfig file to @swc-node/jest options
  3. As now the second piece of code defines swc property it overrides the whole jsc setup in the first piece of code.

The log of the input options and result options are following:

// before transform
 {
  module: 'commonjs',
  sourcemap: 'inline',
  experimentalDecorators: true,
  emitDecoratorMetadata: false,
  esModuleInterop: true,
  swc: {
    filename: '/workspaces/app/createApp.test.ts',
    inputSourceMap: undefined,
    sourceRoot: undefined,
    jsc: {
      externalHelpers: true,
      parser: [Object],
      paths: {},
      keepClassNames: true,
      target: 'es2015',
      transform: [Object]
    }
  }
}
// after transform
 {
  filename: '/workspaces/app/createApp.test.ts',
  jsc: {
    externalHelpers: true,
    parser: { syntax: 'typescript', tsx: true, dynamicImport: true },
    paths: {},
    keepClassNames: true,
    target: 'es2015',
    transform: { react: [Object] }
  },
  minify: false,
  isModule: true,
  module: { type: 'commonjs', noInterop: false },
  sourceMaps: 'inline',
  inlineSourcesContent: true,
  swcrc: false,
  inputSourceMap: undefined,
  sourceRoot: undefined
}

Possible solution

Either use deepMerge to merge all of the options or use another way to provide defaults from tsconfig file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions