testeranto.tiposkripto 0.2.0 → 0.2.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/dist/module/Node.js +361 -154
- package/dist/module/Web.js +362 -171
- package/dist/module/index.js +636 -10
- package/dist/types/Types.d.ts +1 -0
- package/dist/types/lib/tiposkripto/src/BaseAct.d.ts +12 -0
- package/dist/types/lib/tiposkripto/src/BaseAction.d.ts +24 -0
- package/dist/types/lib/tiposkripto/src/BaseArrange.d.ts +11 -0
- package/dist/types/lib/tiposkripto/src/BaseAssert.d.ts +13 -0
- package/dist/types/lib/tiposkripto/src/BaseCheck.d.ts +25 -0
- package/dist/types/lib/tiposkripto/src/BaseFeed.d.ts +15 -0
- package/dist/types/lib/tiposkripto/src/BaseGiven.d.ts +10 -3
- package/dist/types/lib/tiposkripto/src/BaseMap.d.ts +16 -0
- package/dist/types/lib/tiposkripto/src/BaseSetup.d.ts +39 -0
- package/dist/types/lib/tiposkripto/src/BaseSuite.d.ts +3 -3
- package/dist/types/lib/tiposkripto/src/BaseThen.d.ts +9 -3
- package/dist/types/lib/tiposkripto/src/BaseValidate.d.ts +15 -0
- package/dist/types/lib/tiposkripto/src/BaseWhen.d.ts +10 -3
- package/dist/types/lib/tiposkripto/src/CoreTypes.d.ts +29 -24
- package/dist/types/lib/tiposkripto/src/Node.d.ts +3 -3
- package/dist/types/lib/tiposkripto/src/Web.d.ts +3 -3
- package/dist/types/lib/tiposkripto/src/flavored/Decorators.d.ts +22 -0
- package/dist/types/lib/tiposkripto/src/flavored/FluentBuilder.d.ts +31 -0
- package/dist/types/lib/tiposkripto/src/flavored/index.d.ts +17 -0
- package/dist/types/lib/tiposkripto/src/index.d.ts +45 -3
- package/dist/types/lib/tiposkripto/src/types.d.ts +12 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/module/index.js
CHANGED
|
@@ -1,20 +1,562 @@
|
|
|
1
|
+
// src/BaseSetup.ts
|
|
2
|
+
var BaseSetup = class {
|
|
3
|
+
constructor(features, actions, checks, setupCB, initialValues) {
|
|
4
|
+
this.artifacts = [];
|
|
5
|
+
this.fails = 0;
|
|
6
|
+
this.features = features;
|
|
7
|
+
this.actions = actions;
|
|
8
|
+
this.checks = checks;
|
|
9
|
+
this.setupCB = setupCB;
|
|
10
|
+
this.initialValues = initialValues;
|
|
11
|
+
this.fails = 0;
|
|
12
|
+
this.failed = false;
|
|
13
|
+
this.error = null;
|
|
14
|
+
this.store = null;
|
|
15
|
+
this.key = "";
|
|
16
|
+
this.status = void 0;
|
|
17
|
+
}
|
|
18
|
+
addArtifact(path) {
|
|
19
|
+
if (typeof path !== "string") {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
22
|
+
path
|
|
23
|
+
)}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
27
|
+
this.artifacts.push(normalizedPath);
|
|
28
|
+
}
|
|
29
|
+
toObj() {
|
|
30
|
+
return {
|
|
31
|
+
key: this.key,
|
|
32
|
+
actions: (this.actions || []).map((a) => {
|
|
33
|
+
if (a && a.toObj) return a.toObj();
|
|
34
|
+
console.error("Action step is not as expected!", JSON.stringify(a));
|
|
35
|
+
return {};
|
|
36
|
+
}),
|
|
37
|
+
checks: (this.checks || []).map((c) => c && c.toObj ? c.toObj() : {}),
|
|
38
|
+
error: this.error ? [this.error, this.error.stack] : null,
|
|
39
|
+
failed: this.failed,
|
|
40
|
+
features: this.features || [],
|
|
41
|
+
artifacts: this.artifacts,
|
|
42
|
+
status: this.status
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
async afterEach(store, key, artifactory) {
|
|
46
|
+
return store;
|
|
47
|
+
}
|
|
48
|
+
async setup(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
49
|
+
this.key = key;
|
|
50
|
+
this.fails = 0;
|
|
51
|
+
const actualArtifactory = artifactory || ((fPath, value) => {
|
|
52
|
+
});
|
|
53
|
+
const setupArtifactory = (fPath, value) => actualArtifactory(`setup-${key}/${fPath}`, value);
|
|
54
|
+
try {
|
|
55
|
+
this.store = await this.setupThat(
|
|
56
|
+
subject,
|
|
57
|
+
testResourceConfiguration,
|
|
58
|
+
setupArtifactory,
|
|
59
|
+
this.setupCB,
|
|
60
|
+
this.initialValues
|
|
61
|
+
);
|
|
62
|
+
this.status = true;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
this.status = false;
|
|
65
|
+
this.failed = true;
|
|
66
|
+
this.fails++;
|
|
67
|
+
this.error = e;
|
|
68
|
+
return this.store;
|
|
69
|
+
}
|
|
70
|
+
try {
|
|
71
|
+
for (const [actionNdx, actionStep] of (this.actions || []).entries()) {
|
|
72
|
+
try {
|
|
73
|
+
this.store = await actionStep.test(
|
|
74
|
+
this.store,
|
|
75
|
+
testResourceConfiguration
|
|
76
|
+
);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
this.failed = true;
|
|
79
|
+
this.fails++;
|
|
80
|
+
this.error = e;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
for (const [checkNdx, checkStep] of this.checks.entries()) {
|
|
84
|
+
try {
|
|
85
|
+
const filepath = suiteNdx !== void 0 ? `suite-${suiteNdx}/setup-${key}/check-${checkNdx}` : `setup-${key}/check-${checkNdx}`;
|
|
86
|
+
const t = await checkStep.test(
|
|
87
|
+
this.store,
|
|
88
|
+
testResourceConfiguration,
|
|
89
|
+
filepath
|
|
90
|
+
);
|
|
91
|
+
tester(t);
|
|
92
|
+
} catch (e) {
|
|
93
|
+
this.failed = true;
|
|
94
|
+
this.fails++;
|
|
95
|
+
this.error = e;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (e) {
|
|
99
|
+
this.error = e;
|
|
100
|
+
this.failed = true;
|
|
101
|
+
this.fails++;
|
|
102
|
+
} finally {
|
|
103
|
+
try {
|
|
104
|
+
await this.afterEach(this.store, this.key, setupArtifactory);
|
|
105
|
+
} catch (e) {
|
|
106
|
+
this.failed = true;
|
|
107
|
+
this.fails++;
|
|
108
|
+
this.error = e;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return this.store;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/BaseAction.ts
|
|
116
|
+
var BaseAction = class {
|
|
117
|
+
constructor(name, actionCB) {
|
|
118
|
+
this.artifacts = [];
|
|
119
|
+
this.name = name;
|
|
120
|
+
this.actionCB = actionCB;
|
|
121
|
+
}
|
|
122
|
+
addArtifact(path) {
|
|
123
|
+
if (typeof path !== "string") {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
126
|
+
path
|
|
127
|
+
)}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
131
|
+
this.artifacts.push(normalizedPath);
|
|
132
|
+
}
|
|
133
|
+
toObj() {
|
|
134
|
+
const obj = {
|
|
135
|
+
name: this.name,
|
|
136
|
+
status: this.status,
|
|
137
|
+
error: this.error ? `${this.error.name}: ${this.error.message}
|
|
138
|
+
${this.error.stack}` : null,
|
|
139
|
+
artifacts: this.artifacts
|
|
140
|
+
};
|
|
141
|
+
return obj;
|
|
142
|
+
}
|
|
143
|
+
async test(store, testResourceConfiguration) {
|
|
144
|
+
try {
|
|
145
|
+
const result = await this.performAction(
|
|
146
|
+
store,
|
|
147
|
+
this.actionCB,
|
|
148
|
+
testResourceConfiguration
|
|
149
|
+
);
|
|
150
|
+
this.status = true;
|
|
151
|
+
return result;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
this.status = false;
|
|
154
|
+
this.error = e;
|
|
155
|
+
throw e;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// src/BaseCheck.ts
|
|
161
|
+
var BaseCheck = class {
|
|
162
|
+
constructor(name, checkCB) {
|
|
163
|
+
this.artifacts = [];
|
|
164
|
+
this.name = name;
|
|
165
|
+
this.checkCB = checkCB;
|
|
166
|
+
this.error = false;
|
|
167
|
+
this.artifacts = [];
|
|
168
|
+
}
|
|
169
|
+
addArtifact(path) {
|
|
170
|
+
if (typeof path !== "string") {
|
|
171
|
+
throw new Error(
|
|
172
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
173
|
+
path
|
|
174
|
+
)}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
178
|
+
this.artifacts.push(normalizedPath);
|
|
179
|
+
}
|
|
180
|
+
toObj() {
|
|
181
|
+
const obj = {
|
|
182
|
+
name: this.name,
|
|
183
|
+
error: this.error,
|
|
184
|
+
artifacts: this.artifacts,
|
|
185
|
+
status: this.status
|
|
186
|
+
};
|
|
187
|
+
return obj;
|
|
188
|
+
}
|
|
189
|
+
async test(store, testResourceConfiguration, filepath) {
|
|
190
|
+
const addArtifact = this.addArtifact.bind(this);
|
|
191
|
+
try {
|
|
192
|
+
const x = await this.verifyCheck(
|
|
193
|
+
store,
|
|
194
|
+
async (s) => {
|
|
195
|
+
try {
|
|
196
|
+
if (typeof this.checkCB === "function") {
|
|
197
|
+
const result = await this.checkCB(s);
|
|
198
|
+
return result;
|
|
199
|
+
} else {
|
|
200
|
+
return this.checkCB;
|
|
201
|
+
}
|
|
202
|
+
} catch (e) {
|
|
203
|
+
this.error = true;
|
|
204
|
+
throw e;
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
testResourceConfiguration
|
|
208
|
+
);
|
|
209
|
+
this.status = true;
|
|
210
|
+
return x;
|
|
211
|
+
} catch (e) {
|
|
212
|
+
this.status = false;
|
|
213
|
+
this.error = true;
|
|
214
|
+
throw e;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// src/BaseArrange.ts
|
|
220
|
+
var BaseArrange = class extends BaseSetup {
|
|
221
|
+
constructor(features, acts, asserts, arrangeCB, initialValues) {
|
|
222
|
+
super(features, acts, asserts, arrangeCB, initialValues);
|
|
223
|
+
}
|
|
224
|
+
// Alias setup to arrange for AAA pattern
|
|
225
|
+
async arrange(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
226
|
+
return super.setup(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/BaseAct.ts
|
|
231
|
+
var BaseAct = class extends BaseAction {
|
|
232
|
+
constructor(name, actCB) {
|
|
233
|
+
super(name, actCB);
|
|
234
|
+
}
|
|
235
|
+
// Alias performAction to performAct for AAA pattern
|
|
236
|
+
async performAct(store, actCB, testResource) {
|
|
237
|
+
return super.performAction(store, actCB, testResource);
|
|
238
|
+
}
|
|
239
|
+
// Alias test to act for AAA pattern
|
|
240
|
+
async act(store, testResourceConfiguration) {
|
|
241
|
+
return super.test(store, testResourceConfiguration);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// src/BaseAssert.ts
|
|
246
|
+
var BaseAssert = class extends BaseCheck {
|
|
247
|
+
constructor(name, assertCB) {
|
|
248
|
+
super(name, assertCB);
|
|
249
|
+
}
|
|
250
|
+
// Alias verifyCheck to verifyAssert for AAA pattern
|
|
251
|
+
async verifyAssert(store, assertCB, testResourceConfiguration) {
|
|
252
|
+
return super.verifyCheck(store, assertCB, testResourceConfiguration);
|
|
253
|
+
}
|
|
254
|
+
// Alias test to verify for AAA pattern
|
|
255
|
+
async verify(store, testResourceConfiguration, filepath) {
|
|
256
|
+
return super.test(store, testResourceConfiguration, filepath);
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// src/BaseMap.ts
|
|
261
|
+
var BaseMap = class extends BaseSetup {
|
|
262
|
+
constructor(features, feeds, validates, mapCB, initialValues, tableData = []) {
|
|
263
|
+
super(features, feeds, validates, mapCB, initialValues);
|
|
264
|
+
this.tableData = tableData;
|
|
265
|
+
}
|
|
266
|
+
// Alias setup to map for TDT pattern
|
|
267
|
+
async map(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
268
|
+
return super.setup(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx);
|
|
269
|
+
}
|
|
270
|
+
// Method to get table data
|
|
271
|
+
getTableData() {
|
|
272
|
+
return this.tableData || [];
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
// src/BaseFeed.ts
|
|
277
|
+
var BaseFeed = class extends BaseAction {
|
|
278
|
+
constructor(name, feedCB) {
|
|
279
|
+
super(name, feedCB);
|
|
280
|
+
// Row index being processed
|
|
281
|
+
this.rowIndex = -1;
|
|
282
|
+
this.rowData = null;
|
|
283
|
+
}
|
|
284
|
+
// Set the current row data before processing
|
|
285
|
+
setRowData(index, data) {
|
|
286
|
+
this.rowIndex = index;
|
|
287
|
+
this.rowData = data;
|
|
288
|
+
}
|
|
289
|
+
// Alias performAction to feed for TDT pattern
|
|
290
|
+
async feed(store, feedCB, testResource) {
|
|
291
|
+
return super.performAction(store, feedCB, testResource);
|
|
292
|
+
}
|
|
293
|
+
// Alias test to processRow for TDT pattern
|
|
294
|
+
async processRow(store, testResourceConfiguration, rowIndex, rowData) {
|
|
295
|
+
this.setRowData(rowIndex, rowData);
|
|
296
|
+
return super.test(store, testResourceConfiguration);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// src/BaseValidate.ts
|
|
301
|
+
var BaseValidate = class extends BaseCheck {
|
|
302
|
+
constructor(name, validateCB) {
|
|
303
|
+
super(name, validateCB);
|
|
304
|
+
// Expected result for the current row
|
|
305
|
+
this.expectedResult = null;
|
|
306
|
+
}
|
|
307
|
+
// Set expected result before validation
|
|
308
|
+
setExpectedResult(expected) {
|
|
309
|
+
this.expectedResult = expected;
|
|
310
|
+
}
|
|
311
|
+
// Alias verifyCheck to validate for TDT pattern
|
|
312
|
+
async validate(store, validateCB, testResourceConfiguration) {
|
|
313
|
+
return super.verifyCheck(store, validateCB, testResourceConfiguration);
|
|
314
|
+
}
|
|
315
|
+
// Alias test to check for TDT pattern
|
|
316
|
+
async check(store, testResourceConfiguration, filepath, expectedResult) {
|
|
317
|
+
this.setExpectedResult(expectedResult);
|
|
318
|
+
return super.test(store, testResourceConfiguration, filepath);
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
// src/BaseGiven.ts
|
|
323
|
+
var BaseGiven = class extends BaseSetup {
|
|
324
|
+
constructor(features, whens, thens, givenCB, initialValues) {
|
|
325
|
+
super(features, whens, thens, givenCB, initialValues);
|
|
326
|
+
this.artifacts = [];
|
|
327
|
+
this.fails = 0;
|
|
328
|
+
}
|
|
329
|
+
addArtifact(path) {
|
|
330
|
+
if (typeof path !== "string") {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
333
|
+
path
|
|
334
|
+
)}`
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
338
|
+
this.artifacts.push(normalizedPath);
|
|
339
|
+
}
|
|
340
|
+
beforeAll(store) {
|
|
341
|
+
return store;
|
|
342
|
+
}
|
|
343
|
+
toObj() {
|
|
344
|
+
return {
|
|
345
|
+
key: this.key,
|
|
346
|
+
whens: (this.whens || []).map((w) => {
|
|
347
|
+
if (w && w.toObj) return w.toObj();
|
|
348
|
+
console.error("When step is not as expected!", JSON.stringify(w));
|
|
349
|
+
return {};
|
|
350
|
+
}),
|
|
351
|
+
thens: (this.thens || []).map((t) => t && t.toObj ? t.toObj() : {}),
|
|
352
|
+
error: this.error ? [this.error, this.error.stack] : null,
|
|
353
|
+
failed: this.failed,
|
|
354
|
+
features: this.features || [],
|
|
355
|
+
artifacts: this.artifacts,
|
|
356
|
+
status: this.status
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
// Implement BaseSetup's abstract method
|
|
360
|
+
async setupThat(subject, testResourceConfiguration, artifactory, setupCB, initialValues) {
|
|
361
|
+
return this.givenThat(subject, testResourceConfiguration, artifactory, setupCB, initialValues);
|
|
362
|
+
}
|
|
363
|
+
async afterEach(store, key, artifactory) {
|
|
364
|
+
return store;
|
|
365
|
+
}
|
|
366
|
+
async give(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
367
|
+
this.key = key;
|
|
368
|
+
this.fails = 0;
|
|
369
|
+
const actualArtifactory = artifactory || ((fPath, value) => {
|
|
370
|
+
});
|
|
371
|
+
const givenArtifactory = (fPath, value) => actualArtifactory(`given-${key}/${fPath}`, value);
|
|
372
|
+
try {
|
|
373
|
+
this.store = await this.givenThat(
|
|
374
|
+
subject,
|
|
375
|
+
testResourceConfiguration,
|
|
376
|
+
givenArtifactory,
|
|
377
|
+
this.givenCB,
|
|
378
|
+
this.initialValues
|
|
379
|
+
);
|
|
380
|
+
this.status = true;
|
|
381
|
+
} catch (e) {
|
|
382
|
+
this.status = false;
|
|
383
|
+
this.failed = true;
|
|
384
|
+
this.fails++;
|
|
385
|
+
this.error = e;
|
|
386
|
+
return this.store;
|
|
387
|
+
}
|
|
388
|
+
try {
|
|
389
|
+
const whens = this.whens || [];
|
|
390
|
+
for (const [whenNdx, whenStep] of whens.entries()) {
|
|
391
|
+
try {
|
|
392
|
+
this.store = await whenStep.test(
|
|
393
|
+
this.store,
|
|
394
|
+
testResourceConfiguration
|
|
395
|
+
);
|
|
396
|
+
} catch (e) {
|
|
397
|
+
this.failed = true;
|
|
398
|
+
this.fails++;
|
|
399
|
+
this.error = e;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
for (const [thenNdx, thenStep] of this.thens.entries()) {
|
|
403
|
+
try {
|
|
404
|
+
const filepath = suiteNdx !== void 0 ? `suite-${suiteNdx}/given-${key}/then-${thenNdx}` : `given-${key}/then-${thenNdx}`;
|
|
405
|
+
const t = await thenStep.test(
|
|
406
|
+
this.store,
|
|
407
|
+
testResourceConfiguration,
|
|
408
|
+
filepath
|
|
409
|
+
);
|
|
410
|
+
tester(t);
|
|
411
|
+
} catch (e) {
|
|
412
|
+
this.failed = true;
|
|
413
|
+
this.fails++;
|
|
414
|
+
this.error = e;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
} catch (e) {
|
|
418
|
+
this.error = e;
|
|
419
|
+
this.failed = true;
|
|
420
|
+
this.fails++;
|
|
421
|
+
} finally {
|
|
422
|
+
try {
|
|
423
|
+
await this.afterEach(this.store, this.key, givenArtifactory);
|
|
424
|
+
} catch (e) {
|
|
425
|
+
this.failed = true;
|
|
426
|
+
this.fails++;
|
|
427
|
+
this.error = e;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return this.store;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// src/BaseWhen.ts
|
|
435
|
+
var BaseWhen = class extends BaseAction {
|
|
436
|
+
constructor(name, whenCB) {
|
|
437
|
+
super(name, whenCB);
|
|
438
|
+
this.artifacts = [];
|
|
439
|
+
}
|
|
440
|
+
addArtifact(path) {
|
|
441
|
+
if (typeof path !== "string") {
|
|
442
|
+
throw new Error(
|
|
443
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
444
|
+
path
|
|
445
|
+
)}`
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
449
|
+
this.artifacts.push(normalizedPath);
|
|
450
|
+
}
|
|
451
|
+
// Implement BaseAction's abstract method
|
|
452
|
+
async performAction(store, actionCB, testResource) {
|
|
453
|
+
return this.andWhen(store, actionCB, testResource);
|
|
454
|
+
}
|
|
455
|
+
toObj() {
|
|
456
|
+
const obj = {
|
|
457
|
+
name: this.name,
|
|
458
|
+
status: this.status,
|
|
459
|
+
error: this.error ? `${this.error.name}: ${this.error.message}
|
|
460
|
+
${this.error.stack}` : null,
|
|
461
|
+
artifacts: this.artifacts
|
|
462
|
+
};
|
|
463
|
+
return obj;
|
|
464
|
+
}
|
|
465
|
+
async test(store, testResourceConfiguration) {
|
|
466
|
+
try {
|
|
467
|
+
const result = await this.andWhen(
|
|
468
|
+
store,
|
|
469
|
+
this.whenCB,
|
|
470
|
+
testResourceConfiguration
|
|
471
|
+
// proxiedPm
|
|
472
|
+
);
|
|
473
|
+
this.status = true;
|
|
474
|
+
return result;
|
|
475
|
+
} catch (e) {
|
|
476
|
+
this.status = false;
|
|
477
|
+
this.error = e;
|
|
478
|
+
throw e;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// src/BaseThen.ts
|
|
484
|
+
var BaseThen = class extends BaseCheck {
|
|
485
|
+
constructor(name, thenCB) {
|
|
486
|
+
this.artifacts = [];
|
|
487
|
+
this.name = name;
|
|
488
|
+
this.thenCB = thenCB;
|
|
489
|
+
this.error = false;
|
|
490
|
+
this.artifacts = [];
|
|
491
|
+
}
|
|
492
|
+
addArtifact(path) {
|
|
493
|
+
if (typeof path !== "string") {
|
|
494
|
+
throw new Error(
|
|
495
|
+
`[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
|
|
496
|
+
path
|
|
497
|
+
)}`
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
const normalizedPath = path.replace(/\\/g, "/");
|
|
501
|
+
this.artifacts.push(normalizedPath);
|
|
502
|
+
}
|
|
503
|
+
toObj() {
|
|
504
|
+
const obj = {
|
|
505
|
+
name: this.name,
|
|
506
|
+
error: this.error,
|
|
507
|
+
artifacts: this.artifacts,
|
|
508
|
+
status: this.status
|
|
509
|
+
};
|
|
510
|
+
return obj;
|
|
511
|
+
}
|
|
512
|
+
async test(store, testResourceConfiguration, filepath) {
|
|
513
|
+
const addArtifact = this.addArtifact.bind(this);
|
|
514
|
+
try {
|
|
515
|
+
const x = await this.butThen(
|
|
516
|
+
store,
|
|
517
|
+
async (s) => {
|
|
518
|
+
try {
|
|
519
|
+
if (typeof this.thenCB === "function") {
|
|
520
|
+
const result = await this.thenCB(s);
|
|
521
|
+
return result;
|
|
522
|
+
} else {
|
|
523
|
+
return this.thenCB;
|
|
524
|
+
}
|
|
525
|
+
} catch (e) {
|
|
526
|
+
this.error = true;
|
|
527
|
+
throw e;
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
testResourceConfiguration
|
|
531
|
+
// proxiedPm
|
|
532
|
+
);
|
|
533
|
+
this.status = true;
|
|
534
|
+
return x;
|
|
535
|
+
} catch (e) {
|
|
536
|
+
this.status = false;
|
|
537
|
+
this.error = true;
|
|
538
|
+
throw e;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
|
|
1
543
|
// src/index.ts
|
|
2
544
|
var BaseAdapter = () => ({
|
|
3
|
-
|
|
545
|
+
prepareAll: async (input, testResource) => {
|
|
4
546
|
return input;
|
|
5
547
|
},
|
|
6
|
-
|
|
548
|
+
prepareEach: async function(subject, initializer, testResource, initialValues) {
|
|
7
549
|
return subject;
|
|
8
550
|
},
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return
|
|
551
|
+
cleanupEach: async (store, key) => Promise.resolve(store),
|
|
552
|
+
cleanupAll: (store) => void 0,
|
|
553
|
+
verify: async (store, checkCb, testResource) => {
|
|
554
|
+
return checkCb(store);
|
|
13
555
|
},
|
|
14
|
-
|
|
15
|
-
return
|
|
556
|
+
execute: async (store, actionCB, testResource) => {
|
|
557
|
+
return actionCB(store);
|
|
16
558
|
},
|
|
17
|
-
|
|
559
|
+
assert: (x) => x
|
|
18
560
|
});
|
|
19
561
|
var DefaultAdapter = (p) => {
|
|
20
562
|
const base = BaseAdapter();
|
|
@@ -23,7 +565,91 @@ var DefaultAdapter = (p) => {
|
|
|
23
565
|
...p
|
|
24
566
|
};
|
|
25
567
|
};
|
|
568
|
+
function createAAASpecification(Suite, Arrange, Act, Assert) {
|
|
569
|
+
return {
|
|
570
|
+
// Create a suite with AAA pattern
|
|
571
|
+
Suite: {
|
|
572
|
+
Default: (name, arrangements) => {
|
|
573
|
+
const givens = {};
|
|
574
|
+
for (const [key, arrangement] of Object.entries(arrangements)) {
|
|
575
|
+
const { features, acts, asserts, arrangeCB, initialValues } = arrangement;
|
|
576
|
+
givens[key] = Arrange.Default(features, acts, asserts, arrangeCB, initialValues);
|
|
577
|
+
}
|
|
578
|
+
return Suite.Default(name, givens);
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
// Arrange maps to Given
|
|
582
|
+
Arrange: {
|
|
583
|
+
Default: (features, acts, asserts, arrangeCB, initialValues) => {
|
|
584
|
+
return Arrange.Default(features, acts, asserts, arrangeCB, initialValues);
|
|
585
|
+
}
|
|
586
|
+
},
|
|
587
|
+
// Act maps to When
|
|
588
|
+
Act: {
|
|
589
|
+
Default: (name, actCB) => {
|
|
590
|
+
return Act.Default(name, actCB);
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
// Assert maps to Then
|
|
594
|
+
Assert: {
|
|
595
|
+
Default: (name, assertCB) => {
|
|
596
|
+
return Assert.Default(name, assertCB);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function createTDTSpecification(Suite, Map, Feed, Validate) {
|
|
602
|
+
return {
|
|
603
|
+
// Create a suite with TDT pattern
|
|
604
|
+
Suite: {
|
|
605
|
+
Default: (name, maps) => {
|
|
606
|
+
const givens = {};
|
|
607
|
+
for (const [key, map] of Object.entries(maps)) {
|
|
608
|
+
const { features, feeds, validates, mapCB, initialValues, tableData } = map;
|
|
609
|
+
givens[key] = Map.Default(features, feeds, validates, mapCB, initialValues, tableData);
|
|
610
|
+
}
|
|
611
|
+
return Suite.Default(name, givens);
|
|
612
|
+
}
|
|
613
|
+
},
|
|
614
|
+
// Map maps to Given
|
|
615
|
+
Map: {
|
|
616
|
+
Default: (features, feeds, validates, mapCB, initialValues, tableData = []) => {
|
|
617
|
+
return Map.Default(features, feeds, validates, mapCB, initialValues, tableData);
|
|
618
|
+
}
|
|
619
|
+
},
|
|
620
|
+
// Feed maps to When
|
|
621
|
+
Feed: {
|
|
622
|
+
Default: (name, feedCB) => {
|
|
623
|
+
return Feed.Default(name, feedCB);
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
// Validate maps to Then
|
|
627
|
+
Validate: {
|
|
628
|
+
Default: (name, validateCB) => {
|
|
629
|
+
return Validate.Default(name, validateCB);
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
var AAA = createAAASpecification;
|
|
635
|
+
var TDT = createTDTSpecification;
|
|
26
636
|
export {
|
|
637
|
+
AAA,
|
|
638
|
+
BaseAct,
|
|
639
|
+
BaseAction,
|
|
27
640
|
BaseAdapter,
|
|
28
|
-
|
|
641
|
+
BaseArrange,
|
|
642
|
+
BaseAssert,
|
|
643
|
+
BaseCheck,
|
|
644
|
+
BaseFeed,
|
|
645
|
+
BaseGiven,
|
|
646
|
+
BaseMap,
|
|
647
|
+
BaseSetup,
|
|
648
|
+
BaseThen,
|
|
649
|
+
BaseValidate,
|
|
650
|
+
BaseWhen,
|
|
651
|
+
DefaultAdapter,
|
|
652
|
+
TDT,
|
|
653
|
+
createAAASpecification,
|
|
654
|
+
createTDTSpecification
|
|
29
655
|
};
|
package/dist/types/Types.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type ITestconfigV2 = {
|
|
|
7
7
|
featureIngestor: (s: string) => Promise<string>;
|
|
8
8
|
runtimes: Record<string, IBaseTestConfig>;
|
|
9
9
|
documentationGlob?: string;
|
|
10
|
+
stakeholderReactModule?: string;
|
|
10
11
|
};
|
|
11
12
|
export type ICheck = ((x: any) => string);
|
|
12
13
|
export type IChecks = ICheck[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseAction } from "./BaseAction.js";
|
|
2
|
+
import { TestTypeParams_any } from "./CoreTypes.js";
|
|
3
|
+
/**
|
|
4
|
+
* BaseAct extends BaseAction to support AAA pattern.
|
|
5
|
+
* It reuses all Action functionality but with AAA naming.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BaseAct<I extends TestTypeParams_any> extends BaseAction<I> {
|
|
8
|
+
constructor(name: string, actCB: (xyz: I["iselection"]) => I["then"]);
|
|
9
|
+
performAct(store: I["istore"], actCB: (x: I["iselection"]) => I["then"], testResource: any): Promise<any>;
|
|
10
|
+
act(store: I["istore"], testResourceConfiguration: any): Promise<any>;
|
|
11
|
+
}
|
|
12
|
+
export type IActs<I extends TestTypeParams_any> = Record<string, BaseAct<I>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TestTypeParams_any } from "./CoreTypes.js";
|
|
2
|
+
/**
|
|
3
|
+
* BaseAction is the unified base class for all action phases.
|
|
4
|
+
* It covers BDD's When, AAA's Act, and TDT's Feed.
|
|
5
|
+
* @deprecated Use BaseWhen, BaseAct, or BaseFeed for specific patterns
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class BaseAction<I extends TestTypeParams_any> {
|
|
8
|
+
name: string;
|
|
9
|
+
actionCB: (x: I["iselection"]) => I["then"];
|
|
10
|
+
error: Error;
|
|
11
|
+
artifacts: string[];
|
|
12
|
+
status: boolean | undefined;
|
|
13
|
+
addArtifact(path: string): void;
|
|
14
|
+
constructor(name: string, actionCB: (xyz: I["iselection"]) => I["then"]);
|
|
15
|
+
abstract performAction(store: I["istore"], actionCB: (x: I["iselection"]) => I["then"], testResource: any): Promise<any>;
|
|
16
|
+
toObj(): {
|
|
17
|
+
name: string;
|
|
18
|
+
status: boolean | undefined;
|
|
19
|
+
error: string | null;
|
|
20
|
+
artifacts: string[];
|
|
21
|
+
};
|
|
22
|
+
test(store: I["istore"], testResourceConfiguration: any): Promise<any>;
|
|
23
|
+
}
|
|
24
|
+
export type IActions<I extends TestTypeParams_any> = Record<string, BaseAction<I>>;
|