metaltest/lib/metaltest.test.js

27 lines
765 B
JavaScript
Raw Normal View History

2022-11-08 22:29:58 -05:00
import assert from 'node:assert/strict'
2022-12-05 17:10:27 -05:00
import { metaltest, consolereporter } from '../index.js'
2022-11-08 22:29:58 -05:00
const test = metaltest('Metaltest')
let count = 0
test.before(() => count++)
test('success', () => new Promise((s, f) => setTimeout(s, 500)))
test('not equal', () => assert.notEqual({ a: 1 }, { a: 2 }))
test('fail with the message', () => new Promise((s, f) => setTimeout(s, 500)))
test('throw', () => {
return assert.rejects(async () => {
throw new Error('message')
}, { name: 'Error', message: 'message' })
})
export { test }
2022-12-05 17:10:27 -05:00
import { runifmain } from './runifmain.js'
2022-11-08 22:29:58 -05:00
await runifmain(import.meta, async () => {
const stats = await test.run(consolereporter())
assert.equal(count, 4)
assert.equal(stats.success, 4)
assert.equal(stats.fail, 0)
})