testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

es-next/compiler.js fails to resolve module after typescript successfully resolves and compiles it

Open cdaringe opened this issue 2 years ago • 9 comments

What is your Scenario?

I want to:

  • use typescript
  • use tsconfig::compilerOptions::paths (and tsconfig::extends, but not related to this issue)
  • use testcafe

What is the Current behavior?

Internally, the typescript compiler compiles page.test.ts fine. A downstream es-next compiler cannot resolve a module that the typescript compiler resolved.

What is the Expected behavior?

Either not use the es-next compiler, or extend es-next compiler module resolution with paths as used from the typescript compiler.

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

tiny, minimal reproduction posted here: https://github.com/cdaringe/testcafe-path-resolution-typescript

What is your TestCafe test code?

// test/page.test.ts
import { foo } from "foo";
import { ClientFunction } from "testcafe";

fixture`foo`.page("http://localhost:3333");

const log = ClientFunction(() => console.log("sup"));

test("bar", async (t) => {
  foo();
  await log();
  await t.debug();
});
// src/foo.ts
export const foo = () => "bar";

Your complete configuration file

none, cli only.

DEBUG=testcafe* testcafe --compiler-options='typescript.configPath=tsconfig.json' chrome test/

Your complete test report

n/a

Screenshots

Error: Cannot find module 'foo'
Require stack:
- /demo/test/page.test.ts
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/compiler/test-file/formats/es-next/compiler.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/compiler/compilers.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/compiler/index.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/runner/bootstrapper.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/runner/index.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/testcafe.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/index.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/cli/cli.js
- /demo/node_modules/.pnpm/[email protected]/node_modules/testcafe/lib/cli/index.js

Steps to Reproduce

run the reproduction

TestCafe version

2.2.0-rc.1

Node.js version

18.4.0

Command-line arguments

testcafe --compiler-options='typescript.configPath=tsconfig.json' chrome test/

Browser name(s) and version(s)

chrome

Platform(s) and version(s)

macos 12.6.1

Other

n/a

cdaringe avatar Dec 22 '22 00:12 cdaringe

Hi @cdaringe,

You cannot override the target compiler option in the TypeScript configuration file. However, there is PR that supports native ESM. You can use it once it is merged and published.

Aleksey28 avatar Dec 23 '22 08:12 Aleksey28

hey @Aleksey28 , thx for the reply. i've dropped target from the demo so as to keep this bug report focused on the resolution issue. indeed, i don't need that target, i just used a bunch of the defaults from tsc --init, but i appreciate the tip/ref regardless!

cdaringe avatar Dec 23 '22 18:12 cdaringe

Hi @cdaringe,

You're welcome. I'll close the issue. Feel free to contact us if you have further questions.

Aleksey28 avatar Dec 26 '22 07:12 Aleksey28

@Aleksey28 forgive me—the issue should not be closed. The issue should remain open. My above remark was politely stating that your suggestion is not relevant to this specific problem

cdaringe avatar Dec 26 '22 07:12 cdaringe

Ok. In this case, please update your example so that I can run it and reproduce this error.

Aleksey28 avatar Dec 27 '22 06:12 Aleksey28

@Aleksey28, the example is updated and runnable, with instructions in the repo. thanks!

cdaringe avatar Dec 27 '22 10:12 cdaringe

I managed to reproduce the issue. We will update this thread once we have any news.

Aleksey28 avatar Dec 30 '22 11:12 Aleksey28

Thanks for providing a minimal example; I've already spent hours on debugging that in our project. Are there any known workarounds or versions where this bug is not present in?

hendriku avatar Mar 27 '23 06:03 hendriku

@hendriku https://github.com/DevExpress/testcafe/issues/4144

Klaster1 avatar Mar 27 '23 07:03 Klaster1

This issue has been automatically marked as stale because it has not had any activity for a long period. It will be closed and archived if no further activity occurs. However, we may return to this issue in the future. If it still affects you or you have any additional information regarding it, please leave a comment and we will keep it open.

github-actions[bot] avatar Mar 16 '24 01:03 github-actions[bot]

We're closing this issue after a prolonged period of inactivity. If it still affects you, please add a comment to this issue with up-to-date information. Thank you.

github-actions[bot] avatar Mar 26 '24 01:03 github-actions[bot]