Search code examples
reactjspowershelljestjscreate-react-appappveyor

Running Jest tests on Appveyor from powershell


I am trying to run my Jest tests on Appveyor. I am using the asp.net core template for a react app (which uses create-react-app). When I run the tests locally (with npm run test) the tests run fine, I see PASS src\App.test.js with a run-down of the tests that have passed.

In Appveyor, however, an error is thrown from the console, causing my build to fail. The error message is PASS src\App.test.js. So it would seem an error is being emitted from the run somehow, despite the fact it seems to actually be passing. I checked and $LASTEXITCODE is -1

App.Test.js

it('Runs tests', () => { expect(true).toBeTruthy(); });

Appveyor.yml

test_script: - ps: .\build\appveyor\js-tests.ps1

.\build\appveyor\js-tests.ps1

($env:CI = $true) -and (npm run test)

I'm setting the CI environment as this prevents the tests from using "watch". the js-tests script does some other stuff with sorting file locations and a bit of logging etc, but I don't think that is relevant giving the message comes back as a passed test.


Solution

  • Npm sometimes writes normal output to stdErr, which custom PowerShell host on AppVeyor treats as error. Solution is to run those tests in CMD. So wrap them int .cmd file and run with - cmd: prefix.