thymikee / jest-preset-angular

Jest configuration preset for Angular projects.
https://thymikee.github.io/jest-preset-angular/
MIT License
883 stars 304 forks source link

[Bug]: Seems ts-jest 29.2.x broke something #2585

Closed Delagen closed 1 month ago

Delagen commented 1 month ago

Version

14.1.1

Steps to reproduce

Install ts-jest 29.2.x Tune tests in ESM mode

 setupFilesAfterEnv: [
        resolve(currentDir, 'jest.setup.ts'),
    ],

jest.setup.ts

import 'jest-preset-angular/setup-jest.mjs';

const jest = import.meta.jest;

Expected behavior

All works as expected

Actual behavior

jest.setup.ts:11:14 - error TS1470: The 'import.meta' meta-property is not allowed in files which will build into CommonJS output.

    11 const jest = import.meta.jest;
                    ~~~~~~~~~~~

Additional context

No response

Environment

System:
    OS: Windows 11 10.0.26252
    CPU: (6) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
  Binaries:
    Node: 22.4.0
    npm: 10.8.2
  npmPackages:
    jest: ~29.7.0 => 29.7.0
ahnpnl commented 1 month ago

Hi, we have example apps at https://github.com/thymikee/jest-preset-angular/tree/main/examples which already had 29.2.x Would you please put your reproduce scenario there? Thanks!

Delagen commented 1 month ago

@ahnpnl npm i failed with peer dependencies error

Updated to

"typescript": "~5.5.3"
"angular-in-memory-web-api": "^0.18.0",

then tried install again

npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated glob@7.2.3: Glob versions prior to v9 are no longer supported
npm warn deprecated abab@2.0.6: Use your platform's native atob() and btoa() methods instead
npm warn deprecated domexception@4.0.0: Use your platform's native DOMException instead

added 1235 packages, and audited 1236 packages in 2m

150 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

Tried to run npm run test-esm and get error

> example-app-v18@18.0.0 test-esm
> node --experimental-vm-modules --no-warnings ./node_modules/jest/bin/jest.js -c=jest-esm.config.mjs --no-cache

SyntaxError: Unexpected identifier 'assert'
    at compileSourceTextModule (node:internal/modules/esm/utils:337:16)
    at ModuleLoader.moduleStrategy (node:internal/modules/esm/translators:164:18)
    at callTranslator (node:internal/modules/esm/loader:439:14)
    at ModuleLoader.moduleProvider (node:internal/modules/esm/loader:445:30)
    at async ModuleJob._link (node:internal/modules/esm/module_job:106:19)
ahnpnl commented 1 month ago

Hmm CI passes though using yarn. could you pls try yarn instead? Not sure what’s going on with npm though.

Delagen commented 1 month ago

@ahnpnl Seems I find the case of my issue.

Need to set "moduleResolution": "NodeNext" in tsconfig.spec.json, because strange but it stops to work with value Bundler