Skip to content

Inline ts-jest tsconfig options use wrong type #4284

@jessestricker

Description

@jessestricker

When trying to set custom tsconfig compiler options for ts-jest, the generated output is incorrect:

Example .projenrc.ts:

new awscdk.AwsCdkConstructLibrary({
  // ...
  tsJestOptions: {
    transformOptions: {
      tsconfig: TsJestTsconfig.custom({
        compilerOptions: { isolatedModules: true },
      }),
    },
  },
})

This generates the following package.json:

{
  "jest": {
    "transform": {
      "^.+\\.[t]sx?$": [
        "ts-jest",
        {
          "tsconfig": {
            "compilerOptions": {
              "isolatedModules": true
            }
          }
        }
      ]
    }
  }
}

However, when running pj test an error is shown:

  ● Test suite failed to run                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                 
    error TS5023: Unknown compiler option 'compilerOptions'.  

I'm pretty sure that the compilerOptions field in the package.json should not be there. Instead it should look like this, matching the ts-jest docs.

{
  "jest": {
    "transform": {
      "^.+\\.[t]sx?$": [
        "ts-jest",
        {
          "tsconfig": {
            "isolatedModules": true
          }
        }
      ]
    }
  }
}

I suppose a possible fix could be to change the TsJestTsconfig.custom function like this:

-public static custom(config: TypescriptConfigOptions) {
+public static custom(config: TypeScriptCompilerOptions) {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions