Skip to content

Commit e547e3f

Browse files
Document use with Docker containers (#440)
1 parent 262a7bb commit e547e3f

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,53 @@ with:
185185

186186
For example, you can save every test run to an artifact and then download and reference them here.
187187

188+
## Running tests in containers
189+
190+
If you run your tests in a Docker container, you will need a little extra
191+
setup because:
192+
193+
1. You must share your coverage file with jest-coverage-report-action.
194+
2. The absolute paths of your tests must match the paths in the GitHub
195+
workspace if you want test failure and test coverage annotations.
196+
197+
One of the easier ways to do this is to mount the GitHub workspace
198+
inside your test container. Here is a sample action that uses Docker:
199+
200+
```yaml
201+
name: Run tests
202+
203+
on:
204+
pull_request:
205+
206+
jobs:
207+
run_tests:
208+
name: Run tests
209+
runs-on: ubuntu-latest
210+
211+
steps:
212+
# Check out the repository
213+
- uses: actions/checkout@v4
214+
215+
- name: Start containers
216+
run: docker compose -f docker-compose.ci.yml up -d
217+
218+
# install any dependencies since this is a fresh checkout
219+
- name: Install dependencies
220+
run: docker compose -f docker-compose.ci.yml run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE} --workdir ${GITHUB_WORKSPACE} tests yarn install
221+
222+
- name: Run tests
223+
# note the flags passed to jest. if you are running your tests with
224+
# yarn or npm, you should set the equivalent flags there.
225+
run: docker compose -f docker-compose.ci.yml run -v ${GITHUB_WORKSPACE}:${GITHUB_WORKSPACE} --workdir ${GITHUB_WORKSPACE} tests jest --coverage --ci --json --testLocationInResults --outputFile=report.json
226+
227+
- name: Collect test coverage
228+
uses: ArtiomTr/jest-coverage-report-action@v2
229+
if: always() # we should still try to run this even if there are test failures
230+
with:
231+
coverage-file: ./report.json
232+
base-coverage-file: ./report.json
233+
```
234+
188235
## Opt-out coverage comparison features
189236

190237
You can opt-out coverage comparison features to speed-up action. To achieve this, firstly, manually collect coverage to `report.json` file. Then, specify these options for the action:

0 commit comments

Comments
 (0)