testeranto 0.113.1 → 0.121.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.
Files changed (87) hide show
  1. package/README.md +6 -2
  2. package/bundle.js +1 -1
  3. package/dist/common/Init.js +55 -61
  4. package/dist/common/PM/base.js +233 -0
  5. package/dist/common/PM/main.js +217 -434
  6. package/dist/common/build.js +113 -92
  7. package/dist/common/defaultConfig.js +2 -2
  8. package/dist/common/esbuildConfigs/index.js +1 -1
  9. package/dist/common/esbuildConfigs/inputFilesPlugin.js +7 -3
  10. package/dist/common/esbuildConfigs/node.js +5 -3
  11. package/dist/common/esbuildConfigs/web.js +3 -3
  12. package/dist/common/init-docs.js +2 -46
  13. package/dist/common/lib/abstractBase.js +60 -54
  14. package/dist/common/lib/basebuilder.js +7 -8
  15. package/dist/common/lib/classBuilder.js +8 -5
  16. package/dist/common/lib/core.js +6 -18
  17. package/dist/common/lib/index.js +6 -1
  18. package/dist/common/run.js +10 -2
  19. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  20. package/dist/common/utils.js +9 -21
  21. package/dist/module/Init.js +55 -61
  22. package/dist/module/PM/base.js +226 -0
  23. package/dist/module/PM/main.js +218 -435
  24. package/dist/module/Project.js +117 -0
  25. package/dist/module/TestReport.js +13 -4
  26. package/dist/module/build.js +113 -92
  27. package/dist/module/defaultConfig.js +2 -2
  28. package/dist/module/esbuildConfigs/index.js +1 -1
  29. package/dist/module/esbuildConfigs/inputFilesPlugin.js +7 -3
  30. package/dist/module/esbuildConfigs/node.js +5 -3
  31. package/dist/module/esbuildConfigs/web.js +3 -3
  32. package/dist/module/init-docs.js +2 -13
  33. package/dist/module/lib/abstractBase.js +60 -54
  34. package/dist/module/lib/basebuilder.js +7 -8
  35. package/dist/module/lib/classBuilder.js +8 -5
  36. package/dist/module/lib/core.js +6 -18
  37. package/dist/module/lib/index.js +6 -1
  38. package/dist/module/run.js +10 -2
  39. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  40. package/dist/module/utils.js +8 -17
  41. package/dist/prebuild/Project.css +11367 -0
  42. package/dist/prebuild/Project.js +24640 -0
  43. package/dist/prebuild/ReportClient.js +1 -1
  44. package/dist/prebuild/TestReport.js +9 -11
  45. package/dist/prebuild/build.mjs +142 -81
  46. package/dist/prebuild/init-docs.mjs +28 -83
  47. package/dist/prebuild/run.mjs +618 -537
  48. package/dist/tsconfig.tsbuildinfo +1 -1
  49. package/dist/types/Init.d.ts +1 -1
  50. package/dist/types/PM/base.d.ts +38 -0
  51. package/dist/types/PM/main.d.ts +20 -44
  52. package/dist/types/esbuildConfigs/inputFilesPlugin.d.ts +1 -1
  53. package/dist/types/esbuildConfigs/node.d.ts +1 -1
  54. package/dist/types/esbuildConfigs/web.d.ts +1 -1
  55. package/dist/types/lib/abstractBase.d.ts +19 -11
  56. package/dist/types/lib/basebuilder.d.ts +1 -2
  57. package/dist/types/lib/index.d.ts +3 -3
  58. package/dist/types/lib/types.d.ts +2 -5
  59. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  60. package/dist/types/utils.d.ts +4 -7
  61. package/package.json +7 -6
  62. package/src/Init.ts +60 -68
  63. package/src/PM/base.ts +301 -0
  64. package/src/PM/main.ts +276 -567
  65. package/src/Project.tsx +197 -0
  66. package/src/ReportClient.tsx +1 -1
  67. package/src/TestReport.tsx +30 -15
  68. package/src/build.ts +140 -104
  69. package/src/defaultConfig.ts +2 -2
  70. package/src/esbuildConfigs/index.ts +1 -1
  71. package/src/esbuildConfigs/inputFilesPlugin.ts +7 -6
  72. package/src/esbuildConfigs/node.ts +5 -3
  73. package/src/esbuildConfigs/web.ts +4 -3
  74. package/src/init-docs.ts +2 -15
  75. package/src/lib/abstractBase.ts +113 -93
  76. package/src/lib/basebuilder.ts +8 -9
  77. package/src/lib/classBuilder.ts +11 -10
  78. package/src/lib/core.ts +15 -27
  79. package/src/lib/index.ts +13 -6
  80. package/src/lib/types.ts +3 -8
  81. package/src/run.ts +21 -5
  82. package/src/utils.ts +27 -39
  83. package/tsc.log +12 -23
  84. package/dist/common/puppeteerConfiger.js +0 -24
  85. package/dist/module/puppeteerConfiger.js +0 -19
  86. package/dist/types/puppeteerConfiger.d.ts +0 -4
  87. package/src/puppeteerConfiger.ts +0 -26
@@ -21,9 +21,11 @@ export class BaseSuite {
21
21
  }
22
22
  toObj() {
23
23
  const givens = Object.keys(this.givens).map((k) => this.givens[k].toObj());
24
+ const checks = Object.keys(this.checks).map((k) => this.checks[k].toObj());
24
25
  return {
25
26
  name: this.name,
26
27
  givens,
28
+ checks,
27
29
  fails: this.fails,
28
30
  features: this.features(),
29
31
  };
@@ -39,29 +41,28 @@ export class BaseSuite {
39
41
  }
40
42
  async run(input, testResourceConfiguration, artifactory, tLog, pm) {
41
43
  this.testResourceConfiguration = testResourceConfiguration;
42
- tLog("test resources: ", JSON.stringify(testResourceConfiguration));
44
+ // tLog("test resources: ", JSON.stringify(testResourceConfiguration));
43
45
  const suiteArtifactory = (fPath, value) => artifactory(`suite-${this.index}-${this.name}/${fPath}`, value);
44
46
  // console.log("\nSuite:", this.index, this.name);
45
47
  tLog("\nSuite:", this.index, this.name);
46
48
  const sNdx = this.index;
47
49
  const sName = this.name;
50
+ const beforeAllProxy = new Proxy(pm, {
51
+ get(target, prop, receiver) {
52
+ if (prop === "customScreenShot") {
53
+ return (opts, p) => target.customScreenShot(Object.assign(Object.assign({}, opts), {
54
+ // path: `${filepath}/${opts.path}`,
55
+ path: `suite-${sNdx}/beforeAll/${opts.path}` }), p);
56
+ }
57
+ if (prop === "writeFileSync") {
58
+ return (fp, contents) => target[prop](`suite-${sNdx}/beforeAll/${fp}`, contents);
59
+ }
60
+ /* @ts-ignore:next-line */
61
+ return Reflect.get(...arguments);
62
+ },
63
+ });
64
+ const subject = await this.setup(input, suiteArtifactory, testResourceConfiguration, beforeAllProxy);
48
65
  for (const [gKey, g] of Object.entries(this.givens)) {
49
- // console.log("gKey", gKey);
50
- const beforeAllProxy = new Proxy(pm, {
51
- get(target, prop, receiver) {
52
- if (prop === "customScreenShot") {
53
- return (opts, p) => target.customScreenShot(Object.assign(Object.assign({}, opts), {
54
- // path: `${filepath}/${opts.path}`,
55
- path: `suite-${sNdx}/beforeAll/${opts.path}` }), p);
56
- }
57
- if (prop === "writeFileSync") {
58
- return (fp, contents) => target[prop](`suite-${sNdx}/beforeAll/${fp}`, contents);
59
- }
60
- /* @ts-ignore:next-line */
61
- return Reflect.get(...arguments);
62
- },
63
- });
64
- const subject = await this.setup(input, suiteArtifactory, testResourceConfiguration, beforeAllProxy);
65
66
  const giver = this.givens[gKey];
66
67
  try {
67
68
  this.store = await giver.give(subject, gKey, testResourceConfiguration, this.assertThat, suiteArtifactory, tLog, pm, sNdx);
@@ -72,6 +73,9 @@ export class BaseSuite {
72
73
  // return this;
73
74
  }
74
75
  }
76
+ for (const [ndx, thater] of this.checks.entries()) {
77
+ await thater.check(subject, thater.name, testResourceConfiguration, this.assertThat, suiteArtifactory, tLog, pm);
78
+ }
75
79
  try {
76
80
  this.afterAll(this.store, artifactory,
77
81
  // afterAllProxy
@@ -82,17 +86,6 @@ export class BaseSuite {
82
86
  // this.fails.push(this);
83
87
  // return this;
84
88
  }
85
- // for (const [ndx, thater] of this.checks.entries()) {
86
- // await thater.check(
87
- // subject,
88
- // thater.name,
89
- // testResourceConfiguration,
90
- // this.assertThat,
91
- // suiteArtifactory,
92
- // tLog,
93
- // pm
94
- // );
95
- // }
96
89
  // @TODO fix me
97
90
  // for (const k of Object.keys(this.givens)) {
98
91
  // const giver = this.givens[k];
@@ -109,9 +102,7 @@ export class BaseSuite {
109
102
  }
110
103
  }
111
104
  export class BaseGiven {
112
- constructor(name, features, whens, thens, givenCB, initialValues
113
- // key: string
114
- ) {
105
+ constructor(name, features, whens, thens, givenCB, initialValues) {
115
106
  this.name = name;
116
107
  this.features = features;
117
108
  this.whens = whens;
@@ -201,7 +192,8 @@ export class BaseGiven {
201
192
  afterEachProxy);
202
193
  }
203
194
  catch (e) {
204
- console.error("afterEach failed! no error will be recorded!", e);
195
+ console.error("afterEach failed!", e);
196
+ this.error = e.message;
205
197
  }
206
198
  }
207
199
  return this.store;
@@ -220,7 +212,6 @@ export class BaseWhen {
220
212
  }
221
213
  async test(store, testResourceConfiguration, tLog, pm, filepath) {
222
214
  tLog(" When:", this.name);
223
- const name = this.name;
224
215
  const andWhenProxy = new Proxy(pm, {
225
216
  get(target, prop, receiver) {
226
217
  if (prop === "customScreenShot") {
@@ -263,7 +254,16 @@ export class BaseThen {
263
254
  };
264
255
  }
265
256
  async test(store, testResourceConfiguration, tLog, pm, filepath) {
266
- tLog(" Then:", this.name);
257
+ this.go = async (s) => {
258
+ tLog(" Then!!!:", this.name);
259
+ try {
260
+ await this.thenCB(s);
261
+ }
262
+ catch (e) {
263
+ console.log("test failed", e);
264
+ this.error = e.message;
265
+ }
266
+ };
267
267
  try {
268
268
  const butThenProxy = new Proxy(pm, {
269
269
  get(target, prop, receiver) {
@@ -277,7 +277,7 @@ export class BaseThen {
277
277
  return Reflect.get(...arguments);
278
278
  },
279
279
  });
280
- return this.butThen(store, this.thenCB, testResourceConfiguration, butThenProxy).catch((e) => {
280
+ return this.butThen(store, this.go, testResourceConfiguration, butThenProxy).catch((e) => {
281
281
  this.error = true;
282
282
  throw e;
283
283
  });
@@ -288,34 +288,40 @@ export class BaseThen {
288
288
  throw e;
289
289
  }
290
290
  }
291
+ check() { }
291
292
  }
292
293
  export class BaseCheck {
293
- constructor(name, features, checkCB, whens, thens) {
294
+ constructor(name, features, checker, x, checkCB) {
294
295
  this.name = name;
295
296
  this.features = features;
296
297
  this.checkCB = checkCB;
297
- this.whens = whens;
298
- this.thens = thens;
298
+ this.checker = checker;
299
299
  }
300
- async afterEach(store, key, cb, pm) {
301
- return;
300
+ toObj() {
301
+ return {
302
+ key: this.key,
303
+ name: this.name,
304
+ functionAsString: this.checkCB.toString(),
305
+ // thens: this.thens.map((t) => t.toObj()),
306
+ // error: this.error ? [this.error, this.error.stack] : null,
307
+ // fail: this.fail ? [this.fail] : false,
308
+ features: this.features,
309
+ };
310
+ }
311
+ async afterEach(store, key, artifactory, pm) {
312
+ return store;
313
+ }
314
+ beforeAll(store,
315
+ // artifactory: ITestArtifactory
316
+ // subject,
317
+ initializer, artifactory, testResource, initialValues, pm) {
318
+ return store;
302
319
  }
303
320
  async check(subject, key, testResourceConfiguration, tester, artifactory, tLog, pm) {
321
+ this.key = key;
304
322
  tLog(`\n Check: ${this.name}`);
305
- const store = await this.checkThat(subject, testResourceConfiguration, artifactory, pm);
306
- await this.checkCB(Object.entries(this.whens).reduce((a, [key, when]) => {
307
- a[key] = async (payload) => {
308
- return await when(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog, pm, "x");
309
- };
310
- return a;
311
- }, {}), Object.entries(this.thens).reduce((a, [key, then]) => {
312
- a[key] = async (payload) => {
313
- const t = await then(payload, testResourceConfiguration).test(store, testResourceConfiguration, tLog, pm);
314
- tester(t);
315
- };
316
- return a;
317
- }, {}));
318
- await this.afterEach(store, key, () => { }, pm);
323
+ this.store = await this.checkThat(subject, testResourceConfiguration, artifactory, this.checkCB, this.initialValues, pm);
324
+ await this.checker(this.store, pm);
319
325
  return;
320
326
  }
321
327
  }
@@ -1,6 +1,5 @@
1
1
  export class BaseBuilder {
2
2
  constructor(input, suitesOverrides, givenOverides, whenOverides, thenOverides, checkOverides, testResourceRequirement, testSpecification) {
3
- this.input = input;
4
3
  this.artifacts = [];
5
4
  this.artifacts = [];
6
5
  this.testResourceRequirement = testResourceRequirement;
@@ -42,7 +41,7 @@ export class BaseBuilder {
42
41
  puppetMaster.writeFileSync(`bdd_errors.txt`, numberOfFailures.toString());
43
42
  const o = this.toObj();
44
43
  puppetMaster.writeFileSync(`littleBoard.html`, `
45
- <!DOCTYPE html>
44
+ <!DOCTYPE html>
46
45
  <html lang="en">
47
46
 
48
47
  <head>
@@ -52,15 +51,15 @@ export class BaseBuilder {
52
51
  <meta name="viewport" content="width=device-width, initial-scale=1" />
53
52
  <meta name="author" content="" />
54
53
 
55
- <link rel="stylesheet" href="/kokomoBay/docs/TestReport.css" />
56
- <script src="/kokomoBay/docs/TestReport.js"></script>
54
+ <link rel="stylesheet" href="/kokomoBay/testeranto/TestReport.css" />
55
+ <script src="/kokomoBay/testeranto/TestReport.js"></script>
57
56
 
58
57
  </head>
59
58
 
60
- <body>
61
- <h1>Test report</h1>
62
- <div id="root"/>
63
- </body>
59
+ <body>
60
+ <h1>Test report</h1>
61
+ <div id="root"/>
62
+ </body>
64
63
  `);
65
64
  puppetMaster.writeFileSync(`tests.json`, JSON.stringify(this.toObj(), null, 2));
66
65
  return {
@@ -8,8 +8,11 @@ export class ClassBuilder extends BaseBuilder {
8
8
  return a;
9
9
  }, {});
10
10
  const classyGivens = Object.entries(testImplementation.givens).reduce((a, [key, g]) => {
11
- a[key] = (features, whens, thens, givEn) => {
12
- return new givenKlasser.prototype.constructor(key, features, whens, thens, testImplementation.givens[key], givEn);
11
+ a[key] = (features, whens, thens) => {
12
+ // console.log("givEn", givEn.toString());
13
+ return new givenKlasser.prototype.constructor(key, features, whens, thens, testImplementation.givens[key]
14
+ // givEn
15
+ );
13
16
  };
14
17
  return a;
15
18
  }, {});
@@ -25,9 +28,9 @@ export class ClassBuilder extends BaseBuilder {
25
28
  };
26
29
  return a;
27
30
  }, {});
28
- const classyChecks = Object.entries(testImplementation.checks).reduce((a, [key, z]) => {
29
- a[key] = (somestring, features, callback) => {
30
- return new checkKlasser.prototype.constructor(somestring, features, callback, classyWhens, classyThens);
31
+ const classyChecks = Object.entries(testImplementation.checks).reduce((a, [key, chEck]) => {
32
+ a[key] = (name, features, checker) => {
33
+ return new checkKlasser.prototype.constructor(key, features, chEck, checker);
31
34
  };
32
35
  return a;
33
36
  }, {});
@@ -29,15 +29,10 @@ export default class Testeranto extends ClassBuilder {
29
29
  this.uberCatcher = uberCatcher;
30
30
  }
31
31
  async givenThat(subject, testResource, artifactory, initializer, initialValues, pm) {
32
- return fullTestInterface.beforeEach(subject, initializer,
33
- // artifactory,
34
- testResource, initialValues, pm);
32
+ return fullTestInterface.beforeEach(subject, initializer, testResource, initialValues, pm);
35
33
  }
36
34
  afterEach(store, key, artifactory, pm) {
37
- return new Promise((res) => res(fullTestInterface.afterEach(store, key,
38
- // (fPath: string, value: unknown) =>
39
- // artifactory(`after/${fPath}`, value),
40
- pm)));
35
+ return new Promise((res) => res(fullTestInterface.afterEach(store, key, pm)));
41
36
  }
42
37
  }, class When extends BaseWhen {
43
38
  async andWhen(store, whenCB, testResource, pm) {
@@ -93,21 +88,14 @@ export default class Testeranto extends ClassBuilder {
93
88
  }
94
89
  }, class Check extends BaseCheck {
95
90
  constructor(name, features, checkCallback, whens, thens, initialValues) {
96
- super(name, features, checkCallback, whens, thens);
91
+ super(name, features, whens, thens, checkCallback, initialValues);
97
92
  this.initialValues = initialValues;
98
93
  }
99
- async checkThat(subject, testResourceConfiguration, artifactory, pm) {
100
- return fullTestInterface.beforeEach(subject, this.initialValues,
101
- // (fPath: string, value: unknown) =>
102
- // artifactory(`before/${fPath}`, value),
103
- testResourceConfiguration, this.initialValues, pm);
94
+ async checkThat(subject, testResourceConfiguration, artifactory, initializer, initialValues, pm) {
95
+ return fullTestInterface.beforeEach(subject, initializer, testResourceConfiguration, initialValues, pm);
104
96
  }
105
97
  afterEach(store, key, artifactory, pm) {
106
- return new Promise((res) => res(fullTestInterface.afterEach(store, key,
107
- // (fPath: string, value: unknown) =>
108
- // // TODO does not work?
109
- // artifactory(`afterEach2-${this.name}/${fPath}`, value),
110
- pm)));
98
+ return new Promise((res) => res(fullTestInterface.afterEach(store, key, pm)));
111
99
  }
112
100
  }, testResourceRequirement);
113
101
  }
@@ -5,7 +5,12 @@ export const BaseTestInterface = {
5
5
  },
6
6
  afterEach: async (s) => s,
7
7
  afterAll: (store) => undefined,
8
- butThen: async (store, thenCb) => thenCb(store),
8
+ butThen: async (store, thenCb) => {
9
+ try {
10
+ thenCb(store);
11
+ }
12
+ catch (e) { }
13
+ },
9
14
  andWhen: (a) => a,
10
15
  assertThis: () => null,
11
16
  };
@@ -1,5 +1,6 @@
1
1
  import ansiC from "ansi-colors";
2
2
  import readline from "readline";
3
+ import path from "path";
3
4
  import { PM_Main } from "./PM/main";
4
5
  readline.emitKeypressEvents(process.stdin);
5
6
  if (process.stdin.isTTY)
@@ -11,10 +12,17 @@ process.stdin.on("keypress", (str, key) => {
11
12
  process.exit(-1);
12
13
  }
13
14
  });
15
+ const mode = process.argv[3];
16
+ if (mode !== "once" && mode !== "dev") {
17
+ console.error("the 2nd argument should be 'dev' or 'once' ");
18
+ process.exit(-1);
19
+ }
14
20
  import(process.cwd() + "/" + process.argv[2]).then(async (module) => {
21
+ const testName = path.basename(process.argv[2]).split(".")[0];
22
+ console.log("testeranto is running", testName, mode);
15
23
  const rawConfig = module.default;
16
- const config = Object.assign(Object.assign({}, rawConfig), { buildDir: process.cwd() + "/" + rawConfig.outdir });
17
- const pm = new PM_Main(config);
24
+ const config = Object.assign(Object.assign({}, rawConfig), { buildDir: process.cwd() + "/" + `testeranto/${testName}.json` });
25
+ const pm = new PM_Main(config, testName, mode);
18
26
  pm.start();
19
27
  process.stdin.on("keypress", (str, key) => {
20
28
  if (key.name === "q") {