testeranto.tiposkripto 0.2.4 → 0.2.7
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 +181 -31
- package/dist/module/Web.js +184 -33
- package/dist/module/index.js +150 -26
- package/dist/types/lib/tiposkripto/src/BaseGiven.d.ts +4 -1
- package/dist/types/lib/tiposkripto/src/BaseThen.d.ts +1 -1
- package/dist/types/lib/tiposkripto/src/BaseTiposkripto.d.ts +9 -0
- package/dist/types/lib/tiposkripto/src/BaseWhen.d.ts +1 -1
- package/dist/types/lib/tiposkripto/src/CoreTypes.d.ts +7 -6
- package/dist/types/lib/tiposkripto/src/Web.d.ts +1 -0
- package/dist/types/lib/tiposkripto/src/index.d.ts +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/module/Node.js
CHANGED
|
@@ -225,6 +225,7 @@ var BaseGiven = class extends BaseSetup {
|
|
|
225
225
|
super(features, whens, thens, givenCB, initialValues);
|
|
226
226
|
this.artifacts = [];
|
|
227
227
|
this.fails = 0;
|
|
228
|
+
this._parent = null;
|
|
228
229
|
}
|
|
229
230
|
addArtifact(path) {
|
|
230
231
|
if (typeof path !== "string") {
|
|
@@ -258,7 +259,13 @@ var BaseGiven = class extends BaseSetup {
|
|
|
258
259
|
}
|
|
259
260
|
// Implement BaseSetup's abstract method
|
|
260
261
|
async setupThat(subject, testResourceConfiguration, artifactory, setupCB, initialValues) {
|
|
261
|
-
return this.givenThat(
|
|
262
|
+
return this.givenThat(
|
|
263
|
+
subject,
|
|
264
|
+
testResourceConfiguration,
|
|
265
|
+
artifactory,
|
|
266
|
+
setupCB,
|
|
267
|
+
initialValues
|
|
268
|
+
);
|
|
262
269
|
}
|
|
263
270
|
async afterEach(store, key, artifactory) {
|
|
264
271
|
return store;
|
|
@@ -266,14 +273,13 @@ var BaseGiven = class extends BaseSetup {
|
|
|
266
273
|
async give(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
|
|
267
274
|
this.key = key;
|
|
268
275
|
this.fails = 0;
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const givenArtifactory = (fPath, value) => actualArtifactory(`given-${key}/${fPath}`, value);
|
|
276
|
+
this._suiteIndex = suiteNdx;
|
|
277
|
+
const actualArtifactory = artifactory || this.createDefaultArtifactory(key, suiteNdx);
|
|
272
278
|
try {
|
|
273
279
|
this.store = await this.givenThat(
|
|
274
280
|
subject,
|
|
275
281
|
testResourceConfiguration,
|
|
276
|
-
|
|
282
|
+
actualArtifactory,
|
|
277
283
|
this.givenCB,
|
|
278
284
|
this.initialValues
|
|
279
285
|
);
|
|
@@ -289,9 +295,15 @@ var BaseGiven = class extends BaseSetup {
|
|
|
289
295
|
const whens = this.whens || [];
|
|
290
296
|
for (const [whenNdx, whenStep] of whens.entries()) {
|
|
291
297
|
try {
|
|
298
|
+
const whenArtifactory = this.createArtifactoryForWhen(
|
|
299
|
+
key,
|
|
300
|
+
whenNdx,
|
|
301
|
+
suiteNdx
|
|
302
|
+
);
|
|
292
303
|
this.store = await whenStep.test(
|
|
293
304
|
this.store,
|
|
294
|
-
testResourceConfiguration
|
|
305
|
+
testResourceConfiguration,
|
|
306
|
+
whenArtifactory
|
|
295
307
|
);
|
|
296
308
|
} catch (e) {
|
|
297
309
|
this.failed = true;
|
|
@@ -302,10 +314,16 @@ var BaseGiven = class extends BaseSetup {
|
|
|
302
314
|
for (const [thenNdx, thenStep] of this.thens.entries()) {
|
|
303
315
|
try {
|
|
304
316
|
const filepath = suiteNdx !== void 0 ? `suite-${suiteNdx}/given-${key}/then-${thenNdx}` : `given-${key}/then-${thenNdx}`;
|
|
317
|
+
const thenArtifactory = this.createArtifactoryForThen(
|
|
318
|
+
key,
|
|
319
|
+
thenNdx,
|
|
320
|
+
suiteNdx
|
|
321
|
+
);
|
|
305
322
|
const t = await thenStep.test(
|
|
306
323
|
this.store,
|
|
307
324
|
testResourceConfiguration,
|
|
308
|
-
filepath
|
|
325
|
+
filepath,
|
|
326
|
+
thenArtifactory
|
|
309
327
|
);
|
|
310
328
|
tester(t);
|
|
311
329
|
} catch (e) {
|
|
@@ -320,7 +338,7 @@ var BaseGiven = class extends BaseSetup {
|
|
|
320
338
|
this.fails++;
|
|
321
339
|
} finally {
|
|
322
340
|
try {
|
|
323
|
-
await this.afterEach(this.store, this.key,
|
|
341
|
+
await this.afterEach(this.store, this.key, actualArtifactory);
|
|
324
342
|
} catch (e) {
|
|
325
343
|
this.failed = true;
|
|
326
344
|
this.fails++;
|
|
@@ -329,6 +347,80 @@ var BaseGiven = class extends BaseSetup {
|
|
|
329
347
|
}
|
|
330
348
|
return this.store;
|
|
331
349
|
}
|
|
350
|
+
createDefaultArtifactory(givenKey, suiteNdx) {
|
|
351
|
+
const self = this;
|
|
352
|
+
if (self._parent && self._parent.createArtifactory) {
|
|
353
|
+
return self._parent.createArtifactory({
|
|
354
|
+
givenKey,
|
|
355
|
+
suiteIndex: suiteNdx
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
writeFileSync: (filename, payload) => {
|
|
360
|
+
let path = "";
|
|
361
|
+
if (suiteNdx !== void 0) {
|
|
362
|
+
path += `suite-${suiteNdx}/`;
|
|
363
|
+
}
|
|
364
|
+
path += `given-${givenKey}/`;
|
|
365
|
+
path += filename;
|
|
366
|
+
console.log(`[Artifactory] Would write to: ${path}`);
|
|
367
|
+
console.log(`[Artifactory] Content: ${payload.substring(0, 100)}...`);
|
|
368
|
+
},
|
|
369
|
+
screenshot: (filename, payload) => {
|
|
370
|
+
console.log(`[Artifactory] Would take screenshot: ${filename}`);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
createArtifactoryForWhen(givenKey, whenIndex, suiteNdx) {
|
|
375
|
+
const self = this;
|
|
376
|
+
if (self._parent && self._parent.createArtifactory) {
|
|
377
|
+
return self._parent.createArtifactory({
|
|
378
|
+
givenKey,
|
|
379
|
+
whenIndex,
|
|
380
|
+
suiteIndex: suiteNdx
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
writeFileSync: (filename, payload) => {
|
|
385
|
+
let path = "";
|
|
386
|
+
if (suiteNdx !== void 0) {
|
|
387
|
+
path += `suite-${suiteNdx}/`;
|
|
388
|
+
}
|
|
389
|
+
path += `given-${givenKey}/`;
|
|
390
|
+
path += `when-${whenIndex} ${filename}`;
|
|
391
|
+
console.log(`[Artifactory] Would write to: ${path}`);
|
|
392
|
+
console.log(`[Artifactory] Content: ${payload.substring(0, 100)}...`);
|
|
393
|
+
},
|
|
394
|
+
screenshot: (filename, payload) => {
|
|
395
|
+
console.log(`[Artifactory] Would take screenshot: ${filename}`);
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
createArtifactoryForThen(givenKey, thenIndex, suiteNdx) {
|
|
400
|
+
const self = this;
|
|
401
|
+
if (self._parent && self._parent.createArtifactory) {
|
|
402
|
+
return self._parent.createArtifactory({
|
|
403
|
+
givenKey,
|
|
404
|
+
thenIndex,
|
|
405
|
+
suiteIndex: suiteNdx
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
writeFileSync: (filename, payload) => {
|
|
410
|
+
let path = "";
|
|
411
|
+
if (suiteNdx !== void 0) {
|
|
412
|
+
path += `suite-${suiteNdx}/`;
|
|
413
|
+
}
|
|
414
|
+
path += `given-${givenKey}/`;
|
|
415
|
+
path += `then-${thenIndex} ${filename}`;
|
|
416
|
+
console.log(`[Artifactory] Would write to: ${path}`);
|
|
417
|
+
console.log(`[Artifactory] Content: ${payload.substring(0, 100)}...`);
|
|
418
|
+
},
|
|
419
|
+
screenshot: (filename, payload) => {
|
|
420
|
+
console.log(`[Artifactory] Would take screenshot: ${filename}`);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
}
|
|
332
424
|
};
|
|
333
425
|
|
|
334
426
|
// src/BaseWhen.ts
|
|
@@ -341,13 +433,13 @@ var BaseWhen = class extends BaseAction {
|
|
|
341
433
|
async performAction(store, actionCB, testResource) {
|
|
342
434
|
return this.andWhen(store, actionCB, testResource);
|
|
343
435
|
}
|
|
344
|
-
async test(store, testResourceConfiguration) {
|
|
436
|
+
async test(store, testResourceConfiguration, artifactory) {
|
|
345
437
|
try {
|
|
346
438
|
const result = await this.andWhen(
|
|
347
439
|
store,
|
|
348
440
|
this.whenCB,
|
|
349
|
-
testResourceConfiguration
|
|
350
|
-
|
|
441
|
+
testResourceConfiguration,
|
|
442
|
+
artifactory
|
|
351
443
|
);
|
|
352
444
|
this.status = true;
|
|
353
445
|
return result;
|
|
@@ -365,8 +457,7 @@ var BaseThen = class extends BaseCheck {
|
|
|
365
457
|
super(name, thenCB);
|
|
366
458
|
this.thenCB = thenCB;
|
|
367
459
|
}
|
|
368
|
-
async test(store, testResourceConfiguration, filepath) {
|
|
369
|
-
const addArtifact = this.addArtifact.bind(this);
|
|
460
|
+
async test(store, testResourceConfiguration, filepath, artifactory) {
|
|
370
461
|
try {
|
|
371
462
|
const x = await this.butThen(
|
|
372
463
|
store,
|
|
@@ -383,8 +474,8 @@ var BaseThen = class extends BaseCheck {
|
|
|
383
474
|
throw e;
|
|
384
475
|
}
|
|
385
476
|
},
|
|
386
|
-
testResourceConfiguration
|
|
387
|
-
|
|
477
|
+
testResourceConfiguration,
|
|
478
|
+
artifactory
|
|
388
479
|
);
|
|
389
480
|
this.status = true;
|
|
390
481
|
return x;
|
|
@@ -398,18 +489,18 @@ var BaseThen = class extends BaseCheck {
|
|
|
398
489
|
|
|
399
490
|
// src/index.ts
|
|
400
491
|
var BaseAdapter = () => ({
|
|
401
|
-
prepareAll: async (input, testResource) => {
|
|
492
|
+
prepareAll: async (input, testResource, artifactory) => {
|
|
402
493
|
return input;
|
|
403
494
|
},
|
|
404
|
-
prepareEach: async function(subject, initializer, testResource, initialValues) {
|
|
495
|
+
prepareEach: async function(subject, initializer, testResource, initialValues, artifactory) {
|
|
405
496
|
return subject;
|
|
406
497
|
},
|
|
407
|
-
cleanupEach: async (store, key) => Promise.resolve(store),
|
|
408
|
-
cleanupAll: (store) => void 0,
|
|
409
|
-
verify: async (store, checkCb, testResource) => {
|
|
498
|
+
cleanupEach: async (store, key, artifactory) => Promise.resolve(store),
|
|
499
|
+
cleanupAll: (store, artifactory) => void 0,
|
|
500
|
+
verify: async (store, checkCb, testResource, artifactory) => {
|
|
410
501
|
return checkCb(store);
|
|
411
502
|
},
|
|
412
|
-
execute: async (store, actionCB, testResource) => {
|
|
503
|
+
execute: async (store, actionCB, testResource, artifactory) => {
|
|
413
504
|
return actionCB(store);
|
|
414
505
|
},
|
|
415
506
|
assert: (x) => x
|
|
@@ -523,7 +614,7 @@ var BaseSuite = class {
|
|
|
523
614
|
this.failed = true;
|
|
524
615
|
}
|
|
525
616
|
try {
|
|
526
|
-
this.afterAll(this.store);
|
|
617
|
+
this.afterAll(this.store, void 0);
|
|
527
618
|
} catch (e) {
|
|
528
619
|
console.error(JSON.stringify(e));
|
|
529
620
|
}
|
|
@@ -575,17 +666,23 @@ var BaseTiposkripto = class {
|
|
|
575
666
|
const safeFeatures = Array.isArray(features) ? [...features] : [];
|
|
576
667
|
const safeWhens = Array.isArray(whens) ? [...whens] : [];
|
|
577
668
|
const safeThens = Array.isArray(thens) ? [...thens] : [];
|
|
578
|
-
|
|
579
|
-
|
|
669
|
+
const outerThis = this;
|
|
670
|
+
const givenInstance = new class extends BaseGiven {
|
|
671
|
+
async givenThat(subject, testResource, artifactory, initializer, initialValues2) {
|
|
672
|
+
const givenArtifactory = outerThis.createArtifactory({
|
|
673
|
+
givenKey: key,
|
|
674
|
+
suiteIndex: this._suiteIndex
|
|
675
|
+
});
|
|
580
676
|
return fullAdapter.prepareEach(
|
|
581
677
|
subject,
|
|
582
678
|
initializer,
|
|
583
679
|
testResource,
|
|
584
|
-
initialValues2
|
|
680
|
+
initialValues2,
|
|
681
|
+
givenArtifactory
|
|
585
682
|
);
|
|
586
683
|
}
|
|
587
|
-
afterEach(store, key2) {
|
|
588
|
-
return Promise.resolve(fullAdapter.cleanupEach(store, key2));
|
|
684
|
+
afterEach(store, key2, artifactory) {
|
|
685
|
+
return Promise.resolve(fullAdapter.cleanupEach(store, key2, artifactory));
|
|
589
686
|
}
|
|
590
687
|
}(
|
|
591
688
|
safeFeatures,
|
|
@@ -594,6 +691,8 @@ var BaseTiposkripto = class {
|
|
|
594
691
|
testImplementation.givens[key],
|
|
595
692
|
initialValues
|
|
596
693
|
);
|
|
694
|
+
givenInstance._parent = outerThis;
|
|
695
|
+
return givenInstance;
|
|
597
696
|
};
|
|
598
697
|
return a;
|
|
599
698
|
},
|
|
@@ -603,8 +702,8 @@ var BaseTiposkripto = class {
|
|
|
603
702
|
(a, [key, whEn]) => {
|
|
604
703
|
a[key] = (...payload) => {
|
|
605
704
|
const whenInstance = new class extends BaseWhen {
|
|
606
|
-
async andWhen(store, whenCB, testResource) {
|
|
607
|
-
return await fullAdapter.execute(store, whenCB, testResource);
|
|
705
|
+
async andWhen(store, whenCB, testResource, artifactory) {
|
|
706
|
+
return await fullAdapter.execute(store, whenCB, testResource, artifactory);
|
|
608
707
|
}
|
|
609
708
|
}(`${key}: ${payload && payload.toString()}`, whEn(...payload));
|
|
610
709
|
return whenInstance;
|
|
@@ -617,8 +716,8 @@ var BaseTiposkripto = class {
|
|
|
617
716
|
(a, [key, thEn]) => {
|
|
618
717
|
a[key] = (...args) => {
|
|
619
718
|
const thenInstance = new class extends BaseThen {
|
|
620
|
-
async butThen(store, thenCB, testResource) {
|
|
621
|
-
return await fullAdapter.verify(store, thenCB, testResource);
|
|
719
|
+
async butThen(store, thenCB, testResource, artifactory) {
|
|
720
|
+
return await fullAdapter.verify(store, thenCB, testResource, artifactory);
|
|
622
721
|
}
|
|
623
722
|
}(`${key}: ${args && args.toString()}`, thEn(...args));
|
|
624
723
|
return thenInstance;
|
|
@@ -701,6 +800,57 @@ var BaseTiposkripto = class {
|
|
|
701
800
|
this.writeFileSync(reportJson, JSON.stringify(results));
|
|
702
801
|
});
|
|
703
802
|
}
|
|
803
|
+
// Create an artifactory that tracks context
|
|
804
|
+
createArtifactory(context = {}) {
|
|
805
|
+
return {
|
|
806
|
+
writeFileSync: (filename, payload) => {
|
|
807
|
+
let path = "";
|
|
808
|
+
const basePath = this.testResourceConfiguration?.fs || "testeranto";
|
|
809
|
+
if (context.suiteIndex !== void 0) {
|
|
810
|
+
path += `suite-${context.suiteIndex}/`;
|
|
811
|
+
}
|
|
812
|
+
if (context.givenKey) {
|
|
813
|
+
path += `given-${context.givenKey}/`;
|
|
814
|
+
}
|
|
815
|
+
if (context.whenIndex !== void 0) {
|
|
816
|
+
path += `when-${context.whenIndex} `;
|
|
817
|
+
} else if (context.thenIndex !== void 0) {
|
|
818
|
+
path += `then-${context.thenIndex} `;
|
|
819
|
+
}
|
|
820
|
+
path += filename;
|
|
821
|
+
if (!path.match(/\.[a-zA-Z0-9]+$/)) {
|
|
822
|
+
path += ".txt";
|
|
823
|
+
}
|
|
824
|
+
const fullPath = `${basePath}/${path}`;
|
|
825
|
+
this.writeFileSync(fullPath, payload);
|
|
826
|
+
},
|
|
827
|
+
screenshot: (filename, payload) => {
|
|
828
|
+
let path = "";
|
|
829
|
+
const basePath = this.testResourceConfiguration?.fs || "testeranto";
|
|
830
|
+
if (context.suiteIndex !== void 0) {
|
|
831
|
+
path += `suite-${context.suiteIndex}/`;
|
|
832
|
+
}
|
|
833
|
+
if (context.givenKey) {
|
|
834
|
+
path += `given-${context.givenKey}/`;
|
|
835
|
+
}
|
|
836
|
+
if (context.whenIndex !== void 0) {
|
|
837
|
+
path += `when-${context.whenIndex} `;
|
|
838
|
+
} else if (context.thenIndex !== void 0) {
|
|
839
|
+
path += `then-${context.thenIndex} `;
|
|
840
|
+
}
|
|
841
|
+
path += filename;
|
|
842
|
+
if (!path.match(/\.[a-zA-Z0-9]+$/)) {
|
|
843
|
+
path += ".png";
|
|
844
|
+
}
|
|
845
|
+
const fullPath = `${basePath}/${path}`;
|
|
846
|
+
if (this.screenshot) {
|
|
847
|
+
this.screenshot(fullPath, payload);
|
|
848
|
+
} else {
|
|
849
|
+
this.writeFileSync(fullPath, payload);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
704
854
|
async receiveTestResourceConfig(testResourceConfig) {
|
|
705
855
|
if (this.testJobs && this.testJobs.length > 0) {
|
|
706
856
|
return this.testJobs[0].receiveTestResourceConfig(testResourceConfig);
|