sxy-test-runner 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,292 +0,0 @@
1
- // should this be renamed? runTestFile?
2
- import { createTimeProfiler } from 'sxy-dev-tools';
3
- import { showTimeProfiling } from '../../config.js';
4
- import { out, log, debug } from '../../output.js'; //import { runTasks } from './runTasks.js'
5
-
6
- import { addExports } from './addExports.js';
7
- import { shouldCaptureConsoleLog } from './shouldCaptureConsoleLog.js';
8
- import { overrideConsoleLog } from './overrideConsoleLog.js';
9
- import { configBeforeEachFile, configAfterEachFile //configBeforeEachDescribe,
10
- //configAfterEachDescribe,
11
- //configBeforeEachTest,
12
- //configAfterEachTest
13
- } from './configBeforeAfterFuncs.js';
14
- const {
15
- timeProfileAsync
16
- } = await createTimeProfiler(showTimeProfiling);
17
- export async function runTestFile(config, testFile) {
18
- return await timeProfileAsync(`run test file ${testFile.file}`, async () => {
19
- await debug('testFile', testFile); // run before test file
20
-
21
- const fileExports = {};
22
- await configBeforeEachFile(config, fileExports); // const beforeEachFileExports = (config.beforeEachFile)
23
- // ? runTasks(config, config.beforeEachFile)
24
- // : {}
25
- //const describeCounter = 1
26
-
27
- const runDescribePromises = [];
28
-
29
- for (const describe of testFile.describes) {
30
- await runDescribePromises.push(runDescribe(config, describe));
31
- if (config.execution.describes === 'sequential') await runDescribePromises.at(-1);
32
- } //console.log('runDescribePromises', runDescribePromises)
33
-
34
-
35
- const describeResults = await Promise.all(runDescribePromises); //console.log('describeResults', describeResults)
36
-
37
- const describeResultsSummary = {
38
- total: 0,
39
- passes: 0,
40
- errors: 0,
41
- invalid: 0,
42
- itsTotal: 0,
43
- itsPasses: 0
44
- };
45
-
46
- for (const describeResult of describeResults) {
47
- if (describeResult.error === false) {
48
- // no error
49
- describeResultsSummary.total += +(describeResult.success !== null);
50
- describeResultsSummary.passes += +describeResult.success;
51
- describeResultsSummary.invalid += +(describeResult.success === null);
52
- describeResultsSummary.itsTotal += describeResult.itResultsSummary.total;
53
- describeResultsSummary.itsPasses += describeResult.itResultsSummary.passes;
54
- } else {
55
- // error
56
- describeResultsSummary.total += 1;
57
- describeResultsSummary.errors += 1;
58
- }
59
- }
60
-
61
- const testResults = {
62
- file: testFile.file,
63
- success: describeResultsSummary.total > 0 ? describeResultsSummary.total === describeResultsSummary.passes : null,
64
- describeResults,
65
- describeResultsSummary
66
- }; // run after test
67
-
68
- await configAfterEachFile(config, fileExports);
69
- return testResults;
70
-
71
- async function runDescribe(config, describe) {
72
- return await timeProfileAsync(`run describe ${describe.thing}`, async () => {
73
- // afterDescribe
74
- let afterDescribeFunc;
75
-
76
- async function afterDescribe(func) {
77
- if (typeof func !== 'function') {
78
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
79
- }
80
-
81
- afterDescribeFunc = func;
82
- } // beforeEachTest
83
-
84
-
85
- let beforeEachTestFunc;
86
-
87
- async function beforeEachTest(func) {
88
- if (typeof func !== 'function') {
89
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
90
- }
91
-
92
- beforeEachTestFunc = func;
93
- } // afterEachTest
94
-
95
-
96
- let afterEachTestFunc;
97
-
98
- async function afterEachTest(func) {
99
- if (typeof func !== 'function') {
100
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,` + ` received ${typeof func}`);
101
- }
102
-
103
- afterEachTestFunc = func;
104
- }
105
-
106
- let itCounter = 1;
107
- const its = []; // create functions to pass back
108
- // it
109
-
110
- async function it(should, test) {
111
- const thisItCounter = itCounter++;
112
- await its.push({
113
- counter: thisItCounter,
114
- should,
115
- test
116
- });
117
- }
118
-
119
- const test = it;
120
- const describeExports = {};
121
- await configBeforeEachDescribe(config, describeExports);
122
- const describeParcel = {
123
- it,
124
- test,
125
- afterDescribe,
126
- beforeEachTest,
127
- afterEachTest
128
- };
129
- await addExports(describeParcel, describeExports); // capture the console.log output if we can
130
-
131
- let originalConsoleLog, replacementConsoleLog;
132
-
133
- if (await shouldCaptureConsoleLog(config, 'describe')) {
134
- ({
135
- originalConsoleLog,
136
- replacementConsoleLog
137
- } = await overrideConsoleLog());
138
- }
139
-
140
- try {
141
- await describe.tests(describeParcel);
142
- } catch (e) {
143
- const describeErrorResult = {
144
- counter: describe.counter,
145
- thing: describe.thing,
146
- error: e.message,
147
- success: false
148
- };
149
-
150
- if (await shouldCaptureConsoleLog(config, 'describe')) {
151
- console.log = originalConsoleLog; // eslint-disable-line no-console
152
-
153
- describeErrorResult.consoleLogs = replacementConsoleLog.logs;
154
- }
155
-
156
- return describeErrorResult;
157
- } //!!!!! should this be here, or at the end after its?
158
-
159
-
160
- let describeConsoleLogs;
161
-
162
- if (await shouldCaptureConsoleLog(config, 'describe')) {
163
- console.log = originalConsoleLog; // eslint-disable-line no-console
164
-
165
- describeConsoleLogs = replacementConsoleLog.logs; //!!!!!! This needs to be applied
166
- }
167
-
168
- const itResults = [];
169
-
170
- for (const it of its) {
171
- await itResults.push(await runIt(config, it));
172
- }
173
-
174
- const itResultsSummary = {
175
- total: 0,
176
- passes: 0
177
- };
178
-
179
- for (const itResult of itResults) {
180
- itResultsSummary.total += +(itResult.success !== null);
181
- itResultsSummary.passes += +itResult.success;
182
- }
183
-
184
- await debug('itResultsSummary', itResultsSummary);
185
- const describeResult = {
186
- counter: describe.counter,
187
- thing: describe.thing,
188
- error: false,
189
- success: itResultsSummary.total > 0 ? itResultsSummary.passes === itResultsSummary.total : null,
190
- itResults,
191
- itResultsSummary
192
- }; // run after
193
-
194
- if (typeof afterDescribeFunc === 'function') await afterDescribeFunc();
195
- await configAfterEachDescribe(config, describeExports);
196
- return describeResult;
197
-
198
- async function runIt(config, it) {
199
- return await timeProfileAsync(`run it ${it.should}`, async () => {
200
- // run before test/it
201
- const testExports = {};
202
- await configBeforeEachTest(config, testExports);
203
-
204
- if (typeof beforeEachTestFunc === 'function') {
205
- const funcExports = await beforeEachTestFunc();
206
- await addExports(testExports, funcExports);
207
- }
208
-
209
- const testParcel = {};
210
- await addExports(testParcel, testExports); //const thisItCounter = itCounter++ // assign THEN increment
211
- // capture the console.log output if we can
212
-
213
- let originalConsoleLog, replacementConsoleLog;
214
-
215
- if (await shouldCaptureConsoleLog(config, 'test')) {
216
- ({
217
- originalConsoleLog,
218
- replacementConsoleLog
219
- } = await overrideConsoleLog());
220
- } //// run the it
221
-
222
-
223
- let success = null;
224
- let error;
225
- const startTime = await new Date().getTime();
226
-
227
- try {
228
- await it.test(testParcel);
229
- success = true;
230
- } catch (e) {
231
- success = false;
232
- error = e;
233
- }
234
-
235
- const time = (await new Date().getTime()) - startTime;
236
- const itResult = {
237
- //counter: thisItCounter,
238
- counter: it.counter,
239
- should: it.should,
240
- success,
241
- time,
242
- error
243
- };
244
-
245
- if (await shouldCaptureConsoleLog(config, 'test')) {
246
- console.log = originalConsoleLog; // eslint-disable-line no-console
247
-
248
- itResult.consoleLogs = replacementConsoleLog.logs;
249
- } // run after test/it
250
-
251
-
252
- if (typeof afterEachTestFunc === 'function') await afterEachTestFunc();
253
- await configAfterEachTest(config, testExports);
254
- return itResult;
255
- });
256
- }
257
- });
258
- }
259
- });
260
- } // function configBeforeEachFile(config, exports) {
261
- // if (config.beforeEachFile) {
262
- // const theExports = runTasks(config.beforeEachFile, undefined)
263
- // addExports(exports, theExports)
264
- // }
265
- // }
266
- // function configAfterEachFile(config, exports) {
267
- // if (config.afterEachFile) {
268
- // runTasks(config.afterEachFile, exports)
269
- // }
270
- // }
271
- // function configBeforeEachDescribe(config, exports) {
272
- // if (config.beforeEachDescribe) {
273
- // const theExports = runTasks(config.beforeEachDescribe, undefined)
274
- // addExports(exports, theExports)
275
- // }
276
- // }
277
- // function configAfterEachDescribe(config, exports) {
278
- // if (config.afterEachDescribe) {
279
- // runTasks(config.afterEachDescribe, exports)
280
- // }
281
- // }
282
- // function configBeforeEachTest(config, exports) {
283
- // if (config.beforeEachTest) {
284
- // const theExports = runTasks(config.beforeEachTest, undefined)
285
- // addExports(exports, theExports)
286
- // }
287
- // }
288
- // function configAfterEachTest(config, exports) {
289
- // if (config.afterEachTest) {
290
- // runTasks(config.afterEachTest, exports)
291
- // }
292
- // }
@@ -1,348 +0,0 @@
1
- /*
2
- // should this be renamed? runTestFile?
3
-
4
- import { createTimeProfiler } from 'sxy-dev-tools'
5
- import { showTimeProfiling } from '../../config.js'
6
- import { out, log, debug } from '../../output.js'
7
-
8
- //import { runTasks } from './runTasks.js'
9
- import { addExports } from './addExports.js'
10
- import { shouldCaptureConsoleLog } from './shouldCaptureConsoleLog.js'
11
- import { overrideConsoleLog } from './overrideConsoleLog.js'
12
- import {
13
- configBeforeEachFile,
14
- configAfterEachFile,
15
- //configBeforeEachDescribe,
16
- //configAfterEachDescribe,
17
- //configBeforeEachTest,
18
- //configAfterEachTest
19
- } from './configBeforeAfterFuncs.js'
20
-
21
- const { timeProfileAsync } = createTimeProfiler(showTimeProfiling)
22
-
23
-
24
-
25
-
26
-
27
-
28
- export function runTestFile(config, testFile) {
29
-
30
- return timeProfileAsync(`run test file ${testFile.file}`, async () => {
31
-
32
- debug('testFile', testFile)
33
-
34
- // run before test file
35
- const fileExports = {}
36
- configBeforeEachFile(config, fileExports)
37
-
38
- // const beforeEachFileExports = (config.beforeEachFile)
39
- // ? runTasks(config, config.beforeEachFile)
40
- // : {}
41
-
42
- //const describeCounter = 1
43
-
44
- const runDescribePromises = []
45
-
46
- for (const describe of testFile.describes) {
47
-
48
- runDescribePromises.push(
49
- promise( runDescribe(config, describe) )
50
- )
51
-
52
- if (config.execution.describes === 'sequential') await runDescribePromises.at(-1)
53
-
54
- }
55
-
56
- //console.log('runDescribePromises', runDescribePromises)
57
-
58
- const describeResults = Promise.all(runDescribePromises)
59
-
60
- //console.log('describeResults', describeResults)
61
-
62
- const describeResultsSummary = {
63
- total: 0,
64
- passes: 0,
65
- errors: 0,
66
- invalid: 0,
67
- itsTotal: 0,
68
- itsPasses: 0,
69
- }
70
-
71
-
72
- for ( const describeResult of describeResults ) {
73
-
74
- if (describeResult.error === false) { // no error
75
- describeResultsSummary.total += +(describeResult.success !== null)
76
- describeResultsSummary.passes += +describeResult.success
77
- describeResultsSummary.invalid += +(describeResult.success === null)
78
- describeResultsSummary.itsTotal += describeResult.itResultsSummary.total
79
- describeResultsSummary.itsPasses += describeResult.itResultsSummary.passes
80
- } else { // error
81
- describeResultsSummary.total += 1
82
- describeResultsSummary.errors += 1
83
- }
84
-
85
- }
86
-
87
- const testResults = {
88
- file: testFile.file,
89
- success: (describeResultsSummary.total > 0)
90
- ? describeResultsSummary.total === describeResultsSummary.passes
91
- : null,
92
- describeResults,
93
- describeResultsSummary,
94
- }
95
-
96
- // run after test
97
- configAfterEachFile(config, fileExports)
98
-
99
- return testResults
100
-
101
-
102
- function runDescribe(config, describe) {
103
-
104
- return timeProfileAsync(`run describe ${describe.thing}`, () => {
105
-
106
-
107
-
108
- // afterDescribe
109
- let afterDescribeFunc
110
- function afterDescribe(func) {
111
- if (typeof func !== 'function') {
112
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,`
113
- + ` received ${typeof func}`)
114
- }
115
- afterDescribeFunc = func
116
- }
117
-
118
- // beforeEachTest
119
- let beforeEachTestFunc
120
- function beforeEachTest(func) {
121
- if (typeof func !== 'function') {
122
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,`
123
- + ` received ${typeof func}`)
124
- }
125
- beforeEachTestFunc = func
126
- }
127
-
128
- // afterEachTest
129
- let afterEachTestFunc
130
- function afterEachTest(func) {
131
- if (typeof func !== 'function') {
132
- throw new Error(`afterDescribe() error, argument passed to afterDescribe() must be a function,`
133
- + ` received ${typeof func}`)
134
- }
135
- afterEachTestFunc = func
136
- }
137
-
138
-
139
- let itCounter = 1
140
- const its = []
141
-
142
- // create functions to pass back
143
-
144
- // it
145
- function it(should, test) {
146
-
147
- const thisItCounter = itCounter++
148
- its.push({
149
- counter: thisItCounter,
150
- should,
151
- test,
152
- })
153
-
154
- }
155
-
156
- const test = it
157
-
158
-
159
- const describeExports = {}
160
- configBeforeEachDescribe(config, describeExports)
161
-
162
- const describeParcel = { it, test, afterDescribe, beforeEachTest, afterEachTest }
163
- addExports(describeParcel, describeExports)
164
-
165
-
166
-
167
- // capture the console.log output if we can
168
- let originalConsoleLog, replacementConsoleLog
169
- if (shouldCaptureConsoleLog(config, 'describe')) {
170
- ({ originalConsoleLog, replacementConsoleLog } = overrideConsoleLog())
171
- }
172
-
173
- try {
174
- describe.tests(describeParcel)
175
- } catch (e) {
176
- const describeErrorResult = {
177
- counter: describe.counter,
178
- thing: describe.thing,
179
- error: e.message,
180
- success: false
181
- }
182
- if (shouldCaptureConsoleLog(config, 'describe')) {
183
- console.log = originalConsoleLog // eslint-disable-line no-console
184
- describeErrorResult.consoleLogs = replacementConsoleLog.logs
185
- }
186
- return describeErrorResult
187
- }
188
-
189
- //!!!!! should this be here, or at the end after its?
190
-
191
- let describeConsoleLogs
192
- if (shouldCaptureConsoleLog(config, 'describe')) {
193
- console.log = originalConsoleLog // eslint-disable-line no-console
194
- describeConsoleLogs = replacementConsoleLog.logs
195
- //!!!!!! This needs to be applied
196
- }
197
-
198
-
199
- const itResults = []
200
-
201
- for ( const it of its ) {
202
- itResults.push( runIt(config, it) )
203
- }
204
-
205
- const itResultsSummary = {
206
- total: 0,
207
- passes: 0,
208
- }
209
-
210
- for ( const itResult of itResults ) {
211
- itResultsSummary.total += +(itResult.success !== null)
212
- itResultsSummary.passes += +itResult.success
213
- }
214
-
215
- debug('itResultsSummary', itResultsSummary)
216
-
217
- const describeResult = {
218
- counter: describe.counter,
219
- thing: describe.thing,
220
- error: false,
221
- success: (itResultsSummary.total > 0)
222
- ? itResultsSummary.passes === itResultsSummary.total
223
- : null,
224
- itResults,
225
- itResultsSummary
226
- }
227
-
228
- // run after
229
- if (typeof afterDescribeFunc === 'function') afterDescribeFunc()
230
- configAfterEachDescribe(config, describeExports)
231
-
232
- return describeResult
233
-
234
-
235
- function runIt(config, it) {
236
-
237
- return timeProfileAsync(`run it ${it.should}`, () => {
238
-
239
- // run before test/it
240
- const testExports = {}
241
- configBeforeEachTest(config, testExports)
242
- if (typeof beforeEachTestFunc === 'function') {
243
- const funcExports = beforeEachTestFunc()
244
- addExports(testExports, funcExports)
245
- }
246
-
247
- const testParcel = {}
248
- addExports(testParcel, testExports)
249
-
250
-
251
- //const thisItCounter = itCounter++ // assign THEN increment
252
-
253
-
254
- // capture the console.log output if we can
255
- let originalConsoleLog, replacementConsoleLog
256
- if (shouldCaptureConsoleLog(config, 'test')) {
257
- ({ originalConsoleLog, replacementConsoleLog } = overrideConsoleLog())
258
- }
259
-
260
- //// run the it
261
- let success = null
262
- let error
263
- const startTime = (new Date).getTime()
264
- try {
265
- it.test(testParcel)
266
- success = true
267
- } catch (e) {
268
- success = false
269
- error = e
270
- }
271
-
272
- const time = (new Date).getTime() - startTime
273
-
274
- const itResult = {
275
- //counter: thisItCounter,
276
- counter: it.counter,
277
- should: it.should,
278
- success,
279
- time,
280
- error
281
- }
282
-
283
- if (shouldCaptureConsoleLog(config, 'test')) {
284
- console.log = originalConsoleLog // eslint-disable-line no-console
285
- itResult.consoleLogs = replacementConsoleLog.logs
286
- }
287
-
288
-
289
- // run after test/it
290
- if (typeof afterEachTestFunc === 'function') afterEachTestFunc()
291
- configAfterEachTest(config, testExports)
292
-
293
- return itResult
294
-
295
- })
296
-
297
- }
298
-
299
- })
300
-
301
- }
302
-
303
- })
304
-
305
- }
306
-
307
-
308
-
309
- // function configBeforeEachFile(config, exports) {
310
- // if (config.beforeEachFile) {
311
- // const theExports = runTasks(config.beforeEachFile, undefined)
312
- // addExports(exports, theExports)
313
- // }
314
- // }
315
-
316
- // function configAfterEachFile(config, exports) {
317
- // if (config.afterEachFile) {
318
- // runTasks(config.afterEachFile, exports)
319
- // }
320
- // }
321
-
322
- // function configBeforeEachDescribe(config, exports) {
323
- // if (config.beforeEachDescribe) {
324
- // const theExports = runTasks(config.beforeEachDescribe, undefined)
325
- // addExports(exports, theExports)
326
- // }
327
- // }
328
-
329
- // function configAfterEachDescribe(config, exports) {
330
- // if (config.afterEachDescribe) {
331
- // runTasks(config.afterEachDescribe, exports)
332
- // }
333
- // }
334
-
335
- // function configBeforeEachTest(config, exports) {
336
- // if (config.beforeEachTest) {
337
- // const theExports = runTasks(config.beforeEachTest, undefined)
338
- // addExports(exports, theExports)
339
- // }
340
- // }
341
-
342
- // function configAfterEachTest(config, exports) {
343
- // if (config.afterEachTest) {
344
- // runTasks(config.afterEachTest, exports)
345
- // }
346
- // }
347
-
348
- */