I am using yarn workspaces (yarn version 1.22.19) and I would like to run tests for all workspaces, without stopping even if tests fail for one of the workspaces. This is so I can collect all failing tests across all workspaces in one run. I'm running the tests on a github action.
I am running the following command:
yarn workspaces run test --passWithNoTests
All workspaces have a test
script in the package.json
that runs the tests with Jest.
Jest returns an exit code of 1 when tests fail. This causes the yarn workspaces run
command to fail and stop. I would like it to continue and fail only after running tests for all workspaces.
How can I make the yarn workspaces run
continue even if tests fail for one of the workspaces, yet still have it fail at the end?
Edit:
I am running bash.
Using workarounds like set -e
or || true
might help swallow the error, but I do want the command to fail ultimately, I just want it to fail after running all tests.
For example:
Say I have 3 workspaces - workspace a
, workspace b
and workspace c
. All of them have the following script in their package.json
:
test: "jest"
Say tests pass for workspace a
and workspace c
, but fail for workspace b
. My desired result is that running yarn workspaces run test
will run tests for all workspaces (and not stop after tests fail for workspace b
) but for it to fail after running all tests.
Here is my github workflow. It just installs dependencies and runs the test
script which runs the command yarn workspaces run test --passWithNoTests
.
name: Run All Tests
on:
pull_request:
branches: ['develop']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run tests
run: yarn test