@@ -3,6 +3,10 @@ import type { Result } from '../..'
3
3
import type { Finished , Value , Node , NodeTypeToNode , Chapter } from '../../types'
4
4
import type { TestBuiltins , TestOptions } from './types'
5
5
6
+ /**
7
+ * Convert the options provided by the user for each test into the full options
8
+ * used by the testing system
9
+ */
6
10
export function processTestOptions ( rawOptions : TestOptions = { } ) : Exclude < TestOptions , Chapter > {
7
11
return typeof rawOptions === 'number'
8
12
? {
@@ -11,6 +15,10 @@ export function processTestOptions(rawOptions: TestOptions = {}): Exclude<TestOp
11
15
: rawOptions
12
16
}
13
17
18
+ /**
19
+ * Wrapper around the MockedFunction type to provide type checking
20
+ * for mocked functions
21
+ */
14
22
export function asMockedFunc < T extends ( ...args : any [ ] ) => any > ( func : T ) {
15
23
return func as MockedFunction < T >
16
24
}
@@ -19,22 +27,34 @@ export function expectTrue(cond: boolean): asserts cond {
19
27
expect ( cond ) . toEqual ( true )
20
28
}
21
29
30
+ /**
31
+ * Asserts that the provided result is a `Finished`
32
+ */
22
33
export function expectFinishedResult ( result : Result ) : asserts result is Finished {
23
34
expect ( result . status ) . toEqual ( 'finished' )
24
35
}
25
36
37
+ /**
38
+ * Assers that the provided result is both `Finished` and is equal to the given value
39
+ */
26
40
export function expectFinishedResultValue ( result : Result , value : Value ) {
27
41
expectFinishedResult ( result )
28
42
expect ( result . value ) . toEqual ( value )
29
43
}
30
44
45
+ /**
46
+ * Type safe assertion. Expects the given Node to have the provided type
47
+ */
31
48
export function expectNodeType < T extends Node [ 'type' ] > (
32
49
typeStr : T ,
33
50
node : Node
34
51
) : asserts node is NodeTypeToNode < T > {
35
52
expect ( node . type ) . toEqual ( typeStr )
36
53
}
37
54
55
+ /**
56
+ * Calls `eval` on the provided code with the provided builtins
57
+ */
38
58
export function evalWithBuiltins ( code : string , testBuiltins : TestBuiltins = { } ) {
39
59
// Ugly, but if you know how to `eval` code with some builtins attached, please change this.
40
60
const builtins = Object . keys ( testBuiltins ) . map ( key => `const ${ key } = testBuiltins.${ key } ;` )
0 commit comments