testeranto 0.62.0 → 0.73.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 (186) hide show
  1. package/README.md +38 -26
  2. package/dist/cjs-shim.js +2 -2
  3. package/dist/common/Node.js +14 -51
  4. package/dist/common/PM/index.js +71 -0
  5. package/dist/common/PM/main.js +361 -0
  6. package/dist/common/PM/node.js +176 -0
  7. package/dist/common/PM/web.js +174 -0
  8. package/dist/common/Project.js +121 -266
  9. package/dist/common/Puppeteer.js +109 -0
  10. package/dist/common/Reporter.js +119 -0
  11. package/dist/common/Scheduler.js +1 -0
  12. package/dist/common/SubPackages/puppeteer.js +3 -1
  13. package/dist/common/SubPackages/react-dom/component/web.js +98 -45
  14. package/dist/common/SubPackages/react-dom/jsx/web.js +15 -7
  15. package/dist/common/SubPackages/react-test-renderer/MemoExoticComponent/node.js +1 -1
  16. package/dist/common/SubPackages/react-test-renderer/component/index.js +0 -1
  17. package/dist/common/SubPackages/react-test-renderer/fc/web.js +1 -1
  18. package/dist/common/SubPackages/react-test-renderer/jsx/index.js +1 -3
  19. package/dist/common/SubPackages/react-test-renderer/jsx/web.js +1 -1
  20. package/dist/common/SubPackages/react-test-renderer/jsx-promised/index.js +1 -1
  21. package/dist/common/Types.js +2 -32
  22. package/dist/common/Web.js +25 -37
  23. package/dist/common/esbuildConfigs/index.js +5 -5
  24. package/dist/common/esbuildConfigs/node.js +17 -15
  25. package/dist/common/esbuildConfigs/report.js +12 -47
  26. package/dist/common/esbuildConfigs/tests.js +0 -1
  27. package/dist/common/esbuildConfigs/web.js +17 -12
  28. package/dist/common/lib/abstractBase.js +190 -35
  29. package/dist/common/lib/basebuilder.js +56 -29
  30. package/dist/common/lib/classBuilder.js +8 -5
  31. package/dist/common/lib/core.js +42 -17
  32. package/dist/common/lib/index.js +11 -8
  33. package/dist/common/lib/types.js +2 -0
  34. package/dist/common/preload.js +14 -28
  35. package/dist/common/puppeteerConfiger.js +24 -0
  36. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  37. package/dist/module/Node.js +14 -51
  38. package/dist/module/PM/index.js +67 -0
  39. package/dist/module/PM/main.js +331 -0
  40. package/dist/module/PM/node.js +168 -0
  41. package/dist/module/PM/web.js +167 -0
  42. package/dist/module/Project.js +122 -267
  43. package/dist/module/Puppeteer.js +104 -0
  44. package/dist/module/Reporter.js +114 -0
  45. package/dist/module/Scheduler.js +1 -0
  46. package/dist/module/SubPackages/puppeteer.js +3 -1
  47. package/dist/module/SubPackages/react/jsx/node.js +1 -1
  48. package/dist/module/SubPackages/react/jsx/web.js +1 -1
  49. package/dist/module/SubPackages/react-dom/component/node.js +2 -2
  50. package/dist/module/SubPackages/react-dom/component/web.js +98 -45
  51. package/dist/module/SubPackages/react-dom/jsx/web.js +17 -9
  52. package/dist/module/SubPackages/react-test-renderer/MemoExoticComponent/node.js +1 -1
  53. package/dist/module/SubPackages/react-test-renderer/component/index.js +0 -1
  54. package/dist/module/SubPackages/react-test-renderer/fc/web.js +1 -1
  55. package/dist/module/SubPackages/react-test-renderer/jsx/index.js +1 -3
  56. package/dist/module/SubPackages/react-test-renderer/jsx/web.js +1 -1
  57. package/dist/module/SubPackages/react-test-renderer/jsx-promised/index.js +1 -1
  58. package/dist/module/Types.js +3 -30
  59. package/dist/module/Web.js +26 -38
  60. package/dist/module/esbuildConfigs/index.js +5 -5
  61. package/dist/module/esbuildConfigs/node.js +17 -15
  62. package/dist/module/esbuildConfigs/report.js +11 -48
  63. package/dist/module/esbuildConfigs/tests.js +0 -1
  64. package/dist/module/esbuildConfigs/web.js +17 -12
  65. package/dist/module/lib/abstractBase.js +190 -35
  66. package/dist/module/lib/basebuilder.js +56 -29
  67. package/dist/module/lib/classBuilder.js +8 -5
  68. package/dist/module/lib/core.js +44 -19
  69. package/dist/module/lib/index.js +11 -8
  70. package/dist/module/preload.js +15 -27
  71. package/dist/module/puppeteerConfiger.js +19 -0
  72. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  73. package/dist/prebuild/Report.css +1616 -584
  74. package/dist/prebuild/Report.js +2635 -2506
  75. package/dist/types/Node.d.ts +3 -2
  76. package/dist/types/PM/index.d.ts +19 -0
  77. package/dist/types/PM/main.d.ts +28 -0
  78. package/dist/types/PM/node.d.ts +26 -0
  79. package/dist/types/PM/web.d.ts +24 -0
  80. package/dist/types/Project.d.ts +1 -2
  81. package/dist/types/Puppeteer.d.ts +1 -0
  82. package/dist/types/Reporter.d.ts +1 -0
  83. package/dist/types/Scheduler.d.ts +0 -0
  84. package/dist/types/SubPackages/puppeteer.d.ts +3 -3
  85. package/dist/types/SubPackages/react/component/node.d.ts +1 -1
  86. package/dist/types/SubPackages/react/component/web.d.ts +1 -1
  87. package/dist/types/SubPackages/react/jsx/index.d.ts +1 -1
  88. package/dist/types/SubPackages/react/jsx/node.d.ts +1 -1
  89. package/dist/types/SubPackages/react/jsx/web.d.ts +2 -2
  90. package/dist/types/SubPackages/react-dom/component/node.d.ts +2 -2
  91. package/dist/types/SubPackages/react-dom/component/web.d.ts +1 -1
  92. package/dist/types/SubPackages/react-dom/jsx/node.d.ts +1 -1
  93. package/dist/types/SubPackages/react-dom/jsx/web.d.ts +1 -1
  94. package/dist/types/SubPackages/react-test-renderer/MemoExoticComponent/node.d.ts +1 -1
  95. package/dist/types/SubPackages/react-test-renderer/component/index.d.ts +1 -1
  96. package/dist/types/SubPackages/react-test-renderer/component/node.d.ts +1 -1
  97. package/dist/types/SubPackages/react-test-renderer/component/web.d.ts +1 -1
  98. package/dist/types/SubPackages/react-test-renderer/fc/node.d.ts +1 -1
  99. package/dist/types/SubPackages/react-test-renderer/fc/web.d.ts +1 -1
  100. package/dist/types/SubPackages/react-test-renderer/jsx/node.d.ts +1 -1
  101. package/dist/types/SubPackages/react-test-renderer/jsx/web.d.ts +3 -3
  102. package/dist/types/SubPackages/react-test-renderer/jsx-promised/index.d.ts +1 -1
  103. package/dist/types/SubPackages/react-test-renderer/jsx-promised/node.d.ts +1 -1
  104. package/dist/types/SubPackages/react-test-renderer/jsx-promised/web.d.ts +1 -1
  105. package/dist/types/Types.d.ts +19 -100
  106. package/dist/types/Web.d.ts +3 -2
  107. package/dist/types/esbuildConfigs/features.d.ts +1 -1
  108. package/dist/types/esbuildConfigs/index.d.ts +1 -1
  109. package/dist/types/esbuildConfigs/node.d.ts +1 -1
  110. package/dist/types/esbuildConfigs/report.d.ts +4 -0
  111. package/dist/types/esbuildConfigs/tests.d.ts +1 -1
  112. package/dist/types/esbuildConfigs/web.d.ts +1 -1
  113. package/dist/types/lib/abstractBase.d.ts +26 -24
  114. package/dist/types/lib/basebuilder.d.ts +10 -7
  115. package/dist/types/lib/classBuilder.d.ts +4 -3
  116. package/dist/types/lib/core.d.ts +5 -4
  117. package/dist/types/lib/index.d.ts +7 -5
  118. package/dist/types/lib/types.d.ts +62 -0
  119. package/dist/types/preload.d.ts +0 -1
  120. package/dist/types/puppeteerConfiger.d.ts +4 -0
  121. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  122. package/package.json +6 -7
  123. package/src/Node.ts +30 -85
  124. package/src/PM/index.ts +102 -0
  125. package/src/PM/main.ts +420 -0
  126. package/src/PM/node.ts +515 -0
  127. package/src/PM/web.ts +497 -0
  128. package/src/Project.ts +183 -619
  129. package/src/Puppeteer.ts +131 -0
  130. package/src/Report.tsx +158 -44
  131. package/src/Reporter.ts +134 -0
  132. package/src/Scheduler.ts +0 -0
  133. package/src/SubPackages/puppeteer.ts +19 -14
  134. package/src/SubPackages/react/component/node.ts +20 -32
  135. package/src/SubPackages/react/component/web.ts +20 -30
  136. package/src/SubPackages/react/jsx/index.ts +13 -24
  137. package/src/SubPackages/react/jsx/node.ts +5 -8
  138. package/src/SubPackages/react/jsx/web.ts +10 -8
  139. package/src/SubPackages/react-dom/component/node.ts +17 -23
  140. package/src/SubPackages/react-dom/component/web.ts +134 -95
  141. package/src/SubPackages/react-dom/jsx/web.ts +41 -48
  142. package/src/SubPackages/react-test-renderer/MemoExoticComponent/node.ts +27 -37
  143. package/src/SubPackages/react-test-renderer/component/index.ts +16 -30
  144. package/src/SubPackages/react-test-renderer/component/node.ts +5 -11
  145. package/src/SubPackages/react-test-renderer/component/web.ts +5 -11
  146. package/src/SubPackages/react-test-renderer/fc/node.ts +36 -50
  147. package/src/SubPackages/react-test-renderer/fc/web.ts +37 -50
  148. package/src/SubPackages/react-test-renderer/jsx/index.ts +15 -21
  149. package/src/SubPackages/react-test-renderer/jsx/node.ts +6 -10
  150. package/src/SubPackages/react-test-renderer/jsx/web.ts +7 -7
  151. package/src/SubPackages/react-test-renderer/jsx-promised/index.ts +13 -16
  152. package/src/Types.ts +73 -307
  153. package/src/Web.ts +40 -81
  154. package/src/cjs-shim.js +2 -2
  155. package/src/esbuildConfigs/features.ts +3 -4
  156. package/src/esbuildConfigs/index.ts +8 -8
  157. package/src/esbuildConfigs/node.ts +21 -20
  158. package/src/esbuildConfigs/report.ts +15 -51
  159. package/src/esbuildConfigs/tests.ts +3 -9
  160. package/src/esbuildConfigs/web.ts +22 -20
  161. package/src/lib/abstractBase.ts +312 -164
  162. package/src/lib/basebuilder.ts +123 -127
  163. package/src/lib/classBuilder.ts +30 -48
  164. package/src/lib/core.ts +115 -84
  165. package/src/lib/index.ts +58 -56
  166. package/src/lib/types.ts +197 -0
  167. package/src/preload.ts +14 -30
  168. package/src/puppeteerConfiger.ts +26 -0
  169. package/src/web.html.ts +1 -1
  170. package/dist/common/NodeWriter.js +0 -56
  171. package/dist/common/electron.js +0 -196
  172. package/dist/common/lib/browser.js +0 -26
  173. package/dist/common/nodeWriterElectron.js +0 -55
  174. package/dist/module/NodeWriter.js +0 -50
  175. package/dist/module/electron.js +0 -191
  176. package/dist/module/lib/browser.js +0 -22
  177. package/dist/module/nodeWriterElectron.js +0 -52
  178. package/dist/types/NodeWriter.d.ts +0 -2
  179. package/dist/types/lib/browser.d.ts +0 -6
  180. package/dist/types/nodeWriterElectron.d.ts +0 -2
  181. package/src/NodeWriter.ts +0 -69
  182. package/src/electron.ts +0 -250
  183. package/src/lib/browser.ts +0 -34
  184. package/src/nodeWriterElectron.ts +0 -71
  185. package/yarn-error.log +0 -3144
  186. /package/dist/{types/electron.d.ts → module/lib/types.js} +0 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # testeranto
2
2
 
3
- 🚧 WARNING: Testeeranto is still under development and is not ready for production yet. 🚧
3
+ 🚧 WARNING: Testeranto is still under development and is not ready for production yet. 🚧
4
4
 
5
5
  home: [adamwong246.github.io/testeranto](https://adamwong246.github.io/testeranto/)
6
6
 
@@ -17,7 +17,6 @@ example repo: [kokomo bay](https://github.com/ChromaPDX/kokomoBay)
17
17
  - Do you like TDD/BDD?
18
18
  - Do you love Typescript?
19
19
  - Do you hate Jira?
20
- - Do you tolerate electron?
21
20
 
22
21
  If so, then testeranto might be the testing tool you have been looking for!
23
22
 
@@ -27,21 +26,20 @@ Testeranto.ts an Acceptance Test Driven Development ([ATDD](https://en.wikipedia
27
26
 
28
27
  ## Getting started
29
28
 
30
- 1) Write some code.
31
- 2) Write some tests of that code.
32
- 3) Write some features of that code.
33
- 1) Write a `testeranto.mts`, which acts as a config file.
34
- 3) Launch testeranto. The test runner is now rebuilding the docs folder.
35
- 4) Commit the results of those tests.
36
- 5) Your github pages now shows your report, showing your features, linked with your test results.
37
- 6) Optionally add testeranto to your CI.
29
+ 1. Write some code.
30
+ 2. Write some tests of that code.
31
+ 3. Write some features of that code.
32
+ 4. Write a `testeranto.mts`, which acts as a config file.
33
+ 5. Launch testeranto. The test runner is now rebuilding the docs folder.
34
+ 6. Commit the results of those tests.
35
+ 7. Your github pages now shows your report, showing your features, linked with your test results.
36
+ 8. Optionally add testeranto to your CI.
38
37
 
39
38
  ## tech of note
40
39
 
41
40
  - esm - Testeranto uses modern js.
42
41
  - typescript - tests are functions with type parameters
43
- - electron - provides both a node and chrome runtime
44
- - puppeteer - provides node-style tests with a handle to the browser
42
+ - puppeteer - provides access to both node and chrome runtimes
45
43
  - esbuild - used to quickly generate test bundles
46
44
  - graphology - used to store features within a semantic network
47
45
 
@@ -55,9 +53,9 @@ Testeranto.ts an Acceptance Test Driven Development ([ATDD](https://en.wikipedia
55
53
 
56
54
  ## the good parts
57
55
 
58
- Your tests can be run in node, chromium, or both! For example, for a single react component, you could create 3 tests- 1 that runs with react-test-renderer on node, another on chromium which renders the component to the dom, and a 3rd node style test which invokes the component in the browser before interacting with it via puppeteer.
56
+ Your tests can be run in node, chromium, or both.
59
57
 
60
- Testeranto includes a test runner which bundles and executes your tests, taking care to only run the tests which have changed. It is designed to run most tests in parallel, though it has support for tests which require a shared resource, like a port.
58
+ Testeranto includes a test runner which bundles and executes your tests, taking care to only run the tests which have changed.
61
59
 
62
60
  Testeranto includes a test reporter which displays the state of your code in a web app. ([see example](https://chromapdx.github.io/kokomoBay/report.html)) This reporter can also be run locally for the developer's convenience.
63
61
 
@@ -67,25 +65,24 @@ Rather than the traditional method of specifying tests in plain text, Testeranto
67
65
 
68
66
  ## the bad parts
69
67
 
70
- Testeranto is not designed to maximize performance. In dev mode, it runs multiple esbuild processes, electron, 1 node process for each node test and 1 chromium processes for each web test.
68
+ Testeranto is not designed to maximize performance.
71
69
 
72
- Testeranto does not (yet!) of a means of allowing non-coders to affect changes so, as they say, "get good 💪!"
70
+ Testeranto does not (yet!) of a means of allowing non-coders to affect changes so, as they say, "get good 💪!"
73
71
 
74
72
  Because Testeranto is so un-opinionated that it does not provide test infrastructure. You will need to find an existing recipe or implement it yourself, though a public repo of test interfaces exists.
75
73
 
76
74
  ## How it works
77
75
 
78
76
  Testeranto is comprised of 3 parts
79
- 1) The build process reads a config and builds the docs folder, then launches 3 esbuild build processes.
80
- a) Build the features for the html report
81
- b) Build the node-style tests
82
- c) Build the web-style tests
83
- 2) The test runner is an electron app which watches the output of those build processes and launches the tests as those files change.
84
- 3) A Report which links your features, your tests and the results of those tests into a handy website.
85
77
 
86
- ## Electron aka Node vs Chromium
78
+ 1. The build process reads a config and builds the docs folder, then launches 3 esbuild build processes.
87
79
 
88
- At the heart of testeranto is the dual runtime provided by electron. The electron test runner creates an UtilityProcess for each node test and a BrowserWindow for each web test. Each of these processes can communicate to other artifacts over IPC. That is, a node test can invoke a web artifact and send it messages over the IPC channel, and vice-versa. Furthermore, node tests are provided with a puppeteer, providing it access to the web environment, while web tests are provided the electron BrowserWindow, which allows it to similarly bridge the gap between the web runtime and the node runtime.
80
+ - Build the features for the html report
81
+ - Build the node-style tests
82
+ - Build the web-style tests
83
+
84
+ 2. The test runner watches the output of those build processes and launches the tests as those files change.
85
+ 3. A Report which links your features, your tests and the results of those tests into a handy website.
89
86
 
90
87
  ## Hybrid tests
91
88
 
@@ -106,8 +103,8 @@ Testeranto's main API interface is 2 functions, 1 for each run time. You must pa
106
103
  - The "shape" - a TS type signature to which the other arguments must conform.
107
104
  - The "input" - the test subject. The "thing that is to be tested"
108
105
  - the "specification" - This is the Cucumber-style Given/When/Then steps.
109
- - the "implementation" - This is the code which implements the "test specification" in code.
110
- - the "interface" - The code which sets up the test.
106
+ - the "implementation" - This is the code which implements the "test specification" in code.
107
+ - the "interface" - The code which sets up the test.
111
108
 
112
109
  This is designed so that each piece can be worked upon separately. You can think of each argument as the responsibility of a different member of your team.
113
110
 
@@ -115,3 +112,18 @@ This is designed so that each piece can be worked upon separately. You can think
115
112
  - "Product Manager" handles the "specification"
116
113
  - "Middle Engineer" handles the "interface"
117
114
  - "Junior Engineer" handles the "implementation"
115
+
116
+ ## CLI
117
+
118
+ There are 3 commands you should add to your `package.json`
119
+
120
+ ```
121
+ // build the tests once
122
+ "testeranto-esbuild": "ts-node-esm testeranto.mts",
123
+
124
+ // build the tests, watching for changes
125
+ "testeranto-esbuild-dev": "ts-node-esm testeranto.mts",
126
+
127
+ // run the tests
128
+ "testeranto-puppeteer":"ts-node-esm node_modules/testeranto/dist/module/Puppeteer.js",
129
+ ```
package/dist/cjs-shim.js CHANGED
@@ -3,8 +3,8 @@ import path from 'node:path';
3
3
  import url from 'node:url';
4
4
 
5
5
  // globalThis.require = createRequire(import.meta.url);
6
- // globalThis.__filename = url.fileURLToPath(import.meta.url);
7
- // globalThis.__dirname = path.dirname(__filename);
6
+ globalThis.__filename = url.fileURLToPath(import.meta.url);
7
+ globalThis.__dirname = path.dirname(__filename);
8
8
 
9
9
  // const p = `${import.meta.url}/..`;
10
10
  // globalThis.require = createRequire(`${import.meta.url}/..`);
@@ -3,64 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const http_1 = __importDefault(require("http"));
7
- const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
8
6
  const core_js_1 = __importDefault(require("./lib/core.js"));
9
7
  const index_js_1 = require("./lib/index.js");
10
- const NodeWriter_js_1 = require("./NodeWriter.js");
11
- const Types_js_1 = require("./Types.js");
12
- const readJson = async (port) => new Promise((resolve, reject) => {
13
- let json = "";
14
- const request = http_1.default.request({
15
- host: "127.0.0.1",
16
- path: "/json/version",
17
- port,
18
- }, (response) => {
19
- response.on("error", reject);
20
- response.on("data", (chunk) => {
21
- json += chunk.toString();
22
- });
23
- response.on("end", () => {
24
- resolve(JSON.parse(json));
25
- });
26
- });
27
- request.on("error", reject);
28
- request.end();
29
- });
8
+ const node_js_1 = require("./PM/node.js");
30
9
  class NodeTesteranto extends core_js_1.default {
31
10
  constructor(input, testSpecification, testImplementation, testResourceRequirement, testInterface) {
32
- super(input, testSpecification, testImplementation, testResourceRequirement, NodeWriter_js_1.NodeWriter, testInterface);
33
- if (process.argv[2]) {
34
- const testResourceArg = process.argv[2];
35
- try {
36
- const partialTestResource = JSON.parse(testResourceArg);
37
- this.receiveTestResourceConfig(this.testJobs[0], partialTestResource);
38
- }
39
- catch (e) {
40
- console.error(e);
41
- // process.exit(-1);
42
- }
43
- }
44
- else {
45
- // no-op
46
- }
11
+ super(input, testSpecification, testImplementation, testResourceRequirement, testInterface);
47
12
  }
48
- async receiveTestResourceConfig(t, partialTestResource) {
49
- const browser = await readJson("2999").then(async (json) => {
50
- const b = await puppeteer_core_1.default.connect({
51
- browserWSEndpoint: json.webSocketDebuggerUrl,
52
- defaultViewport: null,
53
- });
54
- console.log("connected!", b.isConnected());
55
- return b;
56
- });
57
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource, new Types_js_1.TBrowser(browser));
58
- Promise.all([...artifacts, logPromise]).then(async () => {
59
- // process.exit(await failed ? 1 : 0);
60
- });
13
+ async receiveTestResourceConfig(
14
+ // t: ITestJob,
15
+ partialTestResource) {
16
+ console.log("receiveTestResourceConfig!!", this.testJobs[0].receiveTestResourceConfig);
17
+ const t = JSON.parse(partialTestResource);
18
+ const pm = new node_js_1.PM_Node(t);
19
+ const { failed, artifacts, logPromise } = await this.testJobs[0].receiveTestResourceConfig(pm);
20
+ console.log("test is done, awaiting test result write to fs");
21
+ pm.customclose();
22
+ // Promise.all([...artifacts, logPromise]).then(async () => {
23
+ // // process.exit((await failed) ? 1 : 0);
24
+ // });
61
25
  }
62
26
  }
63
- ;
64
27
  exports.default = async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = index_js_1.defaultTestResourceRequirement) => {
65
28
  return new NodeTesteranto(input, testSpecification, testImplementation, testResourceRequirement, testInterface);
66
29
  };
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ // import {
3
+ // Browser,
4
+ // BrowserContext,
5
+ // BrowserContextOptions,
6
+ // DebugInfo,
7
+ // Page,
8
+ // PuppeteerNode,
9
+ // Target,
10
+ // } from "puppeteer-core";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.PM = void 0;
13
+ const fPaths = [];
14
+ class PM {
15
+ }
16
+ exports.PM = PM;
17
+ // export class PuppetMasterBrowser extends Browser {
18
+ // process(): ChildProcess | null {
19
+ // return super.process();
20
+ // }
21
+ // createBrowserContext(
22
+ // options?: BrowserContextOptions
23
+ // ): Promise<BrowserContext> {
24
+ // throw new Error("Method not implemented.");
25
+ // }
26
+ // browserContexts(): BrowserContext[] {
27
+ // throw new Error("Method not implemented.");
28
+ // }
29
+ // defaultBrowserContext(): BrowserContext {
30
+ // throw new Error("Method not implemented.");
31
+ // }
32
+ // wsEndpoint(): string {
33
+ // throw new Error("Method not implemented.");
34
+ // }
35
+ // newPage(): Promise<Page> {
36
+ // throw new Error("Method not implemented.");
37
+ // }
38
+ // targets(): Target[] {
39
+ // throw new Error("Method not implemented.");
40
+ // }
41
+ // target(): Target {
42
+ // throw new Error("Method not implemented.");
43
+ // }
44
+ // version(): Promise<string> {
45
+ // throw new Error("Method not implemented.");
46
+ // }
47
+ // userAgent(): Promise<string> {
48
+ // throw new Error("Method not implemented.");
49
+ // }
50
+ // close(): Promise<void> {
51
+ // throw new Error("Method not implemented.");
52
+ // }
53
+ // disconnect(): Promise<void> {
54
+ // throw new Error("Method not implemented.");
55
+ // }
56
+ // get connected(): boolean {
57
+ // throw new Error("Method not implemented.");
58
+ // }
59
+ // get debugInfo(): DebugInfo {
60
+ // throw new Error("Method not implemented.");
61
+ // }
62
+ // constructor(...z: []) {
63
+ // super(...z);
64
+ // }
65
+ // // pages(): Promise<Page[]>;
66
+ // pages(): Promise<Page[]> {
67
+ // return new Promise<Page[]>((res, rej) => {
68
+ // res(super.pages());
69
+ // });
70
+ // }
71
+ // }
@@ -0,0 +1,361 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.PM_Main = void 0;
30
+ const fs_1 = __importDefault(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
33
+ const index_js_1 = require("./index.js");
34
+ const fPaths = [];
35
+ const fileStreams3 = [];
36
+ const screenshots3 = [];
37
+ const doneFileStream3 = [];
38
+ class PM_Main extends index_js_1.PM {
39
+ // testResourceConfiguration: ITTestResourceConfiguration;
40
+ constructor(configs
41
+ // testResourceConfig: ITTestResourceConfiguration
42
+ ) {
43
+ super();
44
+ this.launchNode = async (src, dest) => {
45
+ console.log("launchNode", src);
46
+ // childProcesses[src] = "running";
47
+ const destFolder = dest.replace(".mjs", "");
48
+ let argz = "";
49
+ const testConfig = this.configs.tests.find((t) => {
50
+ return t[0] === src;
51
+ });
52
+ if (!testConfig) {
53
+ console.error("missing test config");
54
+ process.exit(-1);
55
+ }
56
+ const testConfigResource = testConfig[2];
57
+ console.log("mark22 testConfigResource", testConfigResource);
58
+ let portsToUse = [];
59
+ if (testConfigResource.ports === 0) {
60
+ argz = JSON.stringify({
61
+ scheduled: true,
62
+ name: src,
63
+ ports: portsToUse,
64
+ fs: destFolder,
65
+ browserWSEndpoint: this.browser.wsEndpoint(),
66
+ });
67
+ }
68
+ else if (testConfigResource.ports > 0) {
69
+ const openPorts = Object.entries(this.ports).filter(([portnumber, portopen]) => portopen);
70
+ if (openPorts.length >= testConfigResource.ports) {
71
+ for (let i = 0; i < testConfigResource.ports; i++) {
72
+ portsToUse.push(openPorts[i][0]);
73
+ this.ports[openPorts[i][0]] = false; // port is now closed
74
+ }
75
+ argz = JSON.stringify({
76
+ scheduled: true,
77
+ name: src,
78
+ // ports: [3333],
79
+ ports: portsToUse,
80
+ fs: ".",
81
+ browserWSEndpoint: this.browser.wsEndpoint(),
82
+ });
83
+ }
84
+ else {
85
+ this.queue.push(src);
86
+ return;
87
+ }
88
+ }
89
+ else {
90
+ console.error("negative port makes no sense", src);
91
+ process.exit(-1);
92
+ }
93
+ const builtfile = dest + ".mjs";
94
+ this.server[builtfile] = await Promise.resolve().then(() => __importStar(require(`${builtfile}?cacheBust=${Date.now()}`))).then((module) => {
95
+ return module.default.then((defaultModule) => {
96
+ defaultModule
97
+ .receiveTestResourceConfig(argz)
98
+ .then((x) => {
99
+ console.log("then", x);
100
+ return x;
101
+ })
102
+ .catch((e) => {
103
+ console.log("catch", e);
104
+ });
105
+ });
106
+ });
107
+ for (let i = 0; i <= portsToUse.length; i++) {
108
+ this.ports[i] = true; //port is open again
109
+ }
110
+ };
111
+ this.launchWeb = (t, dest) => {
112
+ console.log("launchWeb", t, dest);
113
+ const testResourceConfiguration = this.testResourceConfiguration;
114
+ // childProcesses[t] = "running";
115
+ const destFolder = dest.replace(".mjs", "");
116
+ const webArgz = JSON.stringify({
117
+ name: dest,
118
+ ports: [].toString(),
119
+ fs: destFolder,
120
+ browserWSEndpoint: this.browser.wsEndpoint(),
121
+ });
122
+ const evaluation = `import('${dest}.mjs').then(async (x) => {
123
+ console.log("imported", x, (x.default));
124
+ try {
125
+ await (await x.default).receiveTestResourceConfig(${webArgz})
126
+ } catch (e) {
127
+ console.log("fail", e)
128
+ }
129
+ })`;
130
+ const fileStreams2 = [];
131
+ const screenshots2 = [];
132
+ const doneFileStream2 = [];
133
+ this.browser
134
+ .newPage()
135
+ .then((page) => {
136
+ page.exposeFunction("custom-screenshot", async (ssOpts) => {
137
+ const p = ssOpts.path;
138
+ console.log("custom-screenshot", ssOpts);
139
+ const dir = path_1.default.dirname(p);
140
+ console.log("dir", dir);
141
+ fs_1.default.mkdirSync(dir, {
142
+ recursive: true,
143
+ });
144
+ return page.screenshot(Object.assign(Object.assign({}, ssOpts), { path: p }));
145
+ // screenshots.push(
146
+ // page.screenshot({
147
+ // ...ssOpts,
148
+ // path: ssOpts.path,
149
+ // })
150
+ // );
151
+ // const sPromise = page.screenshot({
152
+ // ...ssOpts,
153
+ // path: p,
154
+ // });
155
+ // await sPromise;
156
+ // page.evaluate(`window["screenshot done"]`);
157
+ });
158
+ page.exposeFunction("writeFileSync", (fp, contents) => {
159
+ console.log("writeFileSync", fp);
160
+ // Create directories if they don't exist
161
+ const dir = path_1.default.dirname(fp);
162
+ console.log("dir", dir);
163
+ fs_1.default.mkdirSync(dir, {
164
+ recursive: true,
165
+ });
166
+ // return fs.writeFileSync(fp, contents);
167
+ const p = new Promise(async (res, rej) => {
168
+ fs_1.default.writeFileSync(fp, contents);
169
+ res(fp);
170
+ });
171
+ doneFileStream2.push(p);
172
+ return p;
173
+ });
174
+ page.exposeFunction("existsSync", (fp, contents) => {
175
+ return fs_1.default.existsSync(fp);
176
+ });
177
+ page.exposeFunction("mkdirSync", (fp) => {
178
+ console.log("mkdirsync", fp);
179
+ if (!fs_1.default.existsSync(fp)) {
180
+ return fs_1.default.mkdirSync(fp, {
181
+ recursive: true,
182
+ });
183
+ }
184
+ return false;
185
+ });
186
+ page.exposeFunction("createWriteStream", (fp) => {
187
+ const f = fs_1.default.createWriteStream(fp);
188
+ const p = new Promise((res, rej) => {
189
+ res(fp);
190
+ });
191
+ doneFileStream2.push(p);
192
+ f.on("close", async () => {
193
+ await p;
194
+ });
195
+ fileStreams2.push(f);
196
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams2.length - 1 });
197
+ });
198
+ page.exposeFunction("write", async (uid, contents) => {
199
+ return fileStreams2[uid].write(contents);
200
+ });
201
+ page.exposeFunction("end", async (uid) => {
202
+ return fileStreams2[uid].end();
203
+ });
204
+ page.exposeFunction("customclose", () => {
205
+ console.log("closing doneFileStream2", doneFileStream2);
206
+ // console.log("closing doneFileStream2", doneFileStream2);
207
+ Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
208
+ page.close();
209
+ });
210
+ // page.close();
211
+ // Promise.all(screenshots).then(() => {
212
+ // page.close();
213
+ // });
214
+ // setTimeout(() => {
215
+ // console.log("Delayed for 1 second.");
216
+ // page.close();
217
+ // }, 5000);
218
+ // return page.close();
219
+ });
220
+ return page;
221
+ })
222
+ .then(async (page) => {
223
+ await page.goto(`file://${`${dest}.html`}`, {
224
+ // waitUntil: "load",
225
+ // timeout: 0,
226
+ });
227
+ page.evaluate(evaluation).finally(() => {
228
+ console.log("evaluation failed.", dest);
229
+ });
230
+ return page;
231
+ })
232
+ .then((page) => {
233
+ // console.log("qwe", page);
234
+ // page.close();
235
+ });
236
+ };
237
+ // this.testResourceConfiguration = testResourceConfig;
238
+ // console.log("mkdirsync4", testResourceConfig);
239
+ this.server = {};
240
+ this.configs = configs;
241
+ this.ports = {};
242
+ this.configs.ports.forEach((element) => {
243
+ this.ports[element] = "true"; // set ports as open
244
+ });
245
+ globalThis["mkdirSync"] = (fp) => {
246
+ if (!fs_1.default.existsSync(fp)) {
247
+ return fs_1.default.mkdirSync(fp, {
248
+ recursive: true,
249
+ });
250
+ }
251
+ return false;
252
+ };
253
+ globalThis["writeFileSync"] = (fp, contents) => {
254
+ // Create directories if they don't exist
255
+ const dir = path_1.default.dirname(fp.split("/").slice(0, -1).join("/"));
256
+ console.log("dir", dir);
257
+ fs_1.default.mkdirSync(dir, {
258
+ recursive: true,
259
+ });
260
+ return fs_1.default.writeFileSync(fp, contents);
261
+ };
262
+ globalThis["createWriteStream"] = (filepath) => {
263
+ const f = fs_1.default.createWriteStream(filepath);
264
+ fileStreams3.push(f);
265
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams3.length - 1 });
266
+ };
267
+ globalThis["write"] = (uid, contents) => {
268
+ console.log("write", uid, contents);
269
+ // process.exit();
270
+ fileStreams3[uid].write(contents);
271
+ };
272
+ globalThis["end"] = (uid) => {
273
+ fileStreams3[uid].end();
274
+ };
275
+ globalThis["customclose"] = () => {
276
+ // fileStreams3[uid].end();
277
+ };
278
+ // page.exposeFunction("customclose", () => {
279
+ // console.log("closing doneFileStream2", doneFileStream2);
280
+ // // console.log("closing doneFileStream2", doneFileStream2);
281
+ // Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
282
+ // page.close();
283
+ // });
284
+ // // page.close();
285
+ // // Promise.all(screenshots).then(() => {
286
+ // // page.close();
287
+ // // });
288
+ // // setTimeout(() => {
289
+ // // console.log("Delayed for 1 second.");
290
+ // // page.close();
291
+ // // }, 5000);
292
+ // // return page.close();
293
+ // });
294
+ }
295
+ async startPuppeteer(options, destfolder) {
296
+ this.browser = await puppeteer_core_1.default.launch(options);
297
+ return this.browser;
298
+ }
299
+ end(accessObject) {
300
+ throw new Error("Method not implemented.");
301
+ }
302
+ existsSync(destFolder) {
303
+ return fs_1.default.existsSync(destFolder);
304
+ }
305
+ async mkdirSync(fp) {
306
+ if (!fs_1.default.existsSync(fp)) {
307
+ return fs_1.default.mkdirSync(fp, {
308
+ recursive: true,
309
+ });
310
+ }
311
+ return false;
312
+ }
313
+ writeFileSync(fp, contents) {
314
+ fs_1.default.writeFileSync(fp, contents);
315
+ }
316
+ createWriteStream(filepath) {
317
+ return fs_1.default.createWriteStream(filepath);
318
+ }
319
+ testArtiFactoryfileWriter(tLog, callback) {
320
+ return (fPath, value) => {
321
+ callback(new Promise((res, rej) => {
322
+ tLog("testArtiFactory =>", fPath);
323
+ const cleanPath = path_1.default.resolve(fPath);
324
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
325
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
326
+ fs_1.default.mkdir(targetDir, { recursive: true }, async (error) => {
327
+ if (error) {
328
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
329
+ }
330
+ fs_1.default.writeFileSync(path_1.default.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
331
+ encoding: "utf-8",
332
+ });
333
+ if (Buffer.isBuffer(value)) {
334
+ fs_1.default.writeFileSync(fPath, value, "binary");
335
+ res();
336
+ }
337
+ else if (`string` === typeof value) {
338
+ fs_1.default.writeFileSync(fPath, value.toString(), {
339
+ encoding: "utf-8",
340
+ });
341
+ res();
342
+ }
343
+ else {
344
+ /* @ts-ignore:next-line */
345
+ const pipeStream = value;
346
+ const myFile = fs_1.default.createWriteStream(fPath);
347
+ pipeStream.pipe(myFile);
348
+ pipeStream.on("close", () => {
349
+ myFile.close();
350
+ res();
351
+ });
352
+ }
353
+ });
354
+ }));
355
+ };
356
+ }
357
+ write(accessObject, contents) {
358
+ throw new Error("Method not implemented.");
359
+ }
360
+ }
361
+ exports.PM_Main = PM_Main;