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,59 @@
|
|
|
1
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js';
|
|
2
|
+
import { runTests } from './runTests.js'; // runTests(config, testFiles, failingTests)
|
|
3
|
+
|
|
4
|
+
await mochaDescribe('runTests() function', async function () {
|
|
5
|
+
await mochaIt('should run provided test files and produce an output of results', async function () {
|
|
6
|
+
// create a custom out function to capture the output
|
|
7
|
+
let outBuffer = '';
|
|
8
|
+
|
|
9
|
+
const customOut = (...texts) => {
|
|
10
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const config = await applyConfigDefaults({});
|
|
14
|
+
const testFiles = ['unitTesting/sampleTests/1.test.js'];
|
|
15
|
+
const results = await runTests(config, testFiles, [], customOut); //console.log(results)
|
|
16
|
+
//console.log(outBuffer)
|
|
17
|
+
|
|
18
|
+
await outBuffer.should.include('1 should equal 1');
|
|
19
|
+
await outBuffer.should.include('Tests: 1/1');
|
|
20
|
+
await outBuffer.should.include('Items: 1/1');
|
|
21
|
+
await outBuffer.should.include('Test Files: 1/1');
|
|
22
|
+
});
|
|
23
|
+
await mochaIt('should sensibly handle tallies when test files with no describes are included', async function () {
|
|
24
|
+
// create a custom out function to capture the output
|
|
25
|
+
let outBuffer = '';
|
|
26
|
+
|
|
27
|
+
const customOut = (...texts) => {
|
|
28
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const config = await applyConfigDefaults({});
|
|
32
|
+
const testFiles = ['unitTesting/sampleTests/1.test.js', 'unitTesting/sampleTests/blank.test.js', 'unitTesting/sampleTests/describesWithoutTests.test.js'];
|
|
33
|
+
const results = await runTests(config, testFiles, [], customOut); //console.log(results)
|
|
34
|
+
//console.log(outBuffer)
|
|
35
|
+
|
|
36
|
+
await outBuffer.should.include('1 should equal 1');
|
|
37
|
+
await outBuffer.should.include('Tests: 1/1');
|
|
38
|
+
await outBuffer.should.include('Items: 1/1');
|
|
39
|
+
await outBuffer.should.include('(2 describes without tests)');
|
|
40
|
+
await outBuffer.should.include('Test Files: 1/1');
|
|
41
|
+
await outBuffer.should.include('(2 files without tests)');
|
|
42
|
+
});
|
|
43
|
+
await mochaIt('runs test files sequentially in test mode', async function () {
|
|
44
|
+
// create a custom out function to capture the output
|
|
45
|
+
// let outBuffer = ''
|
|
46
|
+
// const customOut = sync((...texts) => {
|
|
47
|
+
// outBuffer += texts.join(' ') + '\n' // join and save to the buffer
|
|
48
|
+
// })
|
|
49
|
+
const config = await applyConfigDefaults({
|
|
50
|
+
execution: {
|
|
51
|
+
files: 'sequential'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
const testFiles = ['unitTesting/runTests/sequential/1.test.js', 'unitTesting/runTests/sequential/2.test.js'];
|
|
55
|
+
const results = await runTests(config, testFiles, []);
|
|
56
|
+
global.sequential1Status.should.be.true;
|
|
57
|
+
global.sequential2Status.should.be.true;
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
2
|
+
import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js';
|
|
3
|
+
import chalk from 'chalk-extensions';
|
|
4
|
+
import { out as mainOut, log, debug } from '../../output.js';
|
|
5
|
+
import figures from 'figures'; //import { testsState } from '../../testsState.js'
|
|
6
|
+
|
|
7
|
+
import 'sxy-standard/light.js';
|
|
8
|
+
import { indexNumberToLetters } from '../../indexNumberToLetters.js';
|
|
9
|
+
const {
|
|
10
|
+
timeProfileAsync
|
|
11
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
12
|
+
export async function showTestLoadingError(config, test, customOut = undefined) {
|
|
13
|
+
await debug('customOut', customOut);
|
|
14
|
+
const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts); //console.log('testResult', testResult)
|
|
15
|
+
|
|
16
|
+
await timeProfileAsync('show test loading error', () => {
|
|
17
|
+
out();
|
|
18
|
+
out(chalk.grey`File ${test.file}`);
|
|
19
|
+
out(chalk.mediumred`Loading error: ${test.error}`);
|
|
20
|
+
out();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defaultConfig } from './defaultConfig.js';
|
|
2
|
+
import { showTestLoadingError } from './showTestLoadingError.js';
|
|
3
|
+
import { expect } from 'chai'; // showTestLoadingError(config, test) ???
|
|
4
|
+
|
|
5
|
+
await mochaDescribe('showTestLoadingError() function', async function () {
|
|
6
|
+
await mochaIt('should show the loading error of a test after loading failure', async function () {
|
|
7
|
+
const config = defaultConfig;
|
|
8
|
+
const test = {
|
|
9
|
+
file: 'foo.js',
|
|
10
|
+
error: 'There was an error'
|
|
11
|
+
}; // create a custom out function to capture the output
|
|
12
|
+
|
|
13
|
+
let outBuffer = '';
|
|
14
|
+
|
|
15
|
+
const customOut = (...texts) => {
|
|
16
|
+
//console.log('custom out received:', ...texts)
|
|
17
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
18
|
+
//console.log('outBuffer:', outBuffer)
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
await showTestLoadingError(config, test, customOut);
|
|
22
|
+
await console.log(outBuffer);
|
|
23
|
+
await outBuffer.should.include(test.error);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
2
|
+
import { packageName, cliName, configFileName, configLocations, showTimeProfiling } from '../../config.js';
|
|
3
|
+
import chalk from 'chalk-extensions';
|
|
4
|
+
import { out as mainOut, log, debug } from '../../output.js';
|
|
5
|
+
import figures from 'figures'; //import { testsState } from '../../testsState.js'
|
|
6
|
+
|
|
7
|
+
import 'sxy-standard/light.js';
|
|
8
|
+
import { indexNumberToLetters } from '../../indexNumberToLetters.js';
|
|
9
|
+
const {
|
|
10
|
+
timeProfileAsync
|
|
11
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
12
|
+
export async function showTestResult(config, testResult, customOut = undefined) {
|
|
13
|
+
await debug('customOut', customOut);
|
|
14
|
+
const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts); //console.log('testResult', testResult)
|
|
15
|
+
|
|
16
|
+
await timeProfileAsync('show test result', () => {
|
|
17
|
+
out();
|
|
18
|
+
out(chalk.grey`File ${testResult.file}`);
|
|
19
|
+
const indent = ' ';
|
|
20
|
+
|
|
21
|
+
if (testResult.logs.length > 0) {
|
|
22
|
+
out();
|
|
23
|
+
out(indent + chalk.grey`console.logs:`);
|
|
24
|
+
testResult.logs.forEach(async log => {
|
|
25
|
+
log[0] = indent + log[0];
|
|
26
|
+
await out(...log);
|
|
27
|
+
});
|
|
28
|
+
out();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let first = true;
|
|
32
|
+
|
|
33
|
+
for (const describeResult of testResult.describeResults) {
|
|
34
|
+
if (!first) out();
|
|
35
|
+
first = false;
|
|
36
|
+
out(chalk.lightgrey`${describeResult.counter}) describing ` + chalk.brightblue(describeResult.thing));
|
|
37
|
+
out();
|
|
38
|
+
|
|
39
|
+
if (describeResult.logs.length > 0) {
|
|
40
|
+
out(indent + chalk.grey`console.logs:`);
|
|
41
|
+
describeResult.logs.forEach(async log => {
|
|
42
|
+
log[0] = indent + log[0];
|
|
43
|
+
await out(...log);
|
|
44
|
+
});
|
|
45
|
+
out();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (const itResult of describeResult.itResults) {
|
|
49
|
+
//console.log('itResult', itResult)
|
|
50
|
+
const letters = indexNumberToLetters(itResult.counter);
|
|
51
|
+
|
|
52
|
+
if (itResult.success) {
|
|
53
|
+
out(chalk.lightgrey`${indent}${letters})` + chalk.mediumgreen` ${figures.tick} ${itResult.should}`);
|
|
54
|
+
} else {
|
|
55
|
+
out(chalk.lightgrey`${indent}${letters})` + chalk.mediumred` ${figures.cross} ${itResult.should}`);
|
|
56
|
+
out();
|
|
57
|
+
const spacer = `${indent}${' '.repeat(letters.length)} `;
|
|
58
|
+
|
|
59
|
+
if ('actual' in itResult.error && 'expected' in itResult.error) {
|
|
60
|
+
out(chalk.mediumred(`${spacer}${itResult.error.name}: ${itResult.error.message}` //+ `\n${spacer}expected: ${itResult.error.expected}`
|
|
61
|
+
//+ `\n${spacer}received: ${itResult.error.actual}`
|
|
62
|
+
));
|
|
63
|
+
} else {
|
|
64
|
+
out(chalk.mediumred(`${spacer}${itResult.error.name}: ${itResult.error.message}`));
|
|
65
|
+
} // stack trace
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if (config.showErrorTrace) {
|
|
69
|
+
out();
|
|
70
|
+
out(chalk.grey(itResult.error.stack));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
out();
|
|
75
|
+
|
|
76
|
+
if (itResult.logs.length > 0) {
|
|
77
|
+
out(indent + indent + chalk.grey`console.logs:`);
|
|
78
|
+
itResult.logs.forEach(async log => {
|
|
79
|
+
log[0] = indent + indent + log[0];
|
|
80
|
+
await out(...log);
|
|
81
|
+
});
|
|
82
|
+
out();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { defaultConfig } from './defaultConfig.js';
|
|
2
|
+
import { showTestResult } from './showTestResult.js';
|
|
3
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js';
|
|
4
|
+
import { loadTestFile } from './loadTestFile.js';
|
|
5
|
+
import { runTest } from './runTest.js'; // loadTestFile(config, testFile) ???
|
|
6
|
+
|
|
7
|
+
await mochaDescribe('showTestResult() function', async function () {
|
|
8
|
+
await mochaIt('should show the result of a single test that has been run', async function () {
|
|
9
|
+
const config = defaultConfig;
|
|
10
|
+
const sampleTestResult = {
|
|
11
|
+
file: 'unitTesting/sampleTests/1.test.js',
|
|
12
|
+
success: true,
|
|
13
|
+
describeResults: [{
|
|
14
|
+
counter: 1,
|
|
15
|
+
thing: 'Sample test 1',
|
|
16
|
+
success: true,
|
|
17
|
+
itResults: [{
|
|
18
|
+
counter: 1,
|
|
19
|
+
should: '1 should equal 1',
|
|
20
|
+
success: true,
|
|
21
|
+
time: 1,
|
|
22
|
+
error: undefined
|
|
23
|
+
}],
|
|
24
|
+
itResultsSummary: {
|
|
25
|
+
total: 1,
|
|
26
|
+
passes: 1
|
|
27
|
+
}
|
|
28
|
+
}],
|
|
29
|
+
describeResultsSummary: {
|
|
30
|
+
total: 1,
|
|
31
|
+
passes: 1,
|
|
32
|
+
itsTotal: 1,
|
|
33
|
+
itsPasses: 1
|
|
34
|
+
}
|
|
35
|
+
}; // create a custom out function to capture the output
|
|
36
|
+
|
|
37
|
+
let outBuffer = '';
|
|
38
|
+
|
|
39
|
+
const customOut = (...texts) => {
|
|
40
|
+
//console.log('custom out received:', ...texts)
|
|
41
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
42
|
+
//console.log('outBuffer:', outBuffer)
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
await showTestResult(config, sampleTestResult, customOut); //console.log(outBuffer)
|
|
46
|
+
|
|
47
|
+
await outBuffer.should.include(sampleTestResult.file); //console.log('---', sampleTestResult.describeResults[0].thing)
|
|
48
|
+
|
|
49
|
+
await outBuffer.should.include(sampleTestResult.describeResults[0].thing);
|
|
50
|
+
await outBuffer.should.include(sampleTestResult.describeResults[0].itResults[0].should);
|
|
51
|
+
});
|
|
52
|
+
await mochaIt('should show the result of a test with an error', async function () {
|
|
53
|
+
const config = defaultConfig;
|
|
54
|
+
let error;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
await (await chaiExpect(1)).to.equal(2);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
error = e;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const sampleTestResult = {
|
|
63
|
+
file: 'unitTesting/sampleTests/1.test.js',
|
|
64
|
+
success: true,
|
|
65
|
+
describeResults: [{
|
|
66
|
+
counter: 1,
|
|
67
|
+
thing: 'Sample test 1',
|
|
68
|
+
success: true,
|
|
69
|
+
itResults: [{
|
|
70
|
+
counter: 1,
|
|
71
|
+
should: '1 should equal 2',
|
|
72
|
+
success: false,
|
|
73
|
+
error
|
|
74
|
+
}],
|
|
75
|
+
itResultsSummary: {
|
|
76
|
+
total: 1,
|
|
77
|
+
passes: 1
|
|
78
|
+
}
|
|
79
|
+
}],
|
|
80
|
+
describeResultsSummary: {
|
|
81
|
+
total: 1,
|
|
82
|
+
passes: 1,
|
|
83
|
+
itsTotal: 1,
|
|
84
|
+
itsPasses: 1
|
|
85
|
+
}
|
|
86
|
+
}; // create a custom out function to capture the output
|
|
87
|
+
|
|
88
|
+
let outBuffer = '';
|
|
89
|
+
|
|
90
|
+
const customOut = (...texts) => {
|
|
91
|
+
//console.log('custom out received:', ...texts)
|
|
92
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
93
|
+
//console.log('outBuffer:', outBuffer)
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
await showTestResult(config, sampleTestResult, customOut); //console.log(outBuffer)
|
|
97
|
+
|
|
98
|
+
await outBuffer.should.include('AssertionError');
|
|
99
|
+
await outBuffer.should.include('expected 1 to equal 2');
|
|
100
|
+
});
|
|
101
|
+
await mochaIt('shows test results including captured log output', async function () {
|
|
102
|
+
const config = defaultConfig;
|
|
103
|
+
const sampleTestResult = {
|
|
104
|
+
file: 'unitTesting/sampleTests/1.test.js',
|
|
105
|
+
success: true,
|
|
106
|
+
describeResults: [{
|
|
107
|
+
counter: 1,
|
|
108
|
+
thing: 'Sample test 1',
|
|
109
|
+
success: true,
|
|
110
|
+
logs: [['foo']],
|
|
111
|
+
itResults: [{
|
|
112
|
+
counter: 1,
|
|
113
|
+
should: '1 should equal 1',
|
|
114
|
+
success: true,
|
|
115
|
+
time: 1,
|
|
116
|
+
error: undefined,
|
|
117
|
+
logs: [['bar']]
|
|
118
|
+
}],
|
|
119
|
+
itResultsSummary: {
|
|
120
|
+
total: 1,
|
|
121
|
+
passes: 1
|
|
122
|
+
}
|
|
123
|
+
}],
|
|
124
|
+
describeResultsSummary: {
|
|
125
|
+
total: 1,
|
|
126
|
+
passes: 1,
|
|
127
|
+
itsTotal: 1,
|
|
128
|
+
itsPasses: 1
|
|
129
|
+
}
|
|
130
|
+
}; // create a custom out function to capture the output
|
|
131
|
+
|
|
132
|
+
let outBuffer = '';
|
|
133
|
+
|
|
134
|
+
const customOut = (...texts) => {
|
|
135
|
+
//console.log('custom out received:', ...texts)
|
|
136
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
137
|
+
//console.log('outBuffer:', outBuffer)
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
await showTestResult(config, sampleTestResult, customOut); //console.log(outBuffer)
|
|
141
|
+
|
|
142
|
+
await outBuffer.should.include(sampleTestResult.file); //console.log('---', sampleTestResult.describeResults[0].thing)
|
|
143
|
+
|
|
144
|
+
await outBuffer.should.include(sampleTestResult.describeResults[0].thing);
|
|
145
|
+
await outBuffer.should.include('foo');
|
|
146
|
+
await outBuffer.should.include(sampleTestResult.describeResults[0].itResults[0].should);
|
|
147
|
+
await outBuffer.should.include('bar');
|
|
148
|
+
});
|
|
149
|
+
await mochaIt('shows test results including captured log output with a complex file', async function () {
|
|
150
|
+
const config = await applyConfigDefaults({
|
|
151
|
+
execution: {
|
|
152
|
+
files: 'sequential',
|
|
153
|
+
describes: 'sequential',
|
|
154
|
+
tests: 'sequential'
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
const sampleTestFile = 'unitTesting/sampleTests/logging.test.js';
|
|
158
|
+
const sampleTest = await loadTestFile(config, sampleTestFile);
|
|
159
|
+
const testResult = await runTest(config, sampleTest); // create a custom out function to capture the output
|
|
160
|
+
|
|
161
|
+
let outBuffer = '';
|
|
162
|
+
|
|
163
|
+
const customOut = (...texts) => {
|
|
164
|
+
//console.log('custom out received:', ...texts)
|
|
165
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
166
|
+
//console.log('outBuffer:', outBuffer)
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
await showTestResult(config, testResult, customOut);
|
|
170
|
+
await console.log(outBuffer);
|
|
171
|
+
await outBuffer.should.include(testResult.file); //console.log('---', sampleTestResult.describeResults[0].thing)
|
|
172
|
+
|
|
173
|
+
await outBuffer.should.include(testResult.describeResults[0].thing);
|
|
174
|
+
await outBuffer.should.include(testResult.describeResults[0].itResults[0].should);
|
|
175
|
+
await outBuffer.should.include('1st test log');
|
|
176
|
+
await outBuffer.should.include('3rd test log');
|
|
177
|
+
await outBuffer.should.include('4th test log');
|
|
178
|
+
await outBuffer.should.include('6th test log');
|
|
179
|
+
});
|
|
180
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { out as mainOut, log, debug } from '../../output.js';
|
|
2
|
+
export async function validateConfig(config, customOut = undefined) {
|
|
3
|
+
const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts);
|
|
4
|
+
|
|
5
|
+
if (config.execution === undefined) {
|
|
6
|
+
const message = `Config error, config.execution is not defined`;
|
|
7
|
+
await doError(message);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (config.execution.files !== 'parallel' && config.execution.files !== 'sequential') {
|
|
11
|
+
const message = `Config error, config.execution.files should be 'parallel' or 'sequential'`;
|
|
12
|
+
await doError(message);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (config.execution.describes !== 'parallel' && config.execution.describes !== 'sequential') {
|
|
16
|
+
const message = `Config error, config.execution.describes should be 'parallel' or 'sequential'`;
|
|
17
|
+
await doError(message);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (config.execution.tests !== 'parallel' && config.execution.tests !== 'sequential') {
|
|
21
|
+
const message = `Config error, config.execution.tests should be 'parallel' or 'sequential'`;
|
|
22
|
+
await doError(message);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function doError(message) {
|
|
26
|
+
await out(message);
|
|
27
|
+
throw new Error(message);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js';
|
|
2
|
+
import { validateConfig } from './validateConfig.js'; // loadTestFile(config, testFile) ???
|
|
3
|
+
|
|
4
|
+
import { makeCustomOut } from '../../../unitTesting/makeCustomOut.js';
|
|
5
|
+
await mochaDescribe('validateConfig() function', async function () {
|
|
6
|
+
await mochaIt('complains if execution values are not valid', async function () {
|
|
7
|
+
const customOut = await makeCustomOut();
|
|
8
|
+
const config = await applyConfigDefaults({
|
|
9
|
+
execution: {
|
|
10
|
+
files: 'typo'
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
await validateConfig(config, customOut);
|
|
16
|
+
} catch (e) {} // eslint-disable-line
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
await (await customOut.getOutBuffer()).should.include('Config error');
|
|
20
|
+
await (await customOut.getOutBuffer()).should.include('execution.files');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { watchFilesChokidar as watchFiles } from './watchFilesChokidar.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { watchFiles } from './watchFiles.js';
|
|
3
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, callback)
|
|
4
|
+
|
|
5
|
+
await mochaDescribe('watchFiles() function', async function () {
|
|
6
|
+
await mochaIt('should call back when when a file change occurs', async function () {
|
|
7
|
+
await this.timeout(10000);
|
|
8
|
+
const config = await applyConfigDefaults({});
|
|
9
|
+
let eventComplete = false;
|
|
10
|
+
await watchFiles(config, async (filename, event) => {
|
|
11
|
+
eventComplete = true;
|
|
12
|
+
});
|
|
13
|
+
await fs.writeFile('temp/watchFiles-file.js', 'abc');
|
|
14
|
+
await new Promise(async (resolve, reject) => {
|
|
15
|
+
const interval = await setInterval(async () => {
|
|
16
|
+
if (eventComplete) {
|
|
17
|
+
await clearInterval(interval);
|
|
18
|
+
await resolve();
|
|
19
|
+
}
|
|
20
|
+
}, 50);
|
|
21
|
+
});
|
|
22
|
+
await eventComplete.should.equal(true);
|
|
23
|
+
});
|
|
24
|
+
await mochaIt('should call back when when a file change occurs in specified folder', async function () {
|
|
25
|
+
await this.timeout(10000);
|
|
26
|
+
const tempFolder = 'temp/watchFiles';
|
|
27
|
+
const config = await applyConfigDefaults({
|
|
28
|
+
watch: {
|
|
29
|
+
watchFilesBase: tempFolder,
|
|
30
|
+
watchFiles: '**/*.js'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
let eventComplete = false;
|
|
34
|
+
await watchFiles(config, async (filename, event) => {
|
|
35
|
+
eventComplete = true;
|
|
36
|
+
});
|
|
37
|
+
await fs.writeFile(`${tempFolder}/a-file.js`, 'abc');
|
|
38
|
+
await new Promise(async (resolve, reject) => {
|
|
39
|
+
const interval = await setInterval(async () => {
|
|
40
|
+
if (eventComplete) {
|
|
41
|
+
await clearInterval(interval);
|
|
42
|
+
await resolve();
|
|
43
|
+
}
|
|
44
|
+
}, 50);
|
|
45
|
+
});
|
|
46
|
+
await eventComplete.should.equal(true);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { promises as fs, existsSync } from 'fs';
|
|
2
|
+
import figures from 'figures';
|
|
3
|
+
import { watchFilesAndRunTests } from './watchFilesAndRunTests.js';
|
|
4
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, testFiles, dependencyTrees, failingTests)
|
|
5
|
+
|
|
6
|
+
await mochaDescribe('watchFilesAndRunTests() function', async function () {
|
|
7
|
+
const tempFolder = 'temp/watchFilesAndRunTests';
|
|
8
|
+
const baseConfig = await applyConfigDefaults({
|
|
9
|
+
testsBase: tempFolder,
|
|
10
|
+
tests: '**/*.test.js',
|
|
11
|
+
watch: {
|
|
12
|
+
watchFilesBase: tempFolder,
|
|
13
|
+
watchFiles: '**/*.js'
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
await mochaIt('should run a test when a test file is changed', async function () {
|
|
17
|
+
//this.timeout(100000)
|
|
18
|
+
const config = await Object.copy(baseConfig); // create a custom out function to capture the output
|
|
19
|
+
|
|
20
|
+
let outBuffer = '';
|
|
21
|
+
|
|
22
|
+
const customOut = (...texts) => {
|
|
23
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
watchFilesAndRunTests(config, [], {}, [], customOut); //console.log('outBuffer', outBuffer)
|
|
27
|
+
|
|
28
|
+
await outBuffer.should.equal('');
|
|
29
|
+
const testFileName = `${tempFolder}/a.test.js`;
|
|
30
|
+
const thing = 'Sample test 1';
|
|
31
|
+
const should = '1 should equal 1';
|
|
32
|
+
await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
|
|
33
|
+
import { expect, should } from 'chai'
|
|
34
|
+
should()
|
|
35
|
+
|
|
36
|
+
describe('${thing}', ({it}) => {
|
|
37
|
+
|
|
38
|
+
it('${should}', () => {
|
|
39
|
+
expect(1).to.equal(1)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
})`);
|
|
43
|
+
await new Promise(async (resolve, reject) => await setTimeout(resolve, 1000));
|
|
44
|
+
await outBuffer.should.include(testFileName);
|
|
45
|
+
await outBuffer.should.include(thing);
|
|
46
|
+
await outBuffer.should.include(should);
|
|
47
|
+
await outBuffer.should.include(figures.tick);
|
|
48
|
+
});
|
|
49
|
+
await mochaIt('should run a test when a new test file is changed', async function () {
|
|
50
|
+
const config = await Object.copy(baseConfig); // create a custom out function to capture the output
|
|
51
|
+
|
|
52
|
+
let outBuffer = '';
|
|
53
|
+
|
|
54
|
+
const customOut = (...texts) => {
|
|
55
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const testFileName = `${tempFolder}/b.test.js`;
|
|
59
|
+
const thing = 'Sample test 2';
|
|
60
|
+
const should = '2 should equal 2';
|
|
61
|
+
|
|
62
|
+
if (await existsSync(testFileName)) {
|
|
63
|
+
await fs.unlink(testFileName);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
await (await existsSync(testFileName)).should.equal(false);
|
|
67
|
+
await watchFilesAndRunTests(config, [], {}, [], customOut);
|
|
68
|
+
await outBuffer.should.equal('');
|
|
69
|
+
await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
|
|
70
|
+
import { expect, should } from 'chai'
|
|
71
|
+
should()
|
|
72
|
+
|
|
73
|
+
describe('${thing}', ({it}) => {
|
|
74
|
+
|
|
75
|
+
it('${should}', () => {
|
|
76
|
+
expect(2).to.equal(2)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
})`);
|
|
80
|
+
await new Promise(async (resolve, reject) => await setTimeout(resolve, 1000));
|
|
81
|
+
await outBuffer.should.include(testFileName);
|
|
82
|
+
await outBuffer.should.include(thing);
|
|
83
|
+
await outBuffer.should.include(should);
|
|
84
|
+
await outBuffer.should.include(figures.tick);
|
|
85
|
+
});
|
|
86
|
+
await mochaIt('removes a test from tests and dependencyTrees when it is deleted', async function () {
|
|
87
|
+
//this.timeout(100000)
|
|
88
|
+
const config = await Object.copy(baseConfig); // create a custom out function to capture the output
|
|
89
|
+
|
|
90
|
+
let outBuffer = '';
|
|
91
|
+
|
|
92
|
+
const customOut = (...texts) => {
|
|
93
|
+
outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const testFileName = `${tempFolder}/c.test.js`;
|
|
97
|
+
const thing = 'Sample test 3';
|
|
98
|
+
const should = '3 should equal 3';
|
|
99
|
+
|
|
100
|
+
if (!(await existsSync(testFileName))) {
|
|
101
|
+
await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
|
|
102
|
+
import { expect, should } from 'chai'
|
|
103
|
+
should()
|
|
104
|
+
|
|
105
|
+
describe('${thing}', ({it}) => {
|
|
106
|
+
|
|
107
|
+
it('${should}', () => {
|
|
108
|
+
expect(3).to.equal(3)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
})`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
(await existsSync(testFileName)).should.be.true;
|
|
115
|
+
const originalTests = [testFileName];
|
|
116
|
+
const originalDependencyTrees = {
|
|
117
|
+
[testFileName]: ['dep-1.js', 'dep-2.js']
|
|
118
|
+
};
|
|
119
|
+
const tests = await Object.copy(originalTests);
|
|
120
|
+
const dependencyTrees = await Object.copy(originalDependencyTrees);
|
|
121
|
+
await tests.should.include.members([testFileName]);
|
|
122
|
+
await dependencyTrees.should.include.keys([testFileName]);
|
|
123
|
+
await watchFilesAndRunTests(config, tests, dependencyTrees, [], customOut);
|
|
124
|
+
await fs.unlink(testFileName);
|
|
125
|
+
await new Promise(async (resolve, reject) => await setTimeout(resolve, 1000));
|
|
126
|
+
await tests.should.not.include.members([testFileName]);
|
|
127
|
+
await dependencyTrees.should.not.include.keys([testFileName]);
|
|
128
|
+
});
|
|
129
|
+
});
|