sxy-test-runner 1.3.8 → 1.4.1
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/lib/esmReload.unitTest.js +8 -0
- package/dist/cli/lib/load.unitTest copy.js +7 -0
- package/dist/cli/lib/load.unitTest.js +1 -1
- package/dist/cli/lib/loadTestFile.js +21 -10
- package/dist/cli/lib/processWatchEvent.js +1 -0
- package/dist/cli/lib/runTests.js +9 -3
- package/dist/cli/lib/watchFilesAndRunTestsChokidar.js +4 -2
- package/dist/cli/lib/watchFilesAndRunTestsNodeWatch.js +4 -2
- package/dist/cli/once.js +4 -1
- package/dist/describe.js +1 -0
- package/dist/describe.unitTest.js +0 -4
- package/package.json +2 -1
- package/readme.md +5 -8
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'esm-reload'; // this registers the import hook
|
|
2
|
+
|
|
3
|
+
await mochaDescribe('esm-reload module', async function () {
|
|
4
|
+
await mochaIt('load is a function with a cache', async function () {
|
|
5
|
+
await load.should.be.a('function');
|
|
6
|
+
await load.should.include.key('cache');
|
|
7
|
+
});
|
|
8
|
+
});
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import chalk from 'chalk-extensions';
|
|
1
3
|
import { createTimeProfiler } from 'sxy-dev-tools';
|
|
4
|
+
import 'esm-reload'; // registers import reload hook
|
|
5
|
+
|
|
2
6
|
import { showTimeProfiling } from '../../config.js';
|
|
3
7
|
import { out, log, debug, error } from '../../output.js';
|
|
4
|
-
import { join } from 'path';
|
|
5
|
-
import chalk from 'chalk-extensions';
|
|
6
8
|
const {
|
|
7
9
|
timeProfileAsync
|
|
8
10
|
} = await createTimeProfiler(showTimeProfiling);
|
|
9
|
-
|
|
11
|
+
|
|
12
|
+
//import { load } from './load.js.depr/index.js'
|
|
13
|
+
|
|
10
14
|
let loading = null;
|
|
15
|
+
let importIteration = 1;
|
|
16
|
+
async function importFresh(target) {
|
|
17
|
+
return await import(target + `?instance=${importIteration++}`);
|
|
18
|
+
}
|
|
11
19
|
export async function loadTestFile(config, testFile) {
|
|
12
20
|
if (loading !== null) {
|
|
13
21
|
await debug(chalk.yellow`loadTestFile - another file is loading - waiting for it to finish`);
|
|
@@ -41,13 +49,16 @@ export async function loadTestFile(config, testFile) {
|
|
|
41
49
|
////
|
|
42
50
|
|
|
43
51
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
52
|
+
// Old sxy-loader code
|
|
53
|
+
// load(testFileFullUrl, {
|
|
54
|
+
// // scopeObject: { // experimental idea
|
|
55
|
+
// // name: 'scope',
|
|
56
|
+
// // contents: {},
|
|
57
|
+
// // exposeObject: 'scope'
|
|
58
|
+
// // }
|
|
59
|
+
// })
|
|
60
|
+
|
|
61
|
+
await importFresh(testFileFullUrl);
|
|
51
62
|
test.describes = global.__sxy_test_runner__.describes;
|
|
52
63
|
test.error = false;
|
|
53
64
|
} catch (e) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//
|
package/dist/cli/lib/runTests.js
CHANGED
|
@@ -11,7 +11,8 @@ import { loadTestFile } from './loadTestFile.js';
|
|
|
11
11
|
import { runTest } from './runTest.js';
|
|
12
12
|
import { showTestLoadingError } from './showTestLoadingError.js';
|
|
13
13
|
import { showTestResult } from './showTestResult.js';
|
|
14
|
-
import { load } from './load.js'
|
|
14
|
+
//import { load } from './load.js.depr/index.js'
|
|
15
|
+
|
|
15
16
|
const {
|
|
16
17
|
timeProfileAsync
|
|
17
18
|
} = await createTimeProfiler(showTimeProfiling);
|
|
@@ -29,7 +30,8 @@ export async function runTests(config, testFiles, failingTests, customOut = unde
|
|
|
29
30
|
|
|
30
31
|
if (testFiles.length > 0) {
|
|
31
32
|
// clear load cache to allow accessing the new tets
|
|
32
|
-
|
|
33
|
+
//cache.clear()
|
|
34
|
+
|
|
33
35
|
for (const testFile of testFiles) {
|
|
34
36
|
const test = await loadTestFile(config, testFile);
|
|
35
37
|
if (test.error) {
|
|
@@ -65,7 +67,7 @@ export async function runTests(config, testFiles, failingTests, customOut = unde
|
|
|
65
67
|
// wait for the output to complete
|
|
66
68
|
await Promise.allObj(testRunOutPromises);
|
|
67
69
|
});
|
|
68
|
-
await timeProfileAsync('show initial test run results', async () => {
|
|
70
|
+
return await timeProfileAsync('show initial test run results', async () => {
|
|
69
71
|
const out = customOut ? async (...texts) => await customOut(...texts) : async (...texts) => await mainOut(...texts);
|
|
70
72
|
const testsResultsSummary = {
|
|
71
73
|
total: 0,
|
|
@@ -137,5 +139,9 @@ export async function runTests(config, testFiles, failingTests, customOut = unde
|
|
|
137
139
|
}
|
|
138
140
|
await out(chalk.orange`To do: account for tests with loading errors`);
|
|
139
141
|
// out(``)
|
|
142
|
+
|
|
143
|
+
// full success?
|
|
144
|
+
// true/false gets returned to the caller of runTests()
|
|
145
|
+
return testsResultsSummary.itsPasses === testsResultsSummary.itsTotal;
|
|
140
146
|
});
|
|
141
147
|
}
|
|
@@ -11,7 +11,8 @@ import { out, log, debug } from '../../output.js';
|
|
|
11
11
|
import { runTests } from './runTests.js';
|
|
12
12
|
import { buildDependencyTree } from './buildDependencyTree.js';
|
|
13
13
|
import { globArgCombine } from './globArgCombine.js';
|
|
14
|
-
import { load } from './load.js'
|
|
14
|
+
//import { load } from './load.js.depr/index.js'
|
|
15
|
+
|
|
15
16
|
const {
|
|
16
17
|
timeProfileAsync
|
|
17
18
|
} = await createTimeProfiler(showTimeProfiling);
|
|
@@ -111,7 +112,8 @@ export async function watchFilesAndRunTestsChokidar(config, testFiles, dependenc
|
|
|
111
112
|
await debug('toTest', toTest);
|
|
112
113
|
|
|
113
114
|
// clear load cache to allow accesing the new tets
|
|
114
|
-
|
|
115
|
+
//load.cache.clear()
|
|
116
|
+
|
|
115
117
|
const testResults = await runTests(config, toTest, failingTests, customOut);
|
|
116
118
|
});
|
|
117
119
|
}
|
|
@@ -11,7 +11,8 @@ import { out, log, debug } from '../../output.js';
|
|
|
11
11
|
import { runTests } from './runTests.js';
|
|
12
12
|
import { buildDependencyTree } from './buildDependencyTree.js';
|
|
13
13
|
import { globArgCombine } from './globArgCombine.js';
|
|
14
|
-
import { load } from './load.js'
|
|
14
|
+
//import { load } from './load.js.depr/index.js'
|
|
15
|
+
|
|
15
16
|
const {
|
|
16
17
|
timeProfileAsync
|
|
17
18
|
} = await createTimeProfiler(showTimeProfiling);
|
|
@@ -133,7 +134,8 @@ export async function watchFilesAndRunTestsNodeWatch(config, testFiles, dependen
|
|
|
133
134
|
await debug('toTest', toTest);
|
|
134
135
|
|
|
135
136
|
// clear load cache to allow accesing the new test
|
|
136
|
-
|
|
137
|
+
//load.cache.clear()
|
|
138
|
+
|
|
137
139
|
const testResults = await runTests(config, toTest, failingTests, customOut);
|
|
138
140
|
});
|
|
139
141
|
}
|
package/dist/cli/once.js
CHANGED
|
@@ -31,10 +31,13 @@ export async function once() {
|
|
|
31
31
|
const {
|
|
32
32
|
runTests
|
|
33
33
|
} = await import('./lib/runTests.js');
|
|
34
|
+
let exitCode = 2;
|
|
34
35
|
if (testFiles.length > 0) {
|
|
35
36
|
await log(chalk.brightblue`running tests...`);
|
|
36
|
-
await runTests(config, testFiles, []); //// async function, run in thread
|
|
37
|
+
const testsResult = await runTests(config, testFiles, []); //// async function, run in thread
|
|
38
|
+
exitCode = testsResult ? 0 : 3;
|
|
37
39
|
}
|
|
38
40
|
const time = (await new Date().getTime()) - startTime;
|
|
39
41
|
await out(chalk.grey`\n${await time.toLocaleString()}ms\n`);
|
|
42
|
+
await process.exit(exitCode);
|
|
40
43
|
}
|
package/dist/describe.js
CHANGED
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
export async function describe(theThing, tests) {
|
|
17
17
|
if (!global.__sxy_test_runner__) {
|
|
18
18
|
throw new Error(`sxy-test-runner describe() was called, but the test framework has not initialized.` + ` This might be because you have run a test file directly` + `, instead of running 'pnpm sxy-test-runner'`);
|
|
19
|
+
// todo - maybe we can initialise the framework and just run only this test file
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
//const thisDescribeCounter = global.testState.describeCounter++ // ++: assign the value, THEN increment
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
import { describe } from './describe.js';
|
|
3
|
-
|
|
4
|
-
//import { createLoad } from 'sxy-loader'
|
|
5
|
-
//const load = createLoad(import.meta.url)
|
|
6
|
-
|
|
7
3
|
await mochaDescribe('new describe() function', async function () {
|
|
8
4
|
await mochaIt('should run tests and output results', async function () {
|
|
9
5
|
await this.timeout(6000);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sxy-test-runner",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/RobertSandiford/sxy-test-runner",
|
|
6
6
|
"repository": {
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"chokidar": "^3.6.0",
|
|
35
35
|
"cross-env": "^7.0.3",
|
|
36
36
|
"dependency-tree": "^8.1.2",
|
|
37
|
+
"esm-reload": "^1.0.1",
|
|
37
38
|
"figures": "^4.0.1",
|
|
38
39
|
"glob": "^7.2.3",
|
|
39
40
|
"globby": "^12.2.0",
|
package/readme.md
CHANGED
|
@@ -124,12 +124,6 @@ No option to re-run all tests on changes is currently available - I may add this
|
|
|
124
124
|
|
|
125
125
|
Default behaviour is to re-run any failing test any time a change is made, even if that change isn't relevant to the failing test. This is to ensure you can see where attention is needed. Turn this off in the config if it is not convenient for you: config.watch.reRunFailingTests
|
|
126
126
|
|
|
127
|
-
## Reloading modules
|
|
128
|
-
|
|
129
|
-
A key challenge in creating an ESM test runner is re-loading modules due to the engine not letting us clear the import cache of ESM modules. This framework relies on sxy-loader, which uses a babel transform to transform modules into a reloadable format with a controllable cache. A cache of transformed code is kept to keep the process speedy.
|
|
130
|
-
|
|
131
|
-
Performance is a little less than a native module import, but not so much as to be notable inconvenience. Re-running only test related to changes keep performance strong even in very large projects.
|
|
132
|
-
|
|
133
127
|
# Advanced usage
|
|
134
128
|
|
|
135
129
|
## 1. Run tasks at startup - setup
|
|
@@ -201,6 +195,9 @@ describe('something', ({it, beforeEachTest, afterEachTest, afterDescribe}) => {
|
|
|
201
195
|
|
|
202
196
|
```
|
|
203
197
|
|
|
204
|
-
#
|
|
198
|
+
# Exit codes for `once`
|
|
205
199
|
|
|
206
|
-
|
|
200
|
+
0: success
|
|
201
|
+
3: some test errors
|
|
202
|
+
2: other error
|
|
203
|
+
It may also crash due to exceptions without giving any of these errors codes
|