Skip to content

Commit 5a80a33

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

29 files changed

Lines changed: 3048 additions & 165 deletions

.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

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,39 @@ wServices.article
448448
controller.abort('Abort article count request');
449449
```
450450

451+
## Testing
452+
453+
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.
454+
455+
### Running tests
456+
457+
```sh
458+
# Run all tests once
459+
$ npm run test
460+
461+
# Run tests with coverage report
462+
$ npm run test:coverage
463+
```
464+
465+
### Writing tests
466+
467+
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`.
468+
469+
The path aliases from `tsconfig.node.json` (e.g. `@ts/`, `@utils/`) are available in test files via `vitest.config.ts`.
470+
471+
Example (`src/utils/myModule.spec.ts`):
472+
473+
```ts
474+
import { describe, expect, it } from 'vitest';
475+
import { myFunction } from '@utils/myModule';
476+
477+
describe('myFunction', () => {
478+
it('should return the expected result', () => {
479+
expect(myFunction('input')).toBe('expected output');
480+
});
481+
});
482+
```
483+
451484
## Contributing
452485

453486
Check out the [contributing guidelines](.github/CONTRIBUTING.md).

0 commit comments

Comments
 (0)