testeranto 0.38.3 → 0.38.9

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/index.d.mts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { IBaseConfig } from "./IBaseConfig";
2
2
  export type { IBaseConfig };
3
3
  declare type ITTestResourceConfiguration = {
4
- "fs": string;
5
- "ports": number[];
4
+ fs: string;
5
+ ports: number[];
6
6
  };
7
7
  export declare type ITTestResourceRequirement = {
8
- "ports": number;
9
- "fs": string;
8
+ ports: number;
9
+ fs: string;
10
10
  };
11
11
  declare type IRunner = (x: ITTestResourceConfiguration, t: ITLog) => Promise<boolean>;
12
12
  export declare type IT = {
package/dist/index.mjs CHANGED
@@ -1,27 +1,30 @@
1
- import fs from 'fs';
2
- import path from 'path';
3
- const defaultTestResource = { "fs": ".", ports: [] };
4
- const defaultTestResourceRequirement = { "fs": ".", ports: 0 };
1
+ import fs from "fs";
2
+ import path from "path";
3
+ const defaultTestResource = { fs: ".", ports: [] };
4
+ const defaultTestResourceRequirement = {
5
+ fs: ".",
6
+ ports: 0,
7
+ };
5
8
  const fPaths = [];
6
9
  const testArtiFactoryfileWriter = (tLog) => (fp) => (givenNdx) => (key, value) => {
7
10
  tLog("testArtiFactory =>", key);
8
11
  const fPath = `${fp}/${givenNdx}/${key}`;
9
12
  const cleanPath = path.resolve(fPath);
10
13
  fPaths.push(cleanPath.replace(process.cwd(), ``));
11
- const targetDir = cleanPath.split('/').slice(0, -1).join('/');
14
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
12
15
  fs.mkdir(targetDir, { recursive: true }, async (error) => {
13
16
  if (error) {
14
17
  console.error(`❗️testArtiFactory failed`, targetDir, error);
15
18
  }
16
- fs.writeFileSync(path.resolve(targetDir.split('/').slice(0, -1).join('/'), "manifest"), fPaths.join(`\n`), {
17
- encoding: 'utf-8'
19
+ fs.writeFileSync(path.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
20
+ encoding: "utf-8",
18
21
  });
19
22
  if (Buffer.isBuffer(value)) {
20
23
  fs.writeFileSync(fPath, value, "binary");
21
24
  }
22
- else if (`string` === (typeof value)) {
25
+ else if (`string` === typeof value) {
23
26
  fs.writeFileSync(fPath, value.toString(), {
24
- encoding: 'utf-8'
27
+ encoding: "utf-8",
25
28
  });
26
29
  }
27
30
  else {
@@ -46,7 +49,7 @@ export class BaseSuite {
46
49
  return {
47
50
  name: this.name,
48
51
  givens: this.givens.map((g) => g.toObj()),
49
- fails: this.fails
52
+ fails: this.fails,
50
53
  };
51
54
  }
52
55
  setup(s, artifactory) {
@@ -91,7 +94,6 @@ export class BaseGiven {
91
94
  afterAll(store, artifactory) {
92
95
  return;
93
96
  }
94
- ;
95
97
  toObj() {
96
98
  return {
97
99
  name: this.name,
@@ -118,7 +120,8 @@ export class BaseGiven {
118
120
  }
119
121
  catch (e) {
120
122
  this.error = e;
121
- tLog('\u0007'); // bell
123
+ tLog(e);
124
+ tLog("\u0007"); // bell
122
125
  // throw e;
123
126
  }
124
127
  finally {
@@ -215,20 +218,18 @@ export class BaseCheck {
215
218
  async check(subject, ndx, testResourceConfiguration, tester, artifactory, tLog) {
216
219
  tLog(`\n Check: ${this.name}`);
217
220
  const store = await this.checkThat(subject, testResourceConfiguration, artifactory);
218
- await this.checkCB((Object.entries(this.whens)
219
- .reduce((a, [key, when]) => {
221
+ await this.checkCB(Object.entries(this.whens).reduce((a, [key, when]) => {
220
222
  a[key] = async (payload) => {
221
223
  return await when(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog);
222
224
  };
223
225
  return a;
224
- }, {})), (Object.entries(this.thens)
225
- .reduce((a, [key, then]) => {
226
+ }, {}), Object.entries(this.thens).reduce((a, [key, then]) => {
226
227
  a[key] = async (payload) => {
227
228
  const t = await then(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog);
228
229
  tester(t);
229
230
  };
230
231
  return a;
231
- }, {})));
232
+ }, {}));
232
233
  await this.afterEach(store, ndx);
233
234
  return;
234
235
  }
@@ -262,36 +263,31 @@ export class TesterantoLevelZero {
262
263
  }
263
264
  export class TesterantoLevelOne {
264
265
  constructor(testImplementation, testSpecification, input, suiteKlasser, givenKlasser, whenKlasser, thenKlasser, checkKlasser, testResourceRequirement, nameKey) {
265
- const classySuites = Object.entries(testImplementation.Suites)
266
- .reduce((a, [key]) => {
266
+ const classySuites = Object.entries(testImplementation.Suites).reduce((a, [key]) => {
267
267
  a[key] = (somestring, givens, checks) => {
268
268
  return new suiteKlasser.prototype.constructor(somestring, givens, checks);
269
269
  };
270
270
  return a;
271
271
  }, {});
272
- const classyGivens = Object.entries(testImplementation.Givens)
273
- .reduce((a, [key, z]) => {
272
+ const classyGivens = Object.entries(testImplementation.Givens).reduce((a, [key, z]) => {
274
273
  a[key] = (features, whens, thens, ...xtrasW) => {
275
274
  return new givenKlasser.prototype.constructor(z.name, features, whens, thens, z(...xtrasW));
276
275
  };
277
276
  return a;
278
277
  }, {});
279
- const classyWhens = Object.entries(testImplementation.Whens)
280
- .reduce((a, [key, whEn]) => {
278
+ const classyWhens = Object.entries(testImplementation.Whens).reduce((a, [key, whEn]) => {
281
279
  a[key] = (payload) => {
282
280
  return new whenKlasser.prototype.constructor(`${whEn.name}: ${payload && payload.toString()}`, whEn(payload));
283
281
  };
284
282
  return a;
285
283
  }, {});
286
- const classyThens = Object.entries(testImplementation.Thens)
287
- .reduce((a, [key, thEn]) => {
284
+ const classyThens = Object.entries(testImplementation.Thens).reduce((a, [key, thEn]) => {
288
285
  a[key] = (expected, x) => {
289
286
  return new thenKlasser.prototype.constructor(`${thEn.name}: ${expected && expected.toString()}`, thEn(expected));
290
287
  };
291
288
  return a;
292
289
  }, {});
293
- const classyChecks = Object.entries(testImplementation.Checks)
294
- .reduce((a, [key, z]) => {
290
+ const classyChecks = Object.entries(testImplementation.Checks).reduce((a, [key, z]) => {
295
291
  a[key] = (somestring, features, callback) => {
296
292
  return new checkKlasser.prototype.constructor(somestring, features, callback, classyWhens, classyThens);
297
293
  };
@@ -331,7 +327,7 @@ export class TesterantoLevelOne {
331
327
  const numberOfFailures = suiteDone.givens.filter((g) => g.error).length;
332
328
  console.log(`exiting gracefully with ${numberOfFailures} failures.`);
333
329
  process.exitCode = numberOfFailures;
334
- }
330
+ },
335
331
  };
336
332
  });
337
333
  return toReturn;
@@ -340,28 +336,30 @@ export class TesterantoLevelOne {
340
336
  export default async (input, testSpecification, testImplementation, testInterface, nameKey, testResourceRequirement = defaultTestResourceRequirement) => {
341
337
  const butThen = testInterface.butThen || (async (a) => a);
342
338
  const { andWhen } = testInterface;
343
- const actionHandler = testInterface.actionHandler || function (b) {
344
- return b;
345
- };
339
+ const actionHandler = testInterface.actionHandler ||
340
+ function (b) {
341
+ return b;
342
+ };
346
343
  const assertioner = testInterface.assertioner || (async (t) => t);
347
344
  const beforeAll = testInterface.beforeAll || (async (input) => input);
348
- const beforeEach = testInterface.beforeEach || async function (subject, initialValues, testResource) {
349
- return subject;
350
- };
345
+ const beforeEach = testInterface.beforeEach ||
346
+ async function (subject, initialValues, testResource) {
347
+ return subject;
348
+ };
351
349
  const afterEach = testInterface.afterEach || (async (s) => s);
352
350
  const afterAll = testInterface.afterAll || ((store) => undefined);
353
351
  class MrT extends TesterantoLevelOne {
354
352
  constructor() {
355
353
  super(testImplementation,
356
354
  /* @ts-ignore:next-line */
357
- testSpecification, input, (class extends BaseSuite {
355
+ testSpecification, input, class extends BaseSuite {
358
356
  async setup(s, artifactory) {
359
357
  return beforeAll(s, artifactory);
360
358
  }
361
359
  test(t) {
362
360
  return assertioner(t);
363
361
  }
364
- }), class Given extends BaseGiven {
362
+ }, class Given extends BaseGiven {
365
363
  constructor(name, features, whens, thens, initialValues) {
366
364
  super(name, features, whens, thens);
367
365
  this.initialValues = initialValues;
@@ -421,23 +419,23 @@ export default async (input, testSpecification, testImplementation, testInterfac
421
419
  console.log("requesting test resources from pm2 ...", testResourceRequirement);
422
420
  /* @ts-ignore:next-line */
423
421
  process.send({
424
- type: 'testeranto:hola',
422
+ type: "testeranto:hola",
425
423
  data: {
426
- testResourceRequirement
427
- }
424
+ testResourceRequirement,
425
+ },
428
426
  });
429
427
  console.log("awaiting test resources from pm2...");
430
- process.on('message', async function (packet) {
428
+ process.on("message", async function (packet) {
431
429
  const resourcesFromPm2 = packet.data.testResourceConfiguration;
432
- const secondTestResource = (Object.assign(Object.assign({}, JSON.parse(JSON.stringify(resourcesFromPm2))), JSON.parse(JSON.stringify(partialTestResource))));
430
+ const secondTestResource = Object.assign(Object.assign({}, JSON.parse(JSON.stringify(resourcesFromPm2))), JSON.parse(JSON.stringify(partialTestResource)));
433
431
  if (await t.receiveTestResourceConfig(secondTestResource)) {
434
432
  /* @ts-ignore:next-line */
435
433
  process.send({
436
- type: 'testeranto:adios',
434
+ type: "testeranto:adios",
437
435
  data: {
438
436
  testResourceConfiguration: mrt[0].test.testResourceConfiguration,
439
- results: mrt[0].toObj()
440
- }
437
+ results: mrt[0].toObj(),
438
+ },
441
439
  }, (err) => {
442
440
  if (!err) {
443
441
  console.log(`✅`);
@@ -452,9 +450,9 @@ export default async (input, testSpecification, testImplementation, testInterfac
452
450
  }
453
451
  else {
454
452
  console.log("Pass run-time test resources by STDIN");
455
- process.stdin.on('data', async (data) => {
453
+ process.stdin.on("data", async (data) => {
456
454
  const resourcesFromStdin = JSON.parse(data.toString());
457
- const secondTestResource = (Object.assign(Object.assign({}, JSON.parse(JSON.stringify(resourcesFromStdin))), JSON.parse(JSON.stringify(partialTestResource))));
455
+ const secondTestResource = Object.assign(Object.assign({}, JSON.parse(JSON.stringify(resourcesFromStdin))), JSON.parse(JSON.stringify(partialTestResource)));
458
456
  await t.receiveTestResourceConfig(secondTestResource);
459
457
  // process.exit(0); // :-)
460
458
  });