@travetto/test 7.0.0-rc.2 → 7.0.0-rc.3
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 +1 -2
- package/__index__.ts +1 -0
- package/package.json +7 -7
- package/src/assert/util.ts +1 -1
- package/src/communication.ts +66 -0
- package/src/consumer/registry-index.ts +7 -7
- package/src/consumer/types/cumulative.ts +90 -61
- package/src/consumer/types/delegating.ts +23 -20
- package/src/consumer/types/event.ts +11 -4
- package/src/consumer/types/exec.ts +12 -3
- package/src/consumer/types/runnable.ts +2 -1
- package/src/consumer/types/summarizer.ts +4 -2
- package/src/consumer/types/tap-summary.ts +5 -3
- package/src/consumer/types.ts +6 -2
- package/src/execute/executor.ts +23 -12
- package/src/execute/phase.ts +1 -1
- package/src/execute/run.ts +247 -0
- package/src/execute/types.ts +2 -17
- package/src/execute/watcher.ts +30 -56
- package/src/model/common.ts +4 -0
- package/src/model/event.ts +3 -1
- package/src/model/suite.ts +9 -20
- package/src/model/test.ts +47 -1
- package/src/model/util.ts +8 -0
- package/src/registry/registry-adapter.ts +4 -2
- package/src/registry/registry-index.ts +10 -11
- package/src/worker/child.ts +12 -12
- package/src/worker/standard.ts +27 -18
- package/src/worker/types.ts +9 -5
- package/support/bin/run.ts +6 -6
- package/support/cli.test.ts +20 -41
- package/support/cli.test_diff.ts +47 -0
- package/support/cli.test_digest.ts +2 -2
- package/support/cli.test_direct.ts +13 -12
- package/support/cli.test_watch.ts +1 -6
- package/src/execute/runner.ts +0 -87
- package/src/execute/util.ts +0 -108
package/src/execute/util.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { createReadStream } from 'node:fs';
|
|
3
|
-
import fs from 'node:fs/promises';
|
|
4
|
-
import readline from 'node:readline/promises';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
|
|
7
|
-
import { Env, ExecUtil, ShutdownManager, Util, RuntimeIndex, Runtime } from '@travetto/runtime';
|
|
8
|
-
import { TestConfig, TestRun } from '../model/test.ts';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Simple Test Utilities
|
|
12
|
-
*/
|
|
13
|
-
export class RunnerUtil {
|
|
14
|
-
/**
|
|
15
|
-
* Add 50 ms to the shutdown to allow for buffers to output properly
|
|
16
|
-
*/
|
|
17
|
-
static registerCleanup(scope: string): void {
|
|
18
|
-
ShutdownManager.onGracefulShutdown(() => Util.blockingTimeout(50), `test.${scope}.bufferOutput`);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Determine if a given file path is a valid test file
|
|
23
|
-
*/
|
|
24
|
-
static async isTestFile(file: string): Promise<boolean> {
|
|
25
|
-
const reader = readline.createInterface({ input: createReadStream(file) });
|
|
26
|
-
const state = { imp: false, suite: false };
|
|
27
|
-
for await (const line of reader) {
|
|
28
|
-
state.imp ||= line.includes('@travetto/test');
|
|
29
|
-
state.suite ||= line.includes('Suite'); // Decorator or name
|
|
30
|
-
if (state.imp && state.suite) {
|
|
31
|
-
reader.close();
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Find all valid test files given the globs
|
|
40
|
-
*/
|
|
41
|
-
static async* getTestImports(globs?: string[]): AsyncIterable<string> {
|
|
42
|
-
const all = RuntimeIndex.find({
|
|
43
|
-
module: mod => mod.roles.includes('test') || mod.roles.includes('std'),
|
|
44
|
-
folder: folder => folder === 'test',
|
|
45
|
-
file: file => file.role === 'test'
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
// Collect globs
|
|
49
|
-
if (globs?.length) {
|
|
50
|
-
const allFiles = new Map(all.map(file => [file.sourceFile, file]));
|
|
51
|
-
for await (const item of fs.glob(globs)) {
|
|
52
|
-
const source = Runtime.workspaceRelative(path.resolve(item));
|
|
53
|
-
const match = allFiles.get(source);
|
|
54
|
-
if (match && await this.isTestFile(match.sourceFile)) {
|
|
55
|
-
yield match.import;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} else {
|
|
59
|
-
for await (const match of all) {
|
|
60
|
-
if (await this.isTestFile(match.sourceFile)) {
|
|
61
|
-
yield match.import;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Get count of tests for a given set of globs
|
|
69
|
-
* @param globs
|
|
70
|
-
* @returns
|
|
71
|
-
*/
|
|
72
|
-
static async getTestDigest(globs: string[] = ['**/*.ts'], tags?: string[]): Promise<TestConfig[]> {
|
|
73
|
-
const countRes = await ExecUtil.getResult(
|
|
74
|
-
spawn('npx', ['trv', 'test:digest', '-o', 'json', ...globs], {
|
|
75
|
-
env: { ...process.env, ...Env.FORCE_COLOR.export(0), ...Env.NO_COLOR.export(true) }
|
|
76
|
-
}),
|
|
77
|
-
{ catch: true }
|
|
78
|
-
);
|
|
79
|
-
if (!countRes.valid) {
|
|
80
|
-
throw new Error(countRes.stderr);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const testFilter = tags?.length ?
|
|
84
|
-
Util.allowDeny<string, [TestConfig]>(
|
|
85
|
-
tags,
|
|
86
|
-
rule => rule,
|
|
87
|
-
(rule, core) => core.tags?.includes(rule) ?? false
|
|
88
|
-
) :
|
|
89
|
-
((): boolean => true);
|
|
90
|
-
|
|
91
|
-
const parsed: TestConfig[] = countRes.valid ? JSON.parse(countRes.stdout) : [];
|
|
92
|
-
return parsed.filter(testFilter);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Get run events
|
|
97
|
-
*/
|
|
98
|
-
static getTestRuns(tests: TestConfig[]): TestRun[] {
|
|
99
|
-
const events = tests.reduce((runs, test) => {
|
|
100
|
-
if (!runs.has(test.classId)) {
|
|
101
|
-
runs.set(test.classId, { import: test.import, classId: test.classId, methodNames: [], runId: Util.uuid() });
|
|
102
|
-
}
|
|
103
|
-
runs.get(test.classId)!.methodNames!.push(test.methodName);
|
|
104
|
-
return runs;
|
|
105
|
-
}, new Map<string, TestRun>());
|
|
106
|
-
return [...events.values()];
|
|
107
|
-
}
|
|
108
|
-
}
|