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.
- package/dist/cli/index.js +33 -0
- package/dist/cli/init.js +170 -0
- package/dist/cli/init.unitTest.js +0 -0
- package/dist/cli/lib/addBasePath.js +15 -0
- package/dist/cli/lib/addBasePath.unitTest.js +31 -0
- package/dist/cli/lib/addExports.js +12 -0
- package/dist/cli/lib/addExports.unitTest.js +29 -0
- package/dist/cli/lib/applyConfigDefaults.js +41 -0
- package/dist/cli/lib/applyConfigDefaults.unitTest.js +25 -0
- package/dist/cli/lib/buildDependencyTree.js +32 -0
- package/dist/cli/lib/buildDependencyTree.unitTest.js +15 -0
- package/dist/cli/lib/buildDependencyTrees.js +34 -0
- package/dist/cli/lib/buildDependencyTrees.unitTest.js +17 -0
- package/dist/cli/lib/defaultConfig.js +22 -0
- package/dist/cli/lib/defaultConfig.test.js +7 -0
- package/dist/cli/lib/doUserSetup.js +30 -0
- package/dist/cli/lib/doUserSetup.unitTest.js +39 -0
- package/dist/cli/lib/doUserTeardown.js +30 -0
- package/dist/cli/lib/doUserTeardown.unitTest.js +39 -0
- package/dist/cli/lib/findTestFiles.js +24 -0
- package/dist/cli/lib/findTestFiles.unitTest.js +22 -0
- package/dist/cli/lib/getAllowedFlags.js +11 -0
- package/dist/cli/lib/getAllowedFlags.unitTest.js +20 -0
- package/dist/cli/lib/globArgCombine.js +1 -0
- package/dist/cli/lib/globArgCombine.unitTest.js +18 -0
- package/dist/cli/lib/injectProperties.js +11 -0
- package/dist/cli/lib/injectProperties.unitTest.js +75 -0
- package/dist/cli/lib/load.js +3 -0
- package/dist/cli/lib/load.unitTest.js +7 -0
- package/dist/cli/lib/loadConfig.js +21 -0
- package/dist/cli/lib/loadConfig.unitTest.js +15 -0
- package/dist/cli/lib/loadTestFile.js +75 -0
- package/dist/cli/lib/loadTestFile.unitTest.js +45 -0
- package/dist/cli/lib/loadTestFileStatic.js +40 -0
- package/dist/cli/lib/loadTestFileStatic.unitTest.js +29 -0
- package/dist/cli/lib/parseCommandLineArguments.js +57 -0
- package/dist/cli/lib/parseCommandLineArguments.unitTest.js +21 -0
- package/dist/cli/lib/parseDescribe.js +88 -0
- package/dist/cli/lib/parseDescribe.unitTest.js +17 -0
- package/dist/cli/lib/parseItsFromDescribe.js +115 -0
- package/dist/cli/lib/processWatchEvent.js +0 -0
- package/dist/cli/lib/processWatchEvent.unitTest.js +7 -0
- package/dist/cli/lib/reservedExportKeys.js +1 -0
- package/dist/cli/lib/reservedExportKeys.unitTest.js +7 -0
- package/dist/cli/lib/runDescribe.js +29 -0
- package/dist/cli/lib/runDescribe.old copy.js +115 -0
- package/dist/cli/lib/runDescribe.old.js +115 -0
- package/dist/cli/lib/runDescribe.old.unitTest.js +440 -0
- package/dist/cli/lib/runDescribe.unitTest.js +287 -0
- package/dist/cli/lib/runDescribeParseIts.js +87 -0
- package/dist/cli/lib/runDescribeParseIts.unitTest.js +0 -0
- package/dist/cli/lib/runDescribeRun.js +59 -0
- package/dist/cli/lib/runDescribeRun.unitTest.js +293 -0
- package/dist/cli/lib/runDescribeRunIts.js +56 -0
- package/dist/cli/lib/runDescribeRunIts.unitTest.js +0 -0
- package/dist/cli/lib/runIt.js +79 -0
- package/dist/cli/lib/runIt.unitTest.js +294 -0
- package/dist/cli/lib/runTasks.js +42 -0
- package/dist/cli/lib/runTasks.unitTest.js +30 -0
- package/dist/cli/lib/runTest-old.js +159 -0
- package/dist/cli/lib/runTest-old.unitTest.js +183 -0
- package/dist/cli/lib/runTest.js +71 -0
- package/dist/cli/lib/runTest.unitTest.js +269 -0
- package/dist/cli/lib/runTests.js +137 -0
- package/dist/cli/lib/runTests.unitTest.js +59 -0
- package/dist/cli/lib/showTestLoadingError.js +22 -0
- package/dist/cli/lib/showTestLoadingError.unitTest.js +25 -0
- package/dist/cli/lib/showTestResult.js +87 -0
- package/dist/cli/lib/showTestResult.unitTest.js +180 -0
- package/dist/cli/lib/timeProfier.js +7 -0
- package/dist/cli/lib/validateConfig.js +29 -0
- package/dist/cli/lib/validateConfig.unitTest.js +22 -0
- package/dist/cli/lib/watchFiles.js +1 -0
- package/dist/cli/lib/watchFiles.unitTest.js +48 -0
- package/dist/cli/lib/watchFilesAndRunTests.js +2 -0
- package/dist/cli/lib/watchFilesAndRunTests.unitTest.js +129 -0
- package/dist/cli/lib/watchFilesAndRunTestsChokidar.js +142 -0
- package/dist/cli/lib/watchFilesAndRunTestsChokidar.unitTest.js +133 -0
- package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.js +162 -0
- package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.unitTest.js +131 -0
- package/dist/cli/lib/watchFilesChokidar.js +56 -0
- package/dist/cli/lib/watchFilesChokidar.unitTest.js +85 -0
- package/dist/cli/lib/watchFilesNodeWatch.js +42 -0
- package/dist/cli/lib/watchFilesNodeWatch.unitTest.js +48 -0
- package/dist/cli/once.js +47 -0
- package/dist/cli/once.unitTest.js +39 -0
- package/dist/cli/watch.js +100 -0
- package/dist/cli/watch.unitTest.js +117 -0
- package/dist/config.js +7 -0
- package/dist/describe-old.js +257 -0
- package/dist/describe-old.unitTest.js +21 -0
- package/dist/describe.js +24 -0
- package/dist/describe.unitTest.js +27 -0
- package/dist/exported.eslintrc.js +7 -0
- package/dist/index.js +1 -0
- package/dist/indexNumberToLetters.js +13 -0
- package/dist/load.js +3 -0
- package/dist/output.js +17 -0
- package/dist/testing/example.test.js +26 -0
- package/dist/testing/example2.test.js +19 -0
- package/dist/testing/example3.test.js +16 -0
- package/dist/testing/importTimeTarget.js +9 -0
- package/dist/testing/importTimeTarget2.js +11 -0
- package/dist/testing/importTimeTest.js +8 -0
- package/dist/testsState.js +4 -0
- package/dist/timeProfiling.js +9 -0
- package/package.json +68 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/*
|
|
2
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js'
|
|
3
|
+
import { loadTestFile } from './loadTestFile.js'
|
|
4
|
+
import { runTest } from './runTest.js'
|
|
5
|
+
|
|
6
|
+
// loadTestFile(config, testFile) ???
|
|
7
|
+
|
|
8
|
+
const defaultConfig = applyConfigDefaults({})
|
|
9
|
+
|
|
10
|
+
const beforeAfterTestFile = 'unitTesting/runTest/beforeAfter.test.js'
|
|
11
|
+
const beforeAfterTest = loadTestFile(defaultConfig, beforeAfterTestFile)
|
|
12
|
+
|
|
13
|
+
mochaDescribe('runTest() function', function() {
|
|
14
|
+
|
|
15
|
+
mochaIt('should run a test that was previously loaded from a test file', function() {
|
|
16
|
+
|
|
17
|
+
//const config = applyConfigDefaults({})
|
|
18
|
+
|
|
19
|
+
const sampleTestFile = 'unitTesting/runTest/1.test.js'
|
|
20
|
+
const sampleTest = loadTestFile(defaultConfig, sampleTestFile)
|
|
21
|
+
|
|
22
|
+
const testResult = runTest(defaultConfig, sampleTest)
|
|
23
|
+
|
|
24
|
+
//console.log(testResult)
|
|
25
|
+
//console.log(testResult.describeResults[0].itResults)
|
|
26
|
+
//console.log(testResult.describeResults[0].itResultsSummary)
|
|
27
|
+
|
|
28
|
+
testResult.should.include.keys([
|
|
29
|
+
'file',
|
|
30
|
+
'success',
|
|
31
|
+
'describeResults',
|
|
32
|
+
'describeResultsSummary'
|
|
33
|
+
])
|
|
34
|
+
|
|
35
|
+
testResult.success.should.equal(true)
|
|
36
|
+
|
|
37
|
+
testResult.describeResultsSummary.total.should.equal(1)
|
|
38
|
+
testResult.describeResultsSummary.passes.should.equal(1)
|
|
39
|
+
testResult.describeResultsSummary.itsTotal.should.equal(1)
|
|
40
|
+
testResult.describeResultsSummary.itsPasses.should.equal(1)
|
|
41
|
+
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
mochaIt("should run beforeEachFile tasks (before - can't test)", function() {
|
|
45
|
+
|
|
46
|
+
let functionHasRun = false
|
|
47
|
+
global.beforeEachFileFileHasRun = false
|
|
48
|
+
|
|
49
|
+
const ourConfig = {
|
|
50
|
+
beforeEachFile: [
|
|
51
|
+
function() {
|
|
52
|
+
functionHasRun = true
|
|
53
|
+
},
|
|
54
|
+
'unitTesting/runTest/beforeEachFile.js'
|
|
55
|
+
]
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const config = applyConfigDefaults(ourConfig)
|
|
59
|
+
|
|
60
|
+
runTest(config, beforeAfterTest)
|
|
61
|
+
|
|
62
|
+
functionHasRun.should.equal(true)
|
|
63
|
+
global.beforeEachFileFileHasRun.should.equal(true)
|
|
64
|
+
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
mochaIt("should run afterEachFile tasks (after - can't test)", function() {
|
|
68
|
+
|
|
69
|
+
let functionHasRun = false
|
|
70
|
+
global.afterEachFileFileHasRun = false
|
|
71
|
+
|
|
72
|
+
const ourConfig = {
|
|
73
|
+
afterEachFile: [
|
|
74
|
+
function() {
|
|
75
|
+
functionHasRun = true
|
|
76
|
+
},
|
|
77
|
+
'unitTesting/runTest/afterEachFile.js'
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const config = applyConfigDefaults(ourConfig)
|
|
82
|
+
|
|
83
|
+
runTest(config, beforeAfterTest)
|
|
84
|
+
|
|
85
|
+
functionHasRun.should.equal(true)
|
|
86
|
+
global.afterEachFileFileHasRun.should.equal(true)
|
|
87
|
+
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
mochaIt("should run beforeEachDescribe tasks (before - can't test) each describe block", function() {
|
|
91
|
+
|
|
92
|
+
let functionHasRunTimes = 0
|
|
93
|
+
global.beforeEachDescribeFileHasRun = false
|
|
94
|
+
|
|
95
|
+
const ourConfig = {
|
|
96
|
+
beforeEachDescribe: [
|
|
97
|
+
function() {
|
|
98
|
+
functionHasRunTimes++
|
|
99
|
+
},
|
|
100
|
+
'unitTesting/runTest/beforeEachDescribe.js'
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const config = applyConfigDefaults(ourConfig)
|
|
105
|
+
|
|
106
|
+
runTest(config, beforeAfterTest)
|
|
107
|
+
|
|
108
|
+
functionHasRunTimes.should.equal(2)
|
|
109
|
+
global.beforeEachDescribeFileHasRun.should.equal(true)
|
|
110
|
+
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
mochaIt("should run afterEachDescribe tasks (after - can't test) each describe block", function() {
|
|
114
|
+
|
|
115
|
+
let functionHasRunTimes = 0
|
|
116
|
+
global.afterEachDescribeFileHasRun = false
|
|
117
|
+
|
|
118
|
+
const ourConfig = {
|
|
119
|
+
afterEachDescribe: [
|
|
120
|
+
function() {
|
|
121
|
+
functionHasRunTimes++
|
|
122
|
+
},
|
|
123
|
+
'unitTesting/runTest/afterEachDescribe.js'
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const config = applyConfigDefaults(ourConfig)
|
|
128
|
+
|
|
129
|
+
runTest(config, beforeAfterTest)
|
|
130
|
+
|
|
131
|
+
functionHasRunTimes.should.equal(2)
|
|
132
|
+
global.afterEachDescribeFileHasRun.should.equal(true)
|
|
133
|
+
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
mochaIt("should run beforeEachTest tasks (before - can't test) each test/it block", function() {
|
|
137
|
+
|
|
138
|
+
let functionHasRunTimes = 0
|
|
139
|
+
global.beforeEachTestbeforeEachFileFileHasRun = false
|
|
140
|
+
|
|
141
|
+
const ourConfig = {
|
|
142
|
+
beforeEachTest: [
|
|
143
|
+
function() {
|
|
144
|
+
functionHasRunTimes++
|
|
145
|
+
},
|
|
146
|
+
'unitTesting/runTest/beforeEachTest.js'
|
|
147
|
+
]
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const config = applyConfigDefaults(ourConfig)
|
|
151
|
+
|
|
152
|
+
runTest(config, beforeAfterTest)
|
|
153
|
+
|
|
154
|
+
functionHasRunTimes.should.equal(3)
|
|
155
|
+
global.beforeEachTestFileHasRun.should.equal(true)
|
|
156
|
+
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
mochaIt("should run afterEachTest tasks (after - can't test) each test/it block", function() {
|
|
160
|
+
|
|
161
|
+
let functionHasRunTimes = 0
|
|
162
|
+
global.afterEachTestFileFileHasRun = false
|
|
163
|
+
|
|
164
|
+
const ourConfig = {
|
|
165
|
+
afterEachTest: [
|
|
166
|
+
function() {
|
|
167
|
+
functionHasRunTimes++
|
|
168
|
+
},
|
|
169
|
+
'unitTesting/runTest/afterEachTest.js'
|
|
170
|
+
]
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const config = applyConfigDefaults(ourConfig)
|
|
174
|
+
|
|
175
|
+
runTest(config, beforeAfterTest)
|
|
176
|
+
|
|
177
|
+
functionHasRunTimes.should.equal(3)
|
|
178
|
+
global.afterEachTestFileHasRun.should.equal(true)
|
|
179
|
+
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
})
|
|
183
|
+
*/
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools'; //import chalk from 'chalk-extensions'
|
|
2
|
+
|
|
3
|
+
import { out, log, debug } from '../../output.js';
|
|
4
|
+
import { showTimeProfiling } from '../../config.js';
|
|
5
|
+
import { runTasks } from './runTasks.js';
|
|
6
|
+
import { addExports } from './addExports.js';
|
|
7
|
+
import { runDescribe } from './runDescribe.js';
|
|
8
|
+
const {
|
|
9
|
+
timeProfileAsync
|
|
10
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
11
|
+
export async function runTest(config, test) {
|
|
12
|
+
return await timeProfileAsync(`run test ${test.file}`, async () => {
|
|
13
|
+
await debug('test', test); // run before test file
|
|
14
|
+
|
|
15
|
+
const fileExports = {};
|
|
16
|
+
await configBeforeEachFile(config, fileExports); // const beforeEachFileExports = (config.beforeEachFile)
|
|
17
|
+
// ? runTasks(config, config.beforeEachFile)
|
|
18
|
+
// : {}
|
|
19
|
+
//const describeCounter = 1
|
|
20
|
+
|
|
21
|
+
const runDescribePromises = [];
|
|
22
|
+
|
|
23
|
+
for (const describe of test.describes) {
|
|
24
|
+
await runDescribePromises.push(runDescribe(config, describe));
|
|
25
|
+
if (config.execution.describes === 'sequential') await runDescribePromises.at(-1);
|
|
26
|
+
} //console.log('runDescribePromises', runDescribePromises)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
const describeResults = await Promise.all(runDescribePromises); //console.log('describeResults', describeResults)
|
|
30
|
+
|
|
31
|
+
const describeResultsSummary = {
|
|
32
|
+
total: 0,
|
|
33
|
+
passes: 0,
|
|
34
|
+
invalid: 0,
|
|
35
|
+
itsTotal: 0,
|
|
36
|
+
itsPasses: 0
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
for (const describeResult of describeResults) {
|
|
40
|
+
describeResultsSummary.total += +(describeResult.success !== null);
|
|
41
|
+
describeResultsSummary.passes += +describeResult.success;
|
|
42
|
+
describeResultsSummary.invalid += +(describeResult.success === null);
|
|
43
|
+
describeResultsSummary.itsTotal += describeResult.itResultsSummary.total;
|
|
44
|
+
describeResultsSummary.itsPasses += describeResult.itResultsSummary.passes;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const testResults = {
|
|
48
|
+
file: test.file,
|
|
49
|
+
success: describeResultsSummary.total > 0 ? describeResultsSummary.total === describeResultsSummary.passes : null,
|
|
50
|
+
describeResults,
|
|
51
|
+
describeResultsSummary,
|
|
52
|
+
logs: test.logs
|
|
53
|
+
}; // run after test
|
|
54
|
+
|
|
55
|
+
await configAfterEachFile(config, fileExports);
|
|
56
|
+
return testResults;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function configBeforeEachFile(config, exports) {
|
|
61
|
+
if (config.beforeEachFile) {
|
|
62
|
+
const theExports = await runTasks(config.beforeEachFile, undefined);
|
|
63
|
+
await addExports(exports, theExports);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function configAfterEachFile(config, exports) {
|
|
68
|
+
if (config.afterEachFile) {
|
|
69
|
+
await runTasks(config.afterEachFile, exports);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js';
|
|
2
|
+
import { loadTestFile } from './loadTestFile.js';
|
|
3
|
+
import { runTest } from './runTest.js';
|
|
4
|
+
const defaultConfig = await applyConfigDefaults({});
|
|
5
|
+
const beforeAfterTestFile = 'unitTesting/runTest/beforeAfter.test.js';
|
|
6
|
+
const beforeAfterTest = await loadTestFile(defaultConfig, beforeAfterTestFile);
|
|
7
|
+
await mochaDescribe('runTest() function', async function () {
|
|
8
|
+
await mochaIt('should run a test that was previously loaded from a test file', async function () {
|
|
9
|
+
//const config = applyConfigDefaults({})
|
|
10
|
+
const sampleTestFile = 'unitTesting/runTest/1.test.js';
|
|
11
|
+
const sampleTest = await loadTestFile(defaultConfig, sampleTestFile);
|
|
12
|
+
const testResult = await runTest(defaultConfig, sampleTest); //console.log(testResult)
|
|
13
|
+
//console.log(testResult.describeResults[0].itResults)
|
|
14
|
+
//console.log(testResult.describeResults[0].itResultsSummary)
|
|
15
|
+
|
|
16
|
+
await testResult.should.include.keys(['file', 'success', 'describeResults', 'describeResultsSummary']);
|
|
17
|
+
await testResult.success.should.equal(true);
|
|
18
|
+
await testResult.describeResultsSummary.total.should.equal(1);
|
|
19
|
+
await testResult.describeResultsSummary.passes.should.equal(1);
|
|
20
|
+
await testResult.describeResultsSummary.itsTotal.should.equal(1);
|
|
21
|
+
await testResult.describeResultsSummary.itsPasses.should.equal(1);
|
|
22
|
+
});
|
|
23
|
+
await mochaIt('should return sensible results from a test file without any describes', async function () {
|
|
24
|
+
//const config = applyConfigDefaults({})
|
|
25
|
+
const sampleTestFile = 'unitTesting/sampletests/blank.test.js';
|
|
26
|
+
const sampleTest = await loadTestFile(defaultConfig, sampleTestFile);
|
|
27
|
+
const testResult = await runTest(defaultConfig, sampleTest); //console.log(testResult)
|
|
28
|
+
//console.log(testResult.describeResults[0].itResults)
|
|
29
|
+
//console.log(testResult.describeResults[0].itResultsSummary)
|
|
30
|
+
|
|
31
|
+
await testResult.should.include.keys(['file', 'success', 'describeResults', 'describeResultsSummary']);
|
|
32
|
+
(await chaiExpect(testResult.success)).to.be.null; //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
|
+
await mochaIt('should return sensible results from a test file with describes without any its/tests', async function () {
|
|
38
|
+
//const config = applyConfigDefaults({})
|
|
39
|
+
const sampleTestFile = 'unitTesting/sampletests/describesWithoutTests.test.js';
|
|
40
|
+
const sampleTest = await loadTestFile(defaultConfig, sampleTestFile);
|
|
41
|
+
const testResult = await runTest(defaultConfig, sampleTest); //console.log(testResult)
|
|
42
|
+
//console.log(testResult.describeResults[0].itResults)
|
|
43
|
+
//console.log(testResult.describeResults[0].itResultsSummary)
|
|
44
|
+
|
|
45
|
+
await testResult.should.include.keys(['file', 'success', 'describeResults', 'describeResultsSummary']);
|
|
46
|
+
(await chaiExpect(testResult.success)).to.be.null;
|
|
47
|
+
await testResult.describeResultsSummary.total.should.equal(0);
|
|
48
|
+
await testResult.describeResultsSummary.passes.should.equal(0);
|
|
49
|
+
await testResult.describeResultsSummary.invalid.should.equal(2);
|
|
50
|
+
await testResult.describeResultsSummary.itsTotal.should.equal(0);
|
|
51
|
+
await testResult.describeResultsSummary.itsPasses.should.equal(0);
|
|
52
|
+
});
|
|
53
|
+
await mochaIt("should run beforeEachFile tasks (before - can't test)", async function () {
|
|
54
|
+
let functionHasRun = false;
|
|
55
|
+
global.beforeEachFileFileHasRun = false;
|
|
56
|
+
const ourConfig = {
|
|
57
|
+
beforeEachFile: [async function () {
|
|
58
|
+
functionHasRun = true;
|
|
59
|
+
}, 'unitTesting/runTest/beforeEachFile.js']
|
|
60
|
+
};
|
|
61
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
62
|
+
await runTest(config, beforeAfterTest);
|
|
63
|
+
await functionHasRun.should.equal(true);
|
|
64
|
+
await global.beforeEachFileFileHasRun.should.equal(true);
|
|
65
|
+
});
|
|
66
|
+
await mochaIt("should run afterEachFile tasks (after - can't test)", async function () {
|
|
67
|
+
let functionHasRun = false;
|
|
68
|
+
global.afterEachFileFileHasRun = false;
|
|
69
|
+
const ourConfig = {
|
|
70
|
+
afterEachFile: [async function () {
|
|
71
|
+
functionHasRun = true;
|
|
72
|
+
}, 'unitTesting/runTest/afterEachFile.js']
|
|
73
|
+
};
|
|
74
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
75
|
+
await runTest(config, beforeAfterTest);
|
|
76
|
+
await functionHasRun.should.equal(true);
|
|
77
|
+
await global.afterEachFileFileHasRun.should.equal(true);
|
|
78
|
+
});
|
|
79
|
+
await mochaIt("should run beforeEachDescribe tasks (before - can't test) each describe block", async function () {
|
|
80
|
+
let functionHasRunTimes = 0;
|
|
81
|
+
global.beforeEachDescribeFileHasRun = false;
|
|
82
|
+
const ourConfig = {
|
|
83
|
+
beforeEachDescribe: [async function () {
|
|
84
|
+
functionHasRunTimes++;
|
|
85
|
+
}, 'unitTesting/runTest/beforeEachDescribe.js']
|
|
86
|
+
};
|
|
87
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
88
|
+
await runTest(config, beforeAfterTest);
|
|
89
|
+
await functionHasRunTimes.should.equal(2);
|
|
90
|
+
await global.beforeEachDescribeFileHasRun.should.equal(true);
|
|
91
|
+
});
|
|
92
|
+
await mochaIt("should run afterEachDescribe tasks (after - can't test) each describe block", async function () {
|
|
93
|
+
let functionHasRunTimes = 0;
|
|
94
|
+
global.afterEachDescribeFileHasRun = false;
|
|
95
|
+
const ourConfig = {
|
|
96
|
+
afterEachDescribe: [async function () {
|
|
97
|
+
functionHasRunTimes++;
|
|
98
|
+
}, 'unitTesting/runTest/afterEachDescribe.js']
|
|
99
|
+
};
|
|
100
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
101
|
+
await runTest(config, beforeAfterTest);
|
|
102
|
+
await functionHasRunTimes.should.equal(2);
|
|
103
|
+
await global.afterEachDescribeFileHasRun.should.equal(true);
|
|
104
|
+
});
|
|
105
|
+
await mochaIt("should run beforeEachTest tasks (before - can't test) each test/it block", async function () {
|
|
106
|
+
let functionHasRunTimes = 0;
|
|
107
|
+
global.beforeEachTestbeforeEachFileFileHasRun = false;
|
|
108
|
+
const ourConfig = {
|
|
109
|
+
beforeEachTest: [async function () {
|
|
110
|
+
functionHasRunTimes++;
|
|
111
|
+
}, 'unitTesting/runTest/beforeEachTest.js']
|
|
112
|
+
};
|
|
113
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
114
|
+
await runTest(config, beforeAfterTest);
|
|
115
|
+
await functionHasRunTimes.should.equal(3);
|
|
116
|
+
await global.beforeEachTestFileHasRun.should.equal(true);
|
|
117
|
+
});
|
|
118
|
+
await mochaIt("should run afterEachTest tasks (after - can't test) each test/it block", async function () {
|
|
119
|
+
let functionHasRunTimes = 0;
|
|
120
|
+
global.afterEachTestFileFileHasRun = false;
|
|
121
|
+
const ourConfig = {
|
|
122
|
+
afterEachTest: [async function () {
|
|
123
|
+
functionHasRunTimes++;
|
|
124
|
+
}, 'unitTesting/runTest/afterEachTest.js']
|
|
125
|
+
};
|
|
126
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
127
|
+
await runTest(config, beforeAfterTest);
|
|
128
|
+
await functionHasRunTimes.should.equal(3);
|
|
129
|
+
await global.afterEachTestFileHasRun.should.equal(true);
|
|
130
|
+
}); // exports provision to test file
|
|
131
|
+
// current beforeEachFile exports aren't provided
|
|
132
|
+
// perhaps extend sxy-loader to allow this
|
|
133
|
+
|
|
134
|
+
await mochaIt("should pass exported/returned data from beforeEachDescribe tasks", async function () {
|
|
135
|
+
const testFile = 'unitTesting/runTest/beforeEachDescribe.test.js';
|
|
136
|
+
const test = await loadTestFile(defaultConfig, testFile);
|
|
137
|
+
const ourConfig = {
|
|
138
|
+
beforeEachDescribe: [async function () {
|
|
139
|
+
return {
|
|
140
|
+
functionThing: 'foo'
|
|
141
|
+
};
|
|
142
|
+
}, 'unitTesting/runTest/beforeEachDescribeExport.js']
|
|
143
|
+
};
|
|
144
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
145
|
+
await runTest(config, test);
|
|
146
|
+
await global.functionThing.should.equal('foo');
|
|
147
|
+
await global.fileThing.should.equal('bar');
|
|
148
|
+
});
|
|
149
|
+
await mochaIt("should pass exported/returned data from beforeEachTest tasks", async function () {
|
|
150
|
+
const testFile = 'unitTesting/runTest/beforeEachTest.test.js';
|
|
151
|
+
const test = await loadTestFile(defaultConfig, testFile);
|
|
152
|
+
const ourConfig = {
|
|
153
|
+
beforeEachTest: [async function () {
|
|
154
|
+
return {
|
|
155
|
+
functionThing: 'foo'
|
|
156
|
+
};
|
|
157
|
+
}, 'unitTesting/runTest/beforeEachTestExport.js']
|
|
158
|
+
};
|
|
159
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
160
|
+
await runTest(config, test);
|
|
161
|
+
await global.functionThing.should.equal('foo');
|
|
162
|
+
await global.fileThing.should.equal('bar');
|
|
163
|
+
}); // exports pass through
|
|
164
|
+
|
|
165
|
+
await mochaIt("beforeEachFile exports are passed through to afterEachFile", async function () {
|
|
166
|
+
// don't try to reload test, fails due to module caching
|
|
167
|
+
//const testFile = 'unitTesting/runTest/beforeAfter.test.js'
|
|
168
|
+
//const test = loadTestFile(defaultConfig, testFile)
|
|
169
|
+
let exports;
|
|
170
|
+
const ourConfig = {
|
|
171
|
+
beforeEachFile: [async function () {
|
|
172
|
+
return {
|
|
173
|
+
functionThing: 'foo'
|
|
174
|
+
};
|
|
175
|
+
}, 'unitTesting/runTest/beforeEachExport.js'],
|
|
176
|
+
afterEachFile: [async function (theExports) {
|
|
177
|
+
await theExports.should.have.keys(['functionThing', 'fileThing']);
|
|
178
|
+
exports = theExports;
|
|
179
|
+
}]
|
|
180
|
+
};
|
|
181
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
182
|
+
await runTest(config, beforeAfterTest);
|
|
183
|
+
await exports.functionThing.should.equal('foo');
|
|
184
|
+
await exports.fileThing.should.equal('bar');
|
|
185
|
+
});
|
|
186
|
+
await mochaIt("beforeEachDescribe exports are passed through to afterEachDescribe", async function () {
|
|
187
|
+
// don't try to reload test, fails due to module caching
|
|
188
|
+
//const testFile = 'unitTesting/runTest/beforeAfter.test.js'
|
|
189
|
+
//const test = loadTestFile(defaultConfig, testFile)
|
|
190
|
+
let exports;
|
|
191
|
+
const ourConfig = {
|
|
192
|
+
beforeEachDescribe: [async function () {
|
|
193
|
+
return {
|
|
194
|
+
functionThing: 'foo'
|
|
195
|
+
};
|
|
196
|
+
}, 'unitTesting/runTest/beforeEachExport.js'],
|
|
197
|
+
afterEachDescribe: [async function (theExports) {
|
|
198
|
+
exports = theExports;
|
|
199
|
+
}]
|
|
200
|
+
};
|
|
201
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
202
|
+
await runTest(config, beforeAfterTest); //console.log('exports', exports)
|
|
203
|
+
|
|
204
|
+
await exports.functionThing.should.equal('foo');
|
|
205
|
+
await exports.fileThing.should.equal('bar');
|
|
206
|
+
});
|
|
207
|
+
await mochaIt("beforeEachTest exports are passed through to afterEachTest", async function () {
|
|
208
|
+
// don't try to reload test, fails due to module caching
|
|
209
|
+
//const testFile = 'unitTesting/runTest/beforeAfter.test.js'
|
|
210
|
+
//const test = loadTestFile(defaultConfig, testFile)
|
|
211
|
+
let exports;
|
|
212
|
+
const ourConfig = {
|
|
213
|
+
beforeEachTest: [async function () {
|
|
214
|
+
return {
|
|
215
|
+
functionThing: 'foo'
|
|
216
|
+
};
|
|
217
|
+
}, 'unitTesting/runTest/beforeEachExport.js'],
|
|
218
|
+
afterEachTest: [async function (theExports) {
|
|
219
|
+
exports = theExports;
|
|
220
|
+
}]
|
|
221
|
+
};
|
|
222
|
+
const config = await applyConfigDefaults(ourConfig);
|
|
223
|
+
await runTest(config, beforeAfterTest); //console.log('exports', exports)
|
|
224
|
+
|
|
225
|
+
await exports.functionThing.should.equal('foo');
|
|
226
|
+
await exports.fileThing.should.equal('bar');
|
|
227
|
+
});
|
|
228
|
+
await mochaIt("we can run code beforeEachTest and afterEachTest from within the test file", async function () {
|
|
229
|
+
// don't try to reload test, fails due to module caching
|
|
230
|
+
const testFile = 'unitTesting/runTest/internalBeforeAfterEachTest.test.js';
|
|
231
|
+
const test = await loadTestFile(defaultConfig, testFile);
|
|
232
|
+
const config = await applyConfigDefaults({});
|
|
233
|
+
global.internalBeforeEachTestRanNTimes = 0;
|
|
234
|
+
global.internalAfterEachTestRanNTimes = 0;
|
|
235
|
+
await runTest(config, test);
|
|
236
|
+
await global.internalBeforeAfterEachTest_test1Valid.should.equal(true);
|
|
237
|
+
await global.internalBeforeAfterEachTest_test2Valid.should.equal(true);
|
|
238
|
+
await global.internalBeforeAfterEachTest_test3Valid.should.equal(true);
|
|
239
|
+
await global.internalBeforeEachTestRanNTimes.should.equal(3);
|
|
240
|
+
await global.internalAfterEachTestRanNTimes.should.equal(3);
|
|
241
|
+
});
|
|
242
|
+
await mochaIt("we can run code afterDescribe from within descibe in the test file", async function () {
|
|
243
|
+
// don't try to reload test, fails due to module caching
|
|
244
|
+
const testFile = 'unitTesting/runTest/internalAfterDescribeTest.test.js';
|
|
245
|
+
const test = await loadTestFile(defaultConfig, testFile);
|
|
246
|
+
const config = await applyConfigDefaults({});
|
|
247
|
+
global.internalAfterDescribeRanNTimes = 0;
|
|
248
|
+
await runTest(config, test); //global.internalAfterDescribe_test1Valid.should.equal(true)
|
|
249
|
+
//global.internalAfterDescribe_test2Valid.should.equal(true)
|
|
250
|
+
|
|
251
|
+
await global.internalAfterDescribeRanNTimes.should.equal(2);
|
|
252
|
+
});
|
|
253
|
+
await mochaIt('should capture and returns logs from the test when using sequential execution', async function () {
|
|
254
|
+
const config = await applyConfigDefaults({
|
|
255
|
+
execution: {
|
|
256
|
+
files: 'sequential',
|
|
257
|
+
describes: 'sequential',
|
|
258
|
+
tests: 'sequential'
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
const sampleTestFile = 'unitTesting/sampleTests/logging.test.js';
|
|
262
|
+
const sampleTest = await loadTestFile(config, sampleTestFile);
|
|
263
|
+
const testResult = await runTest(config, sampleTest);
|
|
264
|
+
await testResult.describeResults[0].logs.length.should.equal(1);
|
|
265
|
+
await testResult.describeResults[0].itResults[0].logs.length.should.equal(1);
|
|
266
|
+
}); // mochaIt('should not capture logs when not running in sequential mode', function() {
|
|
267
|
+
// throw new Error('to do')
|
|
268
|
+
// })
|
|
269
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
2
|
+
import { showTimeProfiling } from '../../config.js';
|
|
3
|
+
import chalk from 'chalk-extensions';
|
|
4
|
+
import { out as mainOut, log, debug } from '../../output.js';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import figures from 'figures'; //import { testsState } from '../../testsState.js'
|
|
7
|
+
|
|
8
|
+
import 'sxy-standard';
|
|
9
|
+
import { loadTestFile } from './loadTestFile.js';
|
|
10
|
+
import { runTest } from './runTest.js';
|
|
11
|
+
import { showTestLoadingError } from './showTestLoadingError.js';
|
|
12
|
+
import { showTestResult } from './showTestResult.js';
|
|
13
|
+
import { load } from './load.js';
|
|
14
|
+
const {
|
|
15
|
+
timeProfileAsync
|
|
16
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
17
|
+
export async function runTests(config, testFiles, failingTests, customOut = undefined) {
|
|
18
|
+
await debug('runTests failingTests', failingTests);
|
|
19
|
+
const tests = {};
|
|
20
|
+
const testRunPromises = {};
|
|
21
|
+
const erroringTests = {};
|
|
22
|
+
const testRunOutPromises = {}; // exp
|
|
23
|
+
|
|
24
|
+
await timeProfileAsync('run tests', async () => {
|
|
25
|
+
const projectDir = await process.cwd(); ////out(``) // spacer before tests output
|
|
26
|
+
|
|
27
|
+
if (testFiles.length > 0) {
|
|
28
|
+
// clear load cache to allow accesing the new tets
|
|
29
|
+
await load.cache.clear();
|
|
30
|
+
|
|
31
|
+
for (const testFile of testFiles) {
|
|
32
|
+
const test = await loadTestFile(config, testFile);
|
|
33
|
+
|
|
34
|
+
if (test.error) {
|
|
35
|
+
erroringTests[testFile] = test;
|
|
36
|
+
await showTestLoadingError(config, test);
|
|
37
|
+
} else {
|
|
38
|
+
await debug('test', test);
|
|
39
|
+
const testRunPromise = runTest(config, test, customOut);
|
|
40
|
+
testRunPromises[testFile] = testRunPromise;
|
|
41
|
+
testRunOutPromises[testFile] = testRunPromise.then(async testResult => {
|
|
42
|
+
if (testResult.success === true || testResult.success === null) {
|
|
43
|
+
if (await failingTests.includes(testResult.file)) {
|
|
44
|
+
await failingTests.remove(testResult.file);
|
|
45
|
+
}
|
|
46
|
+
} else {
|
|
47
|
+
if (!(await failingTests.includes(testResult.file))) {
|
|
48
|
+
await failingTests.push(testResult.file);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
await showTestResult(config, testResult, customOut);
|
|
53
|
+
}); // wait for the test to complete before proceeding if we are in 'sequential' mode
|
|
54
|
+
|
|
55
|
+
if (config.execution.files === 'sequential') await testRunOutPromises[testFile];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
let runTestResults = {};
|
|
61
|
+
await timeProfileAsync('wait for tests to finish', async () => {
|
|
62
|
+
runTestResults = await Promise.allObj(testRunPromises); // wait for the output to complete
|
|
63
|
+
|
|
64
|
+
await Promise.allObj(testRunOutPromises);
|
|
65
|
+
});
|
|
66
|
+
await timeProfileAsync('show initial test run results', async () => {
|
|
67
|
+
const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts);
|
|
68
|
+
const testsResultsSummary = {
|
|
69
|
+
total: 0,
|
|
70
|
+
passes: 0,
|
|
71
|
+
invalid: 0,
|
|
72
|
+
describesTotal: 0,
|
|
73
|
+
describesPasses: 0,
|
|
74
|
+
describesInvalid: 0,
|
|
75
|
+
itsTotal: 0,
|
|
76
|
+
itsPasses: 0 // itsInvalid: 0 // we don't check whether tests run any asserts (we don't control the assertion lib)
|
|
77
|
+
|
|
78
|
+
}; //console.log('runTestResults', runTestResults)
|
|
79
|
+
|
|
80
|
+
for (const testFile in runTestResults) {
|
|
81
|
+
const runTestResult = runTestResults[testFile]; //console.log('runTestResult', runTestResult)
|
|
82
|
+
|
|
83
|
+
testsResultsSummary.total += +(runTestResult.success !== null);
|
|
84
|
+
testsResultsSummary.passes += +runTestResult.success;
|
|
85
|
+
testsResultsSummary.invalid += +(runTestResult.success === null);
|
|
86
|
+
testsResultsSummary.describesTotal += +runTestResult.describeResultsSummary.total;
|
|
87
|
+
testsResultsSummary.describesPasses += +runTestResult.describeResultsSummary.passes;
|
|
88
|
+
testsResultsSummary.describesInvalid += +runTestResult.describeResultsSummary.invalid;
|
|
89
|
+
testsResultsSummary.itsTotal += +runTestResult.describeResultsSummary.itsTotal;
|
|
90
|
+
testsResultsSummary.itsPasses += +runTestResult.describeResultsSummary.itsPasses; //testsResultsSummary.itsInvalid += +runTestResult.describeResultsSummary.itsInvalid // see comment above, not doing invalid tests
|
|
91
|
+
} //console.log('testsResultsSummary', testsResultsSummary)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
await out(`\n`);
|
|
95
|
+
|
|
96
|
+
if (testsResultsSummary.itsPasses === testsResultsSummary.itsTotal) {
|
|
97
|
+
await out(await chalk.mediumgreen(`${figures.tick}`));
|
|
98
|
+
} else {
|
|
99
|
+
await out(await chalk.mediumred(`${figures.cross}`));
|
|
100
|
+
} // number of tests successful
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
const testsText = `Tests: ${testsResultsSummary.itsPasses}/${testsResultsSummary.itsTotal}`;
|
|
104
|
+
|
|
105
|
+
if (testsResultsSummary.itsPasses === testsResultsSummary.itsTotal) {
|
|
106
|
+
await out(await chalk.mediumgreen(`${testsText}`
|
|
107
|
+
/* ${figures.tick}`*/
|
|
108
|
+
));
|
|
109
|
+
} else {
|
|
110
|
+
await out(await chalk.mediumred(`${testsText}`
|
|
111
|
+
/* ${figures.cross}`*/
|
|
112
|
+
));
|
|
113
|
+
} // number of items successful
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
const describesText = `Items: ${testsResultsSummary.describesPasses}/${testsResultsSummary.describesTotal}`;
|
|
117
|
+
const invalidDescribesText = testsResultsSummary.describesInvalid >= 1 ? testsResultsSummary.describesInvalid === 1 ? await chalk.grey(`(1 describe without tests)`) : await chalk.grey(`(${testsResultsSummary.describesInvalid} describes without tests)`) : '';
|
|
118
|
+
|
|
119
|
+
if (testsResultsSummary.describesPasses === testsResultsSummary.describesTotal) {
|
|
120
|
+
await out((await chalk.mediumgreen(`${describesText}`)) + ' ' + invalidDescribesText);
|
|
121
|
+
} else {
|
|
122
|
+
await out((await chalk.mediumred(`${describesText}`)) + ' ' + invalidDescribesText);
|
|
123
|
+
} // number of test files successful
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
const testFilesText = `Test Files: ${testsResultsSummary.passes}/${testsResultsSummary.total}`;
|
|
127
|
+
const invalidTestFilesText = testsResultsSummary.invalid >= 1 ? testsResultsSummary.invalid === 1 ? await chalk.grey(`(1 file without tests)`) : await chalk.grey(`(${testsResultsSummary.invalid} files without tests)`) : '';
|
|
128
|
+
|
|
129
|
+
if (testsResultsSummary.passes === testsResultsSummary.total) {
|
|
130
|
+
await out((await chalk.mediumgreen(`${testFilesText}`)) + ' ' + invalidTestFilesText);
|
|
131
|
+
} else {
|
|
132
|
+
await out((await chalk.mediumred(`${testFilesText}`)) + ' ' + invalidTestFilesText);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await out(chalk.orange`To do: account for tests with loading errors`); // out(``)
|
|
136
|
+
});
|
|
137
|
+
}
|