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,85 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { watchFilesChokidar } from './watchFilesChokidar.js';
|
|
3
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, testFiles, dependencyTrees, failingTests) ???
|
|
4
|
+
|
|
5
|
+
await mochaDescribe('watchFilesChokidar() function', async function () {
|
|
6
|
+
await mochaIt('should call back when when a file change occurs', async function () {
|
|
7
|
+
await this.timeout(12000);
|
|
8
|
+
const config = await applyConfigDefaults({});
|
|
9
|
+
let eventComplete = false;
|
|
10
|
+
await watchFilesChokidar(config, async (filename, event) => {
|
|
11
|
+
eventComplete = true;
|
|
12
|
+
});
|
|
13
|
+
await fs.writeFile('temp/watchFilesChokidar-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(12000);
|
|
26
|
+
const config = await applyConfigDefaults({
|
|
27
|
+
watch: {
|
|
28
|
+
watchFilesBase: 'temp/watchFilesChokidar',
|
|
29
|
+
watchFiles: '**/*.js'
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
let eventComplete = false;
|
|
33
|
+
await watchFilesChokidar(config, async (filename, event) => {
|
|
34
|
+
eventComplete = true;
|
|
35
|
+
});
|
|
36
|
+
await fs.writeFile('temp/watchFilesChokidar/a-file.js', 'abc');
|
|
37
|
+
await new Promise(async (resolve, reject) => {
|
|
38
|
+
const interval = await setInterval(async () => {
|
|
39
|
+
if (eventComplete) {
|
|
40
|
+
await clearInterval(interval);
|
|
41
|
+
await resolve();
|
|
42
|
+
}
|
|
43
|
+
}, 50);
|
|
44
|
+
});
|
|
45
|
+
await eventComplete.should.equal(true);
|
|
46
|
+
});
|
|
47
|
+
await mochaIt('ignores a file based on ignore glob', async function () {
|
|
48
|
+
await this.timeout(12000);
|
|
49
|
+
const config = await applyConfigDefaults({
|
|
50
|
+
watch: {
|
|
51
|
+
watchFilesBase: 'temp/watchFilesChokidar',
|
|
52
|
+
watchFiles: '**/*.js',
|
|
53
|
+
watchFilesIgnore: 'ignore-file.js'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
let eventComplete = false;
|
|
57
|
+
await watchFilesChokidar(config, async (filename, event) => {
|
|
58
|
+
eventComplete = true;
|
|
59
|
+
});
|
|
60
|
+
await fs.writeFile('temp/watchFilesChokidar/ignore-file.js', 'abc');
|
|
61
|
+
await new Promise(async (resolve, reject) => {
|
|
62
|
+
await setTimeout(resolve, 1000);
|
|
63
|
+
});
|
|
64
|
+
await eventComplete.should.not.equal(true);
|
|
65
|
+
});
|
|
66
|
+
await mochaIt('ignores a file based on ignore globs array', async function () {
|
|
67
|
+
//this.timeout(100000)
|
|
68
|
+
const config = await applyConfigDefaults({
|
|
69
|
+
watch: {
|
|
70
|
+
watchFilesBase: 'temp/watchFilesChokidar',
|
|
71
|
+
watchFiles: '**/*.js',
|
|
72
|
+
watchFilesIgnore: ['first-ignore-file.js', 'ignore-file.js']
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
let eventComplete = false;
|
|
76
|
+
await watchFilesChokidar(config, async (filename, event) => {
|
|
77
|
+
eventComplete = true;
|
|
78
|
+
});
|
|
79
|
+
await fs.writeFile('temp/watchFilesChokidar/ignore-file.js', 'abc');
|
|
80
|
+
await new Promise(async (resolve, reject) => {
|
|
81
|
+
await setTimeout(resolve, 1000);
|
|
82
|
+
});
|
|
83
|
+
await eventComplete.should.not.equal(true);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
2
|
+
import { showTimeProfiling } from '../../config.js';
|
|
3
|
+
import chalk from 'chalk-extensions';
|
|
4
|
+
import minimatch from 'minimatch';
|
|
5
|
+
import slash from 'slash';
|
|
6
|
+
import watch from 'node-watch'; //import chokidar from 'chokidar'
|
|
7
|
+
//import nsfw from 'nsfw'
|
|
8
|
+
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import { out, log, debug } from '../../output.js';
|
|
11
|
+
import { globArgCombine } from './globArgCombine.js';
|
|
12
|
+
const {
|
|
13
|
+
timeProfileAsync
|
|
14
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
15
|
+
export async function watchFilesNodeWatch(config, onEvent) {
|
|
16
|
+
await timeProfileAsync('start watching', async () => {
|
|
17
|
+
//const testGlobs = addBaseToGlobs(config.testsBase, config.tests)
|
|
18
|
+
//const ignoreGlobs = addBaseToGlobs(config.testsBase, config.testsIgnore)
|
|
19
|
+
// indentify a test file
|
|
20
|
+
// identify a file we should be watching and responding to
|
|
21
|
+
const watchFilter = file => (!config.watch.watchFiles || minimatch(file, globArgCombine(config.watch.watchFiles))) && (!config.watch.watchFilesIgnore || !minimatch(file, globArgCombine(config.watch.watchFilesIgnore)));
|
|
22
|
+
|
|
23
|
+
if (!config.watch.watchFilesBase) {
|
|
24
|
+
await out(`No config.watch.watchFilesBase provided, defaulting to '.'`);
|
|
25
|
+
config.watch.watchFilesBase = '.';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const watcher = await watch(config.watch.watchFilesBase, {
|
|
29
|
+
recursive: true,
|
|
30
|
+
filter: watchFilter
|
|
31
|
+
}, async function (event, filename) {
|
|
32
|
+
filename = await slash(filename);
|
|
33
|
+
await debug('watch event');
|
|
34
|
+
await onEvent(filename, event);
|
|
35
|
+
}); // wait until the watcher is ready
|
|
36
|
+
|
|
37
|
+
await new Promise(async (resolve, reject) => {
|
|
38
|
+
await watcher.on('ready', resolve);
|
|
39
|
+
});
|
|
40
|
+
return watcher;
|
|
41
|
+
}); //return new Promise( () => {} ) // infinite promise to let us watch
|
|
42
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { watchFilesNodeWatch } from './watchFilesNodeWatch.js';
|
|
3
|
+
import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, callback)
|
|
4
|
+
|
|
5
|
+
await mochaDescribe('watchFilesNodeWatch() function', async function () {
|
|
6
|
+
await mochaIt('should call back when when a file change occurs', async function () {
|
|
7
|
+
//this.timeout(100000)
|
|
8
|
+
const config = await applyConfigDefaults({});
|
|
9
|
+
let eventComplete = false;
|
|
10
|
+
await watchFilesNodeWatch(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
|
+
//this.timeout(100000)
|
|
26
|
+
const tempFolder = 'temp/watchFilesNodeWatcher';
|
|
27
|
+
const config = await applyConfigDefaults({
|
|
28
|
+
watch: {
|
|
29
|
+
watchFilesBase: tempFolder,
|
|
30
|
+
watchFiles: '**/*.js'
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
let eventComplete = false;
|
|
34
|
+
await watchFilesNodeWatch(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
|
+
});
|
package/dist/cli/once.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
2
|
+
import chalk from 'chalk-extensions';
|
|
3
|
+
import { packageName, configFileName, configLocations, showTimeProfiling } from '../config.js';
|
|
4
|
+
import { out, log, debug } from '../output.js';
|
|
5
|
+
const {
|
|
6
|
+
timeProfileAsync
|
|
7
|
+
} = await createTimeProfiler(showTimeProfiling);
|
|
8
|
+
export async function once() {
|
|
9
|
+
await out(chalk.brightblue`[${packageName}]...`);
|
|
10
|
+
const startTime = await new Date().getTime();
|
|
11
|
+
const {
|
|
12
|
+
loadConfig
|
|
13
|
+
} = await import('./lib/loadConfig.js'); //// async function
|
|
14
|
+
|
|
15
|
+
const userConfig = await loadConfig();
|
|
16
|
+
const {
|
|
17
|
+
applyConfigDefaults
|
|
18
|
+
} = await import('./lib/applyConfigDefaults.js'); //// sync function
|
|
19
|
+
|
|
20
|
+
const config = await applyConfigDefaults(userConfig);
|
|
21
|
+
await log(chalk.brightblue`finding tests...`);
|
|
22
|
+
const {
|
|
23
|
+
findTestFiles
|
|
24
|
+
} = await import('./lib/findTestFiles.js'); //// async function
|
|
25
|
+
|
|
26
|
+
const testFiles = await findTestFiles(config);
|
|
27
|
+
|
|
28
|
+
if (testFiles.length === 0) {
|
|
29
|
+
await out(await chalk.orange(`[${packageName}] Found no tests.` + `\nTests patterns [${await config.tests.join(', ')}].` + `\nCreate tests matching the patterns, ` + `\nor set new patterns in ${configFileName}.* { tests: }`));
|
|
30
|
+
const endTime = await new Date().getTime();
|
|
31
|
+
const time = endTime - startTime;
|
|
32
|
+
await out(await chalk.brightblue(`[${packageName}] time: ${await time.toLocaleString()}ms`));
|
|
33
|
+
await process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const {
|
|
37
|
+
runTests
|
|
38
|
+
} = await import('./lib/runTests.js');
|
|
39
|
+
|
|
40
|
+
if (testFiles.length > 0) {
|
|
41
|
+
await log(chalk.brightblue`running tests...`);
|
|
42
|
+
await runTests(config, testFiles, []); //// async function, run in thread
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const time = (await new Date().getTime()) - startTime;
|
|
46
|
+
await out(chalk.grey`\n${await time.toLocaleString()}ms\n`);
|
|
47
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
import figures from 'figures'
|
|
3
|
+
|
|
4
|
+
import { once } from './once.js'
|
|
5
|
+
|
|
6
|
+
mochaDescribe('once command', function() {
|
|
7
|
+
|
|
8
|
+
mochaIt('should run tests and output results', async function() {
|
|
9
|
+
this.timeout(12000)
|
|
10
|
+
|
|
11
|
+
const originalConsoleLog = console.log
|
|
12
|
+
let consoleLogBuffer = ''
|
|
13
|
+
console.log = sync(function testLog(...texts) {
|
|
14
|
+
consoleLogBuffer += texts.join(' ') + '\n'
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
global.commandLineArguments = []
|
|
18
|
+
|
|
19
|
+
promise( once() )
|
|
20
|
+
await new Promise( (resolve, reject) => { setTimeout(resolve, 8000) } )
|
|
21
|
+
|
|
22
|
+
console.log = originalConsoleLog
|
|
23
|
+
|
|
24
|
+
console.log(consoleLogBuffer)
|
|
25
|
+
|
|
26
|
+
const testFileName = `trialTests/example.test.js`
|
|
27
|
+
const thing = 'The example'
|
|
28
|
+
const should = '1 should equal 1'
|
|
29
|
+
|
|
30
|
+
consoleLogBuffer.should.include( testFileName )
|
|
31
|
+
consoleLogBuffer.should.include( thing )
|
|
32
|
+
consoleLogBuffer.should.include( should )
|
|
33
|
+
consoleLogBuffer.should.include( figures.tick )
|
|
34
|
+
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
*/
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createTimeProfiler } from 'sxy-dev-tools'
|
|
2
|
+
import chalk from 'chalk-extensions'
|
|
3
|
+
import { packageName, showTimeProfiling } from '../config.js'
|
|
4
|
+
import { out, log, debug } from '../output.js'
|
|
5
|
+
const {
|
|
6
|
+
timeProfileAsync
|
|
7
|
+
} = await createTimeProfiler(showTimeProfiling)
|
|
8
|
+
export async function watch() {
|
|
9
|
+
await out(chalk.brightblue`[${packageName}]...`)
|
|
10
|
+
const {
|
|
11
|
+
parseCommandLineArguments
|
|
12
|
+
} = await import('./lib/parseCommandLineArguments.js') //// async function
|
|
13
|
+
|
|
14
|
+
const allowedClArguments = {
|
|
15
|
+
'config': {
|
|
16
|
+
flag: 'c',
|
|
17
|
+
hasValue: true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const clArguments = await parseCommandLineArguments(allowedClArguments)
|
|
21
|
+
await debug('clArguments', clArguments)
|
|
22
|
+
const {
|
|
23
|
+
loadConfig
|
|
24
|
+
} = await import('./lib/loadConfig.js') //// async function
|
|
25
|
+
|
|
26
|
+
const userConfig = 'config' in clArguments ? await loadConfig(clArguments.config) : await loadConfig()
|
|
27
|
+
const {
|
|
28
|
+
applyConfigDefaults
|
|
29
|
+
} = await import('./lib/applyConfigDefaults.js') //// sync function
|
|
30
|
+
|
|
31
|
+
const config = await applyConfigDefaults(userConfig)
|
|
32
|
+
const {
|
|
33
|
+
validateConfig
|
|
34
|
+
} = await import('./lib/validateConfig.js') //// sync function
|
|
35
|
+
|
|
36
|
+
await validateConfig(config)
|
|
37
|
+
const {
|
|
38
|
+
doUserSetup
|
|
39
|
+
} = await import('./lib/doUserSetup.js')
|
|
40
|
+
await doUserSetup(config)
|
|
41
|
+
await out(chalk.brightblue`finding tests...`)
|
|
42
|
+
const {
|
|
43
|
+
findTestFiles
|
|
44
|
+
} = await import('./lib/findTestFiles.js') //// async function
|
|
45
|
+
|
|
46
|
+
const testFiles = await findTestFiles(config)
|
|
47
|
+
await debug(testFiles) // global store of the dependencies of tests
|
|
48
|
+
|
|
49
|
+
let dependencyTrees = {} // store failing tests so we can re-run them.
|
|
50
|
+
|
|
51
|
+
const failingTests = []
|
|
52
|
+
|
|
53
|
+
if (testFiles.length > 0) {
|
|
54
|
+
const {
|
|
55
|
+
buildDependencyTrees
|
|
56
|
+
} = await import('./lib/buildDependencyTrees.js')
|
|
57
|
+
await out(chalk.brightblue`finding initial dependency trees...`)
|
|
58
|
+
dependencyTrees = await buildDependencyTrees(config, testFiles) //// sync function
|
|
59
|
+
|
|
60
|
+
if (config.watch.runAllOnStartup) {
|
|
61
|
+
const {
|
|
62
|
+
runTests
|
|
63
|
+
} = await import('./lib/runTests.js')
|
|
64
|
+
await out(chalk.brightblue`running initial tests...`)
|
|
65
|
+
runTests(config, testFiles, failingTests).then(async () => {
|
|
66
|
+
await out(chalk.brightblue`watching...`)
|
|
67
|
+
}) //// async function, run in separate thread
|
|
68
|
+
}
|
|
69
|
+
} else {
|
|
70
|
+
await out(chalk.brightblue`no tests founds`)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const {
|
|
74
|
+
watchFilesAndRunTests
|
|
75
|
+
} = await import('./lib/watchFilesAndRunTests.js')
|
|
76
|
+
await watchFilesAndRunTests(config, testFiles, dependencyTrees, failingTests) //// async function run in thread
|
|
77
|
+
|
|
78
|
+
await new Promise(async () => {}) // won't run because promise will never finish
|
|
79
|
+
|
|
80
|
+
const {
|
|
81
|
+
doUserTeardown
|
|
82
|
+
} = await import('./lib/doUserTeardown.js')
|
|
83
|
+
await doUserTeardown(config) /////// SET UP?
|
|
84
|
+
// if ( typeof config.setup === 'function' ) {
|
|
85
|
+
// await timeProfile('run setup function', config.setup(/* can we pass anything here? */))
|
|
86
|
+
// }
|
|
87
|
+
} // runInitialTests
|
|
88
|
+
//--find tests
|
|
89
|
+
//if found tests,
|
|
90
|
+
// find dependencyTrees
|
|
91
|
+
// also, run tests
|
|
92
|
+
//else
|
|
93
|
+
// warn
|
|
94
|
+
// dn't run initial tests
|
|
95
|
+
// do we need to find initial test? yes
|
|
96
|
+
// find tests
|
|
97
|
+
// if found tests
|
|
98
|
+
// make dep trees
|
|
99
|
+
// else
|
|
100
|
+
// warn
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import figures from 'figures';
|
|
2
|
+
import { applyConfigDefaults } from './lib/applyConfigDefaults.js';
|
|
3
|
+
import { watch } from './watch.js';
|
|
4
|
+
await mochaDescribe('watch command', async function () {
|
|
5
|
+
await mochaIt('should run tests and output results and display correct tallies', async function () {
|
|
6
|
+
await this.timeout(10000);
|
|
7
|
+
const originalConsoleLog = console.log;
|
|
8
|
+
let consoleLogBuffer = '';
|
|
9
|
+
|
|
10
|
+
console.log = function testLog(...texts) {
|
|
11
|
+
consoleLogBuffer += texts.join(' ') + '\n';
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
global.commandLineArguments = ['--config', 'unitTesting/watch/sxy-test-runner.config.js'];
|
|
15
|
+
watch();
|
|
16
|
+
await new Promise(async (resolve, reject) => {
|
|
17
|
+
await setTimeout(resolve, 8000);
|
|
18
|
+
});
|
|
19
|
+
console.log = originalConsoleLog; //console.log(consoleLogBuffer)
|
|
20
|
+
|
|
21
|
+
const testFileName = `unitTesting/watch/1.test.js`;
|
|
22
|
+
const thing = 'Sample test 1';
|
|
23
|
+
const should = '1 should equal 1';
|
|
24
|
+
await consoleLogBuffer.should.include(testFileName);
|
|
25
|
+
await consoleLogBuffer.should.include(thing);
|
|
26
|
+
await consoleLogBuffer.should.include(should);
|
|
27
|
+
await consoleLogBuffer.should.include(figures.tick);
|
|
28
|
+
await consoleLogBuffer.should.include('Tests: 3/3');
|
|
29
|
+
await consoleLogBuffer.should.include('Items: 2/2');
|
|
30
|
+
await consoleLogBuffer.should.include('Test Files: 2/2');
|
|
31
|
+
});
|
|
32
|
+
await mochaIt('should run tests and display correct tallies', async function () {
|
|
33
|
+
await this.timeout(10000);
|
|
34
|
+
const originalConsoleLog = console.log;
|
|
35
|
+
let consoleLogBuffer = '';
|
|
36
|
+
|
|
37
|
+
console.log = function testLog(...texts) {
|
|
38
|
+
consoleLogBuffer += texts.join(' ') + '\n';
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
global.commandLineArguments = ['--config', 'unitTesting/watch/sxy-test-runner.config.js'];
|
|
42
|
+
watch();
|
|
43
|
+
await new Promise(async (resolve, reject) => {
|
|
44
|
+
await setTimeout(resolve, 8000);
|
|
45
|
+
});
|
|
46
|
+
console.log = originalConsoleLog; //console.log(consoleLogBuffer)
|
|
47
|
+
|
|
48
|
+
const testFileName = `unitTesting/watch/1.test.js`;
|
|
49
|
+
const thing = 'Sample test 1';
|
|
50
|
+
const should = '1 should equal 1';
|
|
51
|
+
await consoleLogBuffer.should.include(testFileName);
|
|
52
|
+
await consoleLogBuffer.should.include(thing);
|
|
53
|
+
await consoleLogBuffer.should.include(should);
|
|
54
|
+
await consoleLogBuffer.should.include(figures.tick);
|
|
55
|
+
});
|
|
56
|
+
await mochaIt('should warn us when there are no tests', async function () {
|
|
57
|
+
await this.timeout(6000);
|
|
58
|
+
const originalConsoleLog = console.log;
|
|
59
|
+
let consoleLogBuffer = '';
|
|
60
|
+
|
|
61
|
+
console.log = function testLog(...texts) {
|
|
62
|
+
consoleLogBuffer += texts.join(' ') + '\n';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
global.commandLineArguments = ['--config', 'sxy-test-runner.no-tests.config.js'];
|
|
66
|
+
watch();
|
|
67
|
+
await new Promise(async (resolve, reject) => {
|
|
68
|
+
await setTimeout(resolve, 4000);
|
|
69
|
+
});
|
|
70
|
+
console.log = originalConsoleLog; //console.log('saved console.log output:')
|
|
71
|
+
//console.log(consoleLogBuffer)
|
|
72
|
+
|
|
73
|
+
await consoleLogBuffer.should.include('no tests found');
|
|
74
|
+
await consoleLogBuffer.should.not.include('describing');
|
|
75
|
+
});
|
|
76
|
+
await mochaIt('should not run tests when asked not to run initial tests', async function () {
|
|
77
|
+
await this.timeout(6000);
|
|
78
|
+
const originalConsoleLog = console.log;
|
|
79
|
+
let consoleLogBuffer = '';
|
|
80
|
+
|
|
81
|
+
console.log = function testLog(...texts) {
|
|
82
|
+
consoleLogBuffer += texts.join(' ') + '\n';
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
global.commandLineArguments = ['--config', 'sxy-test-runner.no-initial-tests.config.js'];
|
|
86
|
+
watch();
|
|
87
|
+
await new Promise(async (resolve, reject) => {
|
|
88
|
+
await setTimeout(resolve, 4000);
|
|
89
|
+
});
|
|
90
|
+
console.log = originalConsoleLog; //console.log('saved console.log output:')
|
|
91
|
+
//console.log(consoleLogBuffer)
|
|
92
|
+
|
|
93
|
+
await consoleLogBuffer.should.not.include('no tests found');
|
|
94
|
+
await consoleLogBuffer.should.not.include('describing');
|
|
95
|
+
await consoleLogBuffer.should.include('watching');
|
|
96
|
+
});
|
|
97
|
+
await mochaIt('setup function and setup file from the config should have run', async function () {
|
|
98
|
+
await this.timeout(6000);
|
|
99
|
+
global.configBasedSetupFunctionRan = false;
|
|
100
|
+
global.watchSetupFileHasRun = false;
|
|
101
|
+
const originalConsoleLog = console.log;
|
|
102
|
+
let consoleLogBuffer = '';
|
|
103
|
+
|
|
104
|
+
console.log = function testLog(...texts) {
|
|
105
|
+
consoleLogBuffer += texts.join(' ') + '\n';
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
global.commandLineArguments = ['--config', 'sxy-test-runner.setup-tasks.config.js'];
|
|
109
|
+
watch();
|
|
110
|
+
await new Promise(async (resolve, reject) => {
|
|
111
|
+
await setTimeout(resolve, 2000);
|
|
112
|
+
});
|
|
113
|
+
console.log = originalConsoleLog;
|
|
114
|
+
await global.configBasedSetupFunctionRan.should.equal(true);
|
|
115
|
+
await global.watchSetupFileHasRun.should.equal(true);
|
|
116
|
+
});
|
|
117
|
+
});
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const packageName = 'sxy-test-runner';
|
|
2
|
+
export const cliName = 'sxy-test';
|
|
3
|
+
export const configFileName = 'sxy-test-runner.config';
|
|
4
|
+
export const configLocations = ['', 'config']; // locations where the configs may be placed in proj folder
|
|
5
|
+
|
|
6
|
+
export const debugging = false;
|
|
7
|
+
export const showTimeProfiling = false;
|