@appthrust/kest 0.3.0 → 0.3.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 +17 -1
- package/package.json +2 -1
- package/ts/actions/apply-namespace.ts +9 -0
- package/ts/actions/apply-status.ts +8 -1
- package/ts/actions/apply.ts +8 -1
- package/ts/actions/assert-absence.ts +2 -0
- package/ts/actions/assert-list.ts +3 -0
- package/ts/actions/assert.ts +3 -0
- package/ts/actions/create.ts +34 -0
- package/ts/actions/delete.ts +3 -0
- package/ts/actions/exec.ts +3 -0
- package/ts/actions/get.ts +3 -0
- package/ts/actions/label.ts +3 -0
- package/ts/actions/types.ts +3 -0
- package/ts/apis/index.ts +88 -0
- package/ts/k8s-resource/index.ts +22 -0
- package/ts/recording/index.ts +81 -115
- package/ts/reporter/markdown/index.ts +23 -0
- package/ts/reporter/markdown/model.ts +63 -0
- package/ts/reporter/markdown/parser/index.ts +361 -0
- package/ts/reporter/markdown/renderer/index.ts +296 -0
- package/ts/reporter/shiki.ts +58 -0
- package/ts/retry.ts +0 -6
- package/ts/scenario/index.ts +29 -29
- package/ts/test.ts +2 -1
- package/ts/reporter/index.ts +0 -0
- package/ts/reporter/markdown.ts +0 -962
package/ts/retry.ts
CHANGED
|
@@ -77,7 +77,6 @@ export async function retryUntil<T>(
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
retries += 1;
|
|
80
|
-
recorder?.record("RetryAttempt", { attempt: retries });
|
|
81
80
|
|
|
82
81
|
try {
|
|
83
82
|
const value = await fn();
|
|
@@ -89,11 +88,6 @@ export async function retryUntil<T>(
|
|
|
89
88
|
return value;
|
|
90
89
|
} catch (err) {
|
|
91
90
|
lastError = err;
|
|
92
|
-
const error = err as Error;
|
|
93
|
-
recorder?.record("RetryFailure", {
|
|
94
|
-
attempt: retries,
|
|
95
|
-
error: { name: error.name, message: error.message },
|
|
96
|
-
});
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
93
|
|
package/ts/scenario/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { applyStatus } from "../actions/apply-status";
|
|
|
7
7
|
import { assert } from "../actions/assert";
|
|
8
8
|
import { assertAbsence } from "../actions/assert-absence";
|
|
9
9
|
import { assertList } from "../actions/assert-list";
|
|
10
|
+
import { create } from "../actions/create";
|
|
10
11
|
import { deleteResource } from "../actions/delete";
|
|
11
12
|
import { exec } from "../actions/exec";
|
|
12
13
|
import { get } from "../actions/get";
|
|
@@ -33,9 +34,9 @@ export interface InternalScenario extends Scenario {
|
|
|
33
34
|
|
|
34
35
|
export function createScenario(deps: CreateScenarioOptions): InternalScenario {
|
|
35
36
|
const { recorder, reporter, reverting } = deps;
|
|
36
|
-
recorder.record("ScenarioStarted", { name: deps.name });
|
|
37
37
|
return {
|
|
38
38
|
apply: createMutateFn(deps, apply),
|
|
39
|
+
create: createMutateFn(deps, create),
|
|
39
40
|
applyStatus: createOneWayMutateFn(deps, applyStatus),
|
|
40
41
|
delete: createOneWayMutateFn(deps, deleteResource),
|
|
41
42
|
label: createOneWayMutateFn(deps, label),
|
|
@@ -83,17 +84,25 @@ const createMutateFn =
|
|
|
83
84
|
options?: undefined | ActionOptions
|
|
84
85
|
): Promise<Output> => {
|
|
85
86
|
const { recorder, kubectl, reverting } = deps;
|
|
86
|
-
const {
|
|
87
|
-
|
|
87
|
+
const { mutate, describe } = action;
|
|
88
|
+
function recordActionStart() {
|
|
89
|
+
recorder.record("ActionStart", {
|
|
90
|
+
description: describe(input),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function recordActionEnd(error: undefined | Error) {
|
|
94
|
+
recorder.record("ActionEnd", { ok: error === undefined, error });
|
|
95
|
+
}
|
|
96
|
+
recordActionStart();
|
|
88
97
|
const fn = mutate({ kubectl });
|
|
89
|
-
let mutateErr:
|
|
98
|
+
let mutateErr: undefined | Error;
|
|
90
99
|
try {
|
|
91
100
|
const { revert, output } = await retryUntil(() => fn(input), {
|
|
92
101
|
...options,
|
|
93
102
|
recorder,
|
|
94
103
|
});
|
|
95
104
|
reverting.add(async () => {
|
|
96
|
-
|
|
105
|
+
recordActionStart(); // to record revert action start
|
|
97
106
|
let revertErr: unknown;
|
|
98
107
|
try {
|
|
99
108
|
await revert();
|
|
@@ -101,25 +110,15 @@ const createMutateFn =
|
|
|
101
110
|
revertErr = err;
|
|
102
111
|
throw err;
|
|
103
112
|
} finally {
|
|
104
|
-
|
|
105
|
-
action: name,
|
|
106
|
-
phase: "revert",
|
|
107
|
-
ok: revertErr === undefined,
|
|
108
|
-
error: revertErr as Error,
|
|
109
|
-
});
|
|
113
|
+
recordActionEnd(revertErr as Error); // to record revert action end
|
|
110
114
|
}
|
|
111
115
|
});
|
|
112
116
|
return output;
|
|
113
117
|
} catch (error) {
|
|
114
|
-
mutateErr = error;
|
|
118
|
+
mutateErr = error as Error;
|
|
115
119
|
throw error;
|
|
116
120
|
} finally {
|
|
117
|
-
|
|
118
|
-
action: name,
|
|
119
|
-
phase: type,
|
|
120
|
-
ok: mutateErr === undefined,
|
|
121
|
-
error: mutateErr as Error,
|
|
122
|
-
});
|
|
121
|
+
recordActionEnd(mutateErr as Error);
|
|
123
122
|
}
|
|
124
123
|
};
|
|
125
124
|
|
|
@@ -137,8 +136,8 @@ const createOneWayMutateFn =
|
|
|
137
136
|
options?: undefined | ActionOptions
|
|
138
137
|
): Promise<Output> => {
|
|
139
138
|
const { recorder, kubectl } = deps;
|
|
140
|
-
const {
|
|
141
|
-
recorder.record("ActionStart", {
|
|
139
|
+
const { mutate, describe } = action;
|
|
140
|
+
recorder.record("ActionStart", { description: describe(input) });
|
|
142
141
|
const fn = mutate({ kubectl });
|
|
143
142
|
let mutateErr: unknown;
|
|
144
143
|
try {
|
|
@@ -148,8 +147,6 @@ const createOneWayMutateFn =
|
|
|
148
147
|
throw error;
|
|
149
148
|
} finally {
|
|
150
149
|
recorder.record("ActionEnd", {
|
|
151
|
-
action: name,
|
|
152
|
-
phase: "mutate",
|
|
153
150
|
ok: mutateErr === undefined,
|
|
154
151
|
error: mutateErr as Error,
|
|
155
152
|
});
|
|
@@ -170,19 +167,20 @@ const createQueryFn =
|
|
|
170
167
|
options?: undefined | ActionOptions
|
|
171
168
|
): Promise<Output> => {
|
|
172
169
|
const { recorder, kubectl } = deps;
|
|
173
|
-
const {
|
|
174
|
-
recorder.record("ActionStart", {
|
|
170
|
+
const { query, describe } = action;
|
|
171
|
+
recorder.record("ActionStart", { description: describe(input) });
|
|
175
172
|
const fn = query({ kubectl });
|
|
173
|
+
let queryErr: unknown;
|
|
176
174
|
try {
|
|
177
175
|
return await retryUntil(() => fn(input), { ...options, recorder });
|
|
178
176
|
} catch (error) {
|
|
177
|
+
queryErr = error;
|
|
178
|
+
throw error;
|
|
179
|
+
} finally {
|
|
179
180
|
recorder.record("ActionEnd", {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
ok: false,
|
|
183
|
-
error: error as Error,
|
|
181
|
+
ok: queryErr === undefined,
|
|
182
|
+
error: queryErr as Error,
|
|
184
183
|
});
|
|
185
|
-
throw error;
|
|
186
184
|
}
|
|
187
185
|
};
|
|
188
186
|
|
|
@@ -202,6 +200,7 @@ const createNewNamespaceFn =
|
|
|
202
200
|
return {
|
|
203
201
|
name: namespaceName,
|
|
204
202
|
apply: createMutateFn(namespacedDeps, apply),
|
|
203
|
+
create: createMutateFn(namespacedDeps, create),
|
|
205
204
|
applyStatus: createOneWayMutateFn(namespacedDeps, applyStatus),
|
|
206
205
|
delete: createOneWayMutateFn(namespacedDeps, deleteResource),
|
|
207
206
|
label: createOneWayMutateFn(namespacedDeps, label),
|
|
@@ -224,6 +223,7 @@ const createUseClusterFn =
|
|
|
224
223
|
const clusterDeps = { ...scenarioDeps, kubectl: clusterKubectl };
|
|
225
224
|
return {
|
|
226
225
|
apply: createMutateFn(clusterDeps, apply),
|
|
226
|
+
create: createMutateFn(clusterDeps, create),
|
|
227
227
|
applyStatus: createOneWayMutateFn(clusterDeps, applyStatus),
|
|
228
228
|
delete: createOneWayMutateFn(clusterDeps, deleteResource),
|
|
229
229
|
label: createOneWayMutateFn(clusterDeps, label),
|
package/ts/test.ts
CHANGED
|
@@ -59,7 +59,7 @@ function makeScenarioTest(runner: BunTestRunner): TestFunction {
|
|
|
59
59
|
reverting,
|
|
60
60
|
reporter,
|
|
61
61
|
});
|
|
62
|
-
|
|
62
|
+
recorder.record("ScenarioStart", { name: label });
|
|
63
63
|
let testErr: undefined | Error;
|
|
64
64
|
try {
|
|
65
65
|
await fn(scenario);
|
|
@@ -67,6 +67,7 @@ function makeScenarioTest(runner: BunTestRunner): TestFunction {
|
|
|
67
67
|
testErr = error as Error;
|
|
68
68
|
}
|
|
69
69
|
await scenario.cleanup();
|
|
70
|
+
recorder.record("ScenarioEnd", {});
|
|
70
71
|
await report(recorder, scenario, testErr);
|
|
71
72
|
if (testErr) {
|
|
72
73
|
throw testErr;
|
package/ts/reporter/index.ts
DELETED
|
File without changes
|