testeranto 0.49.10 → 0.70.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 (250) hide show
  1. package/.nvmrc +1 -0
  2. package/README.md +92 -9
  3. package/dist/cjs-shim.js +12 -0
  4. package/dist/common/Features.js +2 -3
  5. package/dist/common/Node.js +37 -62
  6. package/dist/common/NodeWriter.js +7 -9
  7. package/dist/common/Project.js +130 -627
  8. package/dist/common/SubPackages/puppeteer.js +19 -0
  9. package/dist/common/{subPackages → SubPackages}/react/component/node.js +4 -4
  10. package/dist/common/{subPackages → SubPackages}/react/component/web.js +4 -4
  11. package/dist/common/SubPackages/react/jsx/index.js +13 -0
  12. package/dist/common/SubPackages/react/jsx/node.js +10 -0
  13. package/dist/common/SubPackages/react/jsx/web.js +10 -0
  14. package/dist/common/{subPackages → SubPackages}/react-dom/component/node.js +6 -6
  15. package/dist/common/{subPackages → SubPackages}/react-dom/component/web.js +11 -12
  16. package/dist/common/SubPackages/react-dom/jsx/node.js +39 -0
  17. package/dist/common/{subPackages → SubPackages}/react-dom/jsx/web.js +19 -20
  18. package/dist/common/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +3 -3
  19. package/dist/common/{subPackages → SubPackages}/react-test-renderer/component/index.js +25 -15
  20. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/node.js +3 -5
  21. package/dist/common/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/component}/web.js +3 -5
  22. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/node.js +4 -4
  23. package/dist/common/{subPackages → SubPackages}/react-test-renderer/fc/web.js +4 -4
  24. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -3
  25. package/dist/common/{subPackages/react-test-renderer/jsx-promised → SubPackages/react-test-renderer/jsx}/node.js +4 -4
  26. package/dist/common/{subPackages/react → SubPackages/react-test-renderer}/jsx/web.js +4 -4
  27. package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +3 -3
  28. package/dist/common/{subPackages/react/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +2 -2
  29. package/dist/common/Types.js +2 -0
  30. package/dist/common/Web.js +49 -113
  31. package/dist/common/electron.js +256 -42
  32. package/dist/common/esbuildConfigs/features.js +14 -0
  33. package/dist/common/esbuildConfigs/index.js +20 -0
  34. package/dist/common/esbuildConfigs/node.js +37 -0
  35. package/dist/common/esbuildConfigs/report.js +13 -0
  36. package/dist/common/esbuildConfigs/tests.js +13 -0
  37. package/dist/common/esbuildConfigs/web.js +53 -0
  38. package/dist/common/lib/abstractBase.js +200 -0
  39. package/dist/common/lib/basebuilder.js +86 -0
  40. package/dist/common/lib/classBuilder.js +40 -0
  41. package/dist/common/lib/core.js +81 -0
  42. package/dist/common/lib/index.js +21 -0
  43. package/dist/common/lib/types.js +2 -0
  44. package/dist/common/preload.js +15 -24
  45. package/dist/common/puppeteerConfiger.js +24 -0
  46. package/dist/common/report.html.js +31 -0
  47. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  48. package/dist/common/web.html.js +22 -0
  49. package/dist/module/Features.js +2 -3
  50. package/dist/module/Node.js +37 -62
  51. package/dist/module/NodeWriter.js +7 -9
  52. package/dist/module/Project.js +131 -605
  53. package/dist/module/SubPackages/puppeteer.js +14 -0
  54. package/dist/module/{subPackages → SubPackages}/react/component/node.js +3 -3
  55. package/dist/module/{subPackages → SubPackages}/react/component/web.js +3 -3
  56. package/dist/module/SubPackages/react/jsx/index.js +10 -0
  57. package/dist/module/SubPackages/react/jsx/node.js +5 -0
  58. package/dist/module/SubPackages/react/jsx/web.js +5 -0
  59. package/dist/module/{subPackages → SubPackages}/react-dom/component/node.js +7 -7
  60. package/dist/module/{subPackages → SubPackages}/react-dom/component/web.js +10 -11
  61. package/dist/module/SubPackages/react-dom/jsx/node.js +31 -0
  62. package/dist/module/{subPackages → SubPackages}/react-dom/jsx/web.js +20 -21
  63. package/dist/module/{subPackages → SubPackages}/react-test-renderer/MemoExoticComponent/node.js +3 -3
  64. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/index.js +22 -15
  65. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/node.js +2 -2
  66. package/dist/module/{subPackages → SubPackages}/react-test-renderer/component/web.js +2 -2
  67. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/node.js +3 -3
  68. package/dist/module/{subPackages → SubPackages}/react-test-renderer/fc/web.js +3 -3
  69. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx/index.js +8 -3
  70. package/dist/module/SubPackages/react-test-renderer/jsx/node.js +5 -0
  71. package/dist/module/SubPackages/react-test-renderer/jsx/web.js +5 -0
  72. package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.js +3 -3
  73. package/dist/module/{subPackages/react-test-renderer/jsx → SubPackages/react-test-renderer/jsx-promised}/node.js +1 -1
  74. package/dist/module/Types.js +2 -0
  75. package/dist/module/Web.js +49 -113
  76. package/dist/module/electron.js +257 -43
  77. package/dist/module/esbuildConfigs/features.js +12 -0
  78. package/dist/module/esbuildConfigs/index.js +18 -0
  79. package/dist/module/esbuildConfigs/node.js +32 -0
  80. package/dist/module/esbuildConfigs/report.js +11 -0
  81. package/dist/module/esbuildConfigs/tests.js +11 -0
  82. package/dist/module/esbuildConfigs/web.js +48 -0
  83. package/dist/module/lib/abstractBase.js +192 -0
  84. package/dist/module/lib/basebuilder.js +82 -0
  85. package/dist/module/lib/classBuilder.js +36 -0
  86. package/dist/module/lib/core.js +78 -0
  87. package/dist/module/lib/index.js +17 -0
  88. package/dist/module/lib/types.js +1 -0
  89. package/dist/module/preload.js +12 -24
  90. package/dist/module/puppeteerConfiger.js +19 -0
  91. package/dist/module/report.html.js +29 -0
  92. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  93. package/dist/module/web.html.js +20 -0
  94. package/dist/prebuild/Report.css +10326 -0
  95. package/dist/prebuild/Report.js +37456 -0
  96. package/dist/types/Features.d.ts +5 -5
  97. package/dist/types/Node.d.ts +5 -11
  98. package/dist/types/NodeWriter.d.ts +1 -1
  99. package/dist/types/Project.d.ts +2 -28
  100. package/dist/types/SubPackages/puppeteer.d.ts +6 -0
  101. package/dist/types/SubPackages/react/component/node.d.ts +7 -0
  102. package/dist/types/SubPackages/react/component/web.d.ts +7 -0
  103. package/dist/types/SubPackages/react/jsx/index.d.ts +15 -0
  104. package/dist/types/SubPackages/react/jsx/node.d.ts +4 -0
  105. package/dist/types/SubPackages/react/jsx/web.d.ts +4 -0
  106. package/dist/types/SubPackages/react-dom/component/node.d.ts +12 -0
  107. package/dist/types/SubPackages/react-dom/component/web.d.ts +5 -0
  108. package/dist/types/SubPackages/react-dom/jsx/node.d.ts +6 -0
  109. package/dist/types/SubPackages/react-dom/jsx/web.d.ts +5 -0
  110. package/dist/types/SubPackages/react-test-renderer/MemoExoticComponent/node.d.ts +5 -0
  111. package/dist/types/{subPackages → SubPackages}/react-test-renderer/component/index.d.ts +6 -6
  112. package/dist/types/{subPackages → SubPackages}/react-test-renderer/component/node.d.ts +4 -4
  113. package/dist/types/SubPackages/react-test-renderer/component/web.d.ts +4 -0
  114. package/dist/types/SubPackages/react-test-renderer/fc/node.d.ts +8 -0
  115. package/dist/types/SubPackages/react-test-renderer/fc/web.d.ts +8 -0
  116. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx/index.d.ts +5 -4
  117. package/dist/types/SubPackages/react-test-renderer/jsx/node.d.ts +9 -0
  118. package/dist/types/SubPackages/react-test-renderer/jsx/web.d.ts +9 -0
  119. package/dist/types/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.d.ts +4 -4
  120. package/dist/types/SubPackages/react-test-renderer/jsx-promised/node.d.ts +5 -0
  121. package/dist/types/SubPackages/react-test-renderer/jsx-promised/web.d.ts +5 -0
  122. package/dist/types/Types.d.ts +49 -17
  123. package/dist/types/Web.d.ts +5 -11
  124. package/dist/types/esbuildConfigs/features.d.ts +4 -0
  125. package/dist/types/esbuildConfigs/index.d.ts +4 -0
  126. package/dist/types/esbuildConfigs/node.d.ts +4 -0
  127. package/dist/types/esbuildConfigs/report.d.ts +4 -0
  128. package/dist/types/esbuildConfigs/tests.d.ts +4 -0
  129. package/dist/types/esbuildConfigs/web.d.ts +4 -0
  130. package/dist/types/lib/abstractBase.d.ts +103 -0
  131. package/dist/types/lib/basebuilder.d.ts +25 -0
  132. package/dist/types/lib/classBuilder.d.ts +7 -0
  133. package/dist/types/lib/core.d.ts +8 -0
  134. package/dist/types/lib/index.d.ts +58 -0
  135. package/dist/types/lib/types.d.ts +70 -0
  136. package/dist/types/puppeteerConfiger.d.ts +4 -0
  137. package/dist/types/report.html.d.ts +2 -0
  138. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  139. package/dist/types/web.html.d.ts +2 -0
  140. package/electronBuild.ts +32 -0
  141. package/index.html +30 -0
  142. package/package.json +123 -87
  143. package/src/Features.ts +2 -4
  144. package/src/Node.ts +79 -155
  145. package/src/NodeWriter.ts +22 -22
  146. package/src/Project.ts +185 -783
  147. package/src/Report.tsx +30 -15
  148. package/src/SubPackages/puppeteer.ts +51 -0
  149. package/src/SubPackages/react/component/node.ts +43 -0
  150. package/src/SubPackages/react/component/web.ts +43 -0
  151. package/src/SubPackages/react/jsx/index.ts +32 -0
  152. package/src/SubPackages/react/jsx/node.ts +29 -0
  153. package/src/SubPackages/react/jsx/web.ts +30 -0
  154. package/src/{subPackages → SubPackages}/react-dom/component/node.ts +24 -44
  155. package/src/SubPackages/react-dom/component/web.ts +104 -0
  156. package/src/{subPackages → SubPackages}/react-dom/jsx/index.ts +0 -1
  157. package/src/SubPackages/react-dom/jsx/node.ts +68 -0
  158. package/src/SubPackages/react-dom/jsx/web.ts +102 -0
  159. package/src/SubPackages/react-test-renderer/MemoExoticComponent/node.ts +38 -0
  160. package/src/{subPackages → SubPackages}/react-test-renderer/component/index.ts +37 -49
  161. package/src/SubPackages/react-test-renderer/component/node.ts +16 -0
  162. package/src/SubPackages/react-test-renderer/component/web.ts +16 -0
  163. package/src/SubPackages/react-test-renderer/fc/node.ts +49 -0
  164. package/src/SubPackages/react-test-renderer/fc/web.ts +48 -0
  165. package/src/SubPackages/react-test-renderer/jsx/index.ts +49 -0
  166. package/src/SubPackages/react-test-renderer/jsx/node.ts +20 -0
  167. package/src/SubPackages/react-test-renderer/jsx/web.ts +20 -0
  168. package/src/{subPackages → SubPackages}/react-test-renderer/jsx-promised/index.ts +15 -26
  169. package/src/SubPackages/react-test-renderer/jsx-promised/node.ts +19 -0
  170. package/src/SubPackages/react-test-renderer/jsx-promised/web.ts +22 -0
  171. package/src/Types.ts +114 -17
  172. package/src/Web.ts +100 -225
  173. package/src/cjs-shim.js +12 -0
  174. package/src/electron.ts +303 -45
  175. package/src/esbuildConfigs/features.ts +17 -0
  176. package/src/esbuildConfigs/index.ts +22 -0
  177. package/src/esbuildConfigs/node.ts +60 -0
  178. package/src/esbuildConfigs/report.ts +15 -0
  179. package/src/esbuildConfigs/tests.ts +14 -0
  180. package/src/esbuildConfigs/web.ts +73 -0
  181. package/src/lib/abstractBase.ts +412 -0
  182. package/src/lib/basebuilder.ts +228 -0
  183. package/src/lib/classBuilder.ts +118 -0
  184. package/src/lib/core.ts +214 -0
  185. package/src/lib/index.ts +117 -0
  186. package/src/lib/types.ts +206 -0
  187. package/src/preload.ts +13 -27
  188. package/src/puppeteerConfiger.ts +26 -0
  189. package/src/report.html.ts +29 -0
  190. package/src/web.html.ts +20 -0
  191. package/tests/Rectangle.test.ts +189 -0
  192. package/tsconfig.json +19 -6
  193. package/tsconfig.module.json +15 -4
  194. package/tsconfig.types.json +14 -4
  195. package/yarn-error.log +3144 -0
  196. package/dist/common/core.js +0 -397
  197. package/dist/common/subPackages/react/jsx/index.js +0 -26
  198. package/dist/common/subPackages/react-dom/jsx/node.js +0 -95
  199. package/dist/common/subPackages/react-test-renderer/component/node.js +0 -8
  200. package/dist/common/subPackages/react-test-renderer/component/web.js +0 -8
  201. package/dist/module/Report.js +0 -186
  202. package/dist/module/core.js +0 -388
  203. package/dist/module/subPackages/react/jsx/index.js +0 -22
  204. package/dist/module/subPackages/react/jsx/node.js +0 -5
  205. package/dist/module/subPackages/react/jsx/web.js +0 -5
  206. package/dist/module/subPackages/react-dom/jsx/node.js +0 -87
  207. package/dist/module/subPackages/react-test-renderer/jsx/web.js +0 -5
  208. package/dist/module/subPackages/react-test-renderer/jsx-promised/node.js +0 -5
  209. package/dist/types/core.d.ts +0 -220
  210. package/dist/types/subPackages/react/component/node.d.ts +0 -12
  211. package/dist/types/subPackages/react/component/web.d.ts +0 -12
  212. package/dist/types/subPackages/react/jsx/index.d.ts +0 -15
  213. package/dist/types/subPackages/react/jsx/node.d.ts +0 -4
  214. package/dist/types/subPackages/react/jsx/web.d.ts +0 -4
  215. package/dist/types/subPackages/react-dom/component/node.d.ts +0 -14
  216. package/dist/types/subPackages/react-dom/component/web.d.ts +0 -19
  217. package/dist/types/subPackages/react-dom/jsx/node.d.ts +0 -8
  218. package/dist/types/subPackages/react-dom/jsx/web.d.ts +0 -5
  219. package/dist/types/subPackages/react-test-renderer/MemoExoticComponent/node.d.ts +0 -8
  220. package/dist/types/subPackages/react-test-renderer/component/web.d.ts +0 -9
  221. package/dist/types/subPackages/react-test-renderer/fc/node.d.ts +0 -9
  222. package/dist/types/subPackages/react-test-renderer/fc/web.d.ts +0 -9
  223. package/dist/types/subPackages/react-test-renderer/jsx/node.d.ts +0 -4
  224. package/dist/types/subPackages/react-test-renderer/jsx/web.d.ts +0 -4
  225. package/dist/types/subPackages/react-test-renderer/jsx-promised/node.d.ts +0 -4
  226. package/dist/types/subPackages/react-test-renderer/jsx-promised/web.d.ts +0 -4
  227. package/src/core.ts +0 -1399
  228. package/src/subPackages/react/component/node.ts +0 -75
  229. package/src/subPackages/react/component/web.ts +0 -80
  230. package/src/subPackages/react/jsx/index.ts +0 -64
  231. package/src/subPackages/react/jsx/node.ts +0 -29
  232. package/src/subPackages/react/jsx/web.ts +0 -29
  233. package/src/subPackages/react-dom/component/web.ts +0 -129
  234. package/src/subPackages/react-dom/jsx/node.ts +0 -145
  235. package/src/subPackages/react-dom/jsx/web.ts +0 -145
  236. package/src/subPackages/react-test-renderer/MemoExoticComponent/node.ts +0 -67
  237. package/src/subPackages/react-test-renderer/component/node.ts +0 -30
  238. package/src/subPackages/react-test-renderer/component/web.ts +0 -30
  239. package/src/subPackages/react-test-renderer/fc/node.ts +0 -77
  240. package/src/subPackages/react-test-renderer/fc/web.ts +0 -77
  241. package/src/subPackages/react-test-renderer/jsx/index.ts +0 -51
  242. package/src/subPackages/react-test-renderer/jsx/node.ts +0 -31
  243. package/src/subPackages/react-test-renderer/jsx/web.ts +0 -31
  244. package/src/subPackages/react-test-renderer/jsx-promised/node.ts +0 -31
  245. package/src/subPackages/react-test-renderer/jsx-promised/web.ts +0 -31
  246. /package/dist/common/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  247. /package/dist/common/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
  248. /package/dist/module/{subPackages → SubPackages}/react-dom/jsx/index.js +0 -0
  249. /package/dist/module/{subPackages → SubPackages}/react-test-renderer/jsx-promised/web.js +0 -0
  250. /package/dist/types/{subPackages → SubPackages}/react-dom/jsx/index.d.ts +0 -0
@@ -1,631 +1,157 @@
1
1
  import esbuild from "esbuild";
2
2
  import fs from "fs";
3
- import fsExists from "fs.promises.exists";
4
3
  import path from "path";
5
- import pm2 from "pm2";
6
- import readline from 'readline';
7
- import { WebSocketServer } from 'ws';
4
+ import readline from "readline";
8
5
  import { glob } from "glob";
6
+ import esbuildNodeConfiger from "./esbuildConfigs/node.js";
7
+ import esbuildWebConfiger from "./esbuildConfigs/web.js";
8
+ import esbuildFeaturesConfiger from "./esbuildConfigs/features.js";
9
+ import webHtmlFrame from "./web.html.js";
10
+ import reportHtmlFrame from "./report.html.js";
11
+ var mode = process.argv[2] === "-dev" ? "DEV" : "PROD";
9
12
  readline.emitKeypressEvents(process.stdin);
10
13
  if (process.stdin.isTTY)
11
14
  process.stdin.setRawMode(true);
12
- const TIMEOUT = 2000;
13
- const OPEN_PORT = "";
14
- let webSocketServer;
15
- const getRunnables = (tests, payload = [new Set(), new Set()]) => {
16
- return tests.reduce((pt, cv, cndx, cry) => {
17
- if (cv[1] === "node") {
18
- pt[0].add(cv[0]);
19
- }
20
- else if (cv[1] === "web") {
21
- pt[1].add(cv[0]);
22
- }
23
- if (cv[2].length) {
24
- getRunnables(cv[2], payload);
25
- }
26
- return pt;
27
- }, payload);
15
+ process.stdin.on("keypress", (str, key) => {
16
+ if (key.name === "q") {
17
+ console.log("Testeranto-EsBuild is shutting down...");
18
+ mode = "PROD";
19
+ onDone();
20
+ }
21
+ });
22
+ // setInterval(() => {
23
+ // const memoryUsage = process.memoryUsage();
24
+ // console.log("Memory usage:", memoryUsage);
25
+ // }, 10000); // Check every 10 seconds
26
+ let featuresDone, nodeDone, webDone = false;
27
+ const onFeaturesDone = () => {
28
+ featuresDone = true;
29
+ onDone();
30
+ };
31
+ const onNodeDone = () => {
32
+ nodeDone = true;
33
+ onDone();
34
+ };
35
+ const onWebDone = () => {
36
+ webDone = true;
37
+ onDone();
38
+ };
39
+ const onDone = () => {
40
+ console.log(JSON.stringify({
41
+ featuresDone,
42
+ nodeDone,
43
+ webDone,
44
+ mode,
45
+ }, null, 2));
46
+ if (featuresDone && nodeDone && webDone && mode === "PROD") {
47
+ console.log("Testeranto-EsBuild is all done. Goodbye!");
48
+ process.exit();
49
+ }
50
+ else {
51
+ console.log("Testeranto-EsBuild is still working...");
52
+ }
28
53
  };
29
54
  export class ITProject {
30
55
  constructor(config) {
31
- this.exitCodes = {};
32
56
  this.mode = `up`;
33
- this.ports = {};
34
- this.websockets = {};
35
- this.resourceQueue = [];
36
- this.spinCycle = 0;
37
- this.spinAnimation = "←↖↑↗→↘↓↙";
38
- this.mainLoop = async () => {
39
- if (this.clearScreen) {
40
- console.clear();
41
- }
42
- const procsTable = [];
43
- pm2.list((err, procs) => {
44
- procs.forEach((proc) => {
45
- var _a, _b;
46
- procsTable.push({
47
- name: proc.name,
48
- pid: proc.pid,
49
- pm_id: proc.pm_id,
50
- mem: (_a = proc.monit) === null || _a === void 0 ? void 0 : _a.memory,
51
- cpu: (_b = proc.monit) === null || _b === void 0 ? void 0 : _b.cpu,
52
- "exit code": this.exitCodes[proc.name]
53
- });
54
- });
55
- console.table(procsTable);
56
- console.table(this.resourceQueue);
57
- console.log("webSocketServer.clients", Object.keys(this.websockets));
58
- const resourceRequest = this.resourceQueue.pop();
59
- if (!resourceRequest) {
60
- if (!this.devMode && this.mode === "up") {
61
- this.initiateShutdown("resource request queue is empty");
62
- }
63
- if (this.mode === "down" &&
64
- (procsTable.every((p) => p.pid === 0 || p.pid === undefined) ||
65
- procsTable.length === 0)) {
66
- this.shutdown();
67
- }
57
+ this.config = config;
58
+ Promise.resolve(Promise.all([...this.getSecondaryEndpointsPoints("web")].map(async (sourceFilePath) => {
59
+ const sourceFileSplit = sourceFilePath.split("/");
60
+ const sourceDir = sourceFileSplit.slice(0, -1);
61
+ const sourceFileName = sourceFileSplit[sourceFileSplit.length - 1];
62
+ const sourceFileNameMinusJs = sourceFileName
63
+ .split(".")
64
+ .slice(0, -1)
65
+ .join(".");
66
+ const htmlFilePath = path.normalize(`${process.cwd()}/${config.outdir}/web/${sourceDir.join("/")}/${sourceFileNameMinusJs}.html`);
67
+ const jsfilePath = `./${sourceFileNameMinusJs}.mjs`;
68
+ return fs.promises
69
+ .mkdir(path.dirname(htmlFilePath), { recursive: true })
70
+ .then((x) => fs.writeFileSync(htmlFilePath, webHtmlFrame(jsfilePath, htmlFilePath)));
71
+ })));
72
+ const [nodeEntryPoints, webEntryPoints] = getRunnables(this.config.tests);
73
+ glob(`./${config.outdir}/chunk-*.mjs`, { ignore: "node_modules/**" }).then((chunks) => {
74
+ chunks.forEach((chunk) => {
75
+ fs.unlinkSync(chunk);
76
+ });
77
+ });
78
+ fs.copyFileSync("./node_modules/testeranto/dist/prebuild/Report.js", "./docs/Report.js");
79
+ fs.copyFileSync("./node_modules/testeranto/dist/prebuild/Report.css", "./docs/Report.css");
80
+ fs.writeFileSync(`${config.outdir}/report.html`, reportHtmlFrame());
81
+ Promise.all([
82
+ fs.promises.writeFile(`${config.outdir}/testeranto.json`, JSON.stringify(Object.assign(Object.assign({}, config), { buildDir: process.cwd() + "/" + config.outdir }), null, 2)),
83
+ esbuild
84
+ .context(esbuildFeaturesConfiger(config))
85
+ .then(async (featuresContext) => {
86
+ if (mode == "DEV") {
87
+ await featuresContext.watch();
88
+ onFeaturesDone();
68
89
  }
69
90
  else {
70
- if (resourceRequest.protocol === "ipc") {
71
- this.allocateViaIpc(resourceRequest);
72
- }
73
- else if (resourceRequest.protocol === "ws") {
74
- this.allocateViaWs(resourceRequest);
75
- }
91
+ featuresContext.rebuild().then((v) => {
92
+ onFeaturesDone();
93
+ });
76
94
  }
77
- const upMessage = "Running tests while watching for changes. Use 'q' to initiate shutdown and `x` to kill.";
78
- const downMessage = "Shutdown is in progress. Please wait.";
79
- if (this.devMode) {
80
- if (this.mode === "up") {
81
- console.log(this.spinner(), upMessage);
82
- }
83
- else {
84
- console.log(this.spinner(), downMessage);
85
- }
95
+ return featuresContext;
96
+ }),
97
+ esbuild
98
+ .context(esbuildNodeConfiger(config, nodeEntryPoints))
99
+ .then(async (nodeContext) => {
100
+ if (mode == "DEV") {
101
+ await nodeContext.watch().then((v) => {
102
+ onNodeDone();
103
+ });
86
104
  }
87
105
  else {
88
- if (this.mode === "up") {
89
- console.log(this.spinner(), upMessage);
90
- }
91
- else {
92
- console.log(this.spinner(), downMessage);
93
- }
94
- }
95
- });
96
- };
97
- this.clearScreen = config.clearScreen;
98
- this.devMode = config.devMode;
99
- // mark each port as open
100
- Object.values(config.ports).forEach((port) => {
101
- this.ports[port] = OPEN_PORT;
102
- });
103
- const testPath = `${process.cwd()}/${config.tests}`;
104
- const featurePath = `${process.cwd()}/${config.features}`;
105
- process.stdin.on('keypress', (str, key) => {
106
- if (key.name === 'q') {
107
- this.initiateShutdown("'q' command");
108
- }
109
- });
110
- process.stdin.on('keypress', (str, key) => {
111
- if (key.name === 'x') {
112
- console.log("Shutting down hard!");
113
- process.exit(-1);
114
- }
115
- });
116
- import(testPath).then((tests) => {
117
- this.tests = tests.default;
118
- import(featurePath).then(async (features) => {
119
- this.features = features.default;
120
- await Promise.resolve(Promise.all([
121
- ...this.getSecondaryEndpointsPoints("web")
122
- ]
123
- .map(async (sourceFilePath) => {
124
- const sourceFileSplit = sourceFilePath.split("/");
125
- const sourceDir = sourceFileSplit.slice(0, -1);
126
- const sourceFileName = sourceFileSplit[sourceFileSplit.length - 1];
127
- const sourceFileNameMinusJs = sourceFileName.split(".").slice(0, -1).join(".");
128
- const htmlFilePath = path.normalize(`${process.cwd()}/${config.outdir}/${sourceDir.join("/")}/${sourceFileNameMinusJs}.html`);
129
- const jsfilePath = `./${sourceFileNameMinusJs}.mjs`;
130
- return fs.promises.mkdir(path.dirname(htmlFilePath), { recursive: true }).then(x => fs.writeFileSync(htmlFilePath, `
131
- <!DOCTYPE html>
132
- <html lang="en">
133
- <head>
134
- <script type="module" src="${jsfilePath}"></script>
135
- </head>
136
-
137
- <body>
138
- <h1>${htmlFilePath}</h1>
139
- <div id="root">
140
-
141
- </div>
142
- </body>
143
-
144
- <footer></footer>
145
-
146
- </html>
147
- `));
148
- })));
149
- const [nodeEntryPoints, webEntryPoints] = getRunnables(this.tests);
150
- const esbuildConfigNode = {
151
- define: {
152
- "process.env.FLUENTFFMPEG_COV": "0"
153
- },
154
- absWorkingDir: process.cwd(),
155
- banner: {
156
- js: `import { createRequire } from 'module';const require = createRequire(import.meta.url);`
157
- },
158
- target: "esnext",
159
- format: "esm",
160
- splitting: true,
161
- outExtension: { '.js': '.mjs' },
162
- platform: "node",
163
- external: [
164
- "tests.test.js",
165
- "features.test.js", "react"
166
- ],
167
- outbase: config.outbase,
168
- outdir: config.outdir,
169
- jsx: 'transform',
170
- entryPoints: [...nodeEntryPoints],
171
- bundle: true,
172
- minify: config.minify === true,
173
- write: true,
174
- loader: {
175
- '.js': 'jsx',
176
- '.png': 'binary',
177
- '.jpg': 'binary',
178
- },
179
- plugins: [
180
- ...(config.nodePlugins || []),
181
- {
182
- name: 'rebuild-notify',
183
- setup(build) {
184
- build.onEnd(result => {
185
- console.log(`node build ended with ${result.errors.length} errors`);
186
- console.log(result);
187
- result.errors.length !== 0 && process.exit(-1);
188
- });
189
- }
190
- },
191
- ],
192
- };
193
- const esbuildConfigWeb = {
194
- target: "esnext",
195
- format: "esm",
196
- splitting: true,
197
- outExtension: { '.js': '.mjs' },
198
- alias: {
199
- react: path.resolve("./node_modules/react")
200
- },
201
- external: [
202
- "tests.test.js",
203
- "features.test.js",
204
- // "url",
205
- // "react",
206
- "electron",
207
- "path",
208
- "fs",
209
- "stream",
210
- ],
211
- platform: "browser",
212
- outbase: config.outbase,
213
- outdir: config.outdir,
214
- jsx: 'transform',
215
- entryPoints: [
216
- ...webEntryPoints,
217
- testPath,
218
- featurePath,
219
- ],
220
- bundle: true,
221
- minify: config.minify === true,
222
- write: true,
223
- loader: {
224
- '.js': 'jsx',
225
- '.png': 'binary',
226
- '.jpg': 'binary',
227
- },
228
- plugins: [
229
- ...(config.webPlugins || []),
230
- {
231
- name: 'rebuild-notify',
232
- setup(build) {
233
- build.onEnd(result => {
234
- console.log(`web build ended with ${result.errors.length} errors`);
235
- console.log(result);
236
- result.errors.length !== 0 && process.exit(-1);
237
- });
238
- }
239
- },
240
- ],
241
- };
242
- glob('./dist/chunk-*.mjs', { ignore: 'node_modules/**' }).then((chunks) => {
243
- console.log("deleting chunks", chunks);
244
- chunks.forEach((chunk) => {
245
- console.log("deleting chunk", chunk);
246
- fs.unlinkSync(chunk);
106
+ nodeContext.rebuild().then((v) => {
107
+ onNodeDone();
247
108
  });
248
- });
249
- esbuild.build({
250
- bundle: true,
251
- entryPoints: ["./node_modules/testeranto/dist/module/Report.js"],
252
- minify: config.minify === true,
253
- outbase: config.outbase,
254
- write: true,
255
- outfile: `${config.outdir}/Report.js`,
256
- external: ["tests.test.js", "features.test.js"]
257
- });
258
- fs.writeFileSync(`${config.outdir}/report.html`, `
259
- <!DOCTYPE html>
260
- <html lang="en">
261
-
262
- <head>
263
- <meta name="description" content="Webpage description goes here" />
264
- <meta charset="utf-8" />
265
- <title>kokomoBay - testeranto</title>
266
- <meta name="viewport" content="width=device-width, initial-scale=1" />
267
- <meta name="author" content="" />
268
- <link rel="stylesheet" href="./Report.css" />
269
-
270
- <script type="importmap">
271
- {
272
- "imports": {
273
- "tests.test.js": "./tests.test.js",
274
- "features.test.js": "./features.test.js"
275
- }
276
- }
277
- </script>
278
-
279
-
280
- <script src="./Report.js"></script>
281
- </head>
282
-
283
- <body>
284
- <div id="root">
285
- react is loading
286
- </div>
287
- </body>
288
-
289
- </html>
290
- `);
291
- Promise.all([
292
- esbuild.context(esbuildConfigNode)
293
- .then(async (nodeContext) => {
294
- await nodeContext.watch();
295
- }),
296
- esbuild.context(esbuildConfigWeb)
297
- .then(async (esbuildWeb) => {
298
- await esbuildWeb.watch();
299
- })
300
- ]).then(() => {
301
- if (config.devMode === false) {
302
- console.log("Your tests were built but not run because devMode was false. Exiting gracefully");
303
- process.exit(0);
304
- }
305
- else {
306
- pm2.connect(async (err) => {
307
- if (err) {
308
- console.error(err);
309
- process.exit(-1);
310
- }
311
- else {
312
- console.log(`pm2 is connected`);
313
- }
314
- // run a websocket as an alternative to node IPC
315
- webSocketServer = new WebSocketServer({
316
- port: 8080,
317
- host: "localhost",
318
- });
319
- webSocketServer.on('open', () => {
320
- console.log('open');
321
- });
322
- webSocketServer.on('close', (data) => {
323
- console.log('webSocketServer close: %s', data);
324
- });
325
- webSocketServer.on('listening', () => {
326
- console.log("webSocketServer listening", webSocketServer.address());
327
- });
328
- webSocketServer.on('connection', (webSocket) => {
329
- webSocket.on('message', (webSocketData) => {
330
- const payload = JSON.parse(webSocketData.valueOf().toString());
331
- const messageType = payload.type;
332
- if (messageType === "testeranto:hola") {
333
- const name = payload.data.requirement.name;
334
- const requestedResources = payload.data;
335
- this.websockets[name] = webSocket;
336
- console.log('hola WS! connected: ' + name + ' in ' + Object.getOwnPropertyNames(this.websockets));
337
- this.requestResource(requestedResources.requirement, 'ws');
338
- }
339
- else if (messageType === "testeranto:adios") {
340
- console.log("adios WS", payload.data.testResourceConfiguration.name);
341
- this.releaseTestResourceWs(payload);
342
- }
343
- });
344
- });
345
- const makePath = (fPath, rt) => {
346
- return path.resolve("./" + config.outdir + "/" + fPath.replace(path.extname(fPath), "") + ".mjs");
347
- };
348
- const bootInterval = setInterval(async () => {
349
- const filesToLookup = this.tests
350
- .map(([p, rt]) => {
351
- const filepath = makePath(p, rt);
352
- return {
353
- filepath,
354
- exists: fsExists(filepath),
355
- };
356
- });
357
- const allFilesExist = (await Promise.all(filesToLookup.map((f) => f.exists))).every((b) => b);
358
- if (!allFilesExist) {
359
- console.log(this.spinner(), "waiting for files to build...");
360
- filesToLookup.forEach((f) => {
361
- console.log(f.exists, "\t", f.filepath);
362
- });
363
- }
364
- else {
365
- clearInterval(bootInterval);
366
- pm2.launchBus((err, pm2_bus) => {
367
- pm2_bus.on("testeranto:hola", (packet) => {
368
- this.requestResource(packet.data.requirement, 'ipc');
369
- });
370
- pm2_bus.on("testeranto:adios", (payload) => {
371
- this.releaseTestResourcePm2(payload.data);
372
- });
373
- });
374
- this
375
- .tests
376
- .reduce((m, [inputFilePath, runtime]) => {
377
- const script = makePath(inputFilePath, runtime);
378
- const partialTestResourceByCommandLineArg = `${script} '${JSON.stringify({
379
- name: inputFilePath,
380
- ports: [],
381
- fs: path.resolve(process.cwd(), config.outdir, inputFilePath),
382
- })}'`;
383
- if (runtime === "web") {
384
- const fileAsList = inputFilePath.split("/");
385
- const fileListHead = fileAsList.slice(0, -1);
386
- const fname = fileAsList[fileAsList.length - 1];
387
- const fnameOnly = fname.split(".").slice(0, -1).join(".");
388
- const htmlFile = [config.outdir, ...fileListHead, `${fnameOnly}.html`].join("/");
389
- const jsFile = path.resolve(htmlFile.split(".html")[0] + ".mjs");
390
- console.log("watching", jsFile);
391
- pm2.start({
392
- script: `yarn electron node_modules/testeranto/dist/common/electron.js ${htmlFile} '${JSON.stringify({
393
- scheduled: true,
394
- name: inputFilePath,
395
- ports: [],
396
- fs: path.resolve(process.cwd(), config.outdir, inputFilePath),
397
- })}'`,
398
- name: inputFilePath,
399
- autorestart: false,
400
- args: partialTestResourceByCommandLineArg,
401
- watch: [jsFile],
402
- }, (err, proc) => {
403
- if (err) {
404
- console.error(err);
405
- return pm2.disconnect();
406
- }
407
- });
408
- }
409
- else if (runtime === "node") {
410
- const resolvedPath = path.resolve(script);
411
- console.log("watching", resolvedPath);
412
- pm2.start({
413
- name: inputFilePath,
414
- script: `node ${resolvedPath} '${JSON.stringify({
415
- scheduled: true,
416
- name: inputFilePath,
417
- ports: [],
418
- fs: path.resolve(process.cwd(), config.outdir, inputFilePath),
419
- })}'`,
420
- autorestart: false,
421
- watch: [resolvedPath],
422
- args: partialTestResourceByCommandLineArg
423
- }, (err, proc) => {
424
- if (err) {
425
- console.error(err);
426
- return pm2.disconnect();
427
- }
428
- });
429
- }
430
- this.exitCodes[inputFilePath] = null;
431
- return [inputFilePath, ...m];
432
- }, []);
433
- setInterval(this.mainLoop, TIMEOUT).unref();
434
- }
435
- }, TIMEOUT).unref();
436
- });
437
- }
438
- });
439
- });
440
- });
441
- }
442
- requestResource(requirement, protocol) {
443
- this.resourceQueue.push({ requirement, protocol });
444
- }
445
- getSecondaryEndpointsPoints(runtime) {
446
- if (runtime) {
447
- return this.tests
448
- .filter((t) => {
449
- return (t[1] === runtime);
450
- })
451
- .map((tc) => tc[0]);
452
- }
453
- return this.tests
454
- .map((tc) => tc[0]);
455
- }
456
- initiateShutdown(reason) {
457
- console.log("Shutdown initiated because", reason);
458
- this.mode = "down";
459
- }
460
- shutdown() {
461
- let i = 0;
462
- new Promise((res, reh) => {
463
- console.log("final results: ");
464
- const procsTable = [];
465
- pm2.list((err, procs) => {
466
- procs.forEach((proc, ndx) => {
467
- const exitCode = this.exitCodes[proc.name];
468
- if (exitCode !== 0) {
469
- i++;
470
- }
471
- procsTable.push({
472
- name: proc.name,
473
- pm_id: proc.pm_id,
474
- exitCode
109
+ }
110
+ return nodeContext;
111
+ }),
112
+ esbuild
113
+ .context(esbuildWebConfiger(config, webEntryPoints))
114
+ .then(async (webContext) => {
115
+ if (mode == "DEV") {
116
+ await webContext.watch().then((v) => {
117
+ onWebDone();
475
118
  });
476
- if (ndx === procs.length - 1) {
477
- console.table(procsTable);
478
- res(i);
479
- }
480
- });
481
- });
482
- }).then((failures) => {
483
- pm2.stop("all", (e) => console.error(e));
484
- pm2.disconnect();
485
- console.log(`gracefully exiting with ${failures} failures`);
486
- process.exit(failures);
487
- });
488
- }
489
- spinner() {
490
- this.spinCycle = (this.spinCycle + 1) % this.spinAnimation.length;
491
- return this.spinAnimation[this.spinCycle];
492
- }
493
- async releaseTestResourceWs(payload) {
494
- const name = payload.data.testResourceConfiguration.name;
495
- const failed = payload.data.failed;
496
- this.exitCodes[name] = failed;
497
- Object.keys(this.ports).forEach((port) => {
498
- if (this.ports[port] === name) {
499
- this.ports[port] = OPEN_PORT;
500
- }
501
- });
502
- }
503
- async releaseTestResourcePm2(payload) {
504
- const name = payload.testResourceConfiguration.name;
505
- const failed = payload.failed;
506
- this.exitCodes[name] = failed;
507
- pm2.list((err, processes) => {
508
- processes.forEach((proc) => {
509
- if (proc.name === name) {
510
- Object.keys(this.ports).forEach((port) => {
511
- if (this.ports[port] === name) {
512
- this.ports[port] = OPEN_PORT;
513
- }
119
+ }
120
+ else {
121
+ webContext.rebuild().then((v) => {
122
+ onWebDone();
514
123
  });
515
124
  }
516
- });
517
- });
125
+ return webContext;
126
+ }),
127
+ ]);
518
128
  }
519
- allocateViaWs(resourceRequest) {
520
- const name = resourceRequest.requirement.name;
521
- const testResourceRequirement = resourceRequest.requirement;
522
- const websocket = this.websockets[name];
523
- if ((testResourceRequirement === null || testResourceRequirement === void 0 ? void 0 : testResourceRequirement.ports) === 0) {
524
- websocket.send(JSON.stringify({
525
- data: {
526
- testResourceConfiguration: {
527
- ports: [],
528
- },
529
- }
530
- }));
531
- }
532
- else if (((testResourceRequirement === null || testResourceRequirement === void 0 ? void 0 : testResourceRequirement.ports) || 0) > 0) {
533
- // clear any port-slots associated with this job
534
- Object.values(this.ports).forEach((jobMaybe, portNumber) => {
535
- if (jobMaybe && jobMaybe === name) {
536
- this.ports[portNumber] = OPEN_PORT;
537
- }
538
- });
539
- // find a list of open ports
540
- const foundOpenPorts = Object.keys(this.ports).filter((p) => this.ports[p] === OPEN_PORT);
541
- if (foundOpenPorts.length >= testResourceRequirement.ports) {
542
- const selectionOfPorts = foundOpenPorts.slice(0, testResourceRequirement.ports);
543
- websocket.send(JSON.stringify({
544
- data: {
545
- testResourceConfiguration: {
546
- ports: selectionOfPorts,
547
- },
548
- }
549
- }));
550
- // mark the selected ports as occupied
551
- for (const foundOpenPort of selectionOfPorts) {
552
- this.ports[foundOpenPort] = name;
129
+ getSecondaryEndpointsPoints(runtime) {
130
+ const meta = (ts, st) => {
131
+ ts.forEach((t) => {
132
+ if (t[1] === runtime) {
133
+ st.add(t[0]);
553
134
  }
554
- }
555
- else {
556
- console.log(`no port was open so send the ${name} job to the back of the resourceQueue`);
557
- this.resourceQueue.push(resourceRequest);
558
- }
559
- }
560
- }
561
- allocateViaIpc(resourceRequest) {
562
- const pName = resourceRequest.requirement.name;
563
- const testResourceRequirement = resourceRequest.requirement;
564
- pm2.list((err, processes) => {
565
- console.error(err);
566
- processes.forEach((p) => {
567
- if (p.name === pName && p.pid) {
568
- const message = {
569
- // these fields must be present
570
- id: p.pid,
571
- topic: "some topic",
572
- type: "process:msg",
573
- // Data to be sent
574
- data: {
575
- testResourceConfiguration: {
576
- ports: [],
577
- // fs: fPath,
578
- },
579
- id: p.pm_id,
580
- },
581
- };
582
- if ((testResourceRequirement === null || testResourceRequirement === void 0 ? void 0 : testResourceRequirement.ports) === 0) {
583
- pm2.sendDataToProcessId(p.pm_id, message, function (err, res) {
584
- // console.log("sendDataToProcessId", err, res, message);
585
- });
586
- }
587
- if (((testResourceRequirement === null || testResourceRequirement === void 0 ? void 0 : testResourceRequirement.ports) || 0) > 0) {
588
- // clear any port-slots associated with this job
589
- Object.values(this.ports).forEach((jobMaybe, portNumber) => {
590
- if (jobMaybe && jobMaybe === pName) {
591
- this.ports[portNumber] = OPEN_PORT;
592
- }
593
- });
594
- // find a list of open ports
595
- const foundOpenPorts = Object.keys(this.ports).filter((p) => this.ports[p] === OPEN_PORT);
596
- // if there are enough open port-slots...
597
- if (foundOpenPorts.length >= testResourceRequirement.ports) {
598
- const selectionOfPorts = foundOpenPorts.slice(0, testResourceRequirement.ports);
599
- const message = {
600
- // these fields must be present
601
- id: p.pid,
602
- topic: "some topic",
603
- // process:msg will be send as 'message' on target process
604
- type: "process:msg",
605
- // Data to be sent
606
- data: {
607
- testResourceConfiguration: {
608
- // fs: fPath,
609
- ports: selectionOfPorts,
610
- },
611
- id: p.pid,
612
- },
613
- };
614
- pm2.sendDataToProcessId(p.pm_id, message, function (err, res) {
615
- // no-op
616
- });
617
- // mark the selected ports as occupied
618
- for (const foundOpenPort of selectionOfPorts) {
619
- this.ports[foundOpenPort] = p.pid.toString();
620
- }
621
- }
622
- else {
623
- console.log(`no port was open so send the ${p.pid} job to the back of the resourceQueue`);
624
- this.resourceQueue.push(resourceRequest);
625
- }
626
- }
135
+ if (Array.isArray(t[2])) {
136
+ meta(t[2], st);
627
137
  }
628
138
  });
629
- });
139
+ return st;
140
+ };
141
+ return Array.from(meta(this.config.tests, new Set()));
630
142
  }
631
143
  }
144
+ const getRunnables = (tests, payload = [new Set(), new Set()]) => {
145
+ return tests.reduce((pt, cv, cndx, cry) => {
146
+ if (cv[1] === "node") {
147
+ pt[0].add(cv[0]);
148
+ }
149
+ else if (cv[1] === "web") {
150
+ pt[1].add(cv[0]);
151
+ }
152
+ if (cv[2].length) {
153
+ getRunnables(cv[2], payload);
154
+ }
155
+ return pt;
156
+ }, payload);
157
+ };