sxy-test-runner 1.0.1 → 1.0.3
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.
- package/dist/cli/lib/configBeforeAfterFuncs.js +35 -0
- package/dist/cli/lib/{runDescribeParseIts.unitTest.js → configBeforeAfterFuncs.unitTest.js} +0 -0
- package/dist/cli/lib/loadTestFile.unitTest.js +39 -33
- package/dist/cli/lib/overrideConsoleLog.js +20 -0
- package/dist/cli/lib/{runDescribeRunIts.unitTest.js → overrideConsoleLog.unitTest.js} +0 -0
- package/dist/cli/lib/runDescribe.js +127 -15
- package/dist/cli/lib/runDescribe.unitTest.js +2 -282
- package/dist/cli/lib/runIt.js +30 -39
- package/dist/cli/lib/runIt.unitTest.js +2 -289
- package/dist/cli/lib/runTestFile copy.js +292 -0
- package/dist/cli/lib/runTestFile-old.js +348 -0
- package/dist/cli/lib/runTestFile.js +105 -0
- package/dist/cli/lib/{runTest.unitTest.js → runTestFile.unitTest.js} +30 -35
- package/dist/cli/lib/{runTests.js → runTestFiles.js} +25 -21
- package/dist/cli/lib/runTestFiles.unitTest.js +147 -0
- package/dist/cli/lib/shouldCaptureConsoleLog.js +24 -0
- package/dist/cli/lib/shouldCaptureConsoleLog.unitTest.js +31 -0
- package/dist/cli/once.js +3 -3
- package/dist/cli/watch.js +67 -67
- package/dist/{exported.eslintrc.js → exported.eslintrc.cjs} +0 -0
- package/package.json +3 -3
- package/dist/cli/lib/parseDescribe.js +0 -88
- package/dist/cli/lib/parseDescribe.unitTest.js +0 -17
- package/dist/cli/lib/parseItsFromDescribe.js +0 -115
- package/dist/cli/lib/runDescribe.old copy.js +0 -115
- package/dist/cli/lib/runDescribe.old.js +0 -115
- package/dist/cli/lib/runDescribe.old.unitTest.js +0 -440
- package/dist/cli/lib/runDescribeParseIts.js +0 -87
- package/dist/cli/lib/runDescribeRun.js +0 -59
- package/dist/cli/lib/runDescribeRun.unitTest.js +0 -293
- package/dist/cli/lib/runDescribeRunIts.js +0 -56
- package/dist/cli/lib/runTest.js +0 -71
- package/dist/cli/lib/runTests.unitTest.js +0 -59
- package/dist/cli/lib/timeProfier.js +0 -7
- package/dist/testing/example.test.js +0 -26
- package/dist/testing/example2.test.js +0 -19
- package/dist/testing/example3.test.js +0 -16
- package/dist/testing/importTimeTarget.js +0 -9
- package/dist/testing/importTimeTarget2.js +0 -11
- package/dist/testing/importTimeTest.js +0 -8
package/dist/cli/lib/runIt.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// to be populated with the func from runTestFile.js
|
|
2
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
3
|
+
import { showTimeProfiling } from '../../config.js';
|
|
4
|
+
import { out, log, debug } from '../../output.js';
|
|
5
|
+
import { shouldCaptureConsoleLog } from './shouldCaptureConsoleLog.js';
|
|
6
|
+
import { overrideConsoleLog } from './overrideConsoleLog.js';
|
|
3
7
|
import { addExports } from './addExports.js';
|
|
8
|
+
import { configBeforeEachTest, configAfterEachTest } from './configBeforeAfterFuncs.js';
|
|
9
|
+
const {
|
|
10
|
+
timeProfileAsync
|
|
11
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
4
12
|
export async function runIt(config, it, beforeEachTestFunc, afterEachTestFunc) {
|
|
5
13
|
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
14
|
// run before test/it
|
|
18
|
-
|
|
19
|
-
|
|
20
15
|
const testExports = {};
|
|
21
16
|
await configBeforeEachTest(config, testExports);
|
|
22
17
|
|
|
@@ -27,7 +22,17 @@ export async function runIt(config, it, beforeEachTestFunc, afterEachTestFunc) {
|
|
|
27
22
|
|
|
28
23
|
const testParcel = {};
|
|
29
24
|
await addExports(testParcel, testExports); //const thisItCounter = itCounter++ // assign THEN increment
|
|
30
|
-
|
|
25
|
+
// capture the console.log output if we can
|
|
26
|
+
|
|
27
|
+
let originalConsoleLog, replacementConsoleLog;
|
|
28
|
+
|
|
29
|
+
if (await shouldCaptureConsoleLog(config, 'test')) {
|
|
30
|
+
({
|
|
31
|
+
originalConsoleLog,
|
|
32
|
+
replacementConsoleLog
|
|
33
|
+
} = await overrideConsoleLog());
|
|
34
|
+
} //// run the it
|
|
35
|
+
|
|
31
36
|
|
|
32
37
|
let success = null;
|
|
33
38
|
let error;
|
|
@@ -48,32 +53,18 @@ export async function runIt(config, it, beforeEachTestFunc, afterEachTestFunc) {
|
|
|
48
53
|
should: it.should,
|
|
49
54
|
success,
|
|
50
55
|
time,
|
|
51
|
-
error
|
|
52
|
-
|
|
53
|
-
}; // run after test/it
|
|
56
|
+
error
|
|
57
|
+
};
|
|
54
58
|
|
|
55
|
-
if (
|
|
56
|
-
|
|
59
|
+
if (await shouldCaptureConsoleLog(config, 'test')) {
|
|
60
|
+
console.log = originalConsoleLog; // eslint-disable-line no-console
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
} ////
|
|
62
|
+
itResult.consoleLogs = replacementConsoleLog.logs;
|
|
63
|
+
} // run after test/it
|
|
61
64
|
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
if (typeof afterEachTestFunc === 'function') await afterEachTestFunc();
|
|
67
|
+
await configAfterEachTest(config, testExports);
|
|
68
|
+
return itResult;
|
|
65
69
|
});
|
|
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
70
|
}
|
|
@@ -1,294 +1,7 @@
|
|
|
1
|
-
//import { should } from 'chai'
|
|
2
1
|
import { applyConfigDefaults } from './applyConfigDefaults.js';
|
|
3
2
|
import { loadTestFile } from './loadTestFile.js';
|
|
4
|
-
import { parseDescribe } from './parseDescribe.js';
|
|
5
3
|
import { runIt } from './runIt.js';
|
|
6
|
-
const defaultConfig = await applyConfigDefaults({});
|
|
7
|
-
// const beforeAfterTest = loadTestFile(defaultConfig, beforeAfterTestFile)
|
|
8
|
-
|
|
4
|
+
const defaultConfig = await applyConfigDefaults({});
|
|
9
5
|
await mochaDescribe('runIt() function', async function () {
|
|
10
|
-
await mochaIt('
|
|
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
|
-
// })
|
|
6
|
+
await mochaIt('...', async function () {});
|
|
294
7
|
});
|
|
@@ -0,0 +1,292 @@
|
|
|
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
|
+
// }
|