testeranto.tiposkripto 0.2.21 → 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 CHANGED
@@ -1,3 +1,16 @@
1
1
  # tiposkripto
2
2
 
3
3
  ## the typescript implementation of testeranto
4
+
5
+ ## Supported Patterns
6
+
7
+ 1. **BDD (Behavior Driven Development)**: Given, When, Then (3 verbs) - fully implemented and production-ready
8
+ 2. **TDT (Table-Driven Testing)**: Value, Should, Expected (3 verbs) - core classes implemented, integration in progress
9
+ 3. **Describe-It Pattern (AAA/Arrange-Act-Assert)**: Describe, It (2 verbs) - core classes implemented, integration in progress
10
+
11
+ ## Status
12
+
13
+ - BDD pattern is fully functional and production-ready (uses 3 verbs: Given, When, Then)
14
+ - TDT pattern has core classes (BaseValue, BaseShould, BaseExpected) and specification helpers (createTDTSpecification, Confirm) available (uses 3 verbs)
15
+ - Describe-It pattern (AAA) has core classes (BaseDescribe, BaseIt) and specification helpers (createDescribeItSpecification, DescribeIt) available (uses 2 verbs)
16
+ - BDD is recommended for production use; TDT and Describe-It patterns are available for experimentation
@@ -179,113 +179,6 @@ var BaseSetup = class {
179
179
  }
180
180
  };
181
181
 
182
- // src/BaseAction.ts
183
- var BaseAction = class {
184
- constructor(name, actionCB) {
185
- this.error = null;
186
- this.artifacts = [];
187
- this.name = name;
188
- this.actionCB = actionCB;
189
- }
190
- addArtifact(path2) {
191
- if (typeof path2 !== "string") {
192
- throw new Error(
193
- `[ARTIFACT ERROR] Expected string, got ${typeof path2}: ${JSON.stringify(
194
- path2
195
- )}`
196
- );
197
- }
198
- const normalizedPath = path2.replace(/\\/g, "/");
199
- this.artifacts.push(normalizedPath);
200
- }
201
- toObj() {
202
- const obj = {
203
- name: this.name,
204
- status: this.status,
205
- error: this.error ? `${this.error.name}: ${this.error.message}
206
- ${this.error.stack}` : null,
207
- artifacts: this.artifacts
208
- };
209
- return obj;
210
- }
211
- async test(store, testResourceConfiguration, artifactory) {
212
- try {
213
- const result = await this.performAction(
214
- store,
215
- this.actionCB,
216
- testResourceConfiguration,
217
- artifactory
218
- );
219
- this.status = true;
220
- return result;
221
- } catch (e) {
222
- this.status = false;
223
- this.error = e;
224
- throw e;
225
- }
226
- }
227
- };
228
-
229
- // src/BaseCheck.ts
230
- var BaseCheck = class {
231
- constructor(name, checkCB) {
232
- this.artifacts = [];
233
- this.name = name;
234
- this.checkCB = checkCB;
235
- this.error = false;
236
- this.artifacts = [];
237
- }
238
- addArtifact(path2) {
239
- if (typeof path2 !== "string") {
240
- throw new Error(
241
- `[ARTIFACT ERROR] Expected string, got ${typeof path2}: ${JSON.stringify(
242
- path2
243
- )}`
244
- );
245
- }
246
- const normalizedPath = path2.replace(/\\/g, "/");
247
- this.artifacts.push(normalizedPath);
248
- }
249
- toObj() {
250
- const obj = {
251
- name: this.name,
252
- error: this.error,
253
- artifacts: this.artifacts,
254
- status: this.status
255
- };
256
- return obj;
257
- }
258
- async test(store, testResourceConfiguration, filepath, artifactory) {
259
- const addArtifact = this.addArtifact.bind(this);
260
- try {
261
- const x = await this.verifyCheck(
262
- store,
263
- async (s) => {
264
- try {
265
- if (typeof this.checkCB === "function") {
266
- const result = await this.checkCB(s);
267
- return result;
268
- } else {
269
- return this.checkCB;
270
- }
271
- } catch (e) {
272
- this.error = true;
273
- throw e;
274
- }
275
- },
276
- testResourceConfiguration,
277
- artifactory
278
- );
279
- this.status = true;
280
- return x;
281
- } catch (e) {
282
- this.status = false;
283
- this.error = true;
284
- throw e;
285
- }
286
- }
287
- };
288
-
289
182
  // src/BaseGiven.ts
290
183
  var BaseGiven = class extends BaseSetup {
291
184
  constructor(features, whens, thens, givenCB, initialValues) {
@@ -554,6 +447,53 @@ var BaseGiven = class extends BaseSetup {
554
447
  }
555
448
  };
556
449
 
450
+ // src/BaseAction.ts
451
+ var BaseAction = class {
452
+ constructor(name, actionCB) {
453
+ this.error = null;
454
+ this.artifacts = [];
455
+ this.name = name;
456
+ this.actionCB = actionCB;
457
+ }
458
+ addArtifact(path2) {
459
+ if (typeof path2 !== "string") {
460
+ throw new Error(
461
+ `[ARTIFACT ERROR] Expected string, got ${typeof path2}: ${JSON.stringify(
462
+ path2
463
+ )}`
464
+ );
465
+ }
466
+ const normalizedPath = path2.replace(/\\/g, "/");
467
+ this.artifacts.push(normalizedPath);
468
+ }
469
+ toObj() {
470
+ const obj = {
471
+ name: this.name,
472
+ status: this.status,
473
+ error: this.error ? `${this.error.name}: ${this.error.message}
474
+ ${this.error.stack}` : null,
475
+ artifacts: this.artifacts
476
+ };
477
+ return obj;
478
+ }
479
+ async test(store, testResourceConfiguration, artifactory) {
480
+ try {
481
+ const result = await this.performAction(
482
+ store,
483
+ this.actionCB,
484
+ testResourceConfiguration,
485
+ artifactory
486
+ );
487
+ this.status = true;
488
+ return result;
489
+ } catch (e) {
490
+ this.status = false;
491
+ this.error = e;
492
+ throw e;
493
+ }
494
+ }
495
+ };
496
+
557
497
  // src/BaseWhen.ts
558
498
  var BaseWhen = class extends BaseAction {
559
499
  constructor(name, whenCB) {
@@ -582,6 +522,66 @@ var BaseWhen = class extends BaseAction {
582
522
  }
583
523
  };
584
524
 
525
+ // src/BaseCheck.ts
526
+ var BaseCheck = class {
527
+ constructor(name, checkCB) {
528
+ this.artifacts = [];
529
+ this.name = name;
530
+ this.checkCB = checkCB;
531
+ this.error = false;
532
+ this.artifacts = [];
533
+ }
534
+ addArtifact(path2) {
535
+ if (typeof path2 !== "string") {
536
+ throw new Error(
537
+ `[ARTIFACT ERROR] Expected string, got ${typeof path2}: ${JSON.stringify(
538
+ path2
539
+ )}`
540
+ );
541
+ }
542
+ const normalizedPath = path2.replace(/\\/g, "/");
543
+ this.artifacts.push(normalizedPath);
544
+ }
545
+ toObj() {
546
+ const obj = {
547
+ name: this.name,
548
+ error: this.error,
549
+ artifacts: this.artifacts,
550
+ status: this.status
551
+ };
552
+ return obj;
553
+ }
554
+ async test(store, testResourceConfiguration, filepath, artifactory) {
555
+ const addArtifact = this.addArtifact.bind(this);
556
+ try {
557
+ const x = await this.verifyCheck(
558
+ store,
559
+ async (s) => {
560
+ try {
561
+ if (typeof this.checkCB === "function") {
562
+ const result = await this.checkCB(s);
563
+ return result;
564
+ } else {
565
+ return this.checkCB;
566
+ }
567
+ } catch (e) {
568
+ this.error = true;
569
+ throw e;
570
+ }
571
+ },
572
+ testResourceConfiguration,
573
+ artifactory
574
+ );
575
+ this.status = true;
576
+ return x;
577
+ } catch (e) {
578
+ this.status = false;
579
+ this.error = true;
580
+ throw e;
581
+ }
582
+ }
583
+ };
584
+
585
585
  // src/BaseThen.ts
586
586
  var BaseThen = class extends BaseCheck {
587
587
  constructor(name, thenCB) {
@@ -900,7 +900,7 @@ var BaseTiposkripto = class {
900
900
  }
901
901
  const classySuites = Object.entries(testImplementation.suites).reduce(
902
902
  (a, [key], index) => {
903
- a[key] = (somestring, givens) => {
903
+ a[key] = (somestring, setups) => {
904
904
  const capturedFullAdapter = fullAdapter;
905
905
  return new class extends BaseSuite {
906
906
  afterAll(store, artifactory) {
@@ -924,15 +924,16 @@ var BaseTiposkripto = class {
924
924
  async setup(s, artifactory, tr) {
925
925
  return capturedFullAdapter.prepareAll?.(s, tr, artifactory) ?? s;
926
926
  }
927
- }(somestring, index, givens, instance);
927
+ }(somestring, index, setups, instance);
928
928
  };
929
929
  return a;
930
930
  },
931
931
  {}
932
932
  );
933
- const classyGivens = Object.entries(testImplementation.givens).reduce(
934
- (a, [key, g]) => {
935
- a[key] = (features, whens, thens, gcb, initialValues) => {
933
+ const classyGivens = {};
934
+ if (testImplementation.givens) {
935
+ Object.entries(testImplementation.givens).forEach(([key, g]) => {
936
+ classyGivens[key] = (features, whens, thens, gcb, initialValues) => {
936
937
  const safeFeatures = Array.isArray(features) ? [...features] : [];
937
938
  const safeWhens = Array.isArray(whens) ? [...whens] : [];
938
939
  const safeThens = Array.isArray(thens) ? [...thens] : [];
@@ -967,16 +968,14 @@ var BaseTiposkripto = class {
967
968
  if (givenInstance.setParent) {
968
969
  givenInstance.setParent(instance);
969
970
  }
970
- console.log(`[BaseTiposkripto] Set _parent for given instance`, givenInstance);
971
971
  return givenInstance;
972
972
  };
973
- return a;
974
- },
975
- {}
976
- );
977
- const classyWhens = Object.entries(testImplementation.whens).reduce(
978
- (a, [key, whEn]) => {
979
- a[key] = (...payload) => {
973
+ });
974
+ }
975
+ const classyWhens = {};
976
+ if (testImplementation.whens) {
977
+ Object.entries(testImplementation.whens).forEach(([key, whEn]) => {
978
+ classyWhens[key] = (...payload) => {
980
979
  const capturedFullAdapter = fullAdapter;
981
980
  const whenInstance = new class extends BaseWhen {
982
981
  async andWhen(store, whenCB, testResource, artifactory) {
@@ -990,37 +989,86 @@ var BaseTiposkripto = class {
990
989
  }(`${key}: ${payload && payload.toString()}`, whEn(...payload));
991
990
  return whenInstance;
992
991
  };
993
- return a;
994
- },
995
- {}
996
- );
997
- const classyThens = Object.entries(testImplementation.thens).reduce(
998
- (a, [key, thEn]) => {
999
- a[key] = (...args) => {
992
+ });
993
+ }
994
+ const classyThens = {};
995
+ if (testImplementation.thens) {
996
+ Object.entries(testImplementation.thens).forEach(([key, thEn]) => {
997
+ classyThens[key] = (...args) => {
1000
998
  const capturedFullAdapter = fullAdapter;
1001
999
  const thenInstance = new class extends BaseThen {
1002
- verifyCheck(store, checkCB, testResourceConfiguration2) {
1003
- throw new Error("Method not implemented.");
1004
- }
1005
- async butThen(store, thenCB, testResource, artifactory) {
1006
- return await capturedFullAdapter.verify(
1000
+ verifyCheck(store, checkCB, testResourceConfiguration2, artifactory) {
1001
+ return capturedFullAdapter.verify(
1007
1002
  store,
1008
- thenCB,
1009
- testResource,
1003
+ checkCB,
1004
+ testResourceConfiguration2,
1010
1005
  artifactory
1011
1006
  );
1012
1007
  }
1013
1008
  }(`${key}: ${args && args.toString()}`, thEn(...args));
1014
1009
  return thenInstance;
1015
1010
  };
1016
- return a;
1017
- },
1018
- {}
1019
- );
1011
+ });
1012
+ }
1013
+ const classyValues = {};
1014
+ if (testImplementation.values) {
1015
+ Object.entries(testImplementation.values).forEach(([key, val]) => {
1016
+ classyValues[key] = (features, tableRows, confirmCB, initialValues) => {
1017
+ return new BaseValue(
1018
+ features,
1019
+ tableRows,
1020
+ confirmCB,
1021
+ initialValues
1022
+ );
1023
+ };
1024
+ });
1025
+ }
1026
+ const classyShoulds = {};
1027
+ if (testImplementation.shoulds) {
1028
+ Object.entries(testImplementation.shoulds).forEach(([key, shouldCB]) => {
1029
+ classyShoulds[key] = (...args) => {
1030
+ return new BaseShould(`${key}: ${args && args.toString()}`, shouldCB(...args));
1031
+ };
1032
+ });
1033
+ }
1034
+ const classyExpecteds = {};
1035
+ if (testImplementation.expecteds) {
1036
+ Object.entries(testImplementation.expecteds).forEach(([key, expectedCB]) => {
1037
+ classyExpecteds[key] = (...args) => {
1038
+ return new BaseExpected(`${key}: ${args && args.toString()}`, expectedCB(...args));
1039
+ };
1040
+ });
1041
+ }
1042
+ const classyDescribes = {};
1043
+ if (testImplementation.describes) {
1044
+ Object.entries(testImplementation.describes).forEach(([key, desc]) => {
1045
+ classyDescribes[key] = (features, its, describeCB, initialValues) => {
1046
+ return new BaseDescribe(
1047
+ features,
1048
+ its,
1049
+ describeCB,
1050
+ initialValues
1051
+ );
1052
+ };
1053
+ });
1054
+ }
1055
+ const classyIts = {};
1056
+ if (testImplementation.its) {
1057
+ Object.entries(testImplementation.its).forEach(([key, itCB]) => {
1058
+ classyIts[key] = (...args) => {
1059
+ return new BaseIt(`${key}: ${args && args.toString()}`, itCB(...args));
1060
+ };
1061
+ });
1062
+ }
1020
1063
  this.suitesOverrides = classySuites;
1021
1064
  this.givenOverrides = classyGivens;
1022
1065
  this.whenOverrides = classyWhens;
1023
1066
  this.thenOverrides = classyThens;
1067
+ this.valuesOverrides = classyValues;
1068
+ this.shouldsOverrides = classyShoulds;
1069
+ this.expectedsOverrides = classyExpecteds;
1070
+ this.describesOverrides = classyDescribes;
1071
+ this.itsOverrides = classyIts;
1024
1072
  this.testResourceRequirement = testResourceRequirement;
1025
1073
  this.testSpecification = testSpecification;
1026
1074
  this.specs = testSpecification(
@@ -1116,97 +1164,10 @@ var BaseTiposkripto = class {
1116
1164
  const fullPath = `${basePathClean}/${pathClean}`;
1117
1165
  console.log("[Artifactory] Full path:", fullPath);
1118
1166
  this.writeFileSync(fullPath, payload);
1119
- },
1120
- screenshot: (filename, payload) => {
1121
- let path2 = "";
1122
- const basePath = this.testResourceConfiguration?.fs || "testeranto";
1123
- console.log("[Artifactory Screenshot] Base path:", basePath);
1124
- console.log("[Artifactory Screenshot] Context:", context);
1125
- if (context.suiteIndex !== void 0) {
1126
- path2 += `suite-${context.suiteIndex}/`;
1127
- }
1128
- if (context.givenKey) {
1129
- path2 += `given-${context.givenKey}/`;
1130
- }
1131
- if (context.whenIndex !== void 0) {
1132
- path2 += `when-${context.whenIndex} `;
1133
- } else if (context.thenIndex !== void 0) {
1134
- path2 += `then-${context.thenIndex} `;
1135
- }
1136
- path2 += filename;
1137
- if (!path2.match(/\.[a-zA-Z0-9]+$/)) {
1138
- path2 += ".png";
1139
- }
1140
- const basePathClean = basePath.replace(/\/$/, "");
1141
- const pathClean = path2.replace(/^\//, "");
1142
- const fullPath = `${basePathClean}/${pathClean}`;
1143
- console.log("[Artifactory Screenshot] Full path:", fullPath);
1144
- if (typeof this.screenshot === "function") {
1145
- this.screenshot(fullPath, payload || "");
1146
- } else {
1147
- this.writeFileSync(fullPath, payload || "");
1148
- }
1149
- },
1150
- openScreencast: async (filename) => {
1151
- let path2 = "";
1152
- const basePath = this.testResourceConfiguration?.fs || "testeranto";
1153
- console.log("[Artifactory openScreencast] Base path:", basePath);
1154
- console.log("[Artifactory openScreencast] Context:", context);
1155
- if (context.suiteIndex !== void 0) {
1156
- path2 += `suite-${context.suiteIndex}/`;
1157
- }
1158
- if (context.givenKey) {
1159
- path2 += `given-${context.givenKey}/`;
1160
- }
1161
- if (context.whenIndex !== void 0) {
1162
- path2 += `when-${context.whenIndex} `;
1163
- } else if (context.thenIndex !== void 0) {
1164
- path2 += `then-${context.thenIndex} `;
1165
- }
1166
- path2 += filename;
1167
- if (!path2.match(/\.[a-zA-Z0-9]+$/)) {
1168
- path2 += ".webm";
1169
- }
1170
- const basePathClean = basePath.replace(/\/$/, "");
1171
- const pathClean = path2.replace(/^\//, "");
1172
- const fullPath = `${basePathClean}/${pathClean}`;
1173
- console.log("[Artifactory openScreencast] Full path:", fullPath);
1174
- if (typeof this.openScreencast === "function") {
1175
- await this.openScreencast(fullPath);
1176
- } else {
1177
- console.log("[Artifactory openScreencast] Method not available");
1178
- }
1179
- },
1180
- closeScreencast: async (filename) => {
1181
- let path2 = "";
1182
- const basePath = this.testResourceConfiguration?.fs || "testeranto";
1183
- console.log("[Artifactory closeScreencast] Base path:", basePath);
1184
- console.log("[Artifactory closeScreencast] Context:", context);
1185
- if (context.suiteIndex !== void 0) {
1186
- path2 += `suite-${context.suiteIndex}/`;
1187
- }
1188
- if (context.givenKey) {
1189
- path2 += `given-${context.givenKey}/`;
1190
- }
1191
- if (context.whenIndex !== void 0) {
1192
- path2 += `when-${context.whenIndex} `;
1193
- } else if (context.thenIndex !== void 0) {
1194
- path2 += `then-${context.thenIndex} `;
1195
- }
1196
- path2 += filename;
1197
- if (!path2.match(/\.[a-zA-Z0-9]+$/)) {
1198
- path2 += ".webm";
1199
- }
1200
- const basePathClean = basePath.replace(/\/$/, "");
1201
- const pathClean = path2.replace(/^\//, "");
1202
- const fullPath = `${basePathClean}/${pathClean}`;
1203
- console.log("[Artifactory closeScreencast] Full path:", fullPath);
1204
- if (typeof this.closeScreencast === "function") {
1205
- await this.closeScreencast(fullPath);
1206
- } else {
1207
- console.log("[Artifactory closeScreencast] Method not available");
1208
- }
1209
1167
  }
1168
+ // screenshot, openScreencast, and closeScreencast are only applicable to web runtime
1169
+ // They should be implemented in WebTiposkripto and will be added to the artifactory there
1170
+ // For non-web runtimes, these methods will not be available
1210
1171
  };
1211
1172
  }
1212
1173
  async receiveTestResourceConfig(testResourceConfig) {
@@ -1280,6 +1241,8 @@ var NodeTiposkripto = class extends BaseTiposkripto {
1280
1241
  }
1281
1242
  fs.writeFileSync(filename, payload);
1282
1243
  }
1244
+ // screenshot, openScreencast, and closeScreencast are not applicable to Node runtime
1245
+ // These methods are only for web runtime to capture visual artifacts in browser environments
1283
1246
  };
1284
1247
  var tiposkripto = async (input, testSpecification, testImplementation, testAdapter, testResourceRequirement = defaultTestResourceRequirement) => {
1285
1248
  try {