@travetto/test 5.0.0-rc.6 → 5.0.0-rc.8
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 +2 -2
- package/package.json +7 -7
- package/src/execute/executor.ts +1 -2
- package/src/execute/runner.ts +1 -1
- package/src/execute/util.ts +20 -18
- package/src/execute/watcher.ts +2 -2
- package/src/worker/standard.ts +6 -4
- package/support/cli.test.ts +2 -2
- package/support/cli.test_count.ts +3 -5
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ This module provides unit testing functionality that integrates with the framewo
|
|
|
18
18
|
* [JSON](https://www.json.org), best for integrating with at a code level
|
|
19
19
|
* [xUnit](https://en.wikipedia.org/wiki/XUnit), standard format for CI/CD systems e.g. Jenkins, Bamboo, etc.
|
|
20
20
|
|
|
21
|
-
**Note**: All tests should be under the
|
|
21
|
+
**Note**: All tests should be under the `**/*` folders. The pattern for tests is defined as as a standard glob using [Node](https://nodejs.org)'s built in globbing support.
|
|
22
22
|
|
|
23
23
|
## Definition
|
|
24
24
|
A test suite is a collection of individual tests. All test suites are classes with the [@Suite](https://github.com/travetto/travetto/tree/main/module/test/src/decorator/suite.ts#L13) decorator. Tests are defined as methods on the suite class, using the [@Test](https://github.com/travetto/travetto/tree/main/module/test/src/decorator/test.ts#L20) decorator. All tests intrinsically support `async`/`await`.
|
|
@@ -82,7 +82,7 @@ const tslib_1 = require("tslib");
|
|
|
82
82
|
const Ⲑ_debug_1 = tslib_1.__importStar(require("@travetto/runtime/src/debug.js"));
|
|
83
83
|
const Ⲑ_check_1 = tslib_1.__importStar(require("@travetto/test/src/assert/check.js"));
|
|
84
84
|
const Ⲑ_function_1 = tslib_1.__importStar(require("@travetto/runtime/src/function.js"));
|
|
85
|
-
var ᚕm = ["@travetto/test", "doc/assert-example"];
|
|
85
|
+
var ᚕm = ["@travetto/test", "doc/assert-example.ts"];
|
|
86
86
|
const node_assert_1 = tslib_1.__importDefault(require("node:assert"));
|
|
87
87
|
const test_1 = require("@travetto/test");
|
|
88
88
|
let SimpleTest = class SimpleTest {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/test",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.8",
|
|
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/runtime": "^5.0.0-rc.
|
|
31
|
-
"@travetto/registry": "^5.0.0-rc.
|
|
32
|
-
"@travetto/terminal": "^5.0.0-rc.
|
|
33
|
-
"@travetto/worker": "^5.0.0-rc.
|
|
30
|
+
"@travetto/runtime": "^5.0.0-rc.8",
|
|
31
|
+
"@travetto/registry": "^5.0.0-rc.8",
|
|
32
|
+
"@travetto/terminal": "^5.0.0-rc.8",
|
|
33
|
+
"@travetto/worker": "^5.0.0-rc.8",
|
|
34
34
|
"yaml": "^2.4.5"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/cli": "^5.0.0-rc.
|
|
38
|
-
"@travetto/transformer": "^5.0.0-rc.
|
|
37
|
+
"@travetto/cli": "^5.0.0-rc.8",
|
|
38
|
+
"@travetto/transformer": "^5.0.0-rc.5"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/transformer": {
|
package/src/execute/executor.ts
CHANGED
|
@@ -258,9 +258,8 @@ export class TestExecutor {
|
|
|
258
258
|
* Handle executing a suite's test/tests based on command line inputs
|
|
259
259
|
*/
|
|
260
260
|
static async execute(consumer: TestConsumer, imp: string, ...args: string[]): Promise<void> {
|
|
261
|
-
|
|
262
261
|
try {
|
|
263
|
-
await
|
|
262
|
+
await Runtime.importFrom(imp);
|
|
264
263
|
} catch (err) {
|
|
265
264
|
if (!(err instanceof Error)) {
|
|
266
265
|
throw err;
|
package/src/execute/runner.ts
CHANGED
|
@@ -29,7 +29,7 @@ export class Runner {
|
|
|
29
29
|
|
|
30
30
|
const imports = await RunnerUtil.getTestImports(this.#state.args);
|
|
31
31
|
|
|
32
|
-
console.debug('Running', {
|
|
32
|
+
console.debug('Running', { patterns: this.#state.args });
|
|
33
33
|
|
|
34
34
|
const testCount = await RunnerUtil.getTestCount(this.#state.args);
|
|
35
35
|
await consumer.onStart({ testCount });
|
package/src/execute/util.ts
CHANGED
|
@@ -36,28 +36,30 @@ export class RunnerUtil {
|
|
|
36
36
|
/**
|
|
37
37
|
* Find all valid test files given the globs
|
|
38
38
|
*/
|
|
39
|
-
static async getTestImports(globs?: string[]):
|
|
40
|
-
const
|
|
41
|
-
// Collect globs
|
|
42
|
-
if (globs) {
|
|
43
|
-
for await (const item of fs.glob(globs)) {
|
|
44
|
-
files.add(Runtime.workspaceRelative(item));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const found = RuntimeIndex.find({
|
|
39
|
+
static async* getTestImports(globs?: string[]): AsyncIterable<string> {
|
|
40
|
+
const all = RuntimeIndex.find({
|
|
49
41
|
module: m => m.roles.includes('test') || m.roles.includes('std'),
|
|
50
42
|
folder: f => f === 'test',
|
|
51
43
|
file: f => f.role === 'test'
|
|
52
|
-
})
|
|
53
|
-
.filter(f => files.size === 0 || files.has(f.sourceFile));
|
|
54
|
-
|
|
55
|
-
const validImports = found
|
|
56
|
-
.map(f => this.isTestFile(f.sourceFile).then(valid => ({ import: f.import, valid })));
|
|
44
|
+
});
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.map(x => x.
|
|
46
|
+
// Collect globs
|
|
47
|
+
if (globs?.length) {
|
|
48
|
+
const allFiles = new Map(all.map(x => [x.sourceFile, x]));
|
|
49
|
+
for await (const item of fs.glob(globs)) {
|
|
50
|
+
const src = Runtime.workspaceRelative(item);
|
|
51
|
+
const match = allFiles.get(src);
|
|
52
|
+
if (match && await this.isTestFile(match.sourceFile)) {
|
|
53
|
+
yield match.import;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
for await (const match of all) {
|
|
58
|
+
if (await this.isTestFile(match.sourceFile)) {
|
|
59
|
+
yield match.import;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
package/src/execute/watcher.ts
CHANGED
|
@@ -82,8 +82,8 @@ export class TestWatcher {
|
|
|
82
82
|
process.send?.({ type: 'ready' });
|
|
83
83
|
|
|
84
84
|
if (runAllOnStart) {
|
|
85
|
-
for (const imp of await RunnerUtil.getTestImports()) {
|
|
86
|
-
await
|
|
85
|
+
for await (const imp of await RunnerUtil.getTestImports()) {
|
|
86
|
+
await Runtime.importFrom(imp);
|
|
87
87
|
itr.add(imp);
|
|
88
88
|
}
|
|
89
89
|
}
|
package/src/worker/standard.ts
CHANGED
|
@@ -12,17 +12,19 @@ import { TestEvent } from '../model/event';
|
|
|
12
12
|
* Produce a handler for the child worker
|
|
13
13
|
*/
|
|
14
14
|
export async function buildStandardTestManager(consumer: TestConsumer, imp: string | RunRequest): Promise<void> {
|
|
15
|
-
process.send?.({ type: 'log', message: `Worker Executing ${imp}` });
|
|
16
|
-
|
|
17
15
|
let event: RunEvent;
|
|
16
|
+
process.send?.({ type: 'log', message: `Worker Input ${JSON.stringify(imp)}` });
|
|
17
|
+
|
|
18
18
|
if (typeof imp === 'string') {
|
|
19
19
|
event = { import: imp };
|
|
20
20
|
} else if ('file' in imp) {
|
|
21
|
-
event = { import: RuntimeIndex.getFromSource(imp.file)?.
|
|
21
|
+
event = { import: RuntimeIndex.getFromSource(imp.file)?.import!, class: imp.class, method: imp.method };
|
|
22
22
|
} else {
|
|
23
23
|
event = imp;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
process.send?.({ type: 'log', message: `Worker Executing ${event.import}` });
|
|
27
|
+
|
|
26
28
|
const { module } = RuntimeIndex.getFromImport(event.import!)!;
|
|
27
29
|
const suiteMod = RuntimeIndex.getModule(module);
|
|
28
30
|
|
|
@@ -64,7 +66,7 @@ export async function buildStandardTestManager(consumer: TestConsumer, imp: stri
|
|
|
64
66
|
// Kill on complete
|
|
65
67
|
await channel.destroy();
|
|
66
68
|
|
|
67
|
-
process.send?.({ type: 'log', message: `Worker Finished ${
|
|
69
|
+
process.send?.({ type: 'log', message: `Worker Finished ${event.import}` });
|
|
68
70
|
|
|
69
71
|
// If we received an error, throw it
|
|
70
72
|
if (error) {
|
package/support/cli.test.ts
CHANGED
|
@@ -39,7 +39,7 @@ export class TestCommand implements CliCommandShape {
|
|
|
39
39
|
return (await this.isFirstFile(first)) && rest.length === 0 ? 'single' : this.mode;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
async validate(first: string = '
|
|
42
|
+
async validate(first: string = '**/*', rest: string[]): Promise<CliValidationError | undefined> {
|
|
43
43
|
|
|
44
44
|
const mode = await this.resolvedMode(first, rest);
|
|
45
45
|
|
|
@@ -48,7 +48,7 @@ export class TestCommand implements CliCommandShape {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
async main(first: string = '
|
|
51
|
+
async main(first: string = '**/*', regexes: string[] = []): Promise<void> {
|
|
52
52
|
const { runTests } = await import('./bin/run');
|
|
53
53
|
|
|
54
54
|
return runTests({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliCommand } from '@travetto/cli';
|
|
2
|
-
import { Env, describeFunction } from '@travetto/runtime';
|
|
2
|
+
import { Env, Runtime, describeFunction } from '@travetto/runtime';
|
|
3
3
|
|
|
4
4
|
import { SuiteRegistry } from '../src/registry/suite';
|
|
5
5
|
import { RunnerUtil } from '../src/execute/util';
|
|
@@ -13,12 +13,10 @@ export class TestCountCommand {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async main(patterns: string[]) {
|
|
16
|
-
const imports = await RunnerUtil.getTestImports(patterns);
|
|
17
|
-
|
|
18
16
|
// Load all tests
|
|
19
|
-
for (const imp of
|
|
17
|
+
for await (const imp of await RunnerUtil.getTestImports(patterns)) {
|
|
20
18
|
try {
|
|
21
|
-
await
|
|
19
|
+
await Runtime.importFrom(imp);
|
|
22
20
|
} catch (err) {
|
|
23
21
|
console.error('Failed to import', imp, err);
|
|
24
22
|
}
|