Skip to content

Commit dc0161c

Browse files
authored
[ENG-10680] Migrate to Vitest (#927)
- Ticket: [ENG-10680](https://openscience.atlassian.net/browse/ENG-10680) - Feature flag: n/a ## Summary of Changes 1. Migrated to Vitest. 2. Updated unit tests. 3. Removed some mocks.
1 parent db9445f commit dc0161c

524 files changed

Lines changed: 18033 additions & 26872 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/counter/counter.test.display.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/counter/counter.test.increment.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

.github/scripts/check-coverage-thresholds.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const coverage = require('../../coverage/coverage-summary.json');
2-
const jestConfig = require('../../jest.config.js');
2+
const vitestConfig = require('../../vitest.config.ts');
33

44
const summary = coverage.total;
5-
const thresholds = jestConfig.coverageThreshold.global;
5+
const thresholds = vitestConfig.default.test.coverage.thresholds;
66

77
let failed = false;
88
const errors = [];
@@ -28,7 +28,7 @@ for (const key of ['branches', 'functions', 'lines', 'statements']) {
2828
);
2929
errors.push(
3030
formatErrorsWithAlignedStars(
31-
`Please update the coverageThreshold.global.${key} in the jest.config.js to ---> ${current} <---`,
31+
`Please update test.coverage.thresholds.${key} in vitest.config.ts to ---> ${current} <---`,
3232
true
3333
)
3434
);
@@ -40,9 +40,9 @@ for (const key of ['branches', 'functions', 'lines', 'statements']) {
4040
if (failed) {
4141
const stars = '*'.repeat(warnMessage.length + 8);
4242
console.log('\n\nCongratulations! You have successfully run the coverage check and added tests.');
43-
console.log('\n\nThe jest.config.js file is not insync with your new test additions.');
44-
console.log('Please update the coverage thresholds in jest.config.js.');
45-
console.log('You will need to commit again once you have updated the jst.config.ts file.');
43+
console.log('\n\nThe vitest.config.ts file is not in sync with your new test additions.');
44+
console.log('Please update test.coverage.thresholds in vitest.config.ts.');
45+
console.log('You will need to commit again once you have updated the vitest.config.ts file.');
4646
console.log('This is only necessary until we hit 100% coverage.');
4747
console.log(`\n\n${stars}`);
4848
errors.forEach((err) => {
@@ -54,5 +54,4 @@ if (failed) {
5454
console.log(`${leftBracket}${warnMessage}${rightBracket}`);
5555
console.log(`${leftBracket}${' '.repeat(warnMessage.length)}${rightBracket}`);
5656
console.log(`${stars}\n\n`);
57-
// process.exit(1);
5857
}

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run Jest Tests
1+
name: Run Vitest Tests
22

33
on:
44
pull_request:
@@ -26,7 +26,7 @@ jobs:
2626
- name: Install dependencies
2727
run: npm ci
2828

29-
- name: Run Jest tests
29+
- name: Run Vitest tests
3030
run: npm run ci:test
3131
test-coverage:
3232
runs-on: ubuntu-latest
@@ -43,7 +43,7 @@ jobs:
4343
- name: Install dependencies
4444
run: npm ci
4545

46-
- name: Run Jest tests with coverage
46+
- name: Run Vitest tests with coverage
4747
run: npm run ci:test:coverage
4848

4949
- name: Check coverage thresholds

README.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,23 @@ take up to 60 seconds once the docker build finishes.
3636

3737
## Testing the project
3838

39-
The project uses jest for unit testing.
40-
A "counter" script executes before and after each test run to track how many times the unit
41-
tests are run locally. The output is displayed.
39+
The project uses Vitest through Angular's unit test builder (`ng test`).
40+
A "counter" script displays local run stats after coverage runs.
4241

4342
```bash
44-
npm run test (single test run)
45-
npm run test:watch (single run after file save)
46-
npm run test:coverage (code coverage results)
43+
npm run test # single test run (no watch)
44+
npm run test:one "src/path/to/file.spec.ts" # run one spec file
45+
npm run test:watch # watch mode
46+
npm run test:coverage # coverage reports
4747
```
4848

49-
- all commits must pass the local pipeline for test coverage
49+
Coverage thresholds are configured in `vitest.config.ts` (`test.coverage.thresholds`).
50+
To validate threshold updates after improving coverage:
5051

5152
```bash
5253
npm run test:check-coverage-thresholds
5354
```
5455

55-
- Verifies newly added tests match the thresholds
56-
- This is only used until we hit 100% test coverage
57-
- all commits must pass the local pipeline for test coverage
58-
5956
## Volta
6057

6158
OSF uses volta to manage node and npm versions inside of the repository

angular.json

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"prefix": "osf",
1717
"architect": {
1818
"build": {
19-
"builder": "@angular-devkit/build-angular:application",
19+
"builder": "@angular/build:application",
2020
"options": {
2121
"outputPath": "dist/osf",
2222
"index": "src/index.html",
@@ -166,7 +166,7 @@
166166
"defaultConfiguration": "production"
167167
},
168168
"serve": {
169-
"builder": "@angular-devkit/build-angular:dev-server",
169+
"builder": "@angular/build:dev-server",
170170
"options": {
171171
"hmr": false
172172
},
@@ -196,9 +196,20 @@
196196
"defaultConfiguration": "development"
197197
},
198198
"test": {
199-
"builder": "@angular-devkit/build-angular:jest",
199+
"builder": "@angular/build:unit-test",
200200
"options": {
201-
"tsConfig": "tsconfig.spec.json"
201+
"runnerConfig": "vitest.config.ts",
202+
"coverageInclude": ["src/app/**/*.ts"],
203+
"coverageExclude": [
204+
"src/main.ts",
205+
"src/app/app.{config,routes}.ts",
206+
"**/theme/*.ts",
207+
"**/*.{routes,server}.ts",
208+
"**/index.ts",
209+
"**/mappers/**",
210+
"**/constants/**",
211+
"**/*.{enum,model,type,interface}.ts"
212+
]
202213
}
203214
},
204215
"lint": {

0 commit comments

Comments
 (0)