jest-community / vscode-jest

The optimal flow for Jest based testing in VS Code
MIT License
2.84k stars 293 forks source link

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

Open jaytonic opened 3 months ago

jaytonic commented 3 months ago

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 commented 1 month ago

@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.