Skip to content

Commit 9ffa473

Browse files
authored
Merge pull request #320 from fractal-analytics-platform/playwright
Setup of end to end tests and coverage
2 parents 487fe15 + e9ce450 commit 9ffa473

19 files changed

+2183
-212
lines changed

.github/workflows/coverage.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Coverage
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
pull_request:
7+
branches: ['main']
8+
9+
jobs:
10+
unit_tests:
11+
uses: ./.github/workflows/unit_tests.yaml
12+
13+
end_to_end_tests:
14+
uses: ./.github/workflows/end_to_end_tests.yaml
15+
16+
coverage:
17+
name: Compute coverage
18+
runs-on: ubuntu-22.04
19+
needs: [unit_tests, end_to_end_tests]
20+
21+
steps:
22+
- name: Check out repo
23+
uses: actions/checkout@v4
24+
25+
- name: Set up node
26+
uses: actions/setup-node@v3
27+
with:
28+
node-version: '20'
29+
cache: npm
30+
31+
- name: Install nyc
32+
run: npm install -g nyc
33+
34+
- name: Create coverage-all folder
35+
run: mkdir coverage-all
36+
37+
- name: Download unit coverage
38+
uses: actions/download-artifact@v3
39+
with:
40+
name: unit-coverage
41+
path: coverage-all
42+
43+
- name: Download playwright coverage
44+
uses: actions/download-artifact@v3
45+
with:
46+
name: playwright-coverage
47+
path: coverage-all
48+
49+
- name: Code coverage report
50+
uses: tj-actions/[email protected]
51+
with:
52+
coverage-command: "nyc report --temp-dir ./coverage-all --reporter=text --exclude-after-remap false"

.github/workflows/end_to_end_tests.yaml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
name: End-to-end tests
22

3-
on:
4-
push:
5-
branches: ['main']
6-
pull_request:
7-
branches: ['main']
3+
on: [workflow_call]
84

95
jobs:
106
end_to_end_tests:
117
name: 'Node ${{ matrix.node-version }}'
12-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-22.04
139
timeout-minutes: 10
1410

1511
strategy:
@@ -29,5 +25,20 @@ jobs:
2925
- name: Install dependencies
3026
run: npm install
3127

32-
- name: Run playwright tests (not implemented)
33-
run: echo "Not implemented"
28+
- name: Install Playwright Browsers
29+
run: npx playwright install --with-deps
30+
31+
# Fix for Node 18 issue:
32+
# See: https://github.com/node-fetch/node-fetch/issues/1624
33+
- name: Set fractal-server host for Node 18
34+
if: matrix.node-version == '18'
35+
run: echo "FRACTAL_SERVER_HOST=http://127.0.0.1:8000" >> $GITHUB_ENV
36+
37+
- name: Run Playwright tests
38+
run: npx playwright test
39+
40+
- uses: actions/upload-artifact@v3
41+
with:
42+
name: playwright-coverage
43+
path: coverage-playwright/
44+
retention-days: 30
File renamed without changes.

.github/workflows/unit_tests.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
name: Unit tests
22

3-
on:
4-
push:
5-
branches: ['main']
6-
pull_request:
7-
branches: ['main']
3+
on: [workflow_call]
84

95
jobs:
106
unit_tests:
117
name: 'Node ${{ matrix.node-version }}'
12-
runs-on: ubuntu-20.04
8+
runs-on: ubuntu-22.04
139
timeout-minutes: 10
1410

1511
strategy:
@@ -30,4 +26,10 @@ jobs:
3026
run: npm install
3127

3228
- name: Run vitest tests
33-
run: npm run test
29+
run: npx vitest run --coverage.enabled --coverage.provider=istanbul --coverage.include=src --coverage.reporter=json --coverage.all
30+
31+
- uses: actions/upload-artifact@v3
32+
with:
33+
name: unit-coverage
34+
path: coverage-unit/
35+
retention-days: 30

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ node_modules
99
.idea
1010
*.bak
1111
.*.swp
12-
/tests/.auth
12+
/tests/.auth
13+
coverage*/
14+
.nyc_output

.nycrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"all": true
3+
}

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
*Note: Numbers like (\#123) point to closed Pull Requests on the fractal-web repository.*
22

3+
# Unreleased
4+
5+
* Added end to end tests and coverage configuration (\#320).
6+
37
# 0.6.1
48

59
This release works best with fractal-server >=1.3.12 (since it makes use of the

docs/tests.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,40 @@
22

33
## Unit tests
44

5-
Unit tests are performed via [vitest](https://vitest.dev), via the `test` script defined in `package.json`. Current tests are in the `__tests__` folder.
6-
5+
Unit tests are performed via [vitest](https://vitest.dev), via the `test` script defined in `package.json`.
76

87
## End-to-end testing
98

10-
This is not yet implemented in an automated way (tracked in
11-
https://github.com/fractal-analytics-platform/fractal-web/issues/8), and for
12-
the moment it needs to be done manually.
9+
E2E tests are done using playwright. They can be executed using the following command:
10+
11+
```
12+
npx playwright test
13+
```
14+
15+
To print Svelte webserver log set the environment variable `DEBUG=pw:webserver`.
16+
17+
To execute the tests seeing the browser add the `--headed` flag or the `--debug` flag if you need to watch them step by step.
18+
19+
## Coverage
20+
21+
Coverage for the unit tests:
22+
23+
```
24+
npx vitest run --coverage.enabled --coverage.provider=istanbul --coverage.include=src --coverage.reporter=json --coverage.all
25+
```
26+
27+
Warning: coverage takes some time using the option `--coverage.all`.
28+
29+
Coverage for the playwright tests is automatically collected when running `npx playwright test`.
30+
31+
To generate a merged html report:
32+
33+
```
34+
mkdir coverage-all
35+
cp coverage-playwright/* coverage-all
36+
cp coverage-unit/* coverage-all
37+
npx nyc report --report-dir ./coverage-html --temp-dir ./coverage-all --reporter=html --exclude-after-remap false
38+
```
1339

1440
### Local `fractal-server` instance
1541

0 commit comments

Comments
 (0)