jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.31k stars 6.47k forks source link

[Bug]: Jest processes d.ts file no matter what #15292

Closed zim32 closed 2 months ago

zim32 commented 2 months ago

Version

29.7.0

Steps to reproduce

Here is my jest.config.js:

module.exports = {
    testEnvironment: "node",
    roots: [
        "./dist/cjs/tests"
    ],
    moduleFileExtensions: ["js"],
    testRegex: "\.js$"
};

My dist/cjs/tests folder contains files compiled by typescript. F.e.

-rw-r--r-- 1 container container    27 Sep  3 15:50 alias.decorator.test.d.ts
-rw-r--r-- 1 container container  3068 Sep  3 15:50 alias.decorator.test.js
-rw-r--r-- 1 container container  2065 Sep  3 15:50 alias.decorator.test.js.map

Every time I run npx jest it give me this error:

SyntaxError: /var/www/code/dist/cjs/tests/file-system-loader/services/TestService.d.ts: Unexpected token (2:12)

Expected behavior

I expect that jest ignores .d.ts, .ts or any non .js files in test dir.

Actual behavior

SyntaxError: /var/www/code/dist/cjs/tests/file-system-loader/services/TestService.d.ts: Unexpected token (2:12)

Additional context

No response

Environment

System:
    OS: Linux 5.15 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (16) x64 AMD Ryzen 7 5700U with Radeon Graphics
  Binaries:
    Node: 20.16.0 - /usr/bin/node
    npm: 10.8.2 - /usr/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
zim32 commented 2 months ago

The same error even if I try to disable tranformations by adding transform: {} to jest config.

zim32 commented 2 months ago

Sorry was my mistake

github-actions[bot] commented 1 month ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.