Using Jest Test framework on Bitbucket Cloud Pipelines fails but the Pipelines build was marked as successful

Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.

Summary

The KB provides a solution for using Jest test cases in Bitbucket Cloud Pipelines, where the build was marked as successful while the test failed.

Diagnosis

Looking for the Jest command, the command has the --runInBand flag.

1 jest --runInBand --coverage

You will also notice a reasonably similar error message below on your Pipelines build:

1 2 3 4 5 6 7 8 PASS test/some_folder/latest-1.test.ts PASS test/some_folder/latest-2.test.ts PASS test/some_folder/latest-3.test.ts PASS test/some_folder/latest-4.test.ts FAIL test/some_folder/latest-5.test.ts * Test suite failed to run test/some_folder/latest-5.test.ts:3:27 - error SOME_ERROR_MESSAGE

Cause

Possibly related to --runInBandFlag running on the current process in Bitbucket Cloud Pipelines does not correctly return an exit code whenever something's failed with the test cases.

Solution

Instead of using --runInBand , you can use --maxWorkers flag instead, where it creates a worker pool for running tests, and once it's done, it's appropriately shutting down. Hence, giving the correct exit code for failed test cases.

1 jest --coverage --maxWorkers=2

Updated on March 21, 2025

Still need help?

The Atlassian Community is here for you.