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

TypeScript compilation fails when using Yarn PnP #7412

Closed
testorangemac opened this issue Dec 7, 2022 · 4 comments
Closed

TypeScript compilation fails when using Yarn PnP #7412

testorangemac opened this issue Dec 7, 2022 · 4 comments
Labels
FREQUENCY: level 2 TYPE: enhancement The accepted proposal for future implementation.

Comments

@testorangemac
Copy link

testorangemac commented Dec 7, 2022

What is your Scenario?

TypeScript compilation fails when using Yarn PnP. See the minimal working example repository or the steps to reproduce.

What is the Current behavior?

The following error is reported:

ERROR Cannot prepare tests due to the following error:

Error: TypeScript compilation failed.
C:/git/testcafe-yarn-berry/getting-started.ts (1, 26): File name 'C:/git/testcafe-yarn-berry/.yarn/cache/testcafe-npm-2.1.0-a6f521662e-8d426e4912.zip/node_modules/testcafe/ts-defs/index.d.ts' differs from already included file name 'c:/git/testcafe-yarn-berry/.yarn/cache/testcafe-npm-2.1.0-a6f521662e-8d426e4912.zip/node_modules/testcafe/ts-defs/index.d.ts' only in casing.
  The file is in the program because:
    Root file specified for compilation
    Imported via "testcafe" from file 'C:/git/testcafe-yarn-berry/getting-started.ts' with packageId 'testcafe/ts-defs/index.d.ts@2.1.0'

What is the Expected behavior?

TypeScript compilation works and the test is successfully run.

What is your public website URL? (or attach your complete example)

https://github.com/testorangemac/yarn-testcafe-berry

What is your TestCafe test code?

import { Selector } from "testcafe";

fixture("Getting Started").page(
  "https://devexpress.github.io/testcafe/example"
);

test("My first test", async (t) => {
  await t
    .typeText("#developer-name", "John Smith")
    .click("#submit-button")
    .expect(Selector("#article-header").innerText)
    .eql("Thank you, John Smith!");
});

Your complete configuration file

n/a

Your complete test report

n/a

Screenshots

n/a

Steps to Reproduce

  1. Run yarn init -2 (in a new directory)
  2. Run yarn add -D testcafe
  3. Add the example test file (as getting-started.ts)
  4. Run yarn testcafe chrome getting-started.ts

TestCafe version

2.1.0

Node.js version

v19.2.0

Command-line arguments

chrome getting-started.ts

Browser name(s) and version(s)

Chrome 108

Platform(s) and version(s)

Windows 10 Pro

Other

I have made the following observations:

  • The only difference in the reported error is the drive letter C vs c
  • This only occurs on Windows (verified on Linux)
  • When using JavaScript (renaming the test file to .js) it runs fine
  • Using different TypeScript versions doesn't impact the behavior
  • Patching the TestCafe code to use lower casing after calling process.cwd() fixes the issue and runs the test fine
@testorangemac testorangemac added the TYPE: bug The described behavior is considered as wrong (bug). label Dec 7, 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 Dec 7, 2022
@AlexKamaev
Copy link
Contributor

Thank you for your research and sharing the example. I was able to reproduce the issue.
To the team:
While we still need to research the issue in detail, I found a possible solution, which should be checked.

 private _compileFilesToCache (ts: TypeScriptInstance, filenames: string[]): void {
        const opts    = this._tsConfig.getOptions() as Dictionary<CompilerOptionsValue>;
        
        // NOTE: I added the following line
        filenames = filenames.map(name => TypeScriptTestFileCompiler._normalizeFilename(name));
        
        const program = ts.createProgram([TypeScriptTestFileCompiler.tsDefsPath, ...filenames], opts);

@need-response-app need-response-app bot removed the STATE: Need response An issue that requires a response or attention from the team. label Dec 15, 2022
@AndreyBelym AndreyBelym added TYPE: enhancement The accepted proposal for future implementation. and removed TYPE: bug The described behavior is considered as wrong (bug). labels Dec 16, 2022
@miherlosev
Copy link
Collaborator

Duplicate of #7710

@miherlosev miherlosev marked this as a duplicate of #7710 May 26, 2023
@Asuza
Copy link

Asuza commented Oct 2, 2023

@testorangemac would you be willing to share your patch to resolve this issue? I'm going to see if I can figure it out in the meantime. I'm seeing this when trying to run tests:

Error: TypeScript compilation failed.
C:/dev/myapp/api.mock.ts (1, 29): File name 'C:/dev/myapp/.yarn/cache/testcafe-npm-2.6.2-1e6c5a66b9-65d49c3cdd.zip/node_modules/testcafe/ts-defs/index.d.ts' differs from already included file name 'c:/dev/app028-checkout/.yarn/cache/testcafe-npm-2.6.2-1e6c5a66b9-65d49c3cdd.zip/node_modules/testcafe/ts-defs/index.d.ts' only in casing.
  The file is in the program because:
    Root file specified for compilation
    Imported via 'testcafe' from file 'C:/dev/myapp/api.mock.ts' with packageId 'testcafe/ts-defs/index.d.ts@2.6.2'

I never noticed that the drive letter was the issue until you pointed it out! 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 Oct 2, 2023
@Asuza
Copy link

Asuza commented Oct 2, 2023

Never mind! I applied the change that @AlexKamaev and the tests started just fine. I'm relieved to see the tests running, as this was the last hurdle I had when trying to switch to Yarn PnP. Thank you both.

@aleks-pro aleks-pro removed the STATE: Need response An issue that requires a response or attention from the team. label Oct 4, 2023
AlexKamaev pushed a commit that referenced this issue Oct 12, 2023
## Purpose
TypeScript compilation fails when using Yarn PnP

## Approach
Added file's path normalization for typescript test.
Couldn't add test due to OS specificity

## References
[7412](#7412)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FREQUENCY: level 2 TYPE: enhancement The accepted proposal for future implementation.
Projects
None yet
Development

No branches or pull requests

6 participants