mirror of
https://github.com/napi-rs/napi-rs.git
synced 2025-12-08 19:56:07 +00:00
- Migrated all test files in examples/napi-compat-mode to node:test - Migrated CLI test files to node:test - Migrated examples/napi test framework to support node:test - Removed AVA dependencies from package.json files - Updated test scripts to use node:test - Updated config to reference node:test instead of AVA Co-authored-by: Brooooooklyn <3468483+Brooooooklyn@users.noreply.github.com>
45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
import {
|
|
test,
|
|
after as afterAll,
|
|
afterEach,
|
|
before as beforeAll,
|
|
beforeEach,
|
|
} from 'node:test'
|
|
import assert from 'node:assert'
|
|
|
|
// node:test doesn't have expect-style assertions like Bun/Jest
|
|
// We need to wrap node:assert to provide an expect-like interface
|
|
const expect = (actual) => ({
|
|
toEqual: (expected) => assert.deepStrictEqual(actual, expected),
|
|
toBe: (expected, message) => assert.strictEqual(actual, expected, message),
|
|
toMatch: (expected) => assert.match(actual, expected),
|
|
toThrow: (expected) => {
|
|
if (typeof actual === 'function') {
|
|
if (expected) {
|
|
assert.throws(actual, expected)
|
|
} else {
|
|
assert.throws(actual)
|
|
}
|
|
} else {
|
|
throw new Error('toThrow requires a function')
|
|
}
|
|
},
|
|
not: {
|
|
toEqual: (expected) => assert.notDeepStrictEqual(actual, expected),
|
|
toBe: (expected) => assert.notStrictEqual(actual, expected),
|
|
toThrow: (expected) => {
|
|
if (typeof actual === 'function') {
|
|
if (expected) {
|
|
assert.doesNotThrow(actual, expected)
|
|
} else {
|
|
assert.doesNotThrow(actual)
|
|
}
|
|
} else {
|
|
throw new Error('toThrow requires a function')
|
|
}
|
|
},
|
|
},
|
|
})
|
|
|
|
export { test, afterAll, afterEach, beforeAll, beforeEach, expect }
|