testeranto 0.84.0 → 0.90.0

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 (62) hide show
  1. package/README.md +1 -5
  2. package/bin/init-docs.js +24 -0
  3. package/bundle.js +53 -0
  4. package/dist/common/dist/module/src/Init.js +40 -0
  5. package/dist/common/src/Init.js +30 -0
  6. package/dist/common/src/PM/main.js +45 -9
  7. package/dist/common/src/Project.js +80 -0
  8. package/dist/common/src/Puppeteer.js +1 -1
  9. package/dist/common/{run-tests.js → src/build-tests.js} +10 -5
  10. package/dist/common/src/defaultConfig.js +19 -0
  11. package/dist/common/src/esbuildConfigs/inputFilesPlugin.js +27 -15
  12. package/dist/common/src/init-docs.js +43 -0
  13. package/dist/common/src/lib/abstractBase.js +0 -64
  14. package/dist/common/src/lib/core.js +5 -3
  15. package/dist/common/{build-tests.js → src/run-tests.js} +10 -9
  16. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  17. package/dist/module/src/Init.js +30 -0
  18. package/dist/module/src/PM/main.js +45 -9
  19. package/dist/module/src/Project.js +80 -0
  20. package/dist/module/src/Puppeteer.js +1 -1
  21. package/dist/module/src/build-tests.js +11 -0
  22. package/dist/module/src/defaultConfig.js +17 -0
  23. package/dist/module/src/esbuildConfigs/inputFilesPlugin.js +27 -15
  24. package/dist/module/src/init-docs.js +15 -0
  25. package/dist/module/src/lib/abstractBase.js +0 -64
  26. package/dist/module/src/lib/core.js +5 -3
  27. package/dist/module/src/run-tests.js +11 -0
  28. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  29. package/dist/prebuild/build-tests.mjs +552 -0
  30. package/dist/prebuild/init-docs.mjs +48 -0
  31. package/dist/prebuild/run-tests.mjs +907 -0
  32. package/dist/types/dist/module/src/Init.d.ts +2 -0
  33. package/dist/types/src/build-tests.d.ts +1 -0
  34. package/dist/types/src/defaultConfig.d.ts +3 -0
  35. package/dist/types/src/init-docs.d.ts +1 -0
  36. package/dist/types/src/run-tests.d.ts +1 -0
  37. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  38. package/package.json +10 -13
  39. package/src/Init.ts +28 -0
  40. package/src/PM/main.ts +58 -10
  41. package/src/Project.ts +102 -0
  42. package/src/Puppeteer.ts +1 -1
  43. package/src/build-tests.ts +12 -0
  44. package/src/defaultConfig.ts +20 -0
  45. package/src/esbuildConfigs/inputFilesPlugin.ts +48 -16
  46. package/src/init-docs.ts +19 -0
  47. package/src/lib/abstractBase.ts +0 -67
  48. package/src/lib/core.ts +3 -3
  49. package/src/run-tests.ts +12 -0
  50. package/tsconfig.json +1 -1
  51. package/build-tests.ts +0 -16
  52. package/dist/common/init-docs.js +0 -8
  53. package/dist/module/build-tests.js +0 -10
  54. package/dist/module/init-docs.js +0 -3
  55. package/dist/module/run-tests.js +0 -6
  56. package/dist/prebuild/Puppeteer.mjs +0 -82033
  57. package/dist/types/build-tests.d.ts +0 -3
  58. package/dist/types/init-docs.d.ts +0 -2
  59. package/dist/types/run-tests.d.ts +0 -2
  60. package/init-docs.ts +0 -5
  61. package/pupBuild.js +0 -18
  62. package/run-tests.ts +0 -9
@@ -1,5 +1,35 @@
1
1
  import fs from "fs";
2
2
  export default async (partialConfig) => {
3
3
  const config = Object.assign(Object.assign({}, partialConfig), { buildDir: process.cwd() + "/" + partialConfig.outdir });
4
+ try {
5
+ fs.mkdirSync(`${process.cwd()}/${config.outdir}`);
6
+ }
7
+ catch (_a) {
8
+ // console.log()
9
+ }
4
10
  fs.writeFileSync(`${config.outdir}/testeranto.json`, JSON.stringify(Object.assign(Object.assign({}, config), { buildDir: process.cwd() + "/" + config.outdir }), null, 2));
11
+ try {
12
+ fs.mkdirSync(`${process.cwd()}/${config.outdir}/node`);
13
+ }
14
+ catch (_b) {
15
+ // console.log()
16
+ }
17
+ try {
18
+ fs.mkdirSync(`${process.cwd()}/${config.outdir}/web`);
19
+ }
20
+ catch (_c) {
21
+ // console.log()
22
+ }
23
+ try {
24
+ fs.mkdirSync(`${process.cwd()}/${config.outdir}/features`);
25
+ }
26
+ catch (_d) {
27
+ // console.log()
28
+ }
29
+ try {
30
+ fs.mkdirSync(`${process.cwd()}/${config.outdir}/ts`);
31
+ }
32
+ catch (_e) {
33
+ // console.log()
34
+ }
5
35
  };
@@ -4,8 +4,8 @@ import puppeteer from "puppeteer-core";
4
4
  import crypto from "crypto";
5
5
  import { PM } from "./index.js";
6
6
  import { destinationOfRuntime } from "../utils.js";
7
- const fPaths = [];
8
7
  const fileStreams3 = [];
8
+ const fPaths = [];
9
9
  const files = {};
10
10
  const screenshots = {};
11
11
  export class PM_Main extends PM {
@@ -121,6 +121,7 @@ export class PM_Main extends PM {
121
121
  fs: destFolder,
122
122
  browserWSEndpoint: this.browser.wsEndpoint(),
123
123
  });
124
+ // files[src] = new Set();
124
125
  // const evaluation = `
125
126
  // console.log("importing ${dest}.mjs");
126
127
  // import('${dest}.mjs').then(async (x) => {
@@ -184,9 +185,9 @@ export class PM_Main extends PM {
184
185
  });
185
186
  page.exposeFunction("createWriteStream", (fp, testName) => {
186
187
  const f = fs.createWriteStream(fp);
187
- if (!files[testName]) {
188
- files[testName] = new Set();
189
- }
188
+ // if (!files[testName]) {
189
+ // files[testName] = new Set();
190
+ // }
190
191
  files[testName].add(fp);
191
192
  const p = new Promise((res, rej) => {
192
193
  res(fp);
@@ -318,6 +319,8 @@ export class PM_Main extends PM {
318
319
  })`;
319
320
  const fileStreams2 = [];
320
321
  const doneFileStream2 = [];
322
+ const stdoutStream = fs.createWriteStream(`${dest}/stdout.log`);
323
+ const stderrStream = fs.createWriteStream(`${dest}/stderr.log`);
321
324
  this.browser
322
325
  .newPage()
323
326
  .then((page) => {
@@ -474,9 +477,39 @@ export class PM_Main extends PM {
474
477
  return page;
475
478
  })
476
479
  .then(async (page) => {
477
- // page.on("console", (log) =>
478
- // console.debug(`Log from client: [${log.text()}] `)
479
- // );
480
+ const close = () => {
481
+ console.log("evaluation complete.", dest);
482
+ page.off("pageerror");
483
+ page.close();
484
+ this.deregister(t);
485
+ stderrStream.close();
486
+ stdoutStream.close();
487
+ };
488
+ page.on("pageerror", (err) => {
489
+ console.debug(`Error from ${t}: [${err.name}] `);
490
+ stderrStream.write(err.name);
491
+ if (err.cause) {
492
+ console.debug(`Error from ${t} cause: [${err.cause}] `);
493
+ stderrStream.write(err.cause);
494
+ }
495
+ if (err.stack) {
496
+ console.debug(`Error from stack ${t}: [${err.stack}] `);
497
+ stderrStream.write(err.stack);
498
+ }
499
+ console.debug(`Error from message ${t}: [${err.message}] `);
500
+ stderrStream.write(err.message);
501
+ // close();
502
+ });
503
+ page.on("console", (log) => {
504
+ // console.debug(`Log from ${t}: [${log.text()}] `);
505
+ // console.debug(`Log from ${t}: [${JSON.stringify(log.location())}] `);
506
+ // console.debug(
507
+ // `Log from ${t}: [${JSON.stringify(log.stackTrace())}] `
508
+ // );
509
+ stdoutStream.write(log.text());
510
+ stdoutStream.write(JSON.stringify(log.location()));
511
+ stdoutStream.write(JSON.stringify(log.stackTrace()));
512
+ });
480
513
  await page.goto(`file://${`${dest}.html`}`, {});
481
514
  await page
482
515
  .evaluate(evaluation)
@@ -488,9 +521,12 @@ export class PM_Main extends PM {
488
521
  console.log(e);
489
522
  })
490
523
  .finally(() => {
491
- console.log("evaluation complete.", dest);
524
+ close();
525
+ // console.log("evaluation complete.", dest);
492
526
  // page.close();
493
- this.deregister(t);
527
+ // this.deregister(t);
528
+ // stderrStream.close();
529
+ // stdoutStream.close();
494
530
  });
495
531
  return page;
496
532
  });
@@ -1,3 +1,4 @@
1
+ import { spawn } from "child_process";
1
2
  import esbuild from "esbuild";
2
3
  import fs from "fs";
3
4
  import path from "path";
@@ -9,6 +10,84 @@ import webHtmlFrame from "./web.html.js";
9
10
  readline.emitKeypressEvents(process.stdin);
10
11
  if (process.stdin.isTTY)
11
12
  process.stdin.setRawMode(true);
13
+ const logContent = [];
14
+ function parseTsErrors() {
15
+ try {
16
+ // const logContent = fs.readFileSync(logPath, "utf-8").split("\n");
17
+ const regex = /(^src(.*?))\(\d*,\d*\): error/gm;
18
+ const brokenFilesToLines = {};
19
+ for (let i = 0; i < logContent.length - 1; i++) {
20
+ let m;
21
+ while ((m = regex.exec(logContent[i])) !== null) {
22
+ // This is necessary to avoid infinite loops with zero-width matches
23
+ if (m.index === regex.lastIndex) {
24
+ regex.lastIndex++;
25
+ }
26
+ if (!brokenFilesToLines[m[1]]) {
27
+ brokenFilesToLines[m[1]] = new Set();
28
+ }
29
+ brokenFilesToLines[m[1]].add(i);
30
+ }
31
+ }
32
+ const final = Object.keys(brokenFilesToLines).reduce((mm, lm, ndx) => {
33
+ mm[lm] = Array.from(brokenFilesToLines[lm]).map((l, ndx3) => {
34
+ const a = Array.from(brokenFilesToLines[lm]);
35
+ return Object.keys(a).reduce((mm2, lm2, ndx2) => {
36
+ const acc = [];
37
+ let j = a[lm2] + 1;
38
+ let working = true;
39
+ while (j < logContent.length - 1 && working) {
40
+ if (!logContent[j].match(regex) &&
41
+ working &&
42
+ !logContent[j].match(/^..\/(.*?)\(\d*,\d*\)/)) {
43
+ acc.push(logContent[j]);
44
+ }
45
+ else {
46
+ working = false;
47
+ }
48
+ j++;
49
+ }
50
+ mm2[lm] = [logContent[l], ...acc];
51
+ return mm2;
52
+ }, {})[lm];
53
+ });
54
+ return mm;
55
+ }, {});
56
+ Object.keys(final).forEach((k) => {
57
+ fs.mkdirSync(`./docs/types/${k.split("/").slice(0, -1).join("/")}`, {
58
+ recursive: true,
59
+ });
60
+ fs.writeFileSync(`./docs/types/${k}.type_errors.txt`, final[k].flat().flat().join("\r\n"));
61
+ });
62
+ }
63
+ catch (error) {
64
+ console.error("Error reading or parsing the log file:", error);
65
+ process.exit(1);
66
+ }
67
+ }
68
+ const compile = () => {
69
+ return new Promise((resolve, reject) => {
70
+ const tsc = spawn("tsc", ["-noEmit"]);
71
+ tsc.stdout.on("data", (data) => {
72
+ // console.log(`stdout: ${data}`);
73
+ const lines = data.toString().split("\n");
74
+ logContent.push(...lines);
75
+ });
76
+ tsc.stderr.on("data", (data) => {
77
+ // console.error(`stderr: ${data}`);
78
+ });
79
+ tsc.on("close", (code) => {
80
+ parseTsErrors();
81
+ resolve(`tsc process exited with code ${code}`);
82
+ // if (code !== 0) {
83
+ // resolve(`tsc process exited with code ${code}`);
84
+ // // reject(`tsc process exited with code ${code}`);
85
+ // } else {
86
+ // resolve({});
87
+ // }
88
+ });
89
+ });
90
+ };
12
91
  export class ITProject {
13
92
  constructor(configs) {
14
93
  this.nodeDone = false;
@@ -52,6 +131,7 @@ export class ITProject {
52
131
  }
53
132
  });
54
133
  fs.writeFileSync(`${this.config.outdir}/testeranto.json`, JSON.stringify(Object.assign(Object.assign({}, this.config), { buildDir: process.cwd() + "/" + this.config.outdir }), null, 2));
134
+ compile();
55
135
  Promise.resolve(Promise.all([...this.getSecondaryEndpointsPoints("web")].map(async (sourceFilePath) => {
56
136
  const sourceFileSplit = sourceFilePath.split("/");
57
137
  const sourceDir = sourceFileSplit.slice(0, -1);
@@ -16,7 +16,7 @@ export default async (partialConfig) => {
16
16
  executablePath:
17
17
  // process.env.CHROMIUM_PATH || "/opt/homebrew/bin/chromium",
18
18
  "/opt/homebrew/bin/chromium",
19
- headless: true,
19
+ headless: false,
20
20
  dumpio: true,
21
21
  // timeout: 0,
22
22
  devtools: true,
@@ -0,0 +1,11 @@
1
+ import process from "process";
2
+ import { ITProject } from "./Project";
3
+ if (!process.argv[2]) {
4
+ console.log("You didn't pass a config file");
5
+ process.exit(-1);
6
+ }
7
+ else {
8
+ import(process.cwd() + "/" + process.argv[2]).then((module) => {
9
+ new ITProject(module.default);
10
+ });
11
+ }
@@ -0,0 +1,17 @@
1
+ const config = {
2
+ outdir: "docs",
3
+ tests: [],
4
+ debugger: true,
5
+ clearScreen: false,
6
+ devMode: true,
7
+ minify: false,
8
+ outbase: ".",
9
+ ports: ["3001"],
10
+ externals: [],
11
+ nodePlugins: [],
12
+ webPlugins: [],
13
+ featureIngestor: function (s) {
14
+ throw new Error("Function not implemented.");
15
+ },
16
+ };
17
+ export default config;
@@ -9,13 +9,15 @@ const register = (entrypoint, sources) => {
9
9
  sources.forEach((s) => otherInputs[entrypoint].add(s));
10
10
  };
11
11
  function tree(meta, key) {
12
- return [
13
- key,
14
- ...meta.inputs[key].imports
15
- .filter((x) => x.external !== true)
16
- .filter((x) => x.path.split("/")[0] !== "node_modules")
17
- .map((f) => f.path),
18
- ];
12
+ console.log("searching metafile for", key);
13
+ const outputKey = Object.keys(meta.outputs).find((k) => {
14
+ return meta.outputs[k].entryPoint === key;
15
+ });
16
+ if (!outputKey) {
17
+ console.error("No outputkey found");
18
+ process.exit(-1);
19
+ }
20
+ return Object.keys(meta.outputs[outputKey].inputs).filter((k) => k.startsWith("src"));
19
21
  }
20
22
  export default (platform, entryPoints) => {
21
23
  return {
@@ -34,7 +36,9 @@ export default (platform, entryPoints) => {
34
36
  }
35
37
  const promptPath = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `prompt.txt`);
36
38
  const testPaths = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `tests.json`);
37
- const featuresPath = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `featurePrompt.txt`); // /read ${featuresPath}
39
+ const featuresPath = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `featurePrompt.txt`);
40
+ const stderrPath = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `stderr.log`);
41
+ const stdoutPath = path.join("./docs/", platform, entryPoint.split(".").slice(0, -1).join("."), `stdout.log`);
38
42
  if (result.metafile) {
39
43
  const addableFiles = tree(result.metafile, entryPoint.split("/").slice(1).join("/"))
40
44
  .map((y) => {
@@ -44,23 +48,31 @@ export default (platform, entryPoints) => {
44
48
  return y;
45
49
  })
46
50
  .flat();
51
+ const typeErrorFiles = addableFiles.map((t) => `docs/types/${t}.type_errors.txt`);
47
52
  fs.writeFileSync(promptPath, `
48
- ${[...addableFiles]
53
+ ${addableFiles
49
54
  .map((x) => {
50
55
  return `/add ${x}`;
51
56
  })
52
57
  .join("\n")}
53
- ${[...addableFiles]
58
+
59
+ ${typeErrorFiles
54
60
  .map((x) => {
55
- const f = `docs/ts/${x}.type_errors.txt`;
56
- if (fs.existsSync(f)) {
57
- return `/read ${f}`;
58
- }
61
+ // const f = `docs/types/${x}.type_errors.txt`;
62
+ return `/read ${x}`;
63
+ // if (fs.existsSync(f)) {
64
+ // return `/read ${f}`;
65
+ // }
59
66
  })
60
67
  .join("\n")}
68
+
61
69
  /read ${testPaths}
70
+ /read ${stdoutPath}
71
+ /read ${stderrPath}
72
+
62
73
  /load ${featuresPath}
63
- /code Fix the failing tests described in ${testPaths}. Correct any type signature errors. Implement any method which throws "Function not implemented."
74
+
75
+ /code Fix the failing tests described in ${testPaths}. Correct any type signature errors described in the files [${typeErrorFiles.join(", ")}]. Implement any method which throws "Function not implemented."
64
76
  `);
65
77
  }
66
78
  });
@@ -0,0 +1,15 @@
1
+ import fs from "fs";
2
+ import Init from "../dist/module/src/Init";
3
+ console.log("Initializing a testeranto project");
4
+ if (!process.argv[2]) {
5
+ console.log("You didn't pass a config file, so I will create one for you.");
6
+ fs.writeFileSync("testeranto.mts", fs.readFileSync("node_modules/testeranto/src/defaultConfig.ts"));
7
+ import(process.cwd() + "/" + "testeranto.mts").then((module) => {
8
+ Init(module.default);
9
+ });
10
+ }
11
+ else {
12
+ import(process.cwd() + "/" + process.argv[2]).then((module) => {
13
+ Init(module.default);
14
+ });
15
+ }
@@ -286,70 +286,6 @@ export class BaseGiven {
286
286
  if (prop === "writeFileSync") {
287
287
  return (fp, contents) => target[prop](`suite-${suiteNdx}/given-${key}/afterEach/${fp}`, contents);
288
288
  }
289
- // if (prop === "browser") {
290
- // return new Proxy(target[prop], {
291
- // get(bTarget, bProp, bReceiver) {
292
- // if (bProp === "pages") {
293
- // return async () => {
294
- // return bTarget.pages().then((pages) => {
295
- // return pages.map((page) => {
296
- // return new Proxy(page, {
297
- // get(pTarget, pProp, pReciever) {
298
- // if (pProp === "screenshot") {
299
- // return async (x) => {
300
- // // console.log(
301
- // // "custom-screenshot-MARK-afterEachProxy",
302
- // // window["custom-screenshot"].toString()
303
- // // );
304
- // return pm.customScreenShot(
305
- // {
306
- // ...x,
307
- // path:
308
- // `${testResourceConfiguration.fs}/suite-${suiteNdx}/given-${key}/afterEach` +
309
- // "/" +
310
- // x.path,
311
- // },
312
- // page
313
- // );
314
- // // return await pTarget[pProp]({
315
- // // ...x,
316
- // // path:
317
- // // `${testResourceConfiguration.fs}/suite-${suiteNdx}/given-${key}/afterEach` +
318
- // // "/" +
319
- // // x.path,
320
- // // });
321
- // };
322
- // } else if (pProp === "mainFrame") {
323
- // return () => pTarget[pProp]();
324
- // // return target[pProp];
325
- // // return Reflect.get(...arguments);
326
- // } else if (pProp === "exposeFunction") {
327
- // // return Reflect.get(target, prop, receiver);
328
- // return (...a) => pTarget[pProp](...a);
329
- // // return target[pProp];
330
- // } else if (pProp === "removeExposedFunction") {
331
- // // return Reflect.get(target, prop, receiver);
332
- // return pTarget[pProp].bind(pTarget);
333
- // // return target[pProp];
334
- // }
335
- // // else if (pProp === "#frameManager") {
336
- // // return () => target[pProp](...arguments);
337
- // // }
338
- // else {
339
- // return Reflect.get(...arguments);
340
- // }
341
- // },
342
- // });
343
- // });
344
- // });
345
- // // return (await target.pages()).map((page) => {
346
- // // return new Proxy(page, handler2);
347
- // // });
348
- // };
349
- // }
350
- // },
351
- // });
352
- // }
353
289
  return Reflect.get(...arguments);
354
290
  },
355
291
  });
@@ -37,9 +37,11 @@ export default class Testeranto extends ClassBuilder {
37
37
  }
38
38
  }, class Given extends BaseGiven {
39
39
  async givenThat(subject, testResource, artifactory, initializer, pm) {
40
- return fullTestInterface.beforeEach(subject, initializer, (fPath, value) =>
41
- // TODO does not work?
42
- artifactory(`beforeEach/${fPath}`, value), testResource, this.initialValues, pm);
40
+ return fullTestInterface.beforeEach(subject, initializer,
41
+ // (fPath: string, value: unknown) =>
42
+ // // TODO does not work?
43
+ // artifactory(`beforeEach/${fPath}`, value),
44
+ testResource, this.initialValues, pm);
43
45
  }
44
46
  afterEach(store, key, artifactory, pm) {
45
47
  return new Promise((res) => res(fullTestInterface.afterEach(store, key, (fPath, value) => artifactory(`after/${fPath}`, value), pm)));
@@ -0,0 +1,11 @@
1
+ import Puppeteer from "./Puppeteer.js";
2
+ import process from "process";
3
+ if (!process.argv[2]) {
4
+ console.log("You didn't pass a config file");
5
+ process.exit(-1);
6
+ }
7
+ else {
8
+ import(process.cwd() + "/" + process.argv[2]).then((module) => {
9
+ Puppeteer(module.default);
10
+ });
11
+ }