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