@travetto/test 5.0.9 → 5.0.11
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/package.json +8 -8
- package/src/assert/check.ts +1 -1
- package/src/consumer/serialize.ts +17 -25
- package/src/consumer/types/tap.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/test",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.11",
|
|
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/registry": "^5.0.
|
|
31
|
-
"@travetto/runtime": "^5.0.
|
|
32
|
-
"@travetto/terminal": "^5.0.
|
|
33
|
-
"@travetto/worker": "^5.0.
|
|
34
|
-
"yaml": "^2.
|
|
30
|
+
"@travetto/registry": "^5.0.11",
|
|
31
|
+
"@travetto/runtime": "^5.0.11",
|
|
32
|
+
"@travetto/terminal": "^5.0.11",
|
|
33
|
+
"@travetto/worker": "^5.0.11",
|
|
34
|
+
"yaml": "^2.6.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/cli": "^5.0.
|
|
38
|
-
"@travetto/transformer": "^5.0.
|
|
37
|
+
"@travetto/cli": "^5.0.11",
|
|
38
|
+
"@travetto/transformer": "^5.0.9"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/transformer": {
|
package/src/assert/check.ts
CHANGED
|
@@ -161,7 +161,7 @@ export class AssertCheck {
|
|
|
161
161
|
// Else treat as a simple function to build an error or not
|
|
162
162
|
const res = shouldThrow(err);
|
|
163
163
|
if (res && !(res instanceof Error)) {
|
|
164
|
-
return new AppError(`Invalid check, "${shouldThrow.name}" should return an Error or undefined`, 'data');
|
|
164
|
+
return new AppError(`Invalid check, "${shouldThrow.name}" should return an Error or undefined`, { category: 'data' });
|
|
165
165
|
} else {
|
|
166
166
|
return res;
|
|
167
167
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { AppError,
|
|
1
|
+
import { AppError, hasToJSON } from '@travetto/runtime';
|
|
2
2
|
|
|
3
3
|
import { TestEvent, } from '../model/event';
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
export type SerializedError = {
|
|
6
|
+
export type SerializedError = { [K in keyof Error]: Error[K] extends Function ? never : Error[K] } & { $: true };
|
|
7
7
|
|
|
8
8
|
function isError(e: unknown): e is SerializedError {
|
|
9
9
|
return !!e && (typeof e === 'object') && '$' in e;
|
|
@@ -14,25 +14,20 @@ export class SerializeUtil {
|
|
|
14
14
|
/**
|
|
15
15
|
* Prepare error for transmission
|
|
16
16
|
*/
|
|
17
|
-
static serializeError(e: Error | SerializedError):
|
|
17
|
+
static serializeError(e: Error | SerializedError): SerializedError;
|
|
18
18
|
static serializeError(e: undefined): undefined;
|
|
19
|
-
static serializeError(e: Error | SerializedError | undefined):
|
|
20
|
-
|
|
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 (e instanceof AppError) {
|
|
29
|
-
Object.assign(error, e.toJSON());
|
|
30
|
-
}
|
|
31
|
-
error.message ||= e.message;
|
|
32
|
-
error.stack ??= e.stack?.replace(/.*\[ERR_ASSERTION\]:\s*/, '');
|
|
19
|
+
static serializeError(e: Error | SerializedError | undefined): SerializedError | undefined {
|
|
20
|
+
if (!e) {
|
|
21
|
+
return;
|
|
33
22
|
}
|
|
34
23
|
|
|
35
|
-
return
|
|
24
|
+
return {
|
|
25
|
+
$: true,
|
|
26
|
+
...hasToJSON(e) ? e.toJSON() : e,
|
|
27
|
+
name: e.name,
|
|
28
|
+
message: e.message,
|
|
29
|
+
stack: e.stack?.replace(/.*\[ERR_ASSERTION\]:\s*/, ''),
|
|
30
|
+
};
|
|
36
31
|
}
|
|
37
32
|
|
|
38
33
|
/**
|
|
@@ -42,13 +37,10 @@ export class SerializeUtil {
|
|
|
42
37
|
static deserializeError(e: undefined): undefined;
|
|
43
38
|
static deserializeError(e: Error | SerializedError | undefined): Error | undefined {
|
|
44
39
|
if (isError(e)) {
|
|
45
|
-
const err = new Error();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
err[k] = e[k]!;
|
|
40
|
+
const err = AppError.fromJSON(e) ?? new Error();
|
|
41
|
+
if (!(err instanceof AppError)) {
|
|
42
|
+
const { $: _, ...rest } = e;
|
|
43
|
+
Object.assign(err, rest);
|
|
52
44
|
}
|
|
53
45
|
err.message = e.message;
|
|
54
46
|
err.stack = e.stack;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { stringify } from 'yaml';
|
|
2
2
|
|
|
3
3
|
import { Terminal } from '@travetto/terminal';
|
|
4
|
-
import {
|
|
4
|
+
import { TimeUtil, Runtime, RuntimeIndex, hasToJSON } from '@travetto/runtime';
|
|
5
5
|
|
|
6
6
|
import { TestEvent } from '../../model/event';
|
|
7
7
|
import { SuitesSummary, TestConsumer } from '../types';
|
|
@@ -104,7 +104,7 @@ export class TapEmitter implements TestConsumer {
|
|
|
104
104
|
if (test.status === 'failed') {
|
|
105
105
|
if (test.error && test.error.name !== 'AssertionError') {
|
|
106
106
|
const err = SerializeUtil.deserializeError(test.error);
|
|
107
|
-
this.logMeta({ error: err
|
|
107
|
+
this.logMeta({ error: hasToJSON(err) ? err.toJSON() : err });
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -128,7 +128,7 @@ export class TapEmitter implements TestConsumer {
|
|
|
128
128
|
if (summary.errors.length) {
|
|
129
129
|
this.log('---\n');
|
|
130
130
|
for (const err of summary.errors) {
|
|
131
|
-
this.log(this.#enhancer.failure(err
|
|
131
|
+
this.log(this.#enhancer.failure(hasToJSON(err) ? JSON.stringify(err.toJSON(), null, 2) : `${err}`));
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|