forked from dead-claudia/thallium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal.js
108 lines (86 loc) · 2.62 KB
/
internal.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict"
var Thallium = require("./lib/api/thallium")
var Reports = require("./lib/core/reports")
var Types = Reports.Types
exports.root = function () {
return new Thallium()
}
function d(duration) {
if (duration == null) return 10
if (typeof duration === "number") return duration|0
throw new TypeError("Expected `duration` to be a number if it exists")
}
function s(slow) {
if (slow == null) return 75
if (typeof slow === "number") return slow|0
throw new TypeError("Expected `slow` to be a number if it exists")
}
function p(path) {
if (Array.isArray(path)) return path
throw new TypeError("Expected `path` to be an array of locations")
}
function h(value) {
if (value != null && typeof value._ === "number") return value
throw new TypeError("Expected `value` to be a hook error")
}
/**
* Create a new report, mainly for testing reporters.
*/
exports.reports = {
start: function () {
return new Reports.Start()
},
enter: function (path, duration, slow) {
return new Reports.Enter(p(path), d(duration), s(slow))
},
leave: function (path) {
return new Reports.Leave(p(path))
},
pass: function (path, duration, slow) {
return new Reports.Pass(p(path), d(duration), s(slow))
},
fail: function (path, value, duration, slow) {
return new Reports.Fail(p(path), value, d(duration), s(slow))
},
skip: function (path) {
return new Reports.Skip(p(path))
},
end: function () {
return new Reports.End()
},
error: function (value) {
return new Reports.Error(value)
},
hook: function (path, rootPath, value) {
return new Reports.Hook(p(path), p(rootPath), h(value))
},
}
/**
* Create a new hook error, mainly for testing reporters.
*/
exports.hookErrors = {
beforeAll: function (func, value) {
return new Reports.HookError(Types.BeforeAll, func, value)
},
beforeEach: function (func, value) {
return new Reports.HookError(Types.BeforeEach, func, value)
},
afterEach: function (func, value) {
return new Reports.HookError(Types.AfterEach, func, value)
},
afterAll: function (func, value) {
return new Reports.HookError(Types.AfterAll, func, value)
},
}
/**
* Creates a new location, mainly for testing reporters.
*/
exports.location = function (name, index) {
if (typeof name !== "string") {
throw new TypeError("Expected `name` to be a string")
}
if (typeof index !== "number") {
throw new TypeError("Expected `index` to be a number")
}
return {name: name, index: index|0}
}