jest icon indicating copy to clipboard operation
jest copied to clipboard

Sporadic "Command failed with exit code 1" but no test failure

Open LinqLover opened this issue 3 years ago • 6 comments

🐛 Bug Report

In the CI of my repository, I frequently see this error:

error Command failed with exit code 1.

However, the log before does not show any failure, just some passing tests and some console outputs from the code under test. Locally, I am unable to reproduce this issue.

My tests are defined as asynchronous functions, but I have taken care to use await appropriately so, in theory, this should not be an issue. Nevertheless, it seems as if jest ends before all tests have been completed.

To Reproduce

See link to repl below, unfortunately, the issue occurs sporadically only.

Expected behavior

Either the exit code should be zero, or there should be at least one failing test displayed, or there should be an error message if the test setup is wrong for whatever reason.

Link to repl or repo (highly encouraged)

Just check out my repository where I have collected a number of these flaky builds: https://github.com/LinqLover/downstream-repository-mining/issues/65

envinfo

  • OS: Ubuntu 20.04.2 LTS
  • Node 14.17.0/x64
  • Yarn: v1.22.10
  • jest: ^26.6.3 => 26.6.3

Thanks in advance!

LinqLover avatar Jun 22 '21 12:06 LinqLover

In some cases, I also see some of my tests timing out. This is a problem of myself, of course, but could jest maybe fail to show up a proper timeout error if the test is running asynchronously?

LinqLover avatar Jun 22 '21 13:06 LinqLover

This is weird:

    thrown: "Exceeded timeout of 5000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

In the very first line of my (async) test, I do exactly this and set the timeout to 10000 ms. Apparently my test times out even before it starts ...

LinqLover avatar Jun 22 '21 13:06 LinqLover

This is the most obvious output I have gotten so far:

yarn run v1.22.10
$ cross-env NODE_OPTIONS=--experimental-vm-modules jest
(node:1806) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error: Process completed with exit code 1.

(https://github.com/LinqLover/downstream-repository-mining/runs/2885248978#step:8)

LinqLover avatar Jun 22 '21 13:06 LinqLover

Further investigation has revealed that the issue only appears when running tests from all test files together but not when I only run a single test file. I added some debugging statements at the end of each test and found out that sometimes jest indicates the success of one of these tests before the final console statement is printed!

I guess something with asynchronous test execution is broken. Everything after an await in my test apparently is executed after the jest has already registered the test as a success and then it hangs ...:

https://github.com/LinqLover/downstream-repository-mining/blob/0316d80141db5681eb53e59b306a0b13e851f7f8/test/npm-deps.test.ts#L56-L78

PS: I traced this further down and found out that in my case, the test execution will always be interrupted when the first asynchronous call to fs is awaited.

LinqLover avatar Jun 22 '21 14:06 LinqLover

Reproduction

$ git clone https://github.com/LinqLover/downstream-repository-mining.git
$ cd downstream-repository-mining
$ git checkout 0316d80141db5681eb53e59b306a0b13e851f7f8
$ yarn install
$ yarn test test/references.test.ts  # optionally run with option -i
  yarn run v1.22.10
  $ cross-env NODE_OPTIONS=--experimental-vm-modules jest test/references.test.ts
  (node:1712) ExperimentalWarning: VM Modules is an experimental feature. This feature could change at any time
  (Use `node --trace-warnings ...` to show where the warning was created)
  
   RUNS  test/references.test.ts
  error Command failed with exit code 1.

LinqLover avatar Jun 22 '21 15:06 LinqLover

I have the same issue. Is there any workarounds?

syuilo avatar Sep 20 '22 22:09 syuilo