Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using testcafe with typescript and yarn pnp #6845

Closed
aultac opened this issue Jan 29, 2022 · 4 comments
Closed

Using testcafe with typescript and yarn pnp #6845

aultac opened this issue Jan 29, 2022 · 4 comments
Labels
AREA: docs An issue related to the product documentation. TYPE: enhancement The accepted proposal for future implementation.

Comments

@aultac
Copy link

aultac commented Jan 29, 2022

What is your Scenario?

I'd like to use the latest typescript compiler for testcafe tests with yarn pnp which doesn't provide direct access to the typescript module (it's in a zip file instead).

What are you suggesting?

I don't think testcafe needs to do anything different other than add some documentation to help fellow travelers. You can get this to work with the following 2 steps:

1: unplug typescript from pnp to get it out of the zip file and into your local project:

yarn unplug typescript

2: Get the typescript file location in your .testcafe.js configuration file (it has to be a .js file, not a .json file):

const { execSync } = require('child_process');
const tscbin = execSync('yarn bin tsc').toString().trim();
const tscmodule = tscbin.replace('/bin/tsc','');

module.exports = {
  compilerOptions: {
    typescript: {
      configPath: "tsconfig.test.json",
      customCompilerModulePath: tscmodule,
    }
  }
}

What alternatives have you considered?

No response

Additional context

No response

@aultac aultac added the TYPE: enhancement The accepted proposal for future implementation. label Jan 29, 2022
@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Jan 29, 2022
@felis2803
Copy link
Contributor

Hello @aultac,

Thanks for sharing this method. We will research it and let you know our results.

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 4, 2022
@felis2803 felis2803 added the AREA: docs An issue related to the product documentation. label Feb 4, 2022
@Asuza
Copy link

Asuza commented Feb 11, 2022

@aultac, may I ask how you are starting your tests? I'm trying to get Yarn PnP + TypeScript + TestCafe working, and am running into this issue after making the changes you suggested.

PS C:\dev\projectroot\client> testcafe chrome '.\tc\Tests\**\*.test.ts'
\
error TS6053: File 'tc/Tests/**/*.test.ts' not found.
  The file is in the program because:
    Root file specified for compilation

error TS6231: Could not resolve the path 'chrome' with the extensions: '.ts', '.tsx', '.d.ts'.
  The file is in the program because:
    Root file specified for compilation

For reference, here is my .testcaferc.js file, based on yours:

const { execSync } = require('child_process');
const tscbin = execSync('yarn bin tsc').toString().trim();
const tscmodule = tscbin.replace('/bin/tsc','');

module.exports = {
  screenshots: {
    takeOnFails: true
  },
  compilerOptions: {
    typescript: {
      configPath: 'tc/tsconfig.json',
      customCompilerModulePath: tscmodule,
    }
  }
};

I have no idea why my testcafe chrome '.\tc\Tests\**\*.test.ts' command appears to be trying to find chrome as if it were a script to be compiled, or why it can't seem to find my tests. Thanks!

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 11, 2022
@AlexKamaev AlexKamaev removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 14, 2022
@aultac
Copy link
Author

aultac commented Feb 19, 2022

Do you need to run testcafe from yarn when you're on the command line (as opposed to in package.json)? i.e. yarn run testcafe ....

I used this for my testcafe config:

const { execSync } = require('child_process');
  
// You have to `yarn unplug typescript` to get access to this module for testcafe
const tscloc = execSync('yarn bin tsc').toString().trim().replace('/bin/tsc','');
  
module.exports = {
  src: "test/**/*.test.ts",
  browsers: "chrome",
  appCommand: "yarn run http-server .",
  appInitDelay: 200,
  debugOnFail: true,
  compilerOptions: {
    typescript: {
      configPath: "tsconfig.test.json",
      customCompilerModulePath: tscloc,
    }
  }
}

@need-response-app need-response-app bot added the STATE: Need response An issue that requires a response or attention from the team. label Feb 19, 2022
@miherlosev miherlosev removed the STATE: Need response An issue that requires a response or attention from the team. label Feb 21, 2022
@miherlosev
Copy link
Collaborator

Duplicate of #7710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AREA: docs An issue related to the product documentation. TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

5 participants