sxy-test-runner 1.0.0

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.
Files changed (107) hide show
  1. package/dist/cli/index.js +33 -0
  2. package/dist/cli/init.js +170 -0
  3. package/dist/cli/init.unitTest.js +0 -0
  4. package/dist/cli/lib/addBasePath.js +15 -0
  5. package/dist/cli/lib/addBasePath.unitTest.js +31 -0
  6. package/dist/cli/lib/addExports.js +12 -0
  7. package/dist/cli/lib/addExports.unitTest.js +29 -0
  8. package/dist/cli/lib/applyConfigDefaults.js +41 -0
  9. package/dist/cli/lib/applyConfigDefaults.unitTest.js +25 -0
  10. package/dist/cli/lib/buildDependencyTree.js +32 -0
  11. package/dist/cli/lib/buildDependencyTree.unitTest.js +15 -0
  12. package/dist/cli/lib/buildDependencyTrees.js +34 -0
  13. package/dist/cli/lib/buildDependencyTrees.unitTest.js +17 -0
  14. package/dist/cli/lib/defaultConfig.js +22 -0
  15. package/dist/cli/lib/defaultConfig.test.js +7 -0
  16. package/dist/cli/lib/doUserSetup.js +30 -0
  17. package/dist/cli/lib/doUserSetup.unitTest.js +39 -0
  18. package/dist/cli/lib/doUserTeardown.js +30 -0
  19. package/dist/cli/lib/doUserTeardown.unitTest.js +39 -0
  20. package/dist/cli/lib/findTestFiles.js +24 -0
  21. package/dist/cli/lib/findTestFiles.unitTest.js +22 -0
  22. package/dist/cli/lib/getAllowedFlags.js +11 -0
  23. package/dist/cli/lib/getAllowedFlags.unitTest.js +20 -0
  24. package/dist/cli/lib/globArgCombine.js +1 -0
  25. package/dist/cli/lib/globArgCombine.unitTest.js +18 -0
  26. package/dist/cli/lib/injectProperties.js +11 -0
  27. package/dist/cli/lib/injectProperties.unitTest.js +75 -0
  28. package/dist/cli/lib/load.js +3 -0
  29. package/dist/cli/lib/load.unitTest.js +7 -0
  30. package/dist/cli/lib/loadConfig.js +21 -0
  31. package/dist/cli/lib/loadConfig.unitTest.js +15 -0
  32. package/dist/cli/lib/loadTestFile.js +75 -0
  33. package/dist/cli/lib/loadTestFile.unitTest.js +45 -0
  34. package/dist/cli/lib/loadTestFileStatic.js +40 -0
  35. package/dist/cli/lib/loadTestFileStatic.unitTest.js +29 -0
  36. package/dist/cli/lib/parseCommandLineArguments.js +57 -0
  37. package/dist/cli/lib/parseCommandLineArguments.unitTest.js +21 -0
  38. package/dist/cli/lib/parseDescribe.js +88 -0
  39. package/dist/cli/lib/parseDescribe.unitTest.js +17 -0
  40. package/dist/cli/lib/parseItsFromDescribe.js +115 -0
  41. package/dist/cli/lib/processWatchEvent.js +0 -0
  42. package/dist/cli/lib/processWatchEvent.unitTest.js +7 -0
  43. package/dist/cli/lib/reservedExportKeys.js +1 -0
  44. package/dist/cli/lib/reservedExportKeys.unitTest.js +7 -0
  45. package/dist/cli/lib/runDescribe.js +29 -0
  46. package/dist/cli/lib/runDescribe.old copy.js +115 -0
  47. package/dist/cli/lib/runDescribe.old.js +115 -0
  48. package/dist/cli/lib/runDescribe.old.unitTest.js +440 -0
  49. package/dist/cli/lib/runDescribe.unitTest.js +287 -0
  50. package/dist/cli/lib/runDescribeParseIts.js +87 -0
  51. package/dist/cli/lib/runDescribeParseIts.unitTest.js +0 -0
  52. package/dist/cli/lib/runDescribeRun.js +59 -0
  53. package/dist/cli/lib/runDescribeRun.unitTest.js +293 -0
  54. package/dist/cli/lib/runDescribeRunIts.js +56 -0
  55. package/dist/cli/lib/runDescribeRunIts.unitTest.js +0 -0
  56. package/dist/cli/lib/runIt.js +79 -0
  57. package/dist/cli/lib/runIt.unitTest.js +294 -0
  58. package/dist/cli/lib/runTasks.js +42 -0
  59. package/dist/cli/lib/runTasks.unitTest.js +30 -0
  60. package/dist/cli/lib/runTest-old.js +159 -0
  61. package/dist/cli/lib/runTest-old.unitTest.js +183 -0
  62. package/dist/cli/lib/runTest.js +71 -0
  63. package/dist/cli/lib/runTest.unitTest.js +269 -0
  64. package/dist/cli/lib/runTests.js +137 -0
  65. package/dist/cli/lib/runTests.unitTest.js +59 -0
  66. package/dist/cli/lib/showTestLoadingError.js +22 -0
  67. package/dist/cli/lib/showTestLoadingError.unitTest.js +25 -0
  68. package/dist/cli/lib/showTestResult.js +87 -0
  69. package/dist/cli/lib/showTestResult.unitTest.js +180 -0
  70. package/dist/cli/lib/timeProfier.js +7 -0
  71. package/dist/cli/lib/validateConfig.js +29 -0
  72. package/dist/cli/lib/validateConfig.unitTest.js +22 -0
  73. package/dist/cli/lib/watchFiles.js +1 -0
  74. package/dist/cli/lib/watchFiles.unitTest.js +48 -0
  75. package/dist/cli/lib/watchFilesAndRunTests.js +2 -0
  76. package/dist/cli/lib/watchFilesAndRunTests.unitTest.js +129 -0
  77. package/dist/cli/lib/watchFilesAndRunTestsChokidar.js +142 -0
  78. package/dist/cli/lib/watchFilesAndRunTestsChokidar.unitTest.js +133 -0
  79. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.js +162 -0
  80. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.unitTest.js +131 -0
  81. package/dist/cli/lib/watchFilesChokidar.js +56 -0
  82. package/dist/cli/lib/watchFilesChokidar.unitTest.js +85 -0
  83. package/dist/cli/lib/watchFilesNodeWatch.js +42 -0
  84. package/dist/cli/lib/watchFilesNodeWatch.unitTest.js +48 -0
  85. package/dist/cli/once.js +47 -0
  86. package/dist/cli/once.unitTest.js +39 -0
  87. package/dist/cli/watch.js +100 -0
  88. package/dist/cli/watch.unitTest.js +117 -0
  89. package/dist/config.js +7 -0
  90. package/dist/describe-old.js +257 -0
  91. package/dist/describe-old.unitTest.js +21 -0
  92. package/dist/describe.js +24 -0
  93. package/dist/describe.unitTest.js +27 -0
  94. package/dist/exported.eslintrc.js +7 -0
  95. package/dist/index.js +1 -0
  96. package/dist/indexNumberToLetters.js +13 -0
  97. package/dist/load.js +3 -0
  98. package/dist/output.js +17 -0
  99. package/dist/testing/example.test.js +26 -0
  100. package/dist/testing/example2.test.js +19 -0
  101. package/dist/testing/example3.test.js +16 -0
  102. package/dist/testing/importTimeTarget.js +9 -0
  103. package/dist/testing/importTimeTarget2.js +11 -0
  104. package/dist/testing/importTimeTest.js +8 -0
  105. package/dist/testsState.js +4 -0
  106. package/dist/timeProfiling.js +9 -0
  107. package/package.json +68 -0
@@ -0,0 +1,293 @@
1
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
2
+ import { loadTestFile } from './loadTestFile.js';
3
+ import { runDescribeRun } from './runDescribeRun.js';
4
+ import { parseDescribe } from './parseDescribe.js';
5
+ const defaultConfig = await applyConfigDefaults({}); // const beforeAfterTestFile = 'unitTesting/runTest/beforeAfter.test.js'
6
+ // const beforeAfterTest = loadTestFile(defaultConfig, beforeAfterTestFile)
7
+
8
+ await mochaDescribe('runDescribe() function', async function () {
9
+ await mochaIt('should run an it block that was loaded from a test file', async function () {
10
+ const sampleTestFile = 'unitTesting/runTest/1.test.js';
11
+ const sampleTest = await loadTestFile(defaultConfig, sampleTestFile);
12
+ const sampleDescribe = sampleTest.describes[0];
13
+ const parsedDescribe = await parseDescribe(defaultConfig, sampleDescribe); //console.log('sample describe', sampleDescribe)
14
+
15
+ const describeResult = await runDescribeRun(defaultConfig, sampleDescribe, parsedDescribe); //console.log('describe result', describeResult)
16
+ //console.log(testResult.describeResults[0].itResults)
17
+ //console.log(testResult.describeResults[0].itResultsSummary)
18
+
19
+ await describeResult.should.include.keys(['counter', 'thing', 'success', 'itResults', 'itResultsSummary']);
20
+ await describeResult.success.should.equal(true);
21
+ await describeResult.itResultsSummary.total.should.equal(1);
22
+ await describeResult.itResultsSummary.passes.should.equal(1);
23
+ }); // mochaIt('should return sensible results from a test file without any describes', function() {
24
+ // //const config = applyConfigDefaults({})
25
+ // const sampleTestFile = 'unitTesting/sampletests/blank.test.js'
26
+ // const sampleTest = loadTestFile(defaultConfig, sampleTestFile)
27
+ // const testResult = runTest(defaultConfig, sampleTest)
28
+ // //console.log(testResult)
29
+ // //console.log(testResult.describeResults[0].itResults)
30
+ // //console.log(testResult.describeResults[0].itResultsSummary)
31
+ // testResult.should.include.keys([
32
+ // 'file',
33
+ // 'success',
34
+ // 'describeResults',
35
+ // 'describeResultsSummary'
36
+ // ])
37
+ // chaiExpect(testResult.success).to.be.null
38
+ // //testResult.describeResultsSummary.total.should.equal(1)
39
+ // //testResult.describeResultsSummary.passes.should.equal(1)
40
+ // //testResult.describeResultsSummary.itsTotal.should.equal(1)
41
+ // //testResult.describeResultsSummary.itsPasses.should.equal(1)
42
+ // })
43
+ // mochaIt('should return sensible results from a test file with describes without any its/tests', function() {
44
+ // //const config = applyConfigDefaults({})
45
+ // const sampleTestFile = 'unitTesting/sampletests/describesWithoutTests.test.js'
46
+ // const sampleTest = loadTestFile(defaultConfig, sampleTestFile)
47
+ // const testResult = runTest(defaultConfig, sampleTest)
48
+ // //console.log(testResult)
49
+ // //console.log(testResult.describeResults[0].itResults)
50
+ // //console.log(testResult.describeResults[0].itResultsSummary)
51
+ // testResult.should.include.keys([
52
+ // 'file',
53
+ // 'success',
54
+ // 'describeResults',
55
+ // 'describeResultsSummary'
56
+ // ])
57
+ // chaiExpect(testResult.success).to.be.null
58
+ // testResult.describeResultsSummary.total.should.equal(0)
59
+ // testResult.describeResultsSummary.passes.should.equal(0)
60
+ // testResult.describeResultsSummary.invalid.should.equal(2)
61
+ // testResult.describeResultsSummary.itsTotal.should.equal(0)
62
+ // testResult.describeResultsSummary.itsPasses.should.equal(0)
63
+ // })
64
+ // mochaIt("should run beforeEachFile tasks (before - can't test)", function() {
65
+ // let functionHasRun = false
66
+ // global.beforeEachFileFileHasRun = false
67
+ // const ourConfig = {
68
+ // beforeEachFile: [
69
+ // function() {
70
+ // functionHasRun = true
71
+ // },
72
+ // 'unitTesting/runTest/beforeEachFile.js'
73
+ // ]
74
+ // }
75
+ // const config = applyConfigDefaults(ourConfig)
76
+ // runTest(config, beforeAfterTest)
77
+ // functionHasRun.should.equal(true)
78
+ // global.beforeEachFileFileHasRun.should.equal(true)
79
+ // })
80
+ // mochaIt("should run afterEachFile tasks (after - can't test)", function() {
81
+ // let functionHasRun = false
82
+ // global.afterEachFileFileHasRun = false
83
+ // const ourConfig = {
84
+ // afterEachFile: [
85
+ // function() {
86
+ // functionHasRun = true
87
+ // },
88
+ // 'unitTesting/runTest/afterEachFile.js'
89
+ // ]
90
+ // }
91
+ // const config = applyConfigDefaults(ourConfig)
92
+ // runTest(config, beforeAfterTest)
93
+ // functionHasRun.should.equal(true)
94
+ // global.afterEachFileFileHasRun.should.equal(true)
95
+ // })
96
+ // mochaIt("should run beforeEachDescribe tasks (before - can't test) each describe block", function() {
97
+ // let functionHasRunTimes = 0
98
+ // global.beforeEachDescribeFileHasRun = false
99
+ // const ourConfig = {
100
+ // beforeEachDescribe: [
101
+ // function() {
102
+ // functionHasRunTimes++
103
+ // },
104
+ // 'unitTesting/runTest/beforeEachDescribe.js'
105
+ // ]
106
+ // }
107
+ // const config = applyConfigDefaults(ourConfig)
108
+ // runTest(config, beforeAfterTest)
109
+ // functionHasRunTimes.should.equal(2)
110
+ // global.beforeEachDescribeFileHasRun.should.equal(true)
111
+ // })
112
+ // mochaIt("should run afterEachDescribe tasks (after - can't test) each describe block", function() {
113
+ // let functionHasRunTimes = 0
114
+ // global.afterEachDescribeFileHasRun = false
115
+ // const ourConfig = {
116
+ // afterEachDescribe: [
117
+ // function() {
118
+ // functionHasRunTimes++
119
+ // },
120
+ // 'unitTesting/runTest/afterEachDescribe.js'
121
+ // ]
122
+ // }
123
+ // const config = applyConfigDefaults(ourConfig)
124
+ // runTest(config, beforeAfterTest)
125
+ // functionHasRunTimes.should.equal(2)
126
+ // global.afterEachDescribeFileHasRun.should.equal(true)
127
+ // })
128
+ // mochaIt("should run beforeEachTest tasks (before - can't test) each test/it block", function() {
129
+ // let functionHasRunTimes = 0
130
+ // global.beforeEachTestbeforeEachFileFileHasRun = false
131
+ // const ourConfig = {
132
+ // beforeEachTest: [
133
+ // function() {
134
+ // functionHasRunTimes++
135
+ // },
136
+ // 'unitTesting/runTest/beforeEachTest.js'
137
+ // ]
138
+ // }
139
+ // const config = applyConfigDefaults(ourConfig)
140
+ // runTest(config, beforeAfterTest)
141
+ // functionHasRunTimes.should.equal(3)
142
+ // global.beforeEachTestFileHasRun.should.equal(true)
143
+ // })
144
+ // mochaIt("should run afterEachTest tasks (after - can't test) each test/it block", function() {
145
+ // let functionHasRunTimes = 0
146
+ // global.afterEachTestFileFileHasRun = false
147
+ // const ourConfig = {
148
+ // afterEachTest: [
149
+ // function() {
150
+ // functionHasRunTimes++
151
+ // },
152
+ // 'unitTesting/runTest/afterEachTest.js'
153
+ // ]
154
+ // }
155
+ // const config = applyConfigDefaults(ourConfig)
156
+ // runTest(config, beforeAfterTest)
157
+ // functionHasRunTimes.should.equal(3)
158
+ // global.afterEachTestFileHasRun.should.equal(true)
159
+ // })
160
+ // // exports provision to test file
161
+ // // current beforeEachFile exports aren't provided
162
+ // // perhaps extend sxy-loader to allow this
163
+ // mochaIt("should pass exported/returned data from beforeEachDescribe tasks", function() {
164
+ // const testFile = 'unitTesting/runTest/beforeEachDescribe.test.js'
165
+ // const test = loadTestFile(defaultConfig, testFile)
166
+ // const ourConfig = {
167
+ // beforeEachDescribe: [
168
+ // function() {
169
+ // return { functionThing : 'foo' }
170
+ // },
171
+ // 'unitTesting/runTest/beforeEachDescribeExport.js'
172
+ // ]
173
+ // }
174
+ // const config = applyConfigDefaults(ourConfig)
175
+ // runTest(config, test)
176
+ // global.functionThing.should.equal('foo')
177
+ // global.fileThing.should.equal('bar')
178
+ // })
179
+ // mochaIt("should pass exported/returned data from beforeEachTest tasks", function() {
180
+ // const testFile = 'unitTesting/runTest/beforeEachTest.test.js'
181
+ // const test = loadTestFile(defaultConfig, testFile)
182
+ // const ourConfig = {
183
+ // beforeEachTest: [
184
+ // function() {
185
+ // return { functionThing : 'foo' }
186
+ // },
187
+ // 'unitTesting/runTest/beforeEachTestExport.js'
188
+ // ]
189
+ // }
190
+ // const config = applyConfigDefaults(ourConfig)
191
+ // runTest(config, test)
192
+ // global.functionThing.should.equal('foo')
193
+ // global.fileThing.should.equal('bar')
194
+ // })
195
+ // // exports pass through
196
+ // mochaIt("beforeEachFile exports are passed through to afterEachFile", function() {
197
+ // // don't try to reload test, fails due to module caching
198
+ // //const testFile = 'unitTesting/runTest/beforeAfter.test.js'
199
+ // //const test = loadTestFile(defaultConfig, testFile)
200
+ // let exports
201
+ // const ourConfig = {
202
+ // beforeEachFile: [
203
+ // function() {
204
+ // return { functionThing : 'foo' }
205
+ // },
206
+ // 'unitTesting/runTest/beforeEachExport.js'
207
+ // ],
208
+ // afterEachFile: [
209
+ // function(theExports) {
210
+ // theExports.should.have.keys(['functionThing', 'fileThing'])
211
+ // exports = theExports
212
+ // },
213
+ // ]
214
+ // }
215
+ // const config = applyConfigDefaults(ourConfig)
216
+ // runTest(config, beforeAfterTest)
217
+ // exports.functionThing.should.equal('foo')
218
+ // exports.fileThing.should.equal('bar')
219
+ // })
220
+ // mochaIt("beforeEachDescribe exports are passed through to afterEachDescribe", function() {
221
+ // // don't try to reload test, fails due to module caching
222
+ // //const testFile = 'unitTesting/runTest/beforeAfter.test.js'
223
+ // //const test = loadTestFile(defaultConfig, testFile)
224
+ // let exports
225
+ // const ourConfig = {
226
+ // beforeEachDescribe: [
227
+ // function() {
228
+ // return { functionThing : 'foo' }
229
+ // },
230
+ // 'unitTesting/runTest/beforeEachExport.js'
231
+ // ],
232
+ // afterEachDescribe: [
233
+ // function(theExports) {
234
+ // exports = theExports
235
+ // },
236
+ // ]
237
+ // }
238
+ // const config = applyConfigDefaults(ourConfig)
239
+ // runTest(config, beforeAfterTest)
240
+ // //console.log('exports', exports)
241
+ // exports.functionThing.should.equal('foo')
242
+ // exports.fileThing.should.equal('bar')
243
+ // })
244
+ // mochaIt("beforeEachTest exports are passed through to afterEachTest", function() {
245
+ // // don't try to reload test, fails due to module caching
246
+ // //const testFile = 'unitTesting/runTest/beforeAfter.test.js'
247
+ // //const test = loadTestFile(defaultConfig, testFile)
248
+ // let exports
249
+ // const ourConfig = {
250
+ // beforeEachTest: [
251
+ // function() {
252
+ // return { functionThing : 'foo' }
253
+ // },
254
+ // 'unitTesting/runTest/beforeEachExport.js'
255
+ // ],
256
+ // afterEachTest: [
257
+ // function(theExports) {
258
+ // exports = theExports
259
+ // },
260
+ // ]
261
+ // }
262
+ // const config = applyConfigDefaults(ourConfig)
263
+ // runTest(config, beforeAfterTest)
264
+ // //console.log('exports', exports)
265
+ // exports.functionThing.should.equal('foo')
266
+ // exports.fileThing.should.equal('bar')
267
+ // })
268
+ // mochaIt("we can run code beforeEachTest and afterEachTest from within the test file", function() {
269
+ // // don't try to reload test, fails due to module caching
270
+ // const testFile = 'unitTesting/runTest/internalBeforeAfterEachTest.test.js'
271
+ // const test = loadTestFile(defaultConfig, testFile)
272
+ // const config = applyConfigDefaults({})
273
+ // global.internalBeforeEachTestRanNTimes = 0
274
+ // global.internalAfterEachTestRanNTimes = 0
275
+ // runTest(config, test)
276
+ // global.internalBeforeAfterEachTest_test1Valid.should.equal(true)
277
+ // global.internalBeforeAfterEachTest_test2Valid.should.equal(true)
278
+ // global.internalBeforeAfterEachTest_test3Valid.should.equal(true)
279
+ // global.internalBeforeEachTestRanNTimes.should.equal(3)
280
+ // global.internalAfterEachTestRanNTimes.should.equal(3)
281
+ // })
282
+ // mochaIt("we can run code afterDescribe from within descibe in the test file", function() {
283
+ // // don't try to reload test, fails due to module caching
284
+ // const testFile = 'unitTesting/runTest/internalAfterDescribeTest.test.js'
285
+ // const test = loadTestFile(defaultConfig, testFile)
286
+ // const config = applyConfigDefaults({})
287
+ // global.internalAfterDescribeRanNTimes = 0
288
+ // runTest(config, test)
289
+ // //global.internalAfterDescribe_test1Valid.should.equal(true)
290
+ // //global.internalAfterDescribe_test2Valid.should.equal(true)
291
+ // global.internalAfterDescribeRanNTimes.should.equal(2)
292
+ // })
293
+ });
@@ -0,0 +1,56 @@
1
+ import { timeProfileAsync } from './timeProfier.js';
2
+ import { runTasks } from './runTasks.js';
3
+ import { addExports } from './addExports.js';
4
+ import { debug } from '../../output.js';
5
+ import { runIt } from './runIt.js';
6
+ export async function runDescribeRunIts(config, describe, describeExports, parsedIts) {
7
+ return await timeProfileAsync(`run describe, run its ${describe.thing}`, async () => {
8
+ const {
9
+ its,
10
+ afterDescribeFunc,
11
+ beforeEachTestFunc,
12
+ afterEachTestFunc
13
+ } = parsedIts;
14
+ const itResults = [];
15
+
16
+ for (const it of its) {
17
+ await itResults.push(await runIt(config, it, beforeEachTestFunc, afterEachTestFunc));
18
+ }
19
+
20
+ const itResultsSummary = {
21
+ total: 0,
22
+ passes: 0
23
+ };
24
+
25
+ for (const itResult of itResults) {
26
+ itResultsSummary.total += +(itResult.success !== null);
27
+ itResultsSummary.passes += +itResult.success;
28
+ }
29
+
30
+ await debug('itResultsSummary', itResultsSummary);
31
+ const describeResult = {
32
+ counter: describe.counter,
33
+ thing: describe.thing,
34
+ success: itResultsSummary.total > 0 ? itResultsSummary.passes === itResultsSummary.total : null,
35
+ itResults,
36
+ itResultsSummary
37
+ }; // run after
38
+
39
+ if (typeof afterDescribeFunc === 'function') await afterDescribeFunc();
40
+ await configAfterEachDescribe(config, describeExports);
41
+ return describeResult;
42
+ });
43
+ }
44
+
45
+ async function configBeforeEachDescribe(config, exports) {
46
+ if (config.beforeEachDescribe) {
47
+ const theExports = await runTasks(config.beforeEachDescribe, undefined);
48
+ await addExports(exports, theExports);
49
+ }
50
+ }
51
+
52
+ async function configAfterEachDescribe(config, exports) {
53
+ if (config.afterEachDescribe) {
54
+ await runTasks(config.afterEachDescribe, exports);
55
+ }
56
+ }
File without changes
@@ -0,0 +1,79 @@
1
+ import { timeProfileAsync } from './timeProfier.js';
2
+ import { runTasks } from './runTasks.js';
3
+ import { addExports } from './addExports.js';
4
+ export async function runIt(config, it, beforeEachTestFunc, afterEachTestFunc) {
5
+ return await timeProfileAsync(`run it ${it.should}`, async () => {
6
+ const capturingConsoleLog = config.execution.tests === 'sequential'; //// capture console.log output
7
+
8
+ let previousConsoleLog;
9
+ const logs = [];
10
+
11
+ if (capturingConsoleLog) {
12
+ previousConsoleLog = console.log; // eslint-disable-line no-console
13
+
14
+ console.log = async (...texts) => await logs.push(texts); // eslint-disable-line no-console
15
+
16
+ } ////
17
+ // run before test/it
18
+
19
+
20
+ const testExports = {};
21
+ await configBeforeEachTest(config, testExports);
22
+
23
+ if (typeof beforeEachTestFunc === 'function') {
24
+ const funcExports = await beforeEachTestFunc();
25
+ await addExports(testExports, funcExports);
26
+ }
27
+
28
+ const testParcel = {};
29
+ await addExports(testParcel, testExports); //const thisItCounter = itCounter++ // assign THEN increment
30
+ //// run the it
31
+
32
+ let success = null;
33
+ let error;
34
+ const startTime = await new Date().getTime();
35
+
36
+ try {
37
+ await it.test(testParcel);
38
+ success = true;
39
+ } catch (e) {
40
+ success = false;
41
+ error = e;
42
+ }
43
+
44
+ const time = (await new Date().getTime()) - startTime;
45
+ const itResult = {
46
+ //counter: thisItCounter,
47
+ counter: it.counter,
48
+ should: it.should,
49
+ success,
50
+ time,
51
+ error,
52
+ logs
53
+ }; // run after test/it
54
+
55
+ if (typeof afterEachTestFunc === 'function') await afterEachTestFunc();
56
+ await configAfterEachTest(config, testExports); //// restore previous console.log
57
+
58
+ if (capturingConsoleLog) {
59
+ console.log = previousConsoleLog; // eslint-disable-line no-console
60
+ } ////
61
+
62
+
63
+ return itResult; //testResults.push(testResult)
64
+ //testsState.testResults.push(testResult)
65
+ });
66
+ }
67
+
68
+ async function configBeforeEachTest(config, exports) {
69
+ if (config.beforeEachTest) {
70
+ const theExports = await runTasks(config.beforeEachTest, undefined);
71
+ await addExports(exports, theExports);
72
+ }
73
+ }
74
+
75
+ async function configAfterEachTest(config, exports) {
76
+ if (config.afterEachTest) {
77
+ await runTasks(config.afterEachTest, exports);
78
+ }
79
+ }