@travetto/test 3.4.0 → 3.4.2
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/LICENSE +1 -1
- package/package.json +7 -7
- package/src/consumer/error.ts +77 -0
- package/src/consumer/types/event.ts +2 -2
- package/src/consumer/types/execution.ts +2 -2
- package/src/consumer/types/tap.ts +2 -1
- package/src/worker/child.ts +2 -1
- package/src/worker/standard.ts +2 -1
- package/support/cli.test.ts +3 -3
- package/support/cli.test_child.ts +3 -3
- package/support/cli.test_count.ts +3 -3
- package/support/cli.test_direct.ts +3 -3
- package/support/cli.test_watch.ts +3 -3
- package/src/consumer/util.ts +0 -20
package/LICENSE
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/test",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2",
|
|
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.4.
|
|
31
|
-
"@travetto/registry": "^3.4.
|
|
30
|
+
"@travetto/base": "^3.4.1",
|
|
31
|
+
"@travetto/registry": "^3.4.1",
|
|
32
32
|
"@travetto/terminal": "^3.4.0",
|
|
33
|
-
"@travetto/worker": "^3.4.
|
|
34
|
-
"@travetto/yaml": "^3.4.
|
|
33
|
+
"@travetto/worker": "^3.4.1",
|
|
34
|
+
"@travetto/yaml": "^3.4.1"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/cli": "^3.4.
|
|
38
|
-
"@travetto/transformer": "^3.4.
|
|
37
|
+
"@travetto/cli": "^3.4.6",
|
|
38
|
+
"@travetto/transformer": "^3.4.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/transformer": {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { TypedObject, ObjectUtil } from '@travetto/base';
|
|
2
|
+
|
|
3
|
+
import { TestEvent, } from '../model/event';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export type SerializedError = { $?: boolean, message: string, stack?: string, name: string };
|
|
7
|
+
|
|
8
|
+
function isSerialized(e: unknown): e is SerializedError {
|
|
9
|
+
return !!e && (typeof e === 'object') && '$' in e;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class ErrorUtil {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Prepare error for transmission
|
|
16
|
+
*/
|
|
17
|
+
static serializeError(e: Error | SerializedError): SerializedError;
|
|
18
|
+
static serializeError(e: undefined): undefined;
|
|
19
|
+
static serializeError(e: Error | SerializedError | undefined): SerializedError | undefined {
|
|
20
|
+
let error: SerializedError | undefined;
|
|
21
|
+
|
|
22
|
+
if (e) {
|
|
23
|
+
error = { $: true, name: e.name, message: '' };
|
|
24
|
+
for (const k of TypedObject.keys<{ name: string }>(e)) {
|
|
25
|
+
error[k] = e[k];
|
|
26
|
+
}
|
|
27
|
+
error.name = e.name;
|
|
28
|
+
if (ObjectUtil.hasToJSON(e)) {
|
|
29
|
+
Object.assign(error, e.toJSON());
|
|
30
|
+
}
|
|
31
|
+
error.message ??= e.message;
|
|
32
|
+
error.stack ??= e.stack;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return error;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Reconstitute the error, post serialization
|
|
40
|
+
*/
|
|
41
|
+
static deserializeError(e: Error | SerializedError): Error;
|
|
42
|
+
static deserializeError(e: undefined): undefined;
|
|
43
|
+
static deserializeError(e: Error | SerializedError | undefined): Error | undefined {
|
|
44
|
+
if (isSerialized(e)) {
|
|
45
|
+
const err = new Error();
|
|
46
|
+
|
|
47
|
+
for (const k of TypedObject.keys<{ name: string }>(e)) {
|
|
48
|
+
err[k] = e[k];
|
|
49
|
+
}
|
|
50
|
+
err.message = e.message;
|
|
51
|
+
err.stack = e.stack;
|
|
52
|
+
err.name = e.name;
|
|
53
|
+
return err;
|
|
54
|
+
} else if (e) {
|
|
55
|
+
return e;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Serialize all errors for a given test for transmission between parent/child
|
|
61
|
+
*/
|
|
62
|
+
static serializeTestErrors(out: TestEvent): void {
|
|
63
|
+
if (out.phase === 'after') {
|
|
64
|
+
if (out.type === 'test') {
|
|
65
|
+
if (out.test.error) {
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
67
|
+
out.test.error = this.serializeError(out.test.error) as Error;
|
|
68
|
+
}
|
|
69
|
+
} else if (out.type === 'assertion') {
|
|
70
|
+
if (out.assertion.error) {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
72
|
+
out.assertion.error = this.serializeError(out.assertion.error) as Error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -2,7 +2,7 @@ import { Writable } from 'stream';
|
|
|
2
2
|
|
|
3
3
|
import { TestEvent } from '../../model/event';
|
|
4
4
|
import { TestConsumer } from '../types';
|
|
5
|
-
import {
|
|
5
|
+
import { ErrorUtil } from '../error';
|
|
6
6
|
import { Consumable } from '../registry';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -18,7 +18,7 @@ export class EventStreamer implements TestConsumer {
|
|
|
18
18
|
|
|
19
19
|
onEvent(event: TestEvent): void {
|
|
20
20
|
const out = { ...event };
|
|
21
|
-
|
|
21
|
+
ErrorUtil.serializeTestErrors(out);
|
|
22
22
|
this.#stream.write(`${JSON.stringify(out)}\n`);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -2,7 +2,7 @@ import { ChildCommChannel } from '@travetto/worker';
|
|
|
2
2
|
|
|
3
3
|
import { TestEvent } from '../../model/event';
|
|
4
4
|
import { TestConsumer } from '../types';
|
|
5
|
-
import {
|
|
5
|
+
import { ErrorUtil } from '../error';
|
|
6
6
|
import { Consumable } from '../registry';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -13,7 +13,7 @@ export class ExecutionEmitter extends ChildCommChannel<TestEvent> implements Tes
|
|
|
13
13
|
|
|
14
14
|
onEvent(event: TestEvent): void {
|
|
15
15
|
const out = { ...event };
|
|
16
|
-
|
|
16
|
+
ErrorUtil.serializeTestErrors(out);
|
|
17
17
|
this.send(event.type, out);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { RootIndex } from '@travetto/manifest';
|
|
2
2
|
import { GlobalTerminal, Terminal } from '@travetto/terminal';
|
|
3
|
-
import {
|
|
3
|
+
import { ObjectUtil, TimeUtil } from '@travetto/base';
|
|
4
4
|
import { YamlUtil } from '@travetto/yaml';
|
|
5
5
|
|
|
6
6
|
import { TestEvent } from '../../model/event';
|
|
7
7
|
import { SuitesSummary, TestConsumer } from '../types';
|
|
8
8
|
import { Consumable } from '../registry';
|
|
9
|
+
import { ErrorUtil } from '../error';
|
|
9
10
|
import { TestResultsEnhancer, CONSOLE_ENHANCER } from '../enhancer';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/worker/child.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createWriteStream } from 'fs';
|
|
2
2
|
|
|
3
3
|
import { ManifestFileUtil, RootIndex } from '@travetto/manifest';
|
|
4
|
-
import { ConsoleManager,
|
|
4
|
+
import { ConsoleManager, TimeUtil } from '@travetto/base';
|
|
5
5
|
import { ChildCommChannel } from '@travetto/worker';
|
|
6
6
|
|
|
7
|
+
import { ErrorUtil } from '../consumer/error';
|
|
7
8
|
import { RunnerUtil } from '../execute/util';
|
|
8
9
|
import { Runner } from '../execute/runner';
|
|
9
10
|
import { Events, RunEvent } from './types';
|
package/src/worker/standard.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { RootIndex } from '@travetto/manifest';
|
|
2
|
-
import { ExecUtil
|
|
2
|
+
import { ExecUtil } from '@travetto/base';
|
|
3
3
|
import { ParentCommChannel, Worker } from '@travetto/worker';
|
|
4
4
|
|
|
5
5
|
import { Events, RunEvent } from './types';
|
|
6
6
|
import { TestConsumer } from '../consumer/types';
|
|
7
|
+
import { ErrorUtil } from '../consumer/error';
|
|
7
8
|
import { TestEvent } from '../model/event';
|
|
8
9
|
|
|
9
10
|
let i = 0;
|
package/support/cli.test.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
|
|
|
2
2
|
import fs from 'fs/promises';
|
|
3
3
|
|
|
4
4
|
import { path } from '@travetto/manifest';
|
|
5
|
-
import {
|
|
5
|
+
import { defineEnv } from '@travetto/base';
|
|
6
6
|
import { CliCommandShape, CliCommand, CliValidationError } from '@travetto/cli';
|
|
7
7
|
import { WorkPool } from '@travetto/worker';
|
|
8
8
|
import { Max, Min } from '@travetto/schema';
|
|
@@ -22,9 +22,9 @@ export class TestCommand implements CliCommandShape {
|
|
|
22
22
|
/** Test run mode */
|
|
23
23
|
mode: TestMode = 'standard';
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
preMain(): void {
|
|
26
26
|
EventEmitter.defaultMaxListeners = 1000;
|
|
27
|
-
|
|
27
|
+
defineEnv({ envName: 'test' });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
isFirstFile(first: string): Promise<boolean> {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { defineEnv, ShutdownManager } from '@travetto/base';
|
|
4
4
|
import { CliCommand } from '@travetto/cli';
|
|
5
5
|
|
|
6
6
|
/** Test child worker target */
|
|
7
7
|
@CliCommand({ hidden: true })
|
|
8
8
|
export class TestChildWorkerCommand {
|
|
9
|
-
|
|
9
|
+
preMain(): void {
|
|
10
10
|
EventEmitter.defaultMaxListeners = 1000;
|
|
11
11
|
process.env.FORCE_COLOR = '0';
|
|
12
|
-
|
|
12
|
+
defineEnv({ envName: 'test' });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async main(): Promise<void> {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CliCommand } from '@travetto/cli';
|
|
2
2
|
import { RootIndex } from '@travetto/manifest';
|
|
3
|
-
import {
|
|
3
|
+
import { defineEnv } from '@travetto/base';
|
|
4
4
|
|
|
5
5
|
import { SuiteRegistry } from '../src/registry/suite';
|
|
6
6
|
import { RunnerUtil } from '../src/execute/util';
|
|
@@ -8,8 +8,8 @@ import { RunnerUtil } from '../src/execute/util';
|
|
|
8
8
|
@CliCommand({ hidden: true })
|
|
9
9
|
export class TestCountCommand {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
preMain(): void {
|
|
12
|
+
defineEnv({ debug: false, envName: 'test' });
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
async main(patterns: string[]) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineEnv } from '@travetto/base';
|
|
2
2
|
import { CliCommand } from '@travetto/cli';
|
|
3
3
|
|
|
4
4
|
import { runTests } from './bin/run';
|
|
@@ -10,8 +10,8 @@ export class TestDirectCommand {
|
|
|
10
10
|
|
|
11
11
|
format: TestFormat = 'tap';
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
preMain(): void {
|
|
14
|
+
defineEnv({ envName: 'test' });
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
main(file: string, args: string[]): Promise<void> {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineEnv } from '@travetto/base';
|
|
2
2
|
import { CliCommand, CliUtil } from '@travetto/cli';
|
|
3
3
|
|
|
4
4
|
import { TestFormat } from './bin/types';
|
|
@@ -12,8 +12,8 @@ export class TestWatcherCommand {
|
|
|
12
12
|
format: TestFormat = 'tap';
|
|
13
13
|
mode: 'all' | 'change' = 'all';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
preMain(): void {
|
|
16
|
+
defineEnv({ envName: 'test', dynamic: true });
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
async main(): Promise<void> {
|
package/src/consumer/util.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ErrorUtil } from '@travetto/base';
|
|
2
|
-
import { TestEvent, } from '../model/event';
|
|
3
|
-
|
|
4
|
-
export class ConsumerUtil {
|
|
5
|
-
static serializeErrors(out: TestEvent): void {
|
|
6
|
-
if (out.phase === 'after') {
|
|
7
|
-
if (out.type === 'test') {
|
|
8
|
-
if (out.test.error) {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
10
|
-
out.test.error = ErrorUtil.serializeError(out.test.error) as Error;
|
|
11
|
-
}
|
|
12
|
-
} else if (out.type === 'assertion') {
|
|
13
|
-
if (out.assertion.error) {
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
15
|
-
out.assertion.error = ErrorUtil.serializeError(out.assertion.error) as Error;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|