-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
82 lines (71 loc) · 2.2 KB
/
test.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {deepStrictEqual, rejects} from 'node:assert/strict'
import {test} from 'node:test'
import testReporterJson from '@mafalda-sfu/test-reporter-json'
test('layout', function()
{
deepStrictEqual(typeof testReporterJson, 'function')
})
test('source', async function()
{
const source = [
{data: {name: 'test 1'}, type: 'test:start'},
{data: {name: 'test 1'}, type: 'test:pass'},
{data: {name: 'test 2'}, type: 'test:start'},
{
data: {details: {error: {message: 'test 2 error'}}, name: 'test 2'},
type: 'test:fail'
},
{data: {name: 'test 2', plan: {end: 2, start: 1}}, type: 'test:plan'},
{
data: {message: 'test 2 diagnostic', name: 'test 2'},
type: 'test:diagnostic'
},
{data: {coverage: {}, name: 'test 2'}, type: 'test:coverage'}
]
const asyncGenerator = testReporterJson(source)
deepStrictEqual(typeof asyncGenerator, 'object')
deepStrictEqual(typeof asyncGenerator.next, 'function')
deepStrictEqual(typeof asyncGenerator.return, 'function')
deepStrictEqual(typeof asyncGenerator.throw, 'function')
deepStrictEqual(await asyncGenerator.next(), {
done: false,
value: '{\n' +
' "passed": [\n' +
' {\n' +
' "name": "test 1"\n' +
' }\n' +
' ],\n' +
' "failed": [\n' +
' {\n' +
' "name": "test 2",\n' +
' "details": {\n' +
' "error": {\n' +
' "message": "test 2 error"\n' +
' }\n' +
' }\n' +
' }\n' +
' ],\n' +
' "name": "test 2",\n' +
' "plan": {\n' +
' "end": 2,\n' +
' "start": 1\n' +
' },\n' +
' "diagnostics": [\n' +
' "test 2 diagnostic"\n' +
' ],\n' +
' "coverage": {}\n' +
'}'
})
deepStrictEqual(await asyncGenerator.next(), {done: true, value: undefined})
})
test('unknown event type', async function()
{
const source = [
{type: 'foo'}
]
const asyncGenerator = testReporterJson(source)
await rejects(asyncGenerator.next())
})
// TODO: Node.js added new events, and test runner crashes. Run test runner with
// the reporter to see if it crashes and generated JSON is correct.
test.todo('self execution')