testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

TestCafe can't compile TypeScript test files if tsconfig.json contains the `moduleResolution` option

Open screendriver opened this issue 7 years ago • 10 comments

What is your Test Scenario?

I upgraded from v1.2.1 to v1.3.0 in one of my TypeScript projects. Since the update I get compiler errors as you can see below. I already saw in the docs that I cannot override the module and target options. But these are defined in my existing tsconfig.json and I don't want to change them.

What is the Current behavior?

TestCafe complains with

You cannot override the "target" compiler option in the TypeScript configuration file.
You cannot override the "module" compiler option in the TypeScript configuration file.
ERROR Cannot prepare tests due to an error.

Error: Debug Failure. Unexpected moduleResolution: node

What is the Expected behavior?

Should not fail with errors as before with v1.2.1

What is your web application and your TestCafe test code?

This is my tsconfig.json:

{
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "outDir": "target",
    "moduleResolution": "node",
    "jsx": "react",
    "noEmitOnError": true,
    "importHelpers": true,
    "sourceMap": true,
    "declaration": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "incremental": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "plugins": [{ "name": "typescript-tslint-plugin" }],
    "typeRoots": ["./typings", "./node_modules/@types"]
  },
  "include": ["src/**/*", "test/**/*"],
  "exclude": ["node_modules"]
}

Steps to Reproduce:

  1. Go to my website ...
  2. Execute this command...
  3. See the error...

Your Environment details:

  • testcafe version: 1.3.0
  • node.js version: 12.4.0
  • command-line arguments:
  • browser name and version:
  • platform and version:
  • other:

screendriver avatar Jul 02 '19 19:07 screendriver

Following -- same issue & question, slightly diff environment.

Your Environment details: testcafe version: 1.3.0 node.js version: 10.15.0 typescript: 3.5.2

konpikwastaken avatar Jul 02 '19 20:07 konpikwastaken

I see the same error since yesterday's update to 1.3.0

"compilerOptions": { "module": "esnext", "target": "es6", "lib": ["es2017", "dom"], "sourceMap": true, "allowJs": true, "jsx": "react", "rootDir": "src", "baseUrl": ".", "moduleResolution": "node", "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noImplicitThis": true, "noImplicitAny": false, "strictNullChecks": true, "suppressImplicitAnyIndexErrors": true, "noUnusedLocals": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "paths": { "types": [] }

monicainde avatar Jul 03 '19 08:07 monicainde

Thank you for your reports, we will fix this and provide a patch release ASAP.

AndreyBelym avatar Jul 03 '19 09:07 AndreyBelym

The warnings about overriding the target and module options do not interrupt compilation and can be ignored. However, we will try to reduce the number of conditions that can cause them.

The moduleResolution option is the problematic one. If we want to allow overriding it, we should transform the node and classic values to 2 and 1 respectively because this option has different enum types when configured from CLI/config and API. But I think that we should disable the possibility of overriding it because otherwise, you won't be able to import Selector and ClientFunction from TestCafe.

As a workaround, you can create a separate tsconfig.testcafe.json configuration file which doesn't contain the moduleResolution option and pass it to TestCafe via the tsConfigPath option from the .testcaferc.json configuration file: https://devexpress.github.io/testcafe/documentation/using-testcafe/configuration-file.html#tsconfigpath.

AndreyBelym avatar Jul 03 '19 10:07 AndreyBelym

But I think that we should disable the possibility of overriding

But does that mean we can't use TestCafe out of the box (without a dedicated tsconfig.testcafe.json) as long as my project tsconfig.json defines the moduleResolution property?

screendriver avatar Jul 03 '19 12:07 screendriver

I would prefer if the new feature Customize Compiler Options required an explicit opt in like providing the command line parameter or adding it to the configuration file.

It was rather surprising for me that after the upgrade testcafe uses a tsconfig that was never intended to be used by testcafe.

signed avatar Jul 03 '19 18:07 signed

@signed, try to use the [email protected] version where we have addressed this problem.   If the issue still occurs, please describe your scenario in greater detail and what Customize Compiler Options break it.

LavrovArtem avatar Jul 04 '19 14:07 LavrovArtem

I have a small sample project that is working fine with 1.2.1.

yarn start
yarn testcafe:run

Tests run as expected.

I tried [email protected]:

yarn add -D [email protected]
yarn start
yarn testcafe:run

The tests fail with the following error:

You cannot override the "module" compiler option in the TypeScript configuration file. You cannot override the "target" compiler option in the TypeScript configuration file. ERROR Cannot prepare tests due to an error.

Error: TypeScript compilation failed. Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.

at Function._reportErrors (/sandboxes/typescript/testcafe/node_modules/testcafe/src/compiler/test-file/formats/typescript/compiler.js:38:15) at TypeScriptTestFileCompiler._precompileCode (/sandboxes/typescript/testcafe/node_modules/testcafe/src/compiler/test-file/formats/typescript/compiler.js:79:40) at TypeScriptTestFileCompiler._compileCodeForTestFiles (/sandboxes/typescript/testcafe/node_modules/testcafe/src/compiler/test-file/api-based.js:110:29) at tsConfig.init.then (/sandboxes/typescript/testcafe/node_modules/testcafe/src/compiler/test-file/formats/typescript/compiler.js:53:30)

signed avatar Jul 04 '19 20:07 signed

I apologize for this inconvenience. Unfortunately, our understanding of different TypeScript options wasn't deep enough. I've created a list of all options that can cause compilation problems in this issue: https://github.com/DevExpress/testcafe/issues/3983.

We decided to disable the functionality of automatically detecting and applying TypeScript configuration files - #3986. I still think that this feature can be very useful and won't cause issues if implemented properly - take a look at ts-node. But we won't try to enable it back until we fix all possible combinations of conflicting options and find a way to implement it without breaking user tests.

AndreyBelym avatar Jul 05 '19 10:07 AndreyBelym

This thread has been automatically locked since it is closed and there has not been any recent activity. Please open a new issue for related bugs or feature requests. We recommend you ask TestCafe API, usage and configuration inquiries on StackOverflow.

lock[bot] avatar Jul 15 '19 10:07 lock[bot]