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

[Question] How to run a setup-jest.ts before each test execution? #1164

Open
jaytonic opened this issue Aug 6, 2024 · 1 comment
Open

[Question] How to run a setup-jest.ts before each test execution? #1164

jaytonic opened this issue Aug 6, 2024 · 1 comment

Comments

@jaytonic
Copy link

jaytonic commented Aug 6, 2024

Is your feature request related to a problem? Please describe.
With typical Angular setup with jest, you have some global jest setup(like importing zone.js/testing, some presets, ...).
My tests written with Jest+karma are working fine when I do run jest through the ng test command.
But if I try to run them with vscode-jest, I get such command:

d:; cd 'd:\Dev\Frontend'; ${env:NODE_OPTIONS}=' --require "c:/Program Files/Microsoft VS Code Insiders/resources/app/extensions/ms-vscode.js-debug/src/bootloader.js" --inspect-publish-uid=http'; ${env:VSCODE_INSPECTOR_OPTIONS}=':::{"inspectorIpc":"\\\\.\\pipe\\node-cdp.10376-1b6ac8d8-10.sock","deferredMode":false,"waitForDebugger":"","execPath":"C:\\Program Files\\nodejs\\node.exe","onlyEntrypoint":false,"autoAttachMode":"always","fileCallback":"C:\\Users\\xxx\\AppData\\Local\\Temp\\node-debug-callback-f2209c7ce41c3e57"}'; & 'C:\Program Files\nodejs\node.exe' 'node_modules/jest/bin/jest.js' 'd:/Dev/Frontend/src/app/components/x/y.component.spec.ts' '-t' 'y should call the go back callback when returning' '--runInBand'

Which obviously is not running my setup-jest.ts before, and therefore I get some errors:

    zone-testing.js is needed for the fakeAsync() test helper but could not be found.
            Please make sure that your environment includes zone.js/testing

Describe the solution you'd like
Have a way to provide to vscode-jest, a global script that must be executed before running each test

@connectdotz
Copy link
Collaborator

@jaytonic, if you can run your test in the terminal with ng test, you can try setting the "jest.jestCommandLine": "ng test --" (not sure if you need to add "--" at the end, feel free to play with it) in your settings file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants