metaltest/lib/metaltest.test.js

24 lines
766 B
JavaScript
Raw Normal View History

2022-11-08 22:29:58 -05:00
import assert from 'node:assert/strict'
2022-12-05 22:21:18 -05:00
import { metaltest } from '../index.js'
2022-11-08 22:29:58 -05:00
const test = metaltest('Metaltest')
2022-12-05 22:21:18 -05:00
export { test }
2022-11-08 22:29:58 -05:00
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' })
})
2022-12-05 22:26:51 -05:00
import { runifmain, summaryreporter } from '../index.js'
2022-11-08 22:29:58 -05:00
await runifmain(import.meta, async () => {
2022-12-05 22:26:51 -05:00
const stats = await test.run(summaryreporter())
2022-11-08 22:29:58 -05:00
assert.equal(stats.success, 4)
assert.equal(stats.fail, 0)
2022-12-05 22:22:58 -05:00
assert.equal(stats.total, 4)
assert.equal(stats.title, 'Metaltest')
2022-11-08 22:29:58 -05:00
})