Skip to content

Conversation

@sudo-suhas
Copy link
Owner

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

  • ✅ 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
  • ✅ 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
  • ✅ 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

Testing

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:

npm test              # Run all tests
npm run test:watch    # Watch mode for development
npm run test:src      # Run tests with coverage

Benefits

  1. Better Developer Experience: Watch mode with instant feedback
  2. Built-in Coverage: No need for separate NYC configuration
  3. Self-Documenting Tests: All macro abstractions replaced with explicit test cases
  4. Modern Tooling: Vitest is actively maintained and faster than AVA
  5. Cleaner Test Code: Table-driven patterns instead of opaque macros

Breaking Changes

None for library users. This only affects the development/testing environment.

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.
@sudo-suhas sudo-suhas merged commit 62463dd into master Nov 27, 2025
7 of 8 checks passed
@sudo-suhas sudo-suhas deleted the migrate-to-vitest-and-remove-test-macros branch November 27, 2025 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant