-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.browser.js
239 lines (220 loc) · 7.49 KB
/
index.browser.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// Node, or global
;(function (root) { // eslint-disable-line no-extra-semi
'use strict'
const module = { factories: {} }
Object.defineProperty(module, 'exports', {
get: function () {
return null
},
set: function (val) {
module.factories[`${val.name}Factory`] = val.factory
},
// this property should show up when this object's property names are enumerated
enumerable: true,
// this property may not be deleted
configurable: false,
})
// MODULES_HERE
// resolve the dependency graph
function isPromise (input) {
return input && typeof input.then === 'function'
}
const REPORT_ORDERS = {
NON_DETERMINISTIC: 'non-deterministic',
DETERMINISTIC: 'deterministic',
}
const time = module.factories.timeFactory()
const suites = {}
let supposed = null
// resolve the dependency graph
function Supposed (options) {
const { allSettled } = module.factories.allSettledFactory({})
const { makePlans } = module.factories.makePlansFactory({ allSettled })
const envvars = {
assertionLibrary: {},
reporters: ['LIST'],
useColors: true,
timeUnits: 'us',
reportOrder: REPORT_ORDERS.NON_DETERMINISTIC,
exit: (results) => results,
}
const { ReporterFactory } = module.factories.reporterFactoryFactory({})
const reporterFactory = new ReporterFactory()
const { makeSuiteConfig } = module.factories.makeSuiteConfigFactory({
envvars,
reporterFactory,
REPORT_ORDERS,
})
const config = makeSuiteConfig(options)
const clock = (timeUnits) => time.clock(timeUnits || config.timeUnits)
const duration = (start, end) => time.duration(start, end, config.timeUnits)
const { TestEvent } = module.factories.TestEventFactory({ clock, envvars: config })
const { Pubsub } = module.factories.pubsubFactory({
allSettled,
isPromise,
TestEvent,
})
const pubsub = new Pubsub()
const consoleStyles = module.factories.consoleStylesFactory({ envvars: config }).consoleStyles
const { TallyFactory } = module.factories.TallyFactory({ pubsub, TestEvent, clock, duration })
const { Tally } = TallyFactory({})
reporterFactory.add(Tally)
const ArrayReporter = module.factories.ArrayReporterFactory({}).ArrayReporter
reporterFactory.add(ArrayReporter)
// @deprecated - legacy support
reporterFactory.add(function QuietReporter () { // legacy
return { write: new ArrayReporter().write }
})
reporterFactory.add(module.factories.NoopReporterFactory({}).NoopReporter)
function DefaultFormatter (options) {
return module.factories.DefaultFormatterFactory({
consoleStyles,
TestEvent,
SYMBOLS: (options && options.SYMBOLS) || {
PASSED: ' PASS ',
FAILED: ' FAIL ',
BROKEN: ' !!!! ',
SKIPPED: ' SKIP ',
INFO: ' INFO ',
},
config,
}).DefaultFormatter()
}
function ConsoleReporter (options) {
return module.factories.DomReporterFactory({
TestEvent,
formatter: options.formatter,
envvars: config,
REPORT_ORDERS,
}).DomReporter(options)
}
const listFormatter = module.factories.ListFormatterFactory({ consoleStyles, DefaultFormatter }).ListFormatter()
const SpecFormatter = module.factories.SpecFormatterFactory({ consoleStyles, DefaultFormatter, TestEvent }).SpecFormatter
reporterFactory.add(function ListReporter () {
return {
write: ConsoleReporter({ formatter: listFormatter }).write,
}
}).add(function BlockReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.BlockFormatterFactory({ consoleStyles, DefaultFormatter }).BlockFormatter(),
}).write,
}
}).add(function BriefReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.BriefFormatterFactory({ consoleStyles, DefaultFormatter, TestEvent }).BriefFormatter(),
}).write,
}
}).add(function CsvReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.CsvFormatterFactory({ TestEvent }).CsvFormatter(),
}).write,
}
}).add(function EventReporter () {
return {
write: ConsoleReporter({
formatter: { format: (event) => JSON.stringify(event, null, 2) },
}).write,
}
}).add(function JsonReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.JsonFormatterFactory({ TestEvent }).JsonFormatter(),
}).write,
}
}).add(function MarkdownReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.MarkdownFormatterFactory({ consoleStyles, TestEvent, SpecFormatter, DefaultFormatter }).MarkdownFormatter(),
reportOrder: REPORT_ORDERS.DETERMINISTIC, // non-deterministic not supported
}).write,
}
}).add(function MdReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.MarkdownFormatterFactory({ consoleStyles, TestEvent, SpecFormatter, DefaultFormatter }).MarkdownFormatter(),
reportOrder: REPORT_ORDERS.DETERMINISTIC, // non-deterministic not supported
}).write,
}
}).add(function PerformanceReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.PerformanceFormatterFactory({ consoleStyles, TestEvent }).PerformanceFormatter(),
}).write,
}
}).add(function JustTheDescriptionsReporter () {
return {
write: ConsoleReporter({
formatter: {
format: (event) => {
if (event.type === TestEvent.types.TEST) {
return listFormatter.format(event).split('\n')[0]
} else {
return listFormatter.format(event)
}
},
},
}).write,
}
}).add(function SpecReporter () {
return {
write: ConsoleReporter({
formatter: SpecFormatter(),
reportOrder: REPORT_ORDERS.DETERMINISTIC, // non-deterministic not supported
}).write,
}
}).add(function SummaryReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.SummaryFormatterFactory({
consoleStyles,
DefaultFormatter,
TestEvent,
}).SummaryFormatter(),
}).write,
}
}).add(function TapReporter () {
return {
write: ConsoleReporter({
formatter: module.factories.TapFormatterFactory({ consoleStyles, TestEvent, config }).TapFormatter(),
}).write,
}
})
const { AsyncTest } = module.factories.AsyncTestFactory({
isPromise,
pubsub,
TestEvent,
clock,
duration,
addDurations: time.addDurations,
})
const { hash } = module.factories.hashFactory()
const { BatchComposer } = module.factories.makeBatchFactory({ hash })
const { Suite } = module.factories.SuiteFactory({
allSettled,
AsyncTest,
BatchComposer,
makeSuiteConfig,
pubsub,
reporterFactory,
makePlans,
Tally,
TestEvent,
clock,
envvars: config,
})
const suite = new Suite()
suite.Suite = Supposed
if (!suites[suite.config.name]) {
suites[suite.config.name] = suite
}
return suite
}
supposed = Supposed({ name: 'supposed' })
suites.supposed = supposed
supposed.suites = suites
supposed.time = time
window.supposed = supposed
}(window))