Set up unit testing with JEST (JS)

I got PHPunit working well, but now trying to set up JEST for JS unit testing. First thing I see is the only JS framework included is Mocha, but I use JEST / Jasmine for JS unit testing, so I have tried to create a custom entry.

This is what I have:

Basic:

Name: Jest
Path: C:\www\my_app_dir (Bear in mind this is windows but I use ubuntu bash on windows for cli)
Framework: Custom

Advanced (Optional)

Command: npm test (Again, bear in mind node & npm is installed on bash on windows (Ubuntu), but I installed it on windows anyway)
Parser: teamcity (not sure what option to use here)
Save To: project

When I try to run tests I get this output:

‘“npm”’ is not recognized as an internal or external command, operable program or batch file.

Is it even possible to do what I am trying?
Thanks.

Yes, it’s possible. You should have the npm binary (or whatever it’s on Windows) in your %PATH% environment variable (so you could run npm from cmd.exe or powershell.exe). You should change your JEST output to the one you picked in your parser option (something like npm run test --format teamcity). I’m not familiar if it’s possible to change the output format of JEST though, so you’d do some research on that.

Yeah got it working. I had to install the Jest CLI on windows and change the command to ‘jest’.

Thanks.

1 Like