testeranto.tiposkripto 0.1.24 → 0.1.26

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