testeranto.tiposkripto 0.2.1 → 0.2.3

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.
@@ -1,41 +1,15 @@
1
1
  // src/Node.ts
2
2
  import fs from "fs";
3
3
 
4
- // src/index.ts
5
- var BaseAdapter = () => ({
6
- beforeAll: async (input, testResource) => {
7
- return input;
8
- },
9
- beforeEach: async function(subject, initializer, testResource, initialValues) {
10
- return subject;
11
- },
12
- afterEach: async (store, key) => Promise.resolve(store),
13
- afterAll: (store) => void 0,
14
- butThen: async (store, thenCb, testResource) => {
15
- return thenCb(store);
16
- },
17
- andWhen: async (store, whenCB, testResource) => {
18
- return whenCB(store);
19
- },
20
- assertThis: (x) => x
21
- });
22
- var DefaultAdapter = (p) => {
23
- const base = BaseAdapter();
24
- return {
25
- ...base,
26
- ...p
27
- };
28
- };
29
-
30
- // src/BaseGiven.ts
31
- var BaseGiven = class {
32
- constructor(features, whens, thens, givenCB, initialValues) {
4
+ // src/BaseSetup.ts
5
+ var BaseSetup = class {
6
+ constructor(features, actions, checks, setupCB, initialValues) {
33
7
  this.artifacts = [];
34
8
  this.fails = 0;
35
9
  this.features = features;
36
- this.whens = whens;
37
- this.thens = thens;
38
- this.givenCB = givenCB;
10
+ this.actions = actions;
11
+ this.checks = checks;
12
+ this.setupCB = setupCB;
39
13
  this.initialValues = initialValues;
40
14
  this.fails = 0;
41
15
  this.failed = false;
@@ -55,6 +29,214 @@ var BaseGiven = class {
55
29
  const normalizedPath = path.replace(/\\/g, "/");
56
30
  this.artifacts.push(normalizedPath);
57
31
  }
32
+ toObj() {
33
+ return {
34
+ key: this.key,
35
+ actions: (this.actions || []).map((a) => {
36
+ if (a && a.toObj) return a.toObj();
37
+ console.error("Action step is not as expected!", JSON.stringify(a));
38
+ return {};
39
+ }),
40
+ checks: (this.checks || []).map((c) => c && c.toObj ? c.toObj() : {}),
41
+ error: this.error ? [this.error, this.error.stack] : null,
42
+ failed: this.failed,
43
+ features: this.features || [],
44
+ artifacts: this.artifacts,
45
+ status: this.status
46
+ };
47
+ }
48
+ async afterEach(store, key, artifactory) {
49
+ return store;
50
+ }
51
+ async setup(subject, key, testResourceConfiguration, tester, artifactory, suiteNdx) {
52
+ this.key = key;
53
+ this.fails = 0;
54
+ const actualArtifactory = artifactory || ((fPath, value) => {
55
+ });
56
+ const setupArtifactory = (fPath, value) => actualArtifactory(`setup-${key}/${fPath}`, value);
57
+ try {
58
+ this.store = await this.setupThat(
59
+ subject,
60
+ testResourceConfiguration,
61
+ setupArtifactory,
62
+ this.setupCB,
63
+ this.initialValues
64
+ );
65
+ this.status = true;
66
+ } catch (e) {
67
+ this.status = false;
68
+ this.failed = true;
69
+ this.fails++;
70
+ this.error = e;
71
+ return this.store;
72
+ }
73
+ try {
74
+ for (const [actionNdx, actionStep] of (this.actions || []).entries()) {
75
+ try {
76
+ this.store = await actionStep.test(
77
+ this.store,
78
+ testResourceConfiguration
79
+ );
80
+ } catch (e) {
81
+ this.failed = true;
82
+ this.fails++;
83
+ this.error = e;
84
+ }
85
+ }
86
+ for (const [checkNdx, checkStep] of this.checks.entries()) {
87
+ try {
88
+ const filepath = suiteNdx !== void 0 ? `suite-${suiteNdx}/setup-${key}/check-${checkNdx}` : `setup-${key}/check-${checkNdx}`;
89
+ const t = await checkStep.test(
90
+ this.store,
91
+ testResourceConfiguration,
92
+ filepath
93
+ );
94
+ tester(t);
95
+ } catch (e) {
96
+ this.failed = true;
97
+ this.fails++;
98
+ this.error = e;
99
+ }
100
+ }
101
+ } catch (e) {
102
+ this.error = e;
103
+ this.failed = true;
104
+ this.fails++;
105
+ } finally {
106
+ try {
107
+ await this.afterEach(this.store, this.key, setupArtifactory);
108
+ } catch (e) {
109
+ this.failed = true;
110
+ this.fails++;
111
+ this.error = e;
112
+ }
113
+ }
114
+ return this.store;
115
+ }
116
+ };
117
+
118
+ // src/BaseAction.ts
119
+ var BaseAction = class {
120
+ constructor(name, actionCB) {
121
+ this.artifacts = [];
122
+ this.name = name;
123
+ this.actionCB = actionCB;
124
+ }
125
+ addArtifact(path) {
126
+ if (typeof path !== "string") {
127
+ throw new Error(
128
+ `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
129
+ path
130
+ )}`
131
+ );
132
+ }
133
+ const normalizedPath = path.replace(/\\/g, "/");
134
+ this.artifacts.push(normalizedPath);
135
+ }
136
+ toObj() {
137
+ const obj = {
138
+ name: this.name,
139
+ status: this.status,
140
+ error: this.error ? `${this.error.name}: ${this.error.message}
141
+ ${this.error.stack}` : null,
142
+ artifacts: this.artifacts
143
+ };
144
+ return obj;
145
+ }
146
+ async test(store, testResourceConfiguration) {
147
+ try {
148
+ const result = await this.performAction(
149
+ store,
150
+ this.actionCB,
151
+ testResourceConfiguration
152
+ );
153
+ this.status = true;
154
+ return result;
155
+ } catch (e) {
156
+ this.status = false;
157
+ this.error = e;
158
+ throw e;
159
+ }
160
+ }
161
+ };
162
+
163
+ // src/BaseCheck.ts
164
+ var BaseCheck = class {
165
+ constructor(name, checkCB) {
166
+ this.artifacts = [];
167
+ this.name = name;
168
+ this.checkCB = checkCB;
169
+ this.error = false;
170
+ this.artifacts = [];
171
+ }
172
+ addArtifact(path) {
173
+ if (typeof path !== "string") {
174
+ throw new Error(
175
+ `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
176
+ path
177
+ )}`
178
+ );
179
+ }
180
+ const normalizedPath = path.replace(/\\/g, "/");
181
+ this.artifacts.push(normalizedPath);
182
+ }
183
+ toObj() {
184
+ const obj = {
185
+ name: this.name,
186
+ error: this.error,
187
+ artifacts: this.artifacts,
188
+ status: this.status
189
+ };
190
+ return obj;
191
+ }
192
+ async test(store, testResourceConfiguration, filepath) {
193
+ const addArtifact = this.addArtifact.bind(this);
194
+ try {
195
+ const x = await this.verifyCheck(
196
+ store,
197
+ async (s) => {
198
+ try {
199
+ if (typeof this.checkCB === "function") {
200
+ const result = await this.checkCB(s);
201
+ return result;
202
+ } else {
203
+ return this.checkCB;
204
+ }
205
+ } catch (e) {
206
+ this.error = true;
207
+ throw e;
208
+ }
209
+ },
210
+ testResourceConfiguration
211
+ );
212
+ this.status = true;
213
+ return x;
214
+ } catch (e) {
215
+ this.status = false;
216
+ this.error = true;
217
+ throw e;
218
+ }
219
+ }
220
+ };
221
+
222
+ // src/BaseGiven.ts
223
+ var BaseGiven = class extends BaseSetup {
224
+ constructor(features, whens, thens, givenCB, initialValues) {
225
+ super(features, whens, thens, givenCB, initialValues);
226
+ this.artifacts = [];
227
+ this.fails = 0;
228
+ }
229
+ addArtifact(path) {
230
+ if (typeof path !== "string") {
231
+ throw new Error(
232
+ `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
233
+ path
234
+ )}`
235
+ );
236
+ }
237
+ const normalizedPath = path.replace(/\\/g, "/");
238
+ this.artifacts.push(normalizedPath);
239
+ }
58
240
  beforeAll(store) {
59
241
  return store;
60
242
  }
@@ -74,6 +256,10 @@ var BaseGiven = class {
74
256
  status: this.status
75
257
  };
76
258
  }
259
+ // Implement BaseSetup's abstract method
260
+ async setupThat(subject, testResourceConfiguration, artifactory, setupCB, initialValues) {
261
+ return this.givenThat(subject, testResourceConfiguration, artifactory, setupCB, initialValues);
262
+ }
77
263
  async afterEach(store, key, artifactory) {
78
264
  return store;
79
265
  }
@@ -145,6 +331,141 @@ var BaseGiven = class {
145
331
  }
146
332
  };
147
333
 
334
+ // src/BaseWhen.ts
335
+ var BaseWhen = class extends BaseAction {
336
+ constructor(name, whenCB) {
337
+ super(name, whenCB);
338
+ this.artifacts = [];
339
+ }
340
+ addArtifact(path) {
341
+ if (typeof path !== "string") {
342
+ throw new Error(
343
+ `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
344
+ path
345
+ )}`
346
+ );
347
+ }
348
+ const normalizedPath = path.replace(/\\/g, "/");
349
+ this.artifacts.push(normalizedPath);
350
+ }
351
+ // Implement BaseAction's abstract method
352
+ async performAction(store, actionCB, testResource) {
353
+ return this.andWhen(store, actionCB, testResource);
354
+ }
355
+ toObj() {
356
+ const obj = {
357
+ name: this.name,
358
+ status: this.status,
359
+ error: this.error ? `${this.error.name}: ${this.error.message}
360
+ ${this.error.stack}` : null,
361
+ artifacts: this.artifacts
362
+ };
363
+ return obj;
364
+ }
365
+ async test(store, testResourceConfiguration) {
366
+ try {
367
+ const result = await this.andWhen(
368
+ store,
369
+ this.whenCB,
370
+ testResourceConfiguration
371
+ // proxiedPm
372
+ );
373
+ this.status = true;
374
+ return result;
375
+ } catch (e) {
376
+ this.status = false;
377
+ this.error = e;
378
+ throw e;
379
+ }
380
+ }
381
+ };
382
+
383
+ // src/BaseThen.ts
384
+ var BaseThen = class extends BaseCheck {
385
+ constructor(name, thenCB) {
386
+ this.artifacts = [];
387
+ this.name = name;
388
+ this.thenCB = thenCB;
389
+ this.error = false;
390
+ this.artifacts = [];
391
+ }
392
+ addArtifact(path) {
393
+ if (typeof path !== "string") {
394
+ throw new Error(
395
+ `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
396
+ path
397
+ )}`
398
+ );
399
+ }
400
+ const normalizedPath = path.replace(/\\/g, "/");
401
+ this.artifacts.push(normalizedPath);
402
+ }
403
+ toObj() {
404
+ const obj = {
405
+ name: this.name,
406
+ error: this.error,
407
+ artifacts: this.artifacts,
408
+ status: this.status
409
+ };
410
+ return obj;
411
+ }
412
+ async test(store, testResourceConfiguration, filepath) {
413
+ const addArtifact = this.addArtifact.bind(this);
414
+ try {
415
+ const x = await this.butThen(
416
+ store,
417
+ async (s) => {
418
+ try {
419
+ if (typeof this.thenCB === "function") {
420
+ const result = await this.thenCB(s);
421
+ return result;
422
+ } else {
423
+ return this.thenCB;
424
+ }
425
+ } catch (e) {
426
+ this.error = true;
427
+ throw e;
428
+ }
429
+ },
430
+ testResourceConfiguration
431
+ // proxiedPm
432
+ );
433
+ this.status = true;
434
+ return x;
435
+ } catch (e) {
436
+ this.status = false;
437
+ this.error = true;
438
+ throw e;
439
+ }
440
+ }
441
+ };
442
+
443
+ // src/index.ts
444
+ var BaseAdapter = () => ({
445
+ prepareAll: async (input, testResource) => {
446
+ return input;
447
+ },
448
+ prepareEach: async function(subject, initializer, testResource, initialValues) {
449
+ return subject;
450
+ },
451
+ cleanupEach: async (store, key) => Promise.resolve(store),
452
+ cleanupAll: (store) => void 0,
453
+ verify: async (store, checkCb, testResource) => {
454
+ return checkCb(store);
455
+ },
456
+ execute: async (store, actionCB, testResource) => {
457
+ return actionCB(store);
458
+ },
459
+ assert: (x) => x
460
+ });
461
+ var DefaultAdapter = (p) => {
462
+ const base = BaseAdapter();
463
+ return {
464
+ ...base,
465
+ ...p
466
+ };
467
+ };
468
+
148
469
  // src/BaseSuite.ts
149
470
  var BaseSuite = class {
150
471
  constructor(name, index, givens = {}) {
@@ -254,112 +575,6 @@ var BaseSuite = class {
254
575
  }
255
576
  };
256
577
 
257
- // src/BaseThen.ts
258
- var BaseThen = class {
259
- constructor(name, thenCB) {
260
- this.artifacts = [];
261
- this.name = name;
262
- this.thenCB = thenCB;
263
- this.error = false;
264
- this.artifacts = [];
265
- }
266
- addArtifact(path) {
267
- if (typeof path !== "string") {
268
- throw new Error(
269
- `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
270
- path
271
- )}`
272
- );
273
- }
274
- const normalizedPath = path.replace(/\\/g, "/");
275
- this.artifacts.push(normalizedPath);
276
- }
277
- toObj() {
278
- const obj = {
279
- name: this.name,
280
- error: this.error,
281
- artifacts: this.artifacts,
282
- status: this.status
283
- };
284
- return obj;
285
- }
286
- async test(store, testResourceConfiguration, filepath) {
287
- const addArtifact = this.addArtifact.bind(this);
288
- try {
289
- const x = await this.butThen(
290
- store,
291
- async (s) => {
292
- try {
293
- if (typeof this.thenCB === "function") {
294
- const result = await this.thenCB(s);
295
- return result;
296
- } else {
297
- return this.thenCB;
298
- }
299
- } catch (e) {
300
- this.error = true;
301
- throw e;
302
- }
303
- },
304
- testResourceConfiguration
305
- // proxiedPm
306
- );
307
- this.status = true;
308
- return x;
309
- } catch (e) {
310
- this.status = false;
311
- this.error = true;
312
- throw e;
313
- }
314
- }
315
- };
316
-
317
- // src/BaseWhen.ts
318
- var BaseWhen = class {
319
- constructor(name, whenCB) {
320
- this.artifacts = [];
321
- this.name = name;
322
- this.whenCB = whenCB;
323
- }
324
- addArtifact(path) {
325
- if (typeof path !== "string") {
326
- throw new Error(
327
- `[ARTIFACT ERROR] Expected string, got ${typeof path}: ${JSON.stringify(
328
- path
329
- )}`
330
- );
331
- }
332
- const normalizedPath = path.replace(/\\/g, "/");
333
- this.artifacts.push(normalizedPath);
334
- }
335
- toObj() {
336
- const obj = {
337
- name: this.name,
338
- status: this.status,
339
- error: this.error ? `${this.error.name}: ${this.error.message}
340
- ${this.error.stack}` : null,
341
- artifacts: this.artifacts
342
- };
343
- return obj;
344
- }
345
- async test(store, testResourceConfiguration) {
346
- try {
347
- const result = await this.andWhen(
348
- store,
349
- this.whenCB,
350
- testResourceConfiguration
351
- // proxiedPm
352
- );
353
- this.status = true;
354
- return result;
355
- } catch (e) {
356
- this.status = false;
357
- this.error = e;
358
- throw e;
359
- }
360
- }
361
- };
362
-
363
578
  // src/types.ts
364
579
  var defaultTestResourceRequirement = {
365
580
  ports: 0
@@ -384,13 +599,13 @@ var BaseTiposkripto = class {
384
599
  a[key] = (somestring, givens) => {
385
600
  return new class extends BaseSuite {
386
601
  afterAll(store) {
387
- return fullAdapter.afterAll(store);
602
+ return fullAdapter.cleanupAll(store);
388
603
  }
389
604
  assertThat(t) {
390
- return fullAdapter.assertThis(t);
605
+ return fullAdapter.assert(t);
391
606
  }
392
607
  async setup(s, tr) {
393
- return fullAdapter.beforeAll?.(s, tr) ?? s;
608
+ return fullAdapter.prepareAll?.(s, tr) ?? s;
394
609
  }
395
610
  }(somestring, index, givens);
396
611
  };
@@ -406,7 +621,7 @@ var BaseTiposkripto = class {
406
621
  const safeThens = Array.isArray(thens) ? [...thens] : [];
407
622
  return new class extends BaseGiven {
408
623
  async givenThat(subject, testResource, initializer, initialValues2) {
409
- return fullAdapter.beforeEach(
624
+ return fullAdapter.prepareEach(
410
625
  subject,
411
626
  initializer,
412
627
  testResource,
@@ -414,7 +629,7 @@ var BaseTiposkripto = class {
414
629
  );
415
630
  }
416
631
  afterEach(store, key2) {
417
- return Promise.resolve(fullAdapter.afterEach(store, key2));
632
+ return Promise.resolve(fullAdapter.cleanupEach(store, key2));
418
633
  }
419
634
  }(
420
635
  safeFeatures,
@@ -433,7 +648,7 @@ var BaseTiposkripto = class {
433
648
  a[key] = (...payload) => {
434
649
  const whenInstance = new class extends BaseWhen {
435
650
  async andWhen(store, whenCB, testResource) {
436
- return await fullAdapter.andWhen(store, whenCB, testResource);
651
+ return await fullAdapter.execute(store, whenCB, testResource);
437
652
  }
438
653
  }(`${key}: ${payload && payload.toString()}`, whEn(...payload));
439
654
  return whenInstance;
@@ -447,7 +662,7 @@ var BaseTiposkripto = class {
447
662
  a[key] = (...args) => {
448
663
  const thenInstance = new class extends BaseThen {
449
664
  async butThen(store, thenCB, testResource) {
450
- return await fullAdapter.butThen(store, thenCB, testResource);
665
+ return await fullAdapter.verify(store, thenCB, testResource);
451
666
  }
452
667
  }(`${key}: ${args && args.toString()}`, thEn(...args));
453
668
  return thenInstance;
@@ -474,15 +689,7 @@ var BaseTiposkripto = class {
474
689
  try {
475
690
  const x = await suite2.run(
476
691
  input,
477
- testResourceConfiguration2 || {
478
- name: suite2.name,
479
- fs: process.cwd(),
480
- ports: [],
481
- timeout: 3e4,
482
- retries: 3,
483
- environment: {},
484
- files: []
485
- }
692
+ testResourceConfiguration2
486
693
  );
487
694
  return x;
488
695
  } catch (e) {