-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
43 lines (37 loc) · 1011 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* @japa/assert
*
* (c) Japa.dev
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type { PluginFn } from '@japa/runner/types'
import { Test, TestContext } from '@japa/runner/core'
import { Assert } from './src/assert.js'
import type { PluginConfig } from './src/types.js'
declare module '@japa/runner/core' {
interface TestContext {
assert: Assert
}
}
/**
* Plugin for "@japa/runner"
*/
export function assert(options?: PluginConfig): PluginFn {
if (options?.openApi) {
Assert.registerApiSpecs(options.openApi.schemas, {
exportCoverage: options.openApi.exportCoverage,
reportCoverage: options.openApi.reportCoverage,
})
}
return function () {
TestContext.getter('assert', () => new Assert(), true)
Test.executed(function (test: Test<any>, hasError) {
if (!hasError) {
test.context?.assert.assertions.validate()
}
})
}
}
export { Assert }