testeranto.tiposkripto 0.1.4
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/dist/common/Types.js +2 -0
- package/dist/common/lib/tiposkripto/src/BaseGiven.js +96 -0
- package/dist/common/lib/tiposkripto/src/BaseSuite.js +134 -0
- package/dist/common/lib/tiposkripto/src/BaseThen.js +65 -0
- package/dist/common/lib/tiposkripto/src/BaseTiposkripto.js +192 -0
- package/dist/common/lib/tiposkripto/src/BaseWhen.js +46 -0
- package/dist/common/lib/tiposkripto/src/CoreTypes.js +2 -0
- package/dist/common/lib/tiposkripto/src/Node.js +37 -0
- package/dist/common/lib/tiposkripto/src/Web.js +62 -0
- package/dist/common/lib/tiposkripto/src/index.js +86 -0
- package/dist/common/lib/tiposkripto/src/types.js +6 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/MockGiven.js +22 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/MockThen.js +16 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/MockWhen.js +18 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/adapter.js +24 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/implementation.js +38 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/index.js +17 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/specification.js +19 -0
- package/dist/common/lib/tiposkripto/tests/abstractBase.test/types.js +2 -0
- package/dist/common/package.json +3 -0
- package/dist/common/tsconfig.common.tsbuildinfo +1 -0
- package/dist/module/Types.js +1 -0
- package/dist/module/index.js +689 -0
- package/dist/module/lib/tiposkripto/src/BaseGiven.js +92 -0
- package/dist/module/lib/tiposkripto/src/BaseSuite.js +130 -0
- package/dist/module/lib/tiposkripto/src/BaseThen.js +61 -0
- package/dist/module/lib/tiposkripto/src/BaseTiposkripto.js +189 -0
- package/dist/module/lib/tiposkripto/src/BaseWhen.js +42 -0
- package/dist/module/lib/tiposkripto/src/CoreTypes.js +1 -0
- package/dist/module/lib/tiposkripto/src/Node.js +30 -0
- package/dist/module/lib/tiposkripto/src/Web.js +55 -0
- package/dist/module/lib/tiposkripto/src/index.js +48 -0
- package/dist/module/lib/tiposkripto/src/types.js +3 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/MockGiven.js +18 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/MockThen.js +12 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/MockWhen.js +14 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/adapter.js +21 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/implementation.js +35 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/index.js +12 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/specification.js +15 -0
- package/dist/module/lib/tiposkripto/tests/abstractBase.test/types.js +1 -0
- package/dist/module/package.json +3 -0
- package/dist/module/tsconfig.module.tsbuildinfo +1 -0
- package/dist/types/Types.d.ts +68 -0
- package/dist/types/lib/tiposkripto/src/BaseGiven.d.ts +42 -0
- package/dist/types/lib/tiposkripto/src/BaseSuite.d.ts +46 -0
- package/dist/types/lib/tiposkripto/src/BaseThen.d.ts +28 -0
- package/dist/types/lib/tiposkripto/src/BaseTiposkripto.d.ts +36 -0
- package/dist/types/lib/tiposkripto/src/BaseWhen.d.ts +27 -0
- package/dist/types/lib/tiposkripto/src/CoreTypes.d.ts +55 -0
- package/dist/types/lib/tiposkripto/src/Node.d.ts +9 -0
- package/dist/types/lib/tiposkripto/src/Web.d.ts +9 -0
- package/dist/types/lib/tiposkripto/src/index.d.ts +8 -0
- package/dist/types/lib/tiposkripto/src/types.d.ts +60 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/types.ts
|
|
12
|
+
var defaultTestResourceRequirement;
|
|
13
|
+
var init_types = __esm({
|
|
14
|
+
"src/types.ts"() {
|
|
15
|
+
"use strict";
|
|
16
|
+
defaultTestResourceRequirement = {
|
|
17
|
+
ports: 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// src/BaseGiven.ts
|
|
23
|
+
var BaseGiven;
|
|
24
|
+
var init_BaseGiven = __esm({
|
|
25
|
+
"src/BaseGiven.ts"() {
|
|
26
|
+
"use strict";
|
|
27
|
+
BaseGiven = class {
|
|
28
|
+
constructor(features, whens, thens, givenCB, initialValues) {
|
|
29
|
+
this.artifacts = [];
|
|
30
|
+
this.features = features;
|
|
31
|
+
this.whens = whens;
|
|
32
|
+
this.thens = thens;
|
|
33
|
+
this.givenCB = givenCB;
|
|
34
|
+
this.initialValues = initialValues;
|
|
35
|
+
this.fails = 0;
|
|
36
|
+
}
|
|
37
|
+
addArtifact(path) {
|
|
38
|
+
if (typeof path !== "string") {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
41
|
+
path
|
|
42
|
+
)}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
46
|
+
this.artifacts.push(normalizedPath);
|
|
47
|
+
}
|
|
48
|
+
beforeAll(store) {
|
|
49
|
+
return store;
|
|
50
|
+
}
|
|
51
|
+
toObj() {
|
|
52
|
+
return {
|
|
53
|
+
key: this.key,
|
|
54
|
+
whens: (this.whens || []).map((w) => {
|
|
55
|
+
if (w && w.toObj) return w.toObj();
|
|
56
|
+
console.error("When step is not as expected!", JSON.stringify(w));
|
|
57
|
+
return {};
|
|
58
|
+
}),
|
|
59
|
+
thens: (this.thens || []).map((t) => t && t.toObj ? t.toObj() : {}),
|
|
60
|
+
error: this.error ? [this.error, this.error.stack] : null,
|
|
61
|
+
failed: this.failed,
|
|
62
|
+
features: this.features || [],
|
|
63
|
+
artifacts: this.artifacts,
|
|
64
|
+
status: this.status
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
async afterEach(store, key, artifactory) {
|
|
68
|
+
return store;
|
|
69
|
+
}
|
|
70
|
+
async give(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
71
|
+
this.key = key;
|
|
72
|
+
this.fails = 0;
|
|
73
|
+
const givenArtifactory = (fPath, value) => artifactory(`given-${key}/${fPath}`, value);
|
|
74
|
+
try {
|
|
75
|
+
const addArtifact = this.addArtifact.bind(this);
|
|
76
|
+
this.store = await this.givenThat(
|
|
77
|
+
subject,
|
|
78
|
+
testResourceConfiguration,
|
|
79
|
+
givenArtifactory,
|
|
80
|
+
this.givenCB,
|
|
81
|
+
this.initialValues
|
|
82
|
+
);
|
|
83
|
+
this.status = true;
|
|
84
|
+
} catch (e) {
|
|
85
|
+
this.status = false;
|
|
86
|
+
this.failed = true;
|
|
87
|
+
this.fails++;
|
|
88
|
+
this.error = e.stack;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const whens = this.whens || [];
|
|
92
|
+
for (const [thenNdx, thenStep] of this.thens.entries()) {
|
|
93
|
+
try {
|
|
94
|
+
const t = await thenStep.test(
|
|
95
|
+
this.store,
|
|
96
|
+
testResourceConfiguration,
|
|
97
|
+
`suite-${suiteNdx}/given-${key}/then-${thenNdx}`
|
|
98
|
+
);
|
|
99
|
+
tester(t);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
this.failed = true;
|
|
102
|
+
this.fails++;
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} catch (e) {
|
|
107
|
+
this.error = e.stack;
|
|
108
|
+
this.failed = true;
|
|
109
|
+
} finally {
|
|
110
|
+
try {
|
|
111
|
+
const addArtifact = this.addArtifact.bind(this);
|
|
112
|
+
await this.afterEach(this.store, this.key);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
this.failed = true;
|
|
115
|
+
this.fails++;
|
|
116
|
+
throw e;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return this.store;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// src/BaseSuite.ts
|
|
126
|
+
var BaseSuite;
|
|
127
|
+
var init_BaseSuite = __esm({
|
|
128
|
+
"src/BaseSuite.ts"() {
|
|
129
|
+
"use strict";
|
|
130
|
+
BaseSuite = class {
|
|
131
|
+
constructor(name, index, givens = {}) {
|
|
132
|
+
this.artifacts = [];
|
|
133
|
+
const suiteName = name || "testSuite";
|
|
134
|
+
if (!suiteName) {
|
|
135
|
+
throw new Error("BaseSuite requires a non-empty name");
|
|
136
|
+
}
|
|
137
|
+
this.name = suiteName;
|
|
138
|
+
this.index = index;
|
|
139
|
+
this.givens = givens;
|
|
140
|
+
this.fails = 0;
|
|
141
|
+
}
|
|
142
|
+
addArtifact(path) {
|
|
143
|
+
if (typeof path !== "string") {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
146
|
+
path
|
|
147
|
+
)}`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
151
|
+
this.artifacts.push(normalizedPath);
|
|
152
|
+
}
|
|
153
|
+
features() {
|
|
154
|
+
try {
|
|
155
|
+
const features = Object.keys(this.givens).map((k) => this.givens[k].features).flat().filter((value, index, array) => {
|
|
156
|
+
return array.indexOf(value) === index;
|
|
157
|
+
});
|
|
158
|
+
const stringFeatures = features.map((feature) => {
|
|
159
|
+
if (typeof feature === "string") {
|
|
160
|
+
return feature;
|
|
161
|
+
} else if (feature && typeof feature === "object") {
|
|
162
|
+
return feature.name || JSON.stringify(feature);
|
|
163
|
+
} else {
|
|
164
|
+
return String(feature);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return stringFeatures || [];
|
|
168
|
+
} catch (e) {
|
|
169
|
+
console.error("[ERROR] Failed to extract features:", JSON.stringify(e));
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
toObj() {
|
|
174
|
+
const givens = Object.keys(this.givens).map((k) => {
|
|
175
|
+
const givenObj = this.givens[k].toObj();
|
|
176
|
+
return givenObj;
|
|
177
|
+
});
|
|
178
|
+
return {
|
|
179
|
+
name: this.name,
|
|
180
|
+
givens,
|
|
181
|
+
fails: this.fails,
|
|
182
|
+
failed: this.failed,
|
|
183
|
+
features: this.features(),
|
|
184
|
+
artifacts: this.artifacts ? this.artifacts.filter((art) => typeof art === "string") : []
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
setup(s, artifactory, tr) {
|
|
188
|
+
console.log("mark9");
|
|
189
|
+
return new Promise((res) => res(s));
|
|
190
|
+
}
|
|
191
|
+
assertThat(t) {
|
|
192
|
+
return !!t;
|
|
193
|
+
}
|
|
194
|
+
afterAll(store, artifactory) {
|
|
195
|
+
return store;
|
|
196
|
+
}
|
|
197
|
+
async run(input, testResourceConfiguration) {
|
|
198
|
+
this.testResourceConfiguration = testResourceConfiguration;
|
|
199
|
+
const sNdx = this.index;
|
|
200
|
+
const subject = await this.setup(
|
|
201
|
+
input,
|
|
202
|
+
// suiteArtifactory,
|
|
203
|
+
testResourceConfiguration
|
|
204
|
+
// proxiedPm
|
|
205
|
+
);
|
|
206
|
+
for (const [gKey, g] of Object.entries(this.givens)) {
|
|
207
|
+
const giver = this.givens[gKey];
|
|
208
|
+
try {
|
|
209
|
+
this.store = await giver.give(
|
|
210
|
+
subject,
|
|
211
|
+
gKey,
|
|
212
|
+
testResourceConfiguration,
|
|
213
|
+
this.assertThat,
|
|
214
|
+
sNdx
|
|
215
|
+
);
|
|
216
|
+
this.fails += giver.fails || 0;
|
|
217
|
+
} catch (e) {
|
|
218
|
+
this.failed = true;
|
|
219
|
+
this.fails += 1;
|
|
220
|
+
if (giver.fails) {
|
|
221
|
+
this.fails += giver.fails;
|
|
222
|
+
}
|
|
223
|
+
console.error(`Error in given ${gKey}:`, e);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (this.fails > 0) {
|
|
227
|
+
this.failed = true;
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
this.afterAll(this.store);
|
|
231
|
+
} catch (e) {
|
|
232
|
+
console.error(JSON.stringify(e));
|
|
233
|
+
}
|
|
234
|
+
return this;
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/BaseThen.ts
|
|
241
|
+
var BaseThen;
|
|
242
|
+
var init_BaseThen = __esm({
|
|
243
|
+
"src/BaseThen.ts"() {
|
|
244
|
+
"use strict";
|
|
245
|
+
BaseThen = class {
|
|
246
|
+
constructor(name, thenCB) {
|
|
247
|
+
this.artifacts = [];
|
|
248
|
+
this.name = name;
|
|
249
|
+
this.thenCB = thenCB;
|
|
250
|
+
this.error = false;
|
|
251
|
+
this.artifacts = [];
|
|
252
|
+
}
|
|
253
|
+
addArtifact(path) {
|
|
254
|
+
if (typeof path !== "string") {
|
|
255
|
+
throw new Error(
|
|
256
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
257
|
+
path
|
|
258
|
+
)}`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
262
|
+
this.artifacts.push(normalizedPath);
|
|
263
|
+
}
|
|
264
|
+
toObj() {
|
|
265
|
+
const obj = {
|
|
266
|
+
name: this.name,
|
|
267
|
+
error: this.error,
|
|
268
|
+
artifacts: this.artifacts,
|
|
269
|
+
status: this.status
|
|
270
|
+
};
|
|
271
|
+
return obj;
|
|
272
|
+
}
|
|
273
|
+
async test(store, testResourceConfiguration, filepath) {
|
|
274
|
+
const addArtifact = this.addArtifact.bind(this);
|
|
275
|
+
try {
|
|
276
|
+
const x = await this.butThen(
|
|
277
|
+
store,
|
|
278
|
+
async (s) => {
|
|
279
|
+
try {
|
|
280
|
+
if (typeof this.thenCB === "function") {
|
|
281
|
+
const result = await this.thenCB(s);
|
|
282
|
+
return result;
|
|
283
|
+
} else {
|
|
284
|
+
return this.thenCB;
|
|
285
|
+
}
|
|
286
|
+
} catch (e) {
|
|
287
|
+
this.error = true;
|
|
288
|
+
throw e;
|
|
289
|
+
}
|
|
290
|
+
},
|
|
291
|
+
testResourceConfiguration
|
|
292
|
+
// proxiedPm
|
|
293
|
+
);
|
|
294
|
+
this.status = true;
|
|
295
|
+
return x;
|
|
296
|
+
} catch (e) {
|
|
297
|
+
this.status = false;
|
|
298
|
+
this.error = true;
|
|
299
|
+
throw e;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// src/BaseWhen.ts
|
|
307
|
+
var BaseWhen;
|
|
308
|
+
var init_BaseWhen = __esm({
|
|
309
|
+
"src/BaseWhen.ts"() {
|
|
310
|
+
"use strict";
|
|
311
|
+
BaseWhen = class {
|
|
312
|
+
constructor(name, whenCB) {
|
|
313
|
+
this.artifacts = [];
|
|
314
|
+
this.name = name;
|
|
315
|
+
this.whenCB = whenCB;
|
|
316
|
+
}
|
|
317
|
+
addArtifact(path) {
|
|
318
|
+
if (typeof path !== "string") {
|
|
319
|
+
throw new Error(
|
|
320
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
321
|
+
path
|
|
322
|
+
)}`
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
326
|
+
this.artifacts.push(normalizedPath);
|
|
327
|
+
}
|
|
328
|
+
toObj() {
|
|
329
|
+
const obj = {
|
|
330
|
+
name: this.name,
|
|
331
|
+
status: this.status,
|
|
332
|
+
error: this.error ? `${this.error.name}: ${this.error.message}
|
|
333
|
+
${this.error.stack}` : null,
|
|
334
|
+
artifacts: this.artifacts
|
|
335
|
+
};
|
|
336
|
+
return obj;
|
|
337
|
+
}
|
|
338
|
+
async test(store, testResourceConfiguration) {
|
|
339
|
+
try {
|
|
340
|
+
const result = await this.andWhen(
|
|
341
|
+
store,
|
|
342
|
+
this.whenCB,
|
|
343
|
+
testResourceConfiguration
|
|
344
|
+
// proxiedPm
|
|
345
|
+
);
|
|
346
|
+
this.status = true;
|
|
347
|
+
return result;
|
|
348
|
+
} catch (e) {
|
|
349
|
+
this.status = false;
|
|
350
|
+
this.error = e;
|
|
351
|
+
throw e;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// src/BaseTiposkripto.ts
|
|
359
|
+
var BaseTiposkripto;
|
|
360
|
+
var init_BaseTiposkripto = __esm({
|
|
361
|
+
async "src/BaseTiposkripto.ts"() {
|
|
362
|
+
"use strict";
|
|
363
|
+
await init_index();
|
|
364
|
+
init_BaseGiven();
|
|
365
|
+
init_BaseSuite();
|
|
366
|
+
init_BaseThen();
|
|
367
|
+
init_BaseWhen();
|
|
368
|
+
init_types();
|
|
369
|
+
BaseTiposkripto = class {
|
|
370
|
+
constructor(webOrNode, input, testSpecification, testImplementation, testResourceRequirement = defaultTestResourceRequirement, testAdapter = {}, testResourceConfiguration, wsPort = "3456", wsHost = "localhost") {
|
|
371
|
+
this.totalTests = 0;
|
|
372
|
+
this.artifacts = [];
|
|
373
|
+
this.testResourceConfiguration = testResourceConfiguration;
|
|
374
|
+
const fullAdapter = DefaultAdapter(testAdapter);
|
|
375
|
+
if (!testImplementation.suites || typeof testImplementation.suites !== "object") {
|
|
376
|
+
throw new Error(
|
|
377
|
+
`testImplementation.suites must be an object, got ${typeof testImplementation.suites}: ${JSON.stringify(
|
|
378
|
+
testImplementation.suites
|
|
379
|
+
)}`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
const classySuites = Object.entries(testImplementation.suites).reduce(
|
|
383
|
+
(a, [key], index) => {
|
|
384
|
+
a[key] = (somestring, givens) => {
|
|
385
|
+
return new class extends BaseSuite {
|
|
386
|
+
afterAll(store) {
|
|
387
|
+
return fullAdapter.afterAll(store);
|
|
388
|
+
}
|
|
389
|
+
assertThat(t) {
|
|
390
|
+
return fullAdapter.assertThis(t);
|
|
391
|
+
}
|
|
392
|
+
async setup(s, tr) {
|
|
393
|
+
return fullAdapter.beforeAll?.(s, tr) ?? s;
|
|
394
|
+
}
|
|
395
|
+
}(somestring, index, givens);
|
|
396
|
+
};
|
|
397
|
+
return a;
|
|
398
|
+
},
|
|
399
|
+
{}
|
|
400
|
+
);
|
|
401
|
+
const classyGivens = Object.entries(testImplementation.givens).reduce(
|
|
402
|
+
(a, [key, g]) => {
|
|
403
|
+
a[key] = (features, whens, thens, gcb, initialValues) => {
|
|
404
|
+
const safeFeatures = Array.isArray(features) ? [...features] : [];
|
|
405
|
+
const safeWhens = Array.isArray(whens) ? [...whens] : [];
|
|
406
|
+
const safeThens = Array.isArray(thens) ? [...thens] : [];
|
|
407
|
+
return new class extends BaseGiven {
|
|
408
|
+
async givenThat(subject, testResource, initializer, initialValues2) {
|
|
409
|
+
return fullAdapter.beforeEach(
|
|
410
|
+
subject,
|
|
411
|
+
initializer,
|
|
412
|
+
testResource,
|
|
413
|
+
initialValues2
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
afterEach(store, key2) {
|
|
417
|
+
return Promise.resolve(fullAdapter.afterEach(store, key2));
|
|
418
|
+
}
|
|
419
|
+
}(
|
|
420
|
+
safeFeatures,
|
|
421
|
+
safeWhens,
|
|
422
|
+
safeThens,
|
|
423
|
+
testImplementation.givens[key],
|
|
424
|
+
initialValues
|
|
425
|
+
);
|
|
426
|
+
};
|
|
427
|
+
return a;
|
|
428
|
+
},
|
|
429
|
+
{}
|
|
430
|
+
);
|
|
431
|
+
const classyWhens = Object.entries(testImplementation.whens).reduce(
|
|
432
|
+
(a, [key, whEn]) => {
|
|
433
|
+
a[key] = (...payload) => {
|
|
434
|
+
const whenInstance = new class extends BaseWhen {
|
|
435
|
+
async andWhen(store, whenCB, testResource) {
|
|
436
|
+
return await fullAdapter.andWhen(store, whenCB, testResource);
|
|
437
|
+
}
|
|
438
|
+
}(`${key}: ${payload && payload.toString()}`, whEn(...payload));
|
|
439
|
+
return whenInstance;
|
|
440
|
+
};
|
|
441
|
+
return a;
|
|
442
|
+
},
|
|
443
|
+
{}
|
|
444
|
+
);
|
|
445
|
+
const classyThens = Object.entries(testImplementation.thens).reduce(
|
|
446
|
+
(a, [key, thEn]) => {
|
|
447
|
+
a[key] = (...args) => {
|
|
448
|
+
const thenInstance = new class extends BaseThen {
|
|
449
|
+
async butThen(store, thenCB, testResource) {
|
|
450
|
+
return await fullAdapter.butThen(store, thenCB, testResource);
|
|
451
|
+
}
|
|
452
|
+
}(`${key}: ${args && args.toString()}`, thEn(...args));
|
|
453
|
+
return thenInstance;
|
|
454
|
+
};
|
|
455
|
+
return a;
|
|
456
|
+
},
|
|
457
|
+
{}
|
|
458
|
+
);
|
|
459
|
+
this.suitesOverrides = classySuites;
|
|
460
|
+
this.givenOverrides = classyGivens;
|
|
461
|
+
this.whenOverrides = classyWhens;
|
|
462
|
+
this.thenOverrides = classyThens;
|
|
463
|
+
this.testResourceRequirement = testResourceRequirement;
|
|
464
|
+
this.testSpecification = testSpecification;
|
|
465
|
+
this.specs = testSpecification(
|
|
466
|
+
this.Suites(),
|
|
467
|
+
this.Given(),
|
|
468
|
+
this.When(),
|
|
469
|
+
this.Then()
|
|
470
|
+
);
|
|
471
|
+
this.totalTests = this.calculateTotalTests();
|
|
472
|
+
this.testJobs = this.specs.map((suite) => {
|
|
473
|
+
const suiteRunner = (suite2) => async (testResourceConfiguration2) => {
|
|
474
|
+
try {
|
|
475
|
+
const x = await suite2.run(
|
|
476
|
+
input,
|
|
477
|
+
testResourceConfiguration2 || {
|
|
478
|
+
name: suite2.name,
|
|
479
|
+
fs: process.cwd(),
|
|
480
|
+
ports: [],
|
|
481
|
+
timeout: 3e4,
|
|
482
|
+
retries: 3,
|
|
483
|
+
environment: {},
|
|
484
|
+
files: []
|
|
485
|
+
}
|
|
486
|
+
);
|
|
487
|
+
return x;
|
|
488
|
+
} catch (e) {
|
|
489
|
+
console.error(e.stack);
|
|
490
|
+
throw e;
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
const runner = suiteRunner(suite);
|
|
494
|
+
const totalTests = this.totalTests;
|
|
495
|
+
const testJob = {
|
|
496
|
+
test: suite,
|
|
497
|
+
toObj: () => {
|
|
498
|
+
return suite.toObj();
|
|
499
|
+
},
|
|
500
|
+
runner,
|
|
501
|
+
receiveTestResourceConfig: async (testResourceConfiguration2) => {
|
|
502
|
+
try {
|
|
503
|
+
const suiteDone = await runner(
|
|
504
|
+
testResourceConfiguration2
|
|
505
|
+
);
|
|
506
|
+
const fails = suiteDone.fails;
|
|
507
|
+
return {
|
|
508
|
+
failed: fails > 0,
|
|
509
|
+
fails,
|
|
510
|
+
artifacts: [],
|
|
511
|
+
// this.artifacts is not accessible here
|
|
512
|
+
features: suiteDone.features(),
|
|
513
|
+
tests: 0,
|
|
514
|
+
runTimeTests: totalTests,
|
|
515
|
+
testJob: testJob.toObj()
|
|
516
|
+
};
|
|
517
|
+
} catch (e) {
|
|
518
|
+
console.error(e.stack);
|
|
519
|
+
return {
|
|
520
|
+
failed: true,
|
|
521
|
+
fails: -1,
|
|
522
|
+
artifacts: [],
|
|
523
|
+
features: [],
|
|
524
|
+
tests: 0,
|
|
525
|
+
runTimeTests: -1,
|
|
526
|
+
testJob: testJob.toObj()
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
return testJob;
|
|
532
|
+
});
|
|
533
|
+
this.testJobs[0].receiveTestResourceConfig(
|
|
534
|
+
testResourceConfiguration
|
|
535
|
+
).then((results) => {
|
|
536
|
+
this.writeFileSync(`testeranto/reports/${this.testResourceConfiguration.fs}`, JSON.stringify(results));
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
async receiveTestResourceConfig(testResourceConfig) {
|
|
540
|
+
if (this.testJobs && this.testJobs.length > 0) {
|
|
541
|
+
return this.testJobs[0].receiveTestResourceConfig(testResourceConfig);
|
|
542
|
+
} else {
|
|
543
|
+
throw new Error("No test jobs available");
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
Specs() {
|
|
547
|
+
return this.specs;
|
|
548
|
+
}
|
|
549
|
+
Suites() {
|
|
550
|
+
if (!this.suitesOverrides) {
|
|
551
|
+
throw new Error(
|
|
552
|
+
`suitesOverrides is undefined. classySuites: ${JSON.stringify(
|
|
553
|
+
Object.keys(this.suitesOverrides || {})
|
|
554
|
+
)}`
|
|
555
|
+
);
|
|
556
|
+
}
|
|
557
|
+
return this.suitesOverrides;
|
|
558
|
+
}
|
|
559
|
+
Given() {
|
|
560
|
+
return this.givenOverrides;
|
|
561
|
+
}
|
|
562
|
+
When() {
|
|
563
|
+
return this.whenOverrides;
|
|
564
|
+
}
|
|
565
|
+
Then() {
|
|
566
|
+
return this.thenOverrides;
|
|
567
|
+
}
|
|
568
|
+
// Add a method to access test jobs which can be used by receiveTestResourceConfig
|
|
569
|
+
getTestJobs() {
|
|
570
|
+
return this.testJobs;
|
|
571
|
+
}
|
|
572
|
+
calculateTotalTests() {
|
|
573
|
+
let total = 0;
|
|
574
|
+
for (const suite of this.specs) {
|
|
575
|
+
if (suite && typeof suite === "object") {
|
|
576
|
+
if ("givens" in suite) {
|
|
577
|
+
const givens = suite.givens;
|
|
578
|
+
if (givens && typeof givens === "object") {
|
|
579
|
+
total += Object.keys(givens).length;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return total;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
// src/Node.ts
|
|
591
|
+
var Node_exports = {};
|
|
592
|
+
__export(Node_exports, {
|
|
593
|
+
NodeTiposkripto: () => NodeTiposkripto,
|
|
594
|
+
default: () => Node_default
|
|
595
|
+
});
|
|
596
|
+
import fs from "fs";
|
|
597
|
+
var config, NodeTiposkripto, tiposkripto, Node_default;
|
|
598
|
+
var init_Node = __esm({
|
|
599
|
+
async "src/Node.ts"() {
|
|
600
|
+
"use strict";
|
|
601
|
+
await init_BaseTiposkripto();
|
|
602
|
+
init_types();
|
|
603
|
+
console.log(`[NodeTiposkripto] ${process.argv}`);
|
|
604
|
+
config = process.argv0[2];
|
|
605
|
+
NodeTiposkripto = class extends BaseTiposkripto {
|
|
606
|
+
constructor(input, testSpecification, testImplementation, testResourceRequirement, testAdapter) {
|
|
607
|
+
super(
|
|
608
|
+
"node",
|
|
609
|
+
input,
|
|
610
|
+
testSpecification,
|
|
611
|
+
testImplementation,
|
|
612
|
+
testResourceRequirement,
|
|
613
|
+
testAdapter,
|
|
614
|
+
config
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
writeFileSync(filename, payload) {
|
|
618
|
+
fs.writeFileSync(filename, payload);
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
tiposkripto = async (input, testSpecification, testImplementation, testAdapter, testResourceRequirement = defaultTestResourceRequirement) => {
|
|
622
|
+
try {
|
|
623
|
+
const t = new NodeTiposkripto(
|
|
624
|
+
input,
|
|
625
|
+
testSpecification,
|
|
626
|
+
testImplementation,
|
|
627
|
+
testResourceRequirement,
|
|
628
|
+
testAdapter
|
|
629
|
+
);
|
|
630
|
+
return t;
|
|
631
|
+
} catch (e) {
|
|
632
|
+
console.error(`[Node] Error creating Tiposkripto:`, e);
|
|
633
|
+
console.error(e.stack);
|
|
634
|
+
process.exit(-1);
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
Node_default = tiposkripto;
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
|
|
641
|
+
// src/index.ts
|
|
642
|
+
var tpskrt, tpskrtNode, index_default, BaseAdapter, DefaultAdapter;
|
|
643
|
+
var init_index = __esm({
|
|
644
|
+
async "src/index.ts"() {
|
|
645
|
+
init_types();
|
|
646
|
+
tpskrtNode = await init_Node().then(() => Node_exports);
|
|
647
|
+
tpskrt = tpskrtNode;
|
|
648
|
+
index_default = async (input, testSpecification, testImplementation, testAdapter, testResourceRequirement = defaultTestResourceRequirement, testResourceConfiguration) => {
|
|
649
|
+
return (await tpskrt.default)(
|
|
650
|
+
input,
|
|
651
|
+
testSpecification,
|
|
652
|
+
testImplementation,
|
|
653
|
+
testResourceRequirement,
|
|
654
|
+
testAdapter,
|
|
655
|
+
testResourceConfiguration
|
|
656
|
+
);
|
|
657
|
+
};
|
|
658
|
+
BaseAdapter = () => ({
|
|
659
|
+
beforeAll: async (input, testResource) => {
|
|
660
|
+
return input;
|
|
661
|
+
},
|
|
662
|
+
beforeEach: async function(subject, initializer, testResource, initialValues) {
|
|
663
|
+
return subject;
|
|
664
|
+
},
|
|
665
|
+
afterEach: async (store, key) => Promise.resolve(store),
|
|
666
|
+
afterAll: (store) => void 0,
|
|
667
|
+
butThen: async (store, thenCb, testResource) => {
|
|
668
|
+
return thenCb(store);
|
|
669
|
+
},
|
|
670
|
+
andWhen: async (store, whenCB, testResource) => {
|
|
671
|
+
return whenCB(store);
|
|
672
|
+
},
|
|
673
|
+
assertThis: (x) => x
|
|
674
|
+
});
|
|
675
|
+
DefaultAdapter = (p) => {
|
|
676
|
+
const base = BaseAdapter();
|
|
677
|
+
return {
|
|
678
|
+
...base,
|
|
679
|
+
...p
|
|
680
|
+
};
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
await init_index();
|
|
685
|
+
export {
|
|
686
|
+
BaseAdapter,
|
|
687
|
+
DefaultAdapter,
|
|
688
|
+
index_default as default
|
|
689
|
+
};
|