sxy-test-runner 1.0.13 → 1.0.15

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.
Files changed (78) hide show
  1. package/dist/cli/index.js +2 -6
  2. package/dist/cli/init.js +19 -14
  3. package/dist/cli/lib/addBasePath.js +0 -1
  4. package/dist/cli/lib/addBasePath.unitTest.js +3 -1
  5. package/dist/cli/lib/addExports.unitTest.js +4 -1
  6. package/dist/cli/lib/applyConfigDefaults.js +12 -7
  7. package/dist/cli/lib/applyConfigDefaults.unitTest.js +9 -3
  8. package/dist/cli/lib/buildDependencyTree.js +10 -5
  9. package/dist/cli/lib/buildDependencyTree.unitTest.js +3 -1
  10. package/dist/cli/lib/buildDependencyTrees.js +6 -4
  11. package/dist/cli/lib/buildDependencyTrees.unitTest.js +3 -1
  12. package/dist/cli/lib/defaultConfig.test.js +3 -1
  13. package/dist/cli/lib/doUserSetup.js +0 -3
  14. package/dist/cli/lib/doUserSetup.unitTest.js +3 -1
  15. package/dist/cli/lib/doUserTeardown.js +0 -3
  16. package/dist/cli/lib/doUserTeardown.unitTest.js +3 -1
  17. package/dist/cli/lib/findTestFiles.unitTest.js +3 -1
  18. package/dist/cli/lib/getAllowedFlags.js +0 -2
  19. package/dist/cli/lib/getAllowedFlags.unitTest.js +3 -1
  20. package/dist/cli/lib/injectProperties.js +2 -2
  21. package/dist/cli/lib/injectProperties.unitTest.js +9 -2
  22. package/dist/cli/lib/loadConfig.js +2 -2
  23. package/dist/cli/lib/loadConfig.unitTest.js +3 -2
  24. package/dist/cli/lib/loadTestFile.js +17 -15
  25. package/dist/cli/lib/loadTestFile.unitTest.js +8 -3
  26. package/dist/cli/lib/loadTestFileStatic.js +1 -0
  27. package/dist/cli/lib/loadTestFileStatic.unitTest.js +1 -0
  28. package/dist/cli/lib/parseCommandLineArguments.js +1 -9
  29. package/dist/cli/lib/parseCommandLineArguments.unitTest.js +6 -2
  30. package/dist/cli/lib/parseDescribe.js +12 -18
  31. package/dist/cli/lib/parseDescribe.unitTest.js +6 -2
  32. package/dist/cli/lib/processWatchEvent.unitTest.js +9 -1
  33. package/dist/cli/lib/reservedExportKeys.unitTest.js +3 -1
  34. package/dist/cli/lib/runDescribe.js +4 -7
  35. package/dist/cli/lib/runDescribe.old.js +19 -25
  36. package/dist/cli/lib/runDescribe.unitTest.js +120 -2
  37. package/dist/cli/lib/runDescribeRun.js +3 -7
  38. package/dist/cli/lib/runDescribeRun.unitTest.js +125 -4
  39. package/dist/cli/lib/runIt.js +16 -18
  40. package/dist/cli/lib/runIt.unitTest.js +124 -4
  41. package/dist/cli/lib/runTasks.js +2 -7
  42. package/dist/cli/lib/runTasks.unitTest.js +3 -1
  43. package/dist/cli/lib/runTest-old.js +1 -0
  44. package/dist/cli/lib/runTest-old.unitTest.js +1 -0
  45. package/dist/cli/lib/runTest.js +15 -12
  46. package/dist/cli/lib/runTest.unitTest.js +38 -11
  47. package/dist/cli/lib/runTests.js +36 -35
  48. package/dist/cli/lib/runTests.unitTest.js +15 -8
  49. package/dist/cli/lib/showTestLoadingError.js +6 -6
  50. package/dist/cli/lib/showTestLoadingError.unitTest.js +5 -3
  51. package/dist/cli/lib/showTestResult.js +10 -16
  52. package/dist/cli/lib/showTestResult.unitTest.js +26 -17
  53. package/dist/cli/lib/validateConfig.js +0 -5
  54. package/dist/cli/lib/validateConfig.unitTest.js +2 -3
  55. package/dist/cli/lib/watchFiles.unitTest.js +5 -3
  56. package/dist/cli/lib/watchFilesAndRunTests.js +3 -1
  57. package/dist/cli/lib/watchFilesAndRunTests.unitTest.js +18 -15
  58. package/dist/cli/lib/watchFilesAndRunTestsChokidar.js +22 -29
  59. package/dist/cli/lib/watchFilesAndRunTestsChokidar.unitTest.js +19 -17
  60. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.js +28 -31
  61. package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.unitTest.js +21 -16
  62. package/dist/cli/lib/watchFilesChokidar.js +15 -11
  63. package/dist/cli/lib/watchFilesChokidar.unitTest.js +11 -8
  64. package/dist/cli/lib/watchFilesNodeWatch.js +9 -6
  65. package/dist/cli/lib/watchFilesNodeWatch.unitTest.js +6 -3
  66. package/dist/cli/once.js +0 -6
  67. package/dist/cli/watch.js +18 -14
  68. package/dist/cli/watch.unitTest.js +16 -16
  69. package/dist/describe-old.js +35 -20
  70. package/dist/describe-old.unitTest.js +10 -1
  71. package/dist/describe.js +8 -3
  72. package/dist/describe.unitTest.js +5 -2
  73. package/dist/indexNumberToLetters.js +1 -3
  74. package/dist/output.js +7 -0
  75. package/dist/testsState.js +2 -1
  76. package/package.json +14 -7
  77. package/readme.md +1 -1
  78. package/sxy-loader.config.js +10 -10
@@ -1,10 +1,13 @@
1
1
  import { promises as fs, existsSync } from 'fs';
2
2
  import figures from 'figures';
3
+ import objectCopy from 'sxy-lib-object-copy';
3
4
  import { watchFilesAndRunTests } from './watchFilesAndRunTests.js';
4
- import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
6
+
7
+ // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
8
 
6
9
  await mochaDescribe('watchFilesAndRunTests() function', async function () {
7
- const tempFolder = 'temp/watchFilesAndRunTests';
10
+ const tempFolder = 'watchTests/watchFilesAndRunTests';
8
11
  const baseConfig = await applyConfigDefaults({
9
12
  testsBase: tempFolder,
10
13
  tests: '**/*.test.js',
@@ -15,15 +18,18 @@ await mochaDescribe('watchFilesAndRunTests() function', async function () {
15
18
  });
16
19
  await mochaIt('should run a test when a test file is changed', async function () {
17
20
  //this.timeout(100000)
18
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
19
21
 
20
- let outBuffer = '';
22
+ const config = await objectCopy(baseConfig);
21
23
 
24
+ // create a custom out function to capture the output
25
+ let outBuffer = '';
22
26
  const customOut = (...texts) => {
23
27
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
24
28
  };
25
29
 
26
- watchFilesAndRunTests(config, [], {}, [], customOut); //console.log('outBuffer', outBuffer)
30
+ watchFilesAndRunTests(config, [], {}, [], customOut);
31
+
32
+ //console.log('outBuffer', outBuffer)
27
33
 
28
34
  await outBuffer.should.equal('');
29
35
  const testFileName = `${tempFolder}/a.test.js`;
@@ -47,10 +53,10 @@ describe('${thing}', ({it}) => {
47
53
  await outBuffer.should.include(figures.tick);
48
54
  });
49
55
  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
56
+ const config = await objectCopy(baseConfig);
51
57
 
58
+ // create a custom out function to capture the output
52
59
  let outBuffer = '';
53
-
54
60
  const customOut = (...texts) => {
55
61
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
56
62
  };
@@ -58,11 +64,9 @@ describe('${thing}', ({it}) => {
58
64
  const testFileName = `${tempFolder}/b.test.js`;
59
65
  const thing = 'Sample test 2';
60
66
  const should = '2 should equal 2';
61
-
62
67
  if (await existsSync(testFileName)) {
63
68
  await fs.unlink(testFileName);
64
69
  }
65
-
66
70
  await (await existsSync(testFileName)).should.equal(false);
67
71
  await watchFilesAndRunTests(config, [], {}, [], customOut);
68
72
  await outBuffer.should.equal('');
@@ -85,10 +89,11 @@ describe('${thing}', ({it}) => {
85
89
  });
86
90
  await mochaIt('removes a test from tests and dependencyTrees when it is deleted', async function () {
87
91
  //this.timeout(100000)
88
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
89
92
 
90
- let outBuffer = '';
93
+ const config = await objectCopy(baseConfig);
91
94
 
95
+ // create a custom out function to capture the output
96
+ let outBuffer = '';
92
97
  const customOut = (...texts) => {
93
98
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
94
99
  };
@@ -96,7 +101,6 @@ describe('${thing}', ({it}) => {
96
101
  const testFileName = `${tempFolder}/c.test.js`;
97
102
  const thing = 'Sample test 3';
98
103
  const should = '3 should equal 3';
99
-
100
104
  if (!(await existsSync(testFileName))) {
101
105
  await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
102
106
  import { expect, should } from 'chai'
@@ -110,14 +114,13 @@ describe('${thing}', ({it}) => {
110
114
 
111
115
  })`);
112
116
  }
113
-
114
117
  (await existsSync(testFileName)).should.be.true;
115
118
  const originalTests = [testFileName];
116
119
  const originalDependencyTrees = {
117
120
  [testFileName]: ['dep-1.js', 'dep-2.js']
118
121
  };
119
- const tests = await Object.copy(originalTests);
120
- const dependencyTrees = await Object.copy(originalDependencyTrees);
122
+ const tests = await objectCopy(originalTests);
123
+ const dependencyTrees = await objectCopy(originalDependencyTrees);
121
124
  await tests.should.include.members([testFileName]);
122
125
  await dependencyTrees.should.include.keys([testFileName]);
123
126
  await watchFilesAndRunTests(config, tests, dependencyTrees, [], customOut);
@@ -3,9 +3,9 @@ import { showTimeProfiling } from '../../config.js';
3
3
  import chalk from 'chalk-extensions';
4
4
  import minimatch from 'minimatch';
5
5
  import slash from 'slash';
6
- import watch from 'node-watch'; //import chokidar from 'chokidar'
6
+ import watch from 'node-watch';
7
+ //import chokidar from 'chokidar'
7
8
  //import nsfw from 'nsfw'
8
-
9
9
  import fs from 'fs';
10
10
  import { out, log, debug } from '../../output.js';
11
11
  import { runTests } from './runTests.js';
@@ -21,62 +21,56 @@ export async function watchFilesAndRunTestsChokidar(config, testFiles, dependenc
21
21
  await timeProfileAsync('start watching', async () => {
22
22
  let changedFiles = [];
23
23
  let timeout = null;
24
+ const testFilter = file => minimatch(file, globArgCombine(config.tests)) && (!config.testsIgnore || !minimatch(file, globArgCombine(config.testsIgnore)));
24
25
 
25
- const testFilter = file => minimatch(file, globArgCombine(config.tests)) && (!config.testsIgnore || !minimatch(file, globArgCombine(config.testsIgnore))); // start watching
26
-
27
-
26
+ // start watching
28
27
  await watchFilesChokidar(config, watchEvent);
29
-
30
28
  async function watchEvent(filename, event) {
31
- await debug('chokidar watch event', filename, event); //filename = slash(filename)
32
- // remove dep tree for any tests that are deleted, avoiding trying to run it later
29
+ await debug('chokidar watch event', filename, event);
30
+ //filename = slash(filename)
33
31
 
32
+ // remove dep tree for any tests that are deleted, avoiding trying to run it later
34
33
  if (event === 'remove' && filename in dependencyTrees) {
35
- await testFiles.remove(filename);
34
+ await testFiles.remove(filename); // arrayRemove?
36
35
  delete dependencyTrees[filename];
37
- } // info on the event found
38
-
36
+ }
39
37
 
40
- await out(chalk.grey`change: ${filename} (${event})`); // add the file to changed files
38
+ // info on the event found
39
+ await out(chalk.grey`change: ${filename} (${event})`);
41
40
 
42
- await changedFiles.push([filename, event]); // wait 100ms after any change before processing, to avoid multiple execution?
41
+ // add the file to changed files
42
+ await changedFiles.push([filename, event]);
43
43
 
44
+ // wait 100ms after any change before processing, to avoid multiple execution?
44
45
  if (timeout) {
45
46
  await clearTimeout(timeout);
46
47
  }
47
-
48
48
  timeout = await setTimeout(async () => {
49
49
  await timeProfileAsync('handle changed files', async () => {
50
- await debug('changed files', changedFiles); //out('changed files', changedFiles)
51
-
50
+ await debug('changed files', changedFiles);
51
+ //out('changed files', changedFiles)
52
52
  try {
53
53
  // build related test list
54
54
  const tests = [];
55
-
56
55
  for (const [file, event] of changedFiles) {
57
56
  await debug('check', file);
58
57
  await debug('1 tests', tests);
59
-
60
58
  if (event !== 'remove') {
61
59
  // only check to see if its a test if it exists (has not just been removed)
62
60
  if (await testFilter(file)) {
63
61
  // it is a test file itself, add to run list
64
62
  await debug('its a test', file);
65
63
  await tests.push(file);
66
-
67
64
  if (!(file in dependencyTrees)) {
68
65
  // if its a new test
69
66
  await debug('try to add a new test', file), await addNewTest(file);
70
67
  }
71
68
  }
72
69
  }
73
-
74
70
  await debug('dtrees', dependencyTrees);
75
71
  await debug('2 tests', tests);
76
-
77
72
  for (const f of await Object.getOwnPropertyNames(dependencyTrees)) {
78
73
  await debug('dep tree', f, dependencyTrees[f]);
79
-
80
74
  if (await dependencyTrees[f].some(dep => {
81
75
  debug('checking dep', dep, file);
82
76
  return dep === file;
@@ -88,20 +82,18 @@ export async function watchFilesAndRunTestsChokidar(config, testFiles, dependenc
88
82
  }
89
83
  }
90
84
  }
91
-
92
85
  changedFiles = [];
93
86
  await debug('tests', tests);
94
87
  await debug('3 tests', tests);
95
-
96
88
  if (tests.length) {
97
89
  await timeProfileAsync('run tests related to changes', async () => {
98
90
  await debug('tests', tests);
99
-
100
91
  if (config.reRunFailingTests) {
101
92
  for (const failingTest of failingTests) {
102
93
  if (!(await fs.existsSync(failingTest))) {
103
94
  //debug('remove failing test', failingTest)
104
- await failingTests.remove(failingTest); //(failingTests)
95
+ await failingTests.remove(failingTest); // arrayRemove?
96
+ //(failingTests)
105
97
  }
106
98
  }
107
99
  }
@@ -117,21 +109,22 @@ export async function watchFilesAndRunTestsChokidar(config, testFiles, dependenc
117
109
  passed: 0
118
110
  };
119
111
  await debug('run tests on change');
120
- await debug('toTest', toTest); // clear load cache to allow accesing the new tets
112
+ await debug('toTest', toTest);
121
113
 
114
+ // clear load cache to allow accesing the new tets
122
115
  await load.cache.clear();
123
116
  const testResults = await runTests(config, toTest, failingTests, customOut);
124
117
  });
125
118
  }
126
119
  } catch (e) {
127
120
  await log('watch handler error', e);
128
- } finally {//
121
+ } finally {
122
+ //
129
123
  }
130
124
  });
131
125
  }, 33);
132
126
  } // end of watch event
133
127
 
134
-
135
128
  async function addNewTest(testFile) {
136
129
  await debug('new test', testFile);
137
130
  const dependencyTree = await buildDependencyTree(config, testFile);
@@ -1,10 +1,13 @@
1
1
  import { promises as fs, existsSync } from 'fs';
2
2
  import figures from 'figures';
3
+ import objectCopy from 'sxy-lib-object-copy';
3
4
  import { watchFilesAndRunTestsChokidar } from './watchFilesAndRunTestsChokidar.js';
4
- import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
6
+
7
+ // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
8
 
6
9
  await mochaDescribe('watchFilesAndRunTestsChokidar() function', async function () {
7
- const tempFolder = 'temp/watchFilesAndRunTestsChokidar';
10
+ const tempFolder = 'watchTests/watchFilesAndRunTestsChokidar';
8
11
  const baseConfig = await applyConfigDefaults({
9
12
  testsBase: tempFolder,
10
13
  tests: '**/*.test.js',
@@ -15,17 +18,18 @@ await mochaDescribe('watchFilesAndRunTestsChokidar() function', async function (
15
18
  });
16
19
  await mochaIt('should run a test when a test file is changed', async function () {
17
20
  //this.timeout(100000)
18
- const config = await Object.copy(baseConfig); // ignore the file from the last test, causing load errors
19
21
 
20
- config.testsIgnore = '**/c.test.js'; // create a custom out function to capture the output
22
+ const config = await objectCopy(baseConfig);
23
+ // ignore the file from the last test, causing load errors
24
+ config.testsIgnore = '**/c.test.js';
21
25
 
26
+ // create a custom out function to capture the output
22
27
  let outBuffer = '';
23
-
24
28
  const customOut = (...texts) => {
25
29
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
26
30
  };
27
31
 
28
- const testFileName = 'temp/watchFilesAndRunTestsChokidar/a.test.js';
32
+ const testFileName = 'watchTests/watchFilesAndRunTestsChokidar/a.test.js';
29
33
  const thing = 'Sample test 1';
30
34
  const should = '1 should equal 1';
31
35
  await watchFilesAndRunTestsChokidar(config, [], {}, [], customOut);
@@ -49,12 +53,13 @@ describe('${thing}', ({it}) => {
49
53
  });
50
54
  await mochaIt('should run a test when a new test file is changed', async function () {
51
55
  //this.timeout(100000)
52
- const config = await Object.copy(baseConfig); // ignore the file from the last test, causing load errors
53
56
 
54
- config.testsIgnore = '**/c.test.js'; // create a custom out function to capture the output
57
+ const config = await objectCopy(baseConfig);
58
+ // ignore the file from the last test, causing load errors
59
+ config.testsIgnore = '**/c.test.js';
55
60
 
61
+ // create a custom out function to capture the output
56
62
  let outBuffer = '';
57
-
58
63
  const customOut = (...texts) => {
59
64
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
60
65
  };
@@ -62,11 +67,9 @@ describe('${thing}', ({it}) => {
62
67
  const testFileName = `${tempFolder}/b.test.js`;
63
68
  const thing = 'Sample test 2';
64
69
  const should = '2 should equal 2';
65
-
66
70
  if (await existsSync(testFileName)) {
67
71
  await fs.unlink(testFileName);
68
72
  }
69
-
70
73
  await (await existsSync(testFileName)).should.equal(false);
71
74
  await watchFilesAndRunTestsChokidar(config, [], {}, [], customOut);
72
75
  await outBuffer.should.equal('');
@@ -89,10 +92,11 @@ describe('${thing}', ({it}) => {
89
92
  });
90
93
  await mochaIt('removes a test from tests and dependencyTrees when it is deleted', async function () {
91
94
  //this.timeout(100000)
92
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
93
95
 
94
- let outBuffer = '';
96
+ const config = await objectCopy(baseConfig);
95
97
 
98
+ // create a custom out function to capture the output
99
+ let outBuffer = '';
96
100
  const customOut = (...texts) => {
97
101
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
98
102
  };
@@ -100,7 +104,6 @@ describe('${thing}', ({it}) => {
100
104
  const testFileName = `${tempFolder}/c.test.js`;
101
105
  const thing = 'Sample test 3';
102
106
  const should = '3 should equal 3';
103
-
104
107
  if (!(await existsSync(testFileName))) {
105
108
  await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
106
109
  import { expect, should } from 'chai'
@@ -114,14 +117,13 @@ describe('${thing}', ({it}) => {
114
117
 
115
118
  })`);
116
119
  }
117
-
118
120
  (await existsSync(testFileName)).should.be.true;
119
121
  const originalTests = [testFileName];
120
122
  const originalDependencyTrees = {
121
123
  [testFileName]: ['dep-1.js', 'dep-2.js']
122
124
  };
123
- const tests = await Object.copy(originalTests);
124
- const dependencyTrees = await Object.copy(originalDependencyTrees);
125
+ const tests = await objectCopy(originalTests);
126
+ const dependencyTrees = await objectCopy(originalDependencyTrees);
125
127
  await tests.should.include.members([testFileName]);
126
128
  await dependencyTrees.should.include.keys([testFileName]);
127
129
  await watchFilesAndRunTestsChokidar(config, tests, dependencyTrees, [], customOut);
@@ -2,10 +2,10 @@ import { createTimeProfiler } from 'sxy-dev-tools';
2
2
  import { showTimeProfiling } from '../../config.js';
3
3
  import chalk from 'chalk-extensions';
4
4
  import minimatch from 'minimatch';
5
- import slash from 'slash'; //import watch from 'node-watch'
5
+ import slash from 'slash';
6
+ //import watch from 'node-watch'
6
7
  //import chokidar from 'chokidar'
7
8
  //import nsfw from 'nsfw'
8
-
9
9
  import fs from 'fs';
10
10
  import { out, log, debug } from '../../output.js';
11
11
  import { runTests } from './runTests.js';
@@ -23,81 +23,76 @@ export async function watchFilesAndRunTestsNodeWatch(config, testFiles, dependen
23
23
  await timeProfileAsync('init watching', async () => {
24
24
  await debug('failingTests', failingTests);
25
25
  const testsGlobs = await addBasePath(config.testsBase, config.tests);
26
- const testsIgnoreGlobs = await addBasePath(config.testsBase, config.testsIgnore); // indentify a test file
26
+ const testsIgnoreGlobs = await addBasePath(config.testsBase, config.testsIgnore);
27
27
 
28
- const testFilter = //file => minimatch(file, globArgCombine(config.tests))
28
+ // indentify a test file
29
+ const testFilter =
30
+ //file => minimatch(file, globArgCombine(config.tests))
29
31
  // && ! minimatch(file, globArgCombine(config.testsIgnore))
30
32
  file => {
31
33
  debug('test filter', file, globArgCombine(testsGlobs), globArgCombine(testsIgnoreGlobs), minimatch(file, globArgCombine(testsGlobs)), minimatch(file, globArgCombine(testsIgnoreGlobs)), minimatch(file, globArgCombine(testsGlobs)) && !minimatch(file, globArgCombine(testsIgnoreGlobs)));
32
34
  return minimatch(file, globArgCombine(testsGlobs)) && !minimatch(file, globArgCombine(testsIgnoreGlobs));
33
- }; //log('tests glob', globArgCombine(testsGlobs))
34
- //log('testsIgnore glob', globArgCombine(testsIgnoreGlobs))
35
+ };
35
36
 
37
+ //log('tests glob', globArgCombine(testsGlobs))
38
+ //log('testsIgnore glob', globArgCombine(testsIgnoreGlobs))
36
39
 
37
40
  let changedFiles = [];
38
41
  let timeout = null;
39
-
40
42
  if (!config.watch.watchFilesBase) {
41
43
  await out(`No config.watch.watchFilesBase provided, defaulting to '.'`);
42
44
  config.watch.watchFilesBase = '.';
43
45
  }
44
-
45
46
  watcher = await watchFilesNodeWatch(config, watchEvent);
46
-
47
47
  async function watchEvent(filename, event) {
48
48
  await debug('handle watch event ', filename, event);
49
- filename = await slash(filename); // remove dep tree for any tests that are deleted, avoiding trying to run it later
49
+ filename = await slash(filename);
50
+
51
+ // remove dep tree for any tests that are deleted, avoiding trying to run it later
50
52
 
51
53
  if (event === 'remove') {
52
54
  await debug('removing test', filename);
53
-
54
55
  if (filename in dependencyTrees) {
55
- await testFiles.remove(filename);
56
+ await testFiles.remove(filename); // arrayRemove?
56
57
  delete dependencyTrees[filename];
57
58
  }
58
- } // info on the event found
59
-
59
+ }
60
60
 
61
- await out(chalk.grey`change: ${filename} (${event})`); // add the file to changed files
61
+ // info on the event found
62
+ await out(chalk.grey`change: ${filename} (${event})`);
62
63
 
63
- await changedFiles.push([filename, event]); // wait 100ms after any change before processing, to avoid multiple execution?
64
+ // add the file to changed files
65
+ await changedFiles.push([filename, event]);
64
66
 
67
+ // wait 100ms after any change before processing, to avoid multiple execution?
65
68
  if (timeout) {
66
69
  await clearTimeout(timeout);
67
70
  }
68
-
69
71
  timeout = await setTimeout(async () => {
70
72
  await timeProfileAsync('handle changed files', async () => {
71
73
  await debug('changedFiles', changedFiles);
72
-
73
74
  try {
74
75
  // build related test list
75
76
  const tests = [];
76
-
77
77
  for (const [file, event] of changedFiles) {
78
78
  await debug('check', file);
79
79
  await debug('1 tests', tests);
80
-
81
80
  if (event !== 'remove') {
82
81
  // only check to see if its a test if it exists (has not just been removed)
83
82
  if (await testFilter(file)) {
84
83
  // it is a test file itself, add to run list
85
84
  await debug('its a test', file);
86
85
  await tests.push(file);
87
-
88
86
  if (!(file in dependencyTrees)) {
89
87
  // if its a new test
90
88
  await debug('try to add a new test', file), await addNewTest(file);
91
89
  }
92
90
  }
93
91
  }
94
-
95
92
  await debug('dtrees', dependencyTrees);
96
93
  await debug('2 tests', tests);
97
-
98
94
  for (const f of await Object.getOwnPropertyNames(dependencyTrees)) {
99
95
  await debug('dep tree', f, dependencyTrees[f]);
100
-
101
96
  if (await dependencyTrees[f].some(dep => {
102
97
  debug('checking dep', dep, file);
103
98
  return dep === file;
@@ -109,20 +104,18 @@ export async function watchFilesAndRunTestsNodeWatch(config, testFiles, dependen
109
104
  }
110
105
  }
111
106
  }
112
-
113
107
  changedFiles = [];
114
108
  await debug('tests', tests);
115
109
  await debug('3 tests', tests);
116
-
117
110
  if (tests.length) {
118
111
  await timeProfileAsync('run tests related to changes', async () => {
119
112
  await debug('tests', tests);
120
-
121
113
  if (config.reRunFailingTests) {
122
114
  for (const failingTest of failingTests) {
123
115
  if (!(await fs.existsSync(failingTest))) {
124
116
  //debug('remove failing test', failingTest)
125
- await failingTests.remove(failingTest); //(failingTests)
117
+ await failingTests.remove(failingTest); // arrayRemove?
118
+ //(failingTests)
126
119
  }
127
120
  }
128
121
  }
@@ -138,21 +131,25 @@ export async function watchFilesAndRunTestsNodeWatch(config, testFiles, dependen
138
131
  passed: 0
139
132
  };
140
133
  await debug('run tests on change');
141
- await debug('toTest', toTest); // clear load cache to allow accesing the new test
134
+ await debug('toTest', toTest);
142
135
 
136
+ // clear load cache to allow accesing the new test
143
137
  await load.cache.clear();
144
138
  const testResults = await runTests(config, toTest, failingTests, customOut);
145
139
  });
146
140
  }
147
141
  } catch (e) {
148
142
  await log('watch handler error', e);
149
- } finally {//
143
+ } finally {
144
+ //
150
145
  }
151
146
  });
152
147
  }, 33);
153
148
  }
154
149
  });
155
- await out(chalk.brightblue`watching...`); //return new Promise( () => {} ) // infinite promise to let us watch
150
+ await out(chalk.brightblue`watching...`);
151
+
152
+ //return new Promise( () => {} ) // infinite promise to let us watch
156
153
 
157
154
  async function addNewTest(testFile) {
158
155
  await debug('new test', testFile);
@@ -1,10 +1,13 @@
1
1
  import { promises as fs, existsSync } from 'fs';
2
2
  import figures from 'figures';
3
+ import objectCopy from 'sxy-lib-object-copy';
3
4
  import { watchFilesAndRunTestsNodeWatch } from './watchFilesAndRunTestsNodeWatch.js';
4
- import { applyConfigDefaults } from './applyConfigDefaults.js'; // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
+ import { applyConfigDefaults } from './applyConfigDefaults.js';
6
+
7
+ // watchFiles(config, testFiles, dependencyTrees, failingTests)
5
8
 
6
9
  await mochaDescribe('watchFilesAndRunTestsNodeWatch() function', async function () {
7
- const tempFolder = 'temp/watchFilesAndRunTestsNodeWatch';
10
+ const tempFolder = 'watchTests/watchFilesAndRunTestsNodeWatch';
8
11
  const baseConfig = await applyConfigDefaults({
9
12
  testsBase: tempFolder,
10
13
  tests: '**/*.test.js',
@@ -15,15 +18,18 @@ await mochaDescribe('watchFilesAndRunTestsNodeWatch() function', async function
15
18
  });
16
19
  await mochaIt('should run a test when a test file is changed', async function () {
17
20
  //this.timeout(100000)
18
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
19
21
 
20
- let outBuffer = '';
22
+ const config = await objectCopy(baseConfig);
21
23
 
24
+ // create a custom out function to capture the output
25
+ let outBuffer = '';
22
26
  const customOut = (...texts) => {
23
27
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
24
28
  };
25
29
 
26
- watchFilesAndRunTestsNodeWatch(config, [], {}, [], customOut); //console.log('outBuffer', outBuffer)
30
+ watchFilesAndRunTestsNodeWatch(config, [], {}, [], customOut);
31
+
32
+ //console.log('outBuffer', outBuffer)
27
33
 
28
34
  await outBuffer.should.equal('');
29
35
  const testFileName = `${tempFolder}/a.test.js`;
@@ -48,10 +54,10 @@ describe('${thing}', ({it}) => {
48
54
  await outBuffer.should.include(figures.tick);
49
55
  });
50
56
  await mochaIt('should run a test when a new test file is changed', async function () {
51
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
57
+ const config = await objectCopy(baseConfig);
52
58
 
59
+ // create a custom out function to capture the output
53
60
  let outBuffer = '';
54
-
55
61
  const customOut = (...texts) => {
56
62
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
57
63
  };
@@ -59,11 +65,9 @@ describe('${thing}', ({it}) => {
59
65
  const testFileName = `${tempFolder}/b.test.js`;
60
66
  const thing = 'Sample test 2';
61
67
  const should = '2 should equal 2';
62
-
63
68
  if (await existsSync(testFileName)) {
64
69
  await fs.unlink(testFileName);
65
70
  }
66
-
67
71
  await (await existsSync(testFileName)).should.equal(false);
68
72
  await watchFilesAndRunTestsNodeWatch(config, [], {}, [], customOut);
69
73
  await outBuffer.should.equal('');
@@ -78,7 +82,9 @@ describe('${thing}', ({it}) => {
78
82
  })
79
83
 
80
84
  })`);
81
- await new Promise(async (resolve, reject) => await setTimeout(resolve, 1000)); //console.log('out', outBuffer)
85
+ await new Promise(async (resolve, reject) => await setTimeout(resolve, 1000));
86
+
87
+ //console.log('out', outBuffer)
82
88
 
83
89
  await outBuffer.should.include(testFileName);
84
90
  await outBuffer.should.include(thing);
@@ -87,10 +93,11 @@ describe('${thing}', ({it}) => {
87
93
  });
88
94
  await mochaIt('removes a test from tests and dependencyTrees when it is deleted', async function () {
89
95
  //this.timeout(100000)
90
- const config = await Object.copy(baseConfig); // create a custom out function to capture the output
91
96
 
92
- let outBuffer = '';
97
+ const config = await objectCopy(baseConfig);
93
98
 
99
+ // create a custom out function to capture the output
100
+ let outBuffer = '';
94
101
  const customOut = (...texts) => {
95
102
  outBuffer += texts.join(' ') + '\n'; // join and save to the buffer
96
103
  };
@@ -98,7 +105,6 @@ describe('${thing}', ({it}) => {
98
105
  const testFileName = `${tempFolder}/c.test.js`;
99
106
  const thing = 'Sample test 3';
100
107
  const should = '3 should equal 3';
101
-
102
108
  if (!(await existsSync(testFileName))) {
103
109
  await fs.writeFile(testFileName, `import { describe } from '../../dist/index.js'
104
110
  import { expect, should } from 'chai'
@@ -112,14 +118,13 @@ describe('${thing}', ({it}) => {
112
118
 
113
119
  })`);
114
120
  }
115
-
116
121
  (await existsSync(testFileName)).should.be.true;
117
122
  const originalTests = [testFileName];
118
123
  const originalDependencyTrees = {
119
124
  [testFileName]: ['dep-1.js', 'dep-2.js']
120
125
  };
121
- const tests = await Object.copy(originalTests);
122
- const dependencyTrees = await Object.copy(originalDependencyTrees);
126
+ const tests = await objectCopy(originalTests);
127
+ const dependencyTrees = await objectCopy(originalDependencyTrees);
123
128
  await tests.should.include.members([testFileName]);
124
129
  await dependencyTrees.should.include.keys([testFileName]);
125
130
  await watchFilesAndRunTestsNodeWatch(config, tests, dependencyTrees, [], customOut);