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