@travetto/test 3.0.0-rc.9 → 3.0.1-rc.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/README.md +8 -5
- package/package.json +8 -8
- package/src/consumer/types/tap.ts +1 -1
- package/src/execute/util.ts +1 -1
- package/src/execute/watcher.ts +23 -12
- package/src/worker/child.ts +20 -1
- package/src/worker/standard.ts +10 -6
- package/support/{main.test-direct.ts → bin/direct.ts} +1 -1
- package/support/cli.test.ts +1 -1
- package/support/main.test-child.ts +0 -32
- package/support/main.test-watch.ts +0 -8
package/README.md
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
**Install: @travetto/test**
|
|
7
7
|
```bash
|
|
8
8
|
npm install @travetto/test
|
|
9
|
+
|
|
10
|
+
# or
|
|
11
|
+
|
|
12
|
+
yarn add @travetto/test
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
This module provides unit testing functionality that integrates with the framework. It is a declarative framework, using decorators to define tests and suites. The test produces results in the following formats:
|
|
@@ -80,12 +84,13 @@ const tslib_1 = require("tslib");
|
|
|
80
84
|
const Ⲑ_check_1 = tslib_1.__importStar(require("@travetto/test/src/assert/check.js"));
|
|
81
85
|
const Ⲑ_root_index_1 = tslib_1.__importStar(require("@travetto/manifest/src/root-index.js"));
|
|
82
86
|
const Ⲑ_decorator_1 = tslib_1.__importStar(require("@travetto/registry/src/decorator.js"));
|
|
87
|
+
var ᚕf = "@travetto/test/doc/assert-example.js";
|
|
83
88
|
const assert_1 = tslib_1.__importDefault(require("assert"));
|
|
84
89
|
const test_1 = require("@travetto/test");
|
|
85
90
|
let SimpleTest = class SimpleTest {
|
|
86
|
-
static Ⲑinit = Ⲑ_root_index_1.RootIndex.registerFunction(SimpleTest,
|
|
91
|
+
static Ⲑinit = Ⲑ_root_index_1.RootIndex.registerFunction(SimpleTest, ᚕf, 1887908328, { test: { hash: 102834457 } }, false, false);
|
|
87
92
|
async test() {
|
|
88
|
-
Ⲑ_check_1.AssertCheck.check({ file:
|
|
93
|
+
Ⲑ_check_1.AssertCheck.check({ file: ᚕf, line: 10, text: "{ size: 20, address: { state: 'VA' } }", operator: "deepStrictEqual" }, true, { size: 20, address: { state: 'VA' } }, {});
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
96
|
tslib_1.__decorate([
|
|
@@ -217,7 +222,7 @@ class SimpleTest {
|
|
|
217
222
|
|
|
218
223
|
## Running Tests
|
|
219
224
|
|
|
220
|
-
To run the tests you can either call the [Command Line Interface](https://github.com/travetto/travetto/tree/main/module/cli#readme "CLI infrastructure for
|
|
225
|
+
To run the tests you can either call the [Command Line Interface](https://github.com/travetto/travetto/tree/main/module/cli#readme "CLI infrastructure for Travetto framework") by invoking
|
|
221
226
|
|
|
222
227
|
**Terminal: Test Help Output**
|
|
223
228
|
```bash
|
|
@@ -230,8 +235,6 @@ Options:
|
|
|
230
235
|
-c, --concurrency <concurrency> Number of tests to run concurrently (default: 4)
|
|
231
236
|
-m, --mode <mode> Test run mode (default: "standard")
|
|
232
237
|
-h, --help display help for command
|
|
233
|
-
|
|
234
|
-
[s[r[u
|
|
235
238
|
```
|
|
236
239
|
|
|
237
240
|
The regexes are the patterns of tests you want to run, and all tests must be found under the `test/` folder.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/test",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1-rc.1",
|
|
4
4
|
"description": "Declarative test framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unit-testing",
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"directory": "module/test"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/base": "^3.0.
|
|
31
|
-
"@travetto/registry": "^3.0.
|
|
32
|
-
"@travetto/terminal": "^3.0.0
|
|
33
|
-
"@travetto/worker": "^3.0.
|
|
34
|
-
"@travetto/yaml": "^3.0.
|
|
30
|
+
"@travetto/base": "^3.0.1-rc.1",
|
|
31
|
+
"@travetto/registry": "^3.0.1-rc.1",
|
|
32
|
+
"@travetto/terminal": "^3.0.0",
|
|
33
|
+
"@travetto/worker": "^3.0.1-rc.1",
|
|
34
|
+
"@travetto/yaml": "^3.0.1-rc.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/cli": "^3.0.
|
|
38
|
-
"@travetto/transformer": "^3.0.
|
|
37
|
+
"@travetto/cli": "^3.0.1-rc.1",
|
|
38
|
+
"@travetto/transformer": "^3.0.1-rc.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/transformer": {
|
|
@@ -142,7 +142,7 @@ export class TapEmitter implements TestConsumer {
|
|
|
142
142
|
`${this.#enhancer.total(summary.failed)}`,
|
|
143
143
|
'skipped',
|
|
144
144
|
this.#enhancer.total(summary.skipped),
|
|
145
|
-
`# (Total Test Time: ${TimeUtil.prettyDelta(summary.duration)}, Total Run Time: ${TimeUtil.
|
|
145
|
+
`# (Total Test Time: ${TimeUtil.prettyDelta(summary.duration)}, Total Run Time: ${TimeUtil.prettyDeltaSinceTime(this.#start)})`
|
|
146
146
|
].join(' '));
|
|
147
147
|
}
|
|
148
148
|
}
|
package/src/execute/util.ts
CHANGED
|
@@ -41,7 +41,7 @@ export class RunnerUtil {
|
|
|
41
41
|
.filter(f => globs.some(g => g.test(f.import)));
|
|
42
42
|
|
|
43
43
|
const validFiles = files
|
|
44
|
-
.map(f => this.isTestFile(f.
|
|
44
|
+
.map(f => this.isTestFile(f.sourceFile).then(valid => ({ file: f.sourceFile, valid })));
|
|
45
45
|
|
|
46
46
|
return (await Promise.all(validFiles))
|
|
47
47
|
.filter(x => x.valid)
|
package/src/execute/watcher.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RootRegistry, MethodSource } from '@travetto/registry';
|
|
2
2
|
import { WorkPool, IterableWorkSet, ManualAsyncIterator } from '@travetto/worker';
|
|
3
3
|
import { RootIndex } from '@travetto/manifest';
|
|
4
|
-
import { ObjectUtil } from '@travetto/base';
|
|
5
|
-
import { DynamicFileLoader } from '@travetto/base/src/internal/file-loader';
|
|
4
|
+
import { ConsoleManager, defineGlobalEnv, ObjectUtil } from '@travetto/base';
|
|
6
5
|
|
|
7
6
|
import { SuiteRegistry } from '../registry/suite';
|
|
8
7
|
import { buildStandardTestManager } from '../worker/standard';
|
|
@@ -65,9 +64,10 @@ export class TestWatcher {
|
|
|
65
64
|
}
|
|
66
65
|
});
|
|
67
66
|
|
|
68
|
-
|
|
67
|
+
// If a file is changed, but doesn't emit classes, re-run whole file
|
|
68
|
+
RootRegistry.onNonClassChanges(file => itr.add(file));
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
await RootRegistry.init();
|
|
71
71
|
|
|
72
72
|
process.on('message', ev => {
|
|
73
73
|
if (isRunEvent(ev)) {
|
|
@@ -75,20 +75,31 @@ export class TestWatcher {
|
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
DynamicFileLoader.onLoadEvent(ev => {
|
|
80
|
-
if (ev.action === 'update') {
|
|
81
|
-
itr.add(ev.file);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
78
|
+
process.send?.('ready');
|
|
84
79
|
|
|
85
80
|
if (runAllOnStart) {
|
|
86
81
|
for (const test of await RootIndex.findTest({})) {
|
|
87
|
-
await import(test.
|
|
88
|
-
itr.add(test.
|
|
82
|
+
await import(test.import);
|
|
83
|
+
itr.add(test.sourceFile);
|
|
89
84
|
}
|
|
90
85
|
}
|
|
91
86
|
|
|
92
87
|
await pool.process(src);
|
|
93
88
|
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export async function main(format: string = 'tap', runAllOnStart: string = 'true'): Promise<void> {
|
|
92
|
+
defineGlobalEnv({ test: true, dynamic: true });
|
|
93
|
+
console.log('Starting');
|
|
94
|
+
ConsoleManager.setDebugFromEnv();
|
|
95
|
+
// Quit on parent disconnect
|
|
96
|
+
if (process.send) {
|
|
97
|
+
process.on('disconnect', () => process.exit(0));
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
await TestWatcher.watch(format, runAllOnStart !== 'false');
|
|
101
|
+
console.log('Done');
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error(err);
|
|
104
|
+
}
|
|
94
105
|
}
|
package/src/worker/child.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from 'fs/promises';
|
|
2
|
+
|
|
3
|
+
import { path } from '@travetto/manifest';
|
|
4
|
+
import { ConsoleManager, defineGlobalEnv, ErrorUtil, TimeUtil } from '@travetto/base';
|
|
2
5
|
import { ChildCommChannel } from '@travetto/worker';
|
|
3
6
|
|
|
4
7
|
import { RunnerUtil } from '../execute/util';
|
|
@@ -28,6 +31,16 @@ export class TestChildWorker extends ChildCommChannel<RunEvent> {
|
|
|
28
31
|
* Start the worker
|
|
29
32
|
*/
|
|
30
33
|
async activate(): Promise<void> {
|
|
34
|
+
if (/\b@travetto[/]test\b/.test(process.env.DEBUG ?? '')) {
|
|
35
|
+
const handle = await fs.open(path.resolve(`.trv-test-worker.${process.pid}.log`), 'a');
|
|
36
|
+
const stdout = handle.createWriteStream();
|
|
37
|
+
|
|
38
|
+
const c = new console.Console({ stdout, inspectOptions: { depth: 4, colors: false } });
|
|
39
|
+
ConsoleManager.set({ onLog: (ev) => c[ev.level](process.pid, ...ev.args) });
|
|
40
|
+
} else {
|
|
41
|
+
ConsoleManager.set({ onLog: () => { } });
|
|
42
|
+
}
|
|
43
|
+
|
|
31
44
|
RunnerUtil.registerCleanup('worker');
|
|
32
45
|
|
|
33
46
|
// Listen for inbound requests
|
|
@@ -75,4 +88,10 @@ export class TestChildWorker extends ChildCommChannel<RunEvent> {
|
|
|
75
88
|
concurrency: 1
|
|
76
89
|
}).run();
|
|
77
90
|
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function main(): Promise<void> {
|
|
94
|
+
defineGlobalEnv({ test: true, set: { FORCE_COLOR: 0 } });
|
|
95
|
+
ConsoleManager.setDebugFromEnv();
|
|
96
|
+
await new TestChildWorker().activate();
|
|
78
97
|
}
|
package/src/worker/standard.ts
CHANGED
|
@@ -32,14 +32,18 @@ export function buildStandardTestManager(consumer: TestConsumer): () => Worker<s
|
|
|
32
32
|
const event = buildEvent(file);
|
|
33
33
|
|
|
34
34
|
const { module } = RootIndex.getEntry(event.file!)!;
|
|
35
|
-
const cwd = RootIndex.getModule(module)!.
|
|
35
|
+
const cwd = RootIndex.getModule(module)!.sourcePath;
|
|
36
36
|
|
|
37
37
|
const channel = new ParentCommChannel<TestEvent & { error?: Error }>(
|
|
38
|
-
ExecUtil.fork(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
ExecUtil.fork(
|
|
39
|
+
RootIndex.resolveFileImport('@travetto/cli/support/entry.cli'),
|
|
40
|
+
['main', '@travetto/test/src/worker/child.ts'],
|
|
41
|
+
{
|
|
42
|
+
cwd,
|
|
43
|
+
env: { TRV_MANIFEST: RootIndex.getModule(module)!.outputPath },
|
|
44
|
+
stdio: [0, 'ignore', 2, 'ipc']
|
|
45
|
+
}
|
|
46
|
+
)
|
|
43
47
|
);
|
|
44
48
|
|
|
45
49
|
await channel.once(Events.READY); // Wait for the child to be ready
|
package/support/cli.test.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class TestCommand extends CliCommand<Options> {
|
|
|
27
27
|
if (!this._types) {
|
|
28
28
|
this._types = RootIndex
|
|
29
29
|
.findSrc({ filter: /consumer\/types\/.*/, profiles: ['test'] })
|
|
30
|
-
.map(x => readFileSync(`${x.
|
|
30
|
+
.map(x => readFileSync(`${x.outputFile}`, 'utf8').match(/Consumable.?[(]'([^']+)/)?.[1])
|
|
31
31
|
.filter((x?: string): x is string => !!x);
|
|
32
32
|
}
|
|
33
33
|
return this._types;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
|
|
3
|
-
import { ConsoleManager, defineGlobalEnv } from '@travetto/base';
|
|
4
|
-
import { path } from '@travetto/manifest';
|
|
5
|
-
|
|
6
|
-
import { TestChildWorker } from '../src/worker/child';
|
|
7
|
-
|
|
8
|
-
export async function customLogs(): Promise<void> {
|
|
9
|
-
if (/\b@travetto[/]test\b/.test(process.env.DEBUG ?? '')) {
|
|
10
|
-
const handle = await fs.open(path.resolve(`.trv-test-worker.${process.pid}.log`), 'a');
|
|
11
|
-
const stdout = handle.createWriteStream();
|
|
12
|
-
|
|
13
|
-
const c = new console.Console({
|
|
14
|
-
stdout,
|
|
15
|
-
inspectOptions: { depth: 4 },
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
ConsoleManager.set({
|
|
19
|
-
onLog: (ev) => c[ev.level](process.pid, ...ev.args)
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
ConsoleManager.set({ onLog: () => { } });
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function main(): Promise<void> {
|
|
27
|
-
defineGlobalEnv({ test: true });
|
|
28
|
-
ConsoleManager.setDebugFromEnv();
|
|
29
|
-
|
|
30
|
-
await customLogs();
|
|
31
|
-
return new TestChildWorker().activate();
|
|
32
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ConsoleManager, defineGlobalEnv } from '@travetto/base';
|
|
2
|
-
import { TestWatcher } from '../src/execute/watcher';
|
|
3
|
-
|
|
4
|
-
export async function main(format: string = 'tap', runAllOnStart: string = 'true'): Promise<void> {
|
|
5
|
-
defineGlobalEnv({ test: true, dynamic: true });
|
|
6
|
-
ConsoleManager.setDebugFromEnv();
|
|
7
|
-
await TestWatcher.watch(format, runAllOnStart !== 'false');
|
|
8
|
-
}
|