test: migrate from AVA to Vitest and remove test macros#221
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR migrates the test suite from AVA to Vitest and eliminates all test macros by expanding them into explicit, self-documenting test cases. This improves developer experience with watch mode, built-in coverage reporting, and makes each test independently readable.
Key Changes
Dependencies and Configuration
@vitest/coverage-v8)eslint-plugin-avaand addeslint-plugin-vitestvitest.config.jswith ES Modules support, parallel execution, and coverage configurationTest Migration (153 test files transformed)
t.deepEqual()withexpect().toEqual()t.truthy()withexpect().toBeTruthy()t.throws()withexpect().toThrow()import { test, expect, describe } from 'vitest'Test Macro Elimination
test/_macros.jsentirely (contained 6 test macro patterns)setsAggTypemacro into explicit aggregation type testsvalidatedCorrectlymacro into table-driven validation testsmakeSetsOptionMacrogenerated tests into explicit option testsillegalCallmacro into explicit error tests withtoThrow()illegalParamTypemacro into explicit TypeError testsTest Utilities
test/testutil/package for shared test helper functionstest/testutil/index.jsrecursiveToJSONfromsrc/core/util.jsPackage Scripts
test:src:vitest run --coverage(single-step execution)reportscript (now redundant with Vitest)coveragescript (now redundant with Vitest)test:watch:vitestfor local development with watch modetest:typedefunchanged for TypeScript type checkingESLint Configuration
plugin:ava/recommendedfromtest/.eslintrc.ymlplugin:vitest/recommendedtotest/.eslintrc.ymlCI/CD
.github/workflows/build.ymlto usenpm testinstead of separatenpm run coverageBug Fixes
src/suggesters/phase-suggester.js(incorrectly named file, should bephrase-suggester.jswhich already exists)Documentation
README.mdwith new test commands using VitestCONTRIBUTING.mdwith Vitest test instructionstest/testing-guidelines.mdcfor test writing guidelinesTesting
All 153 test files have been transformed and are passing. Coverage levels are maintained at the same levels as before the migration.
To run tests locally:
Benefits
Breaking Changes
None for library users. This only affects the development/testing environment.