Skip to content

Commit 62463dd

Browse files
authored
test: migrate from AVA to Vitest and remove test macros (#221)
Replace AVA test framework with Vitest and eliminate all test macros by expanding them into explicit, self-documenting test cases. This migration improves developer experience with watch mode, built-in coverage reporting, and makes each test independently readable. Key changes: Dependencies and Configuration: - Replace AVA with Vitest for test execution - Remove NYC in favor of Vitest's built-in coverage (@vitest/coverage-v8) - Remove eslint-plugin-ava and add eslint-plugin-vitest - Create vitest.config.js with ES Modules support, parallel execution, and coverage configuration matching previous NYC settings - Configure coverage to generate html, lcov, and text reports in a single test run Test Migration (153 test files transformed): - Convert all test files from AVA syntax to Vitest syntax - Replace AVA's `t.deepEqual()` with `expect().toEqual()` - Replace AVA's `t.truthy()` with `expect().toBeTruthy()` - Replace AVA's `t.throws()` with `expect().toThrow()` - Use explicit imports: `import { test, expect, describe } from 'vitest'` Test Macro Elimination: - Remove test/_macros.js entirely (contained 6 test macro patterns) - Expand `setsAggType` macro into explicit aggregation type tests - Expand `validatedCorrectly` macro into table-driven validation tests - Expand `makeSetsOptionMacro` generated tests into explicit option tests - Expand `illegalCall` macro into explicit error tests with toThrow() - Expand `illegalParamType` macro into explicit TypeError tests - All expanded tests follow table-driven patterns for maintainability Test Utilities: - Create test/testutil/ package for shared test helper functions - Add type checking utilities for parameter validation - Export all utilities from test/testutil/index.js - Reuse existing recursiveToJSON from src/core/util.js Package Scripts: - Update test:src: `vitest run --coverage` (single-step execution) - Remove report script (now redundant with Vitest) - Remove coverage script (now redundant with Vitest) - Add test:watch: `vitest` for local development with watch mode - Keep test:typedef unchanged for TypeScript type checking ESLint Configuration: - Remove plugin:ava/recommended from test/.eslintrc.yml - Add plugin:vitest/recommended to test/.eslintrc.yml - Update plugins array to use vitest instead of ava CI/CD: - Update .github/workflows/build.yml to use `npm test` instead of separate `npm run coverage` (coverage now generated during test run) - Maintain testing on Node.js 20.x, 22.x, 24.x - Preserve Coveralls integration with lcov format Bug Fixes: - Remove src/suggesters/phase-suggester.js (incorrectly named file, should be phrase-suggester.js which already exists) Documentation: - Update README.md with new test commands using Vitest - Update CONTRIBUTING.md with Vitest test instructions - Add test/testing-guidelines.mdc for test writing guidelines This migration maintains test coverage while improving code clarity and developer experience. All 153 test files now use explicit, self-documenting test cases instead of opaque macro invocations.
1 parent 377e727 commit 62463dd

File tree

168 files changed

+20008
-12186
lines changed

Some content is hidden

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

168 files changed

+20008
-12186
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ jobs:
3131
- name: Install dependencies
3232
run: npm ci
3333
- name: Check
34-
run: |
35-
npm run check
36-
npm run coverage
34+
run: npm run check
3735
- name: Coveralls
3836
uses: coverallsapp/[email protected]
3937
with:

CONTRIBUTING.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,25 @@ elastic-builder is published to npm.
3535

3636
### Run tests
3737

38-
This project uses eslint for javascript linting and ava for testing. Run
39-
linting using `npm run lint` and run tests using `npm run test`. Or run both using:
38+
This project uses eslint for javascript linting and vitest for testing. Run
39+
linting using `npm run lint` and run tests using `npm test`. Or run both using:
4040
```
4141
npm run check
4242
```
4343
This should take care of formatting as well thanks to [eslint-plugin-prettier][3].
4444

45+
You can also run tests in watch mode during development:
46+
```
47+
npm run test:watch
48+
```
49+
50+
To generate coverage reports:
51+
```
52+
npm run test:src
53+
```
54+
55+
Coverage reports are generated in the `coverage/` directory.
56+
4557
### (Optional) Add yourself as a contributor
4658

4759
Thanks for contributing! Go ahead and add yourself to the list of contributors

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,20 @@ Run unit tests:
367367
npm test
368368
```
369369

370+
Run tests in watch mode:
371+
372+
```
373+
npm run test:watch
374+
```
375+
376+
Run tests with coverage:
377+
378+
```
379+
npm run test:src
380+
```
381+
382+
Coverage reports are generated in the `coverage/` directory.
383+
370384
## Credits
371385

372386
`elastic-builder` is heavily inspired by [`elastic.js`][elastic-js] and the

0 commit comments

Comments
 (0)