Skip to content

Commit dbe033a

Browse files
author
Olivier Costi
committed
chore: add unit test structure
1 parent c2f2670 commit dbe033a

29 files changed

+3050
-166
lines changed

.github/CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@ In production the root folder will be used.
1212

1313
As of v1.9.0 this repository uses [conventional commit messages](https://conventionalcommits.org).
1414

15+
### Testing
16+
17+
The project uses [Vitest](https://vitest.dev/) as its test framework. Tests are colocated with their source files in the `src/` directory. Each test file is named `<module>.spec.ts` and placed next to the module it tests.
18+
19+
#### Running tests
20+
21+
```sh
22+
# Run all tests once
23+
$ npm run test
24+
25+
# Run tests with coverage report
26+
$ npm run test:coverage
27+
```
28+
29+
#### Writing tests
30+
31+
Test files should be placed next to the source file they test, within the `src/` directory. Each test file should be named `<module>.spec.ts`.
32+
33+
The path aliases from `tsconfig.node.json` (e.g. `@ts/`, `@utils/`) are available in test files via `vitest.config.ts`.
34+
35+
Example (`src/utils/myModule.spec.ts`):
36+
37+
```ts
38+
import { describe, expect, it } from 'vitest';
39+
import { myFunction } from '@utils/myModule';
40+
41+
describe('myFunction', () => {
42+
it('should return the expected result', () => {
43+
expect(myFunction('input')).toBe('expected output');
44+
});
45+
});
46+
```
47+
1548
### Publishing
1649

1750
1. Switch to master branch

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ jobs:
3434
name: build
3535
path: dist
3636

37+
test:
38+
name: Test
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v4
43+
44+
- name: Setup Node.js
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: 22.14.0
48+
49+
- name: Install dependencies
50+
run: npm ci
51+
52+
- name: Run tests
53+
run: npm run test
54+
3755
generate:
3856
name: Generate SDK
3957
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)