Skip to content

Commit fbd7355

Browse files
authored
test: add unit tests (NASA-AMMOS#44)
- Add initial unit testing framework via Vitest - Reorganize e2e tests in their own folder - Reorganize package.json scripts to distinguish between e2e tests and unit tests - Update testing documentation
1 parent e34db57 commit fbd7355

28 files changed

+1816
-36
lines changed

.github/workflows/test.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,24 @@ jobs:
4444
run: npm ci
4545
- name: Build (UI)
4646
run: npm run build
47-
- name: Install Playwright Dependencies (Test)
47+
- name: Install Playwright Dependencies (Test - e2e)
4848
run: npx playwright install chromium --with-deps
49-
- name: Test
50-
run: npm test
51-
- name: Upload Results (Test)
49+
- name: Test (e2e)
50+
run: npm run test:e2e
51+
- name: Test (unit)
52+
run: npm run test:unit
53+
- name: Upload Results (Test - e2e)
5254
if: always()
5355
uses: actions/upload-artifact@v3
5456
with:
5557
name: 🎭 Playwright Run Results
56-
path: test-results
58+
path: e2e-test-results
59+
- name: Upload Results (Test - unit)
60+
if: always()
61+
uses: actions/upload-artifact@v3
62+
with:
63+
name: ⚡ Vitest Run Results
64+
path: unit-test-results
5765
- name: Print Logs for Services (Aerie)
5866
if: always()
5967
run: docker compose -f docker-compose-test.yml logs -t

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
.DS_Store
22
build
33
node_modules
4-
test-results
4+
e2e-test-results
5+
unit-test-results
56
/.svelte-kit
67
/package
78
/static/version.json

docs/TESTING.md

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
# Testing
22

3-
This document describes the testing development workflow. Tests in this repo are tested using the [Playwright](https://playwright.dev/) testing library.
3+
This document describes the testing development workflow. End-to-end tests are run using the [Playwright](https://playwright.dev/) testing library. Unit tests are run using the [Vitest](https://vitest.dev/) library.
44

5-
All tests assume a production build of the project is available:
5+
## End-to-end
6+
7+
All end-to-end tests assume a production build of the project is available:
68

79
```sh
810
npm run build
911
```
1012

11-
All tests also assume all Aerie services are running and available on `localhost`. See the example [docker-compose-test.yml](../docker-compose-test.yml) for an example of how to run the complete Aerie system. Notice we disable authentication for simplicity when running our end-to-end tests. You can reference the [Aerie deployment documentation](https://github.com/NASA-AMMOS/aerie/tree/develop/deployment) for more detailed deployment information.
13+
All end-to-end tests also assume all Aerie services are running and available on `localhost`. See the example [docker-compose-test.yml](../docker-compose-test.yml) for an example of how to run the complete Aerie system. Notice we disable authentication for simplicity when running our end-to-end tests. You can reference the [Aerie deployment documentation](https://github.com/NASA-AMMOS/aerie/tree/develop/deployment) for more detailed deployment information.
1214

13-
To execute tests normally (i.e. not in debug mode), use the following command:
15+
To execute end-to-end tests normally (i.e. not in debug mode), use the following command:
1416

1517
```sh
16-
npm test
18+
npm run test:e2e
1719
```
1820

1921
If this is your first time running the tests you may need to install the Playwright browser drivers:
@@ -24,19 +26,27 @@ npx playwright install
2426

2527
If something fails read the Playwright error carefully as it usually describes a quick fix. You can also look for the error in the [Playwright GitHub Issues](https://github.com/microsoft/playwright/issues) if you need more help.
2628

27-
## Debug
29+
### Debug
2830

2931
The debug test script runs the [Playwright inspector](https://playwright.dev/docs/inspector), which runs in headed debug mode so you can step through tests and watch them as they execute.
3032

3133
```sh
32-
npm run test:debug
34+
npm run test:e2e:debug
3335
```
3436

35-
## Codegen
37+
### Codegen
3638

3739
The codegen test script runs the [Playwright test generator](https://playwright.dev/docs/codegen), which automatically generates [locators](https://playwright.dev/docs/locators) as you click elements on the page. It can greatly save test development time. The generator requires an instance of the application already running to select against.
3840

3941
```sh
40-
npm run test:dev # Starts aerie-ui
41-
npm run test:codegen # Starts codegen
42+
npm run test:e2e:dev # Starts aerie-ui
43+
npm run test:e2e:codegen # Starts codegen
44+
```
45+
46+
## Unit
47+
48+
To execute unit tests use the following command:
49+
50+
```sh
51+
npm run test:unit
4252
```

0 commit comments

Comments
 (0)