name: write-tests description: Write or update tape-six tests for a module or feature. Use when asked to write tests, add test coverage, or create typing tests for node-re2.
Write Tests for node-re2
Write or update tests using the tape-six testing library.
Steps
- Read
node_modules/tape-six/TESTING.mdfor the full tape-six API reference (assertions, hooks, patterns, configuration). - Identify the module or feature to test. Read its source code to understand the public API.
- Check existing tests in
tests/for node-re2 conventions and patterns. - Create or update the test file in
tests/:- For runtime tests use
.mjs. - Import RE2 with:
import {RE2} from '../re2.js'; - Import tape-six with:
import test from 'tape-six'; - Test with both string and Buffer inputs — Buffer support is a first-class feature.
- Test edge cases: empty strings, no match, global flag behavior, lastIndex, Unicode input.
- For runtime tests use
- For TypeScript typing tests, update
ts-tests/test-types.ts:- Verify typed usage patterns compile correctly. // turbo
- Run the new test file directly to verify:
node tests/test-<name>.mjs// turbo - Run the full test suite to check for regressions:
npm test- If debugging, use
npm run test:seq(runs sequentially, easier to trace issues).
- If debugging, use
- Report results and any failures.
node-re2 test conventions
- Test file naming:
test-*.mjsintests/. - TypeScript typing tests:
test-*.tsints-tests/. - Runtime tests (
.mjs): ESM imports,import test from 'tape-six'. - Tests are configured in
package.jsonunder the"tape6"section. - Test files should be directly executable:
node tests/test-foo.mjs. - Existing tests use synchronous
t => { ... }style (not async/promise-based). - Always test both string and Buffer variants of methods.
- Use
t.ok(),t.equal(),t.deepEqual(),t.fail()for assertions. - Use try/catch blocks to test error conditions (e.g., invalid patterns throwing
SyntaxError).