sxy-test-runner 1.0.11 → 1.0.13

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.
@@ -1,105 +0,0 @@
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
- import { runDescribe } from './runDescribe.js';
15
- const {
16
- timeProfileAsync
17
- } = await createTimeProfiler(showTimeProfiling);
18
- export async function runTestFile(config, testFile) {
19
- return await timeProfileAsync(`run test file ${testFile.file}`, async () => {
20
- await debug('testFile', testFile); // run before test file
21
-
22
- const fileExports = {};
23
- await configBeforeEachFile(config, fileExports); // const beforeEachFileExports = (config.beforeEachFile)
24
- // ? runTasks(config, config.beforeEachFile)
25
- // : {}
26
- //const describeCounter = 1
27
-
28
- const runDescribePromises = [];
29
-
30
- for (const describe of testFile.describes) {
31
- await runDescribePromises.push(runDescribe(config, describe));
32
- if (config.execution.describes === 'sequential') await runDescribePromises.at(-1);
33
- } //console.log('runDescribePromises', runDescribePromises)
34
-
35
-
36
- const describeResults = await Promise.all(runDescribePromises); //console.log('describeResults', describeResults)
37
-
38
- const describeResultsSummary = {
39
- total: 0,
40
- passes: 0,
41
- errors: 0,
42
- invalid: 0,
43
- itsTotal: 0,
44
- itsPasses: 0
45
- };
46
-
47
- for (const describeResult of describeResults) {
48
- if (describeResult.error === false) {
49
- // no error
50
- describeResultsSummary.total += +(describeResult.success !== null);
51
- describeResultsSummary.passes += +describeResult.success;
52
- describeResultsSummary.invalid += +(describeResult.success === null);
53
- describeResultsSummary.itsTotal += describeResult.itResultsSummary.total;
54
- describeResultsSummary.itsPasses += describeResult.itResultsSummary.passes;
55
- } else {
56
- // error
57
- describeResultsSummary.total += 1;
58
- describeResultsSummary.errors += 1;
59
- }
60
- }
61
-
62
- const testResults = {
63
- file: testFile.file,
64
- success: describeResultsSummary.total > 0 ? describeResultsSummary.total === describeResultsSummary.passes : null,
65
- describeResults,
66
- describeResultsSummary,
67
- consoleLogs: testFile.consoleLogs
68
- }; // run after test
69
-
70
- await configAfterEachFile(config, fileExports);
71
- return testResults;
72
- });
73
- } // function configBeforeEachFile(config, exports) {
74
- // if (config.beforeEachFile) {
75
- // const theExports = runTasks(config.beforeEachFile, undefined)
76
- // addExports(exports, theExports)
77
- // }
78
- // }
79
- // function configAfterEachFile(config, exports) {
80
- // if (config.afterEachFile) {
81
- // runTasks(config.afterEachFile, exports)
82
- // }
83
- // }
84
- // function configBeforeEachDescribe(config, exports) {
85
- // if (config.beforeEachDescribe) {
86
- // const theExports = runTasks(config.beforeEachDescribe, undefined)
87
- // addExports(exports, theExports)
88
- // }
89
- // }
90
- // function configAfterEachDescribe(config, exports) {
91
- // if (config.afterEachDescribe) {
92
- // runTasks(config.afterEachDescribe, exports)
93
- // }
94
- // }
95
- // function configBeforeEachTest(config, exports) {
96
- // if (config.beforeEachTest) {
97
- // const theExports = runTasks(config.beforeEachTest, undefined)
98
- // addExports(exports, theExports)
99
- // }
100
- // }
101
- // function configAfterEachTest(config, exports) {
102
- // if (config.afterEachTest) {
103
- // runTasks(config.afterEachTest, exports)
104
- // }
105
- // }
@@ -1,264 +0,0 @@
1
- import { applyConfigDefaults } from './applyConfigDefaults.js';
2
- import { loadTestFile } from './loadTestFile.js';
3
- import { runTestFile } from './runTestFile.js';
4
- const defaultConfig = await applyConfigDefaults({});
5
- const beforeAfterTestFile = 'unitTesting/runTest/beforeAfter.test.js';
6
- const beforeAfterTest = await loadTestFile(defaultConfig, beforeAfterTestFile);
7
- await mochaDescribe('runTestFile() function', async function () {
8
- await mochaIt('should run a block of tests 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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 runTestFile(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 handle describe blocks that throw errors", async function () {
254
- // don't try to reload test, fails due to module caching
255
- const testFile = 'unitTesting/sampleTests/throwingDescribe.test.js';
256
- const test = await loadTestFile(defaultConfig, testFile);
257
- const config = await applyConfigDefaults({}); //global.internalAfterDescribeRanNTimes = 0
258
-
259
- const testResult = await runTestFile(config, test); //console.log('testResult', testResult)
260
-
261
- testResult.success.should.be.false;
262
- await testResult.describeResultsSummary.errors.should.equal(1); //global.internalAfterDescribeRanNTimes.should.equal(2)
263
- });
264
- });
@@ -1,141 +0,0 @@
1
- // should this be renamed? runTestFile?
2
- import { createTimeProfiler } from 'sxy-dev-tools';
3
- import { showTimeProfiling } from '../../config.js';
4
- import chalk from 'chalk-extensions';
5
- import { out as mainOut, log, debug } from '../../output.js';
6
- import figures from 'figures'; //import { testsState } from '../../testsState.js'
7
-
8
- import 'sxy-standard';
9
- import { loadTestFile } from './loadTestFile.js';
10
- import { runTestFile } from './runTestFile.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 runTestFiles(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 test files', async () => {
25
- //const projectDir = process.cwd()
26
- ////out(``) // spacer before tests output
27
- if (testFiles.length > 0) {
28
- // clear load cache to allow accesing the new tests
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 = runTestFile(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 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
- describesErrors: 0,
75
- describesInvalid: 0,
76
- itsTotal: 0,
77
- itsPasses: 0 // itsInvalid: 0 // we don't check whether tests run any asserts (we don't control the assertion lib)
78
-
79
- }; // add the erroring tests to the total, as they will not be in the test results data
80
-
81
- testsResultsSummary.total += await Object.count(erroringTests); //console.log('runTestResults', runTestResults)
82
-
83
- for (const testFile in runTestResults) {
84
- const runTestResult = runTestResults[testFile];
85
- testsResultsSummary.total += +(runTestResult.success !== null);
86
- testsResultsSummary.passes += +runTestResult.success;
87
- testsResultsSummary.invalid += +(runTestResult.success === null);
88
- testsResultsSummary.describesTotal += +runTestResult.describeResultsSummary.total;
89
- testsResultsSummary.describesPasses += +runTestResult.describeResultsSummary.passes;
90
- testsResultsSummary.describesErrors += +runTestResult.describeResultsSummary.errors;
91
- testsResultsSummary.describesInvalid += +runTestResult.describeResultsSummary.invalid;
92
- testsResultsSummary.itsTotal += +runTestResult.describeResultsSummary.itsTotal;
93
- testsResultsSummary.itsPasses += +runTestResult.describeResultsSummary.itsPasses; //testsResultsSummary.itsInvalid += +runTestResult.describeResultsSummary.itsInvalid // see comment above, not doing invalid tests
94
- } //console.log('testsResultsSummary', testsResultsSummary)
95
-
96
-
97
- await out(`\n`);
98
-
99
- if (testsResultsSummary.passes === testsResultsSummary.total && testsResultsSummary.itsPasses === testsResultsSummary.itsTotal) {
100
- await out(await chalk.mediumgreen(`${figures.tick}`));
101
- } else {
102
- await out(await chalk.mediumred(`${figures.cross}`));
103
- } // number of tests successful
104
-
105
-
106
- const testsText = `Tests: ${testsResultsSummary.itsPasses}/${testsResultsSummary.itsTotal}`;
107
-
108
- if (testsResultsSummary.itsPasses === testsResultsSummary.itsTotal) {
109
- await out(await chalk.mediumgreen(`${testsText}`
110
- /* ${figures.tick}`*/
111
- ));
112
- } else {
113
- await out(await chalk.mediumred(`${testsText}`
114
- /* ${figures.cross}`*/
115
- ));
116
- } // number of items successful
117
-
118
-
119
- const describesText = `Items: ${testsResultsSummary.describesPasses}/${testsResultsSummary.describesTotal}`;
120
- const erroringDescribesText = testsResultsSummary.describesErrors >= 1 ? testsResultsSummary.describesErrors === 1 ? await chalk.grey(` (1 describe threw an exception)`) : await chalk.grey(` (${testsResultsSummary.describesInvalid} describes threw exceptions)`) : '';
121
- const invalidDescribesText = testsResultsSummary.describesInvalid >= 1 ? testsResultsSummary.describesInvalid === 1 ? await chalk.grey(` (1 describe without tests)`) : await chalk.grey(` (${testsResultsSummary.describesInvalid} describes without tests)`) : '';
122
-
123
- if (testsResultsSummary.describesPasses === testsResultsSummary.describesTotal) {
124
- await out((await chalk.mediumgreen(`${describesText}`)) + erroringDescribesText + invalidDescribesText);
125
- } else {
126
- await out((await chalk.mediumred(`${describesText}`)) + erroringDescribesText + invalidDescribesText);
127
- } // number of test files successful
128
-
129
-
130
- const testFilesText = `Test Files: ${testsResultsSummary.passes}/${testsResultsSummary.total}`;
131
- const throwingTestFilesText = (await Object.count(erroringTests)) >= 1 ? (await Object.count(erroringTests)) === 1 ? await chalk.grey(` (1 file threw an exception)`) : await chalk.grey(` (${testsResultsSummary.invalid} files threw exceptions)`) : '';
132
- const invalidTestFilesText = testsResultsSummary.invalid >= 1 ? testsResultsSummary.invalid === 1 ? await chalk.grey(` (1 file without tests)`) : await chalk.grey(` (${testsResultsSummary.invalid} files without tests)`) : '';
133
-
134
- if (testsResultsSummary.passes === testsResultsSummary.total) {
135
- await out((await chalk.mediumgreen(`${testFilesText}`)) + throwingTestFilesText + invalidTestFilesText);
136
- } else {
137
- await out((await chalk.mediumred(`${testFilesText}`)) + throwingTestFilesText + invalidTestFilesText);
138
- } // out(``)
139
-
140
- });
141
- }
@@ -1,147 +0,0 @@
1
- import figures from 'figures';
2
- import { applyConfigDefaults } from './applyConfigDefaults.js';
3
- import { runTestFiles } from './runTestFiles.js'; // runTests(config, testFiles, failingTests)
4
-
5
- await mochaDescribe('runTestFiles() function', async function () {
6
- await mochaIt('should run provided test files and produce an output of results', async function () {
7
- // create a custom out function to capture the output
8
- let outBuffer = '';
9
-
10
- const customOut = (...texts) => {
11
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
12
- };
13
-
14
- const config = await applyConfigDefaults({});
15
- const testFiles = ['unitTesting/sampleTests/1.test.js'];
16
- await runTestFiles(config, testFiles, [], customOut); //console.log(results)
17
- //console.log(outBuffer)
18
-
19
- await outBuffer.should.include('1 should equal 1');
20
- await outBuffer.should.include('Tests: 1/1');
21
- await outBuffer.should.include('Items: 1/1');
22
- await outBuffer.should.include('Test Files: 1/1');
23
- });
24
- await mochaIt('should show test file results and also captured console log output', async function () {
25
- // create a custom out function to capture the output
26
- let outBuffer = '';
27
-
28
- const customOut = (...texts) => {
29
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
30
- };
31
-
32
- const config = await applyConfigDefaults({
33
- execution: {
34
- files: 'sequential',
35
- describes: 'sequential',
36
- tests: 'sequential'
37
- }
38
- });
39
- const testFiles = ['unitTesting/sampleTests/consoleLog.test.js'];
40
- await runTestFiles(config, testFiles, [], customOut); //console.log(results)
41
-
42
- await console.log(outBuffer);
43
- await outBuffer.should.include('1 should equal 1');
44
- await outBuffer.should.include('Tests: 1/1');
45
- await outBuffer.should.include('Items: 1/1');
46
- await outBuffer.should.include('Test Files: 1/1');
47
- await outBuffer.should.include('foo\n');
48
- await outBuffer.should.include('bar\n');
49
- await outBuffer.should.include('baz\n');
50
- await outBuffer.should.include('bim\n');
51
- await outBuffer.should.include('fip\n');
52
- await outBuffer.should.include('fop');
53
- });
54
- /*
55
- mochaIt('should provide a coherent results return object', function() {
56
- // create a custom out function to capture the output
57
- let outBuffer = ''
58
- const customOut = sync((...texts) => {
59
- outBuffer += texts.join(' ') + '\n' // join and save to the buffer
60
- })
61
- const config = applyConfigDefaults({})
62
- const testFiles = [
63
- 'unitTesting/sampleTests/1.test.js'
64
- ]
65
- const results = runTestFiles(config, testFiles, [], customOut)
66
- console.log(results)
67
- })
68
- */
69
-
70
- await mochaIt('should sensibly handle tallies when test files with no describes are included', async function () {
71
- // create a custom out function to capture the output
72
- let outBuffer = '';
73
-
74
- const customOut = (...texts) => {
75
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
76
- };
77
-
78
- const config = await applyConfigDefaults({});
79
- const testFiles = ['unitTesting/sampleTests/1.test.js', 'unitTesting/sampleTests/blank.test.js', 'unitTesting/sampleTests/describesWithoutTests.test.js'];
80
- await runTestFiles(config, testFiles, [], customOut); //console.log(results)
81
- //console.log(outBuffer)
82
-
83
- await outBuffer.should.include('1 should equal 1');
84
- await outBuffer.should.include('Tests: 1/1');
85
- await outBuffer.should.include('Items: 1/1');
86
- await outBuffer.should.include('(2 describes without tests)');
87
- await outBuffer.should.include('Test Files: 1/1');
88
- await outBuffer.should.include('(2 files without tests)');
89
- });
90
- await mochaIt('runs test files sequentially in test mode', async function () {
91
- // create a custom out function to capture the output
92
- let outBuffer = '';
93
-
94
- const customOut = (...texts) => {
95
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
96
- };
97
-
98
- const config = await applyConfigDefaults({
99
- execution: {
100
- files: 'sequential'
101
- }
102
- });
103
- const testFiles = ['unitTesting/runTests/sequential/1.test.js', 'unitTesting/runTests/sequential/2.test.js'];
104
- await runTestFiles(config, testFiles, [], customOut);
105
- global.sequential1Status.should.be.true;
106
- global.sequential2Status.should.be.true;
107
- });
108
- await mochaIt('should display sensible results when a file throws on load', async function () {
109
- // create a custom out function to capture the output
110
- let outBuffer = '';
111
-
112
- const customOut = (...texts) => {
113
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
114
- };
115
-
116
- const config = await applyConfigDefaults({});
117
- const testFiles = ['unitTesting/sampleTests/throwingFile.test.js'];
118
- await runTestFiles(config, testFiles, [], customOut); //console.log(results)
119
- //console.log(outBuffer)
120
-
121
- await outBuffer.should.include(figures.cross);
122
- await outBuffer.should.include('Tests: 0/0');
123
- await outBuffer.should.include('Items: 0/0');
124
- await outBuffer.should.include('Test Files: 0/1');
125
- await outBuffer.should.include('(1 file threw an exception)');
126
- });
127
- await mochaIt('should display sensible results when an exception is thrown during a describe', async function () {
128
- // create a custom out function to capture the output
129
- let outBuffer = '';
130
-
131
- const customOut = (...texts) => {
132
- outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
133
- };
134
-
135
- const config = await applyConfigDefaults({});
136
- const testFiles = ['unitTesting/sampleTests/throwingDescribe.test.js'];
137
- await runTestFiles(config, testFiles, [], customOut); //console.log(results)
138
- //console.log(outBuffer)
139
-
140
- await outBuffer.should.include('Describe error');
141
- await outBuffer.should.include(figures.cross);
142
- await outBuffer.should.include('Tests: 0/0');
143
- await outBuffer.should.include('Items: 0/1');
144
- await outBuffer.should.include('(1 describe threw an exception)');
145
- await outBuffer.should.include('Test Files: 0/1');
146
- });
147
- });