- Add vitest ^2 + @vitest/coverage-v8 ^2 as devDependencies - Add `test` and `test:coverage` scripts to package.json - Create vitest.config.ts with resolve.alias to mock ponder virtual modules (ponder:schema, ponder:registry) and point kraiken-lib/version to source - Add coverage/ to .gitignore - Add tests/**/* and vitest.config.ts to tsconfig.json include - Create tests/__mocks__/ponder-schema.ts and ponder-registry.ts stubs - Create tests/stats.test.ts — 48 tests covering ring buffer logic, segment updates, hourly advancement, projections, ETH reserve snapshots, all exported async helpers with mock Ponder contexts - Create tests/version.test.ts — 14 tests covering isCompatibleVersion, getVersionMismatchError, and validateContractVersion (compatible / mismatch / error paths, existing-meta upsert path) - Create tests/abi.test.ts — 6 tests covering validateAbi and validateContractAbi Tests placed at tests/ (not src/tests/) so Ponder's Vite build does not attempt to execute test files as event handlers on startup. Result: 68 tests pass, 100% line/statement/function coverage on all helpers (stats.ts, version.ts, abi.ts, logger.ts) — exceeds 95% target. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
723 B
TypeScript
27 lines
723 B
TypeScript
import { defineConfig } from 'vitest/config';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, resolve } from 'path';
|
|
|
|
const rootDir = dirname(fileURLToPath(import.meta.url));
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
globals: false,
|
|
environment: 'node',
|
|
coverage: {
|
|
provider: 'v8',
|
|
include: ['src/helpers/**/*.ts'],
|
|
reporter: ['text', 'lcov'],
|
|
thresholds: {
|
|
lines: 95,
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'ponder:schema': resolve(rootDir, 'tests/__mocks__/ponder-schema.ts'),
|
|
'ponder:registry': resolve(rootDir, 'tests/__mocks__/ponder-registry.ts'),
|
|
'kraiken-lib/version': resolve(rootDir, '../../kraiken-lib/src/version.ts'),
|
|
},
|
|
},
|
|
});
|