testeranto 0.70.0 → 0.74.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 (98) hide show
  1. package/README.md +9 -18
  2. package/dist/common/Node.js +7 -34
  3. package/dist/common/PM/index.js +71 -0
  4. package/dist/common/PM/main.js +370 -0
  5. package/dist/common/PM/node.js +84 -0
  6. package/dist/common/PM/web.js +129 -0
  7. package/dist/common/Project.js +20 -2
  8. package/dist/common/Puppeteer.js +109 -0
  9. package/dist/common/Reporter.js +119 -0
  10. package/dist/common/Scheduler.js +1 -0
  11. package/dist/common/SubPackages/puppeteer.js +3 -1
  12. package/dist/common/SubPackages/react/jsx/index.js +14 -2
  13. package/dist/common/SubPackages/react-dom/component/web.js +98 -45
  14. package/dist/common/SubPackages/react-test-renderer/jsx/index.js +0 -1
  15. package/dist/common/Web.js +24 -44
  16. package/dist/common/esbuildConfigs/web.js +3 -1
  17. package/dist/common/lib/abstractBase.js +189 -41
  18. package/dist/common/lib/basebuilder.js +56 -29
  19. package/dist/common/lib/classBuilder.js +6 -2
  20. package/dist/common/lib/core.js +41 -45
  21. package/dist/common/lib/index.js +2 -1
  22. package/dist/common/preload.js +14 -18
  23. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  24. package/dist/module/Node.js +7 -34
  25. package/dist/module/PM/index.js +67 -0
  26. package/dist/module/PM/main.js +340 -0
  27. package/dist/module/PM/node.js +77 -0
  28. package/dist/module/PM/web.js +122 -0
  29. package/dist/module/Project.js +20 -2
  30. package/dist/module/Puppeteer.js +104 -0
  31. package/dist/module/Reporter.js +114 -0
  32. package/dist/module/Scheduler.js +1 -0
  33. package/dist/module/SubPackages/puppeteer.js +3 -1
  34. package/dist/module/SubPackages/react/jsx/index.js +11 -2
  35. package/dist/module/SubPackages/react/jsx/node.js +1 -1
  36. package/dist/module/SubPackages/react-dom/component/web.js +98 -45
  37. package/dist/module/SubPackages/react-test-renderer/jsx/index.js +0 -1
  38. package/dist/module/Web.js +24 -44
  39. package/dist/module/esbuildConfigs/web.js +3 -1
  40. package/dist/module/lib/abstractBase.js +189 -41
  41. package/dist/module/lib/basebuilder.js +56 -29
  42. package/dist/module/lib/classBuilder.js +6 -2
  43. package/dist/module/lib/core.js +41 -45
  44. package/dist/module/lib/index.js +2 -1
  45. package/dist/module/preload.js +15 -14
  46. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  47. package/dist/prebuild/Report.css +1616 -584
  48. package/dist/prebuild/Report.js +2635 -2506
  49. package/dist/types/PM/index.d.ts +19 -0
  50. package/dist/types/PM/main.d.ts +26 -0
  51. package/dist/types/PM/node.d.ts +25 -0
  52. package/dist/types/PM/web.d.ts +24 -0
  53. package/dist/types/Reporter.d.ts +1 -0
  54. package/dist/types/Scheduler.d.ts +0 -0
  55. package/dist/types/SubPackages/react/jsx/index.d.ts +2 -5
  56. package/dist/types/SubPackages/react-dom/component/web.d.ts +1 -1
  57. package/dist/types/lib/abstractBase.d.ts +13 -12
  58. package/dist/types/lib/basebuilder.d.ts +4 -2
  59. package/dist/types/lib/classBuilder.d.ts +2 -2
  60. package/dist/types/lib/core.d.ts +4 -4
  61. package/dist/types/lib/index.d.ts +6 -5
  62. package/dist/types/lib/types.d.ts +16 -24
  63. package/dist/types/preload.d.ts +0 -1
  64. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  65. package/package.json +3 -5
  66. package/src/Node.ts +8 -47
  67. package/src/PM/index.ts +102 -0
  68. package/src/PM/main.ts +452 -0
  69. package/src/PM/node.ts +122 -0
  70. package/src/PM/web.ts +162 -0
  71. package/src/Project.ts +21 -2
  72. package/src/Puppeteer.ts +131 -0
  73. package/src/Report.tsx +160 -46
  74. package/src/Reporter.ts +134 -0
  75. package/src/Scheduler.ts +0 -0
  76. package/src/SubPackages/puppeteer.ts +3 -3
  77. package/src/SubPackages/react/jsx/index.ts +13 -3
  78. package/src/SubPackages/react/jsx/node.ts +5 -8
  79. package/src/SubPackages/react-dom/component/web.ts +126 -67
  80. package/src/SubPackages/react-test-renderer/jsx/index.ts +0 -1
  81. package/src/Web.ts +25 -69
  82. package/src/esbuildConfigs/web.ts +4 -2
  83. package/src/lib/abstractBase.ts +260 -65
  84. package/src/lib/basebuilder.ts +121 -100
  85. package/src/lib/classBuilder.ts +5 -4
  86. package/src/lib/core.ts +58 -59
  87. package/src/lib/index.ts +10 -9
  88. package/src/lib/types.ts +18 -27
  89. package/src/preload.ts +14 -14
  90. package/dist/common/NodeWriter.js +0 -54
  91. package/dist/common/electron.js +0 -266
  92. package/dist/module/NodeWriter.js +0 -48
  93. package/dist/module/electron.js +0 -261
  94. package/dist/types/NodeWriter.d.ts +0 -2
  95. package/src/NodeWriter.ts +0 -72
  96. package/src/electron.ts +0 -317
  97. package/yarn-error.log +0 -3144
  98. /package/dist/types/{electron.d.ts → Puppeteer.d.ts} +0 -0
package/README.md CHANGED
@@ -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
 
@@ -40,8 +39,7 @@ Testeranto.ts an Acceptance Test Driven Development ([ATDD](https://en.wikipedia
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
 
@@ -67,7 +65,7 @@ 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
70
  Testeranto does not (yet!) of a means of allowing non-coders to affect changes so, as they say, "get good 💪!"
73
71
 
@@ -83,13 +81,9 @@ Testeranto is comprised of 3 parts
83
81
  - Build the node-style tests
84
82
  - Build the web-style tests
85
83
 
86
- 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
+ 2. The test runner watches the output of those build processes and launches the tests as those files change.
87
85
  3. A Report which links your features, your tests and the results of those tests into a handy website.
88
86
 
89
- ## Electron aka Node vs Chromium
90
-
91
- 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.
92
-
93
87
  ## Hybrid tests
94
88
 
95
89
  Consider the a scenario: You have an http server which serves a frontend react component. You have multiple ways you can test this.
@@ -121,18 +115,15 @@ This is designed so that each piece can be worked upon separately. You can think
121
115
 
122
116
  ## CLI
123
117
 
124
- There are 4 commands you should add to your `package.json`
118
+ There are 3 commands you should add to your `package.json`
125
119
 
126
120
  ```
127
- // build the tests
121
+ // build the tests once
128
122
  "testeranto-esbuild": "ts-node-esm testeranto.mts",
129
123
 
130
- // run the tests
131
- "testeranto-electron": "electron node_modules/testeranto/dist/common/electron.js",
124
+ // build the tests, watching for changes
125
+ "testeranto-esbuild-dev": "ts-node-esm testeranto.mts",
132
126
 
133
- // build and run the tests as src files change
134
- "testeranto-dev": "yarn testeranto-esbuild -devmode ; yarn testeranto-electron -devmode"
135
-
136
- // build the tests, then run the tests
137
- "testeranto": "yarn testeranto-esbuild && yarn testeranto-electron"
127
+ // run the tests
128
+ "testeranto-puppeteer":"ts-node-esm node_modules/testeranto/dist/module/Puppeteer.js",
138
129
  ```
@@ -3,45 +3,18 @@ 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 puppeteer_core_1 = __importDefault(require("puppeteer-core"));
7
6
  const core_js_1 = __importDefault(require("./lib/core.js"));
8
7
  const index_js_1 = require("./lib/index.js");
9
- const NodeWriter_js_1 = require("./NodeWriter.js");
10
- const puppeteerConfiger_js_1 = __importDefault(require("./puppeteerConfiger.js"));
8
+ const node_js_1 = require("./PM/node.js");
11
9
  class NodeTesteranto extends core_js_1.default {
12
10
  constructor(input, testSpecification, testImplementation, testResourceRequirement, testInterface) {
13
- super(input, testSpecification, testImplementation, testResourceRequirement, NodeWriter_js_1.NodeWriter, testInterface);
14
- if (process.argv[2]) {
15
- const testResourceArg = process.argv[2];
16
- try {
17
- const partialTestResource = JSON.parse(testResourceArg);
18
- this.receiveTestResourceConfig(this.testJobs[0], partialTestResource);
19
- }
20
- catch (e) {
21
- console.error(e);
22
- // process.exit(-1);
23
- }
24
- }
25
- else {
26
- // no-op
27
- }
11
+ super(input, testSpecification, testImplementation, testResourceRequirement, testInterface);
28
12
  }
29
- async receiveTestResourceConfig(t, partialTestResource) {
30
- const browser = await (0, puppeteerConfiger_js_1.default)("2999").then(async (json) => {
31
- const b = await puppeteer_core_1.default.connect({
32
- browserWSEndpoint: json.webSocketDebuggerUrl,
33
- defaultViewport: null,
34
- });
35
- console.log("connected!", b.isConnected());
36
- return b;
37
- });
38
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource, {
39
- browser,
40
- ipc: process.parentPort,
41
- });
42
- Promise.all([...artifacts, logPromise]).then(async () => {
43
- process.exit((await failed) ? 1 : 0);
44
- });
13
+ async receiveTestResourceConfig(partialTestResource) {
14
+ const t = JSON.parse(partialTestResource);
15
+ const pm = new node_js_1.PM_Node(t);
16
+ const { failed, artifacts, logPromise } = await this.testJobs[0].receiveTestResourceConfig(pm);
17
+ pm.customclose();
45
18
  }
46
19
  }
47
20
  exports.default = async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = index_js_1.defaultTestResourceRequirement) => {
@@ -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,370 @@
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 files = {}; // = new Set<string>();
37
+ const screenshots = {};
38
+ class PM_Main extends index_js_1.PM {
39
+ constructor(configs) {
40
+ super();
41
+ this.launchNode = async (src, dest) => {
42
+ console.log("launchNode", src);
43
+ const destFolder = dest.replace(".mjs", "");
44
+ let argz = "";
45
+ const testConfig = this.configs.tests.find((t) => {
46
+ return t[0] === src;
47
+ });
48
+ if (!testConfig) {
49
+ console.error("missing test config");
50
+ process.exit(-1);
51
+ }
52
+ const testConfigResource = testConfig[2];
53
+ let portsToUse = [];
54
+ if (testConfigResource.ports === 0) {
55
+ argz = JSON.stringify({
56
+ scheduled: true,
57
+ name: src,
58
+ ports: portsToUse,
59
+ fs: destFolder,
60
+ browserWSEndpoint: this.browser.wsEndpoint(),
61
+ });
62
+ }
63
+ else if (testConfigResource.ports > 0) {
64
+ const openPorts = Object.entries(this.ports).filter(([portnumber, portopen]) => portopen);
65
+ if (openPorts.length >= testConfigResource.ports) {
66
+ for (let i = 0; i < testConfigResource.ports; i++) {
67
+ portsToUse.push(openPorts[i][0]);
68
+ this.ports[openPorts[i][0]] = false; // port is now closed
69
+ }
70
+ argz = JSON.stringify({
71
+ scheduled: true,
72
+ name: src,
73
+ // ports: [3333],
74
+ ports: portsToUse,
75
+ fs: ".",
76
+ browserWSEndpoint: this.browser.wsEndpoint(),
77
+ });
78
+ }
79
+ else {
80
+ this.queue.push(src);
81
+ return;
82
+ }
83
+ }
84
+ else {
85
+ console.error("negative port makes no sense", src);
86
+ process.exit(-1);
87
+ }
88
+ const builtfile = dest + ".mjs";
89
+ this.server[builtfile] = await Promise.resolve().then(() => __importStar(require(`${builtfile}?cacheBust=${Date.now()}`))).then((module) => {
90
+ return module.default.then((defaultModule) => {
91
+ defaultModule
92
+ .receiveTestResourceConfig(argz)
93
+ .then((x) => {
94
+ console.log("then", x);
95
+ return x;
96
+ })
97
+ .catch((e) => {
98
+ console.log("catch", e);
99
+ });
100
+ });
101
+ });
102
+ for (let i = 0; i <= portsToUse.length; i++) {
103
+ this.ports[i] = true; //port is open again
104
+ }
105
+ };
106
+ this.launchWeb = (t, dest) => {
107
+ console.log("launchWeb", t, dest);
108
+ const destFolder = dest.replace(".mjs", "");
109
+ const webArgz = JSON.stringify({
110
+ name: dest,
111
+ ports: [].toString(),
112
+ fs: destFolder,
113
+ browserWSEndpoint: this.browser.wsEndpoint(),
114
+ });
115
+ const evaluation = `import('${dest}.mjs').then(async (x) => {
116
+ console.log("imported", x, (x.default));
117
+ try {
118
+ await (await x.default).receiveTestResourceConfig(${webArgz})
119
+ } catch (e) {
120
+ console.log("fail", e)
121
+ }
122
+ })`;
123
+ const fileStreams2 = [];
124
+ // const screenshots2: Promise<any>[] = [];
125
+ const doneFileStream2 = [];
126
+ this.browser
127
+ .newPage()
128
+ .then((page) => {
129
+ page.exposeFunction("custom-screenshot", async (ssOpts, testName) => {
130
+ console.log("main.ts browser custom-screenshot", testName);
131
+ const p = ssOpts.path;
132
+ const dir = path_1.default.dirname(p);
133
+ fs_1.default.mkdirSync(dir, {
134
+ recursive: true,
135
+ });
136
+ files[testName].add(ssOpts.path);
137
+ const sPromise = page.screenshot(Object.assign(Object.assign({}, ssOpts), { path: p }));
138
+ if (!screenshots[testName]) {
139
+ screenshots[testName] = [];
140
+ }
141
+ screenshots[testName].push(sPromise);
142
+ // sPromise.then(())
143
+ await sPromise;
144
+ return sPromise;
145
+ // page.evaluate(`window["screenshot done"]`);
146
+ });
147
+ page.exposeFunction("writeFileSync", (fp, contents, testName) => {
148
+ const dir = path_1.default.dirname(fp);
149
+ fs_1.default.mkdirSync(dir, {
150
+ recursive: true,
151
+ });
152
+ const p = new Promise(async (res, rej) => {
153
+ fs_1.default.writeFileSync(fp, contents);
154
+ res(fp);
155
+ });
156
+ doneFileStream2.push(p);
157
+ if (!files[testName]) {
158
+ files[testName] = new Set();
159
+ }
160
+ files[testName].add(fp);
161
+ return p;
162
+ });
163
+ page.exposeFunction("existsSync", (fp, contents) => {
164
+ return fs_1.default.existsSync(fp);
165
+ });
166
+ page.exposeFunction("mkdirSync", (fp) => {
167
+ if (!fs_1.default.existsSync(fp)) {
168
+ return fs_1.default.mkdirSync(fp, {
169
+ recursive: true,
170
+ });
171
+ }
172
+ return false;
173
+ });
174
+ page.exposeFunction("createWriteStream", (fp, testName) => {
175
+ const f = fs_1.default.createWriteStream(fp);
176
+ if (!files[testName]) {
177
+ files[testName] = new Set();
178
+ }
179
+ files[testName].add(fp);
180
+ const p = new Promise((res, rej) => {
181
+ res(fp);
182
+ });
183
+ doneFileStream2.push(p);
184
+ f.on("close", async () => {
185
+ await p;
186
+ });
187
+ fileStreams2.push(f);
188
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams2.length - 1 });
189
+ });
190
+ page.exposeFunction("write", async (uid, contents) => {
191
+ return fileStreams2[uid].write(contents);
192
+ });
193
+ page.exposeFunction("end", async (uid) => {
194
+ return fileStreams2[uid].end();
195
+ });
196
+ page.exposeFunction("customclose", (p, testName) => {
197
+ fs_1.default.writeFileSync(p + "/manifest.json", JSON.stringify(Array.from(files[testName])));
198
+ delete files[testName];
199
+ Promise.all(screenshots[testName] || []).then(() => {
200
+ delete screenshots[testName];
201
+ page.close();
202
+ });
203
+ // globalThis["writeFileSync"](
204
+ // p + "/manifest.json",
205
+ // // files.entries()
206
+ // JSON.stringify(Array.from(files[testName]))
207
+ // );
208
+ // console.log("closing doneFileStream2", doneFileStream2);
209
+ // console.log("closing doneFileStream2", doneFileStream2);
210
+ // Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
211
+ // page.close();
212
+ // });
213
+ // Promise.all(screenshots).then(() => {
214
+ // page.close();
215
+ // });
216
+ // setTimeout(() => {
217
+ // console.log("Delayed for 1 second.");
218
+ // page.close();
219
+ // }, 5000);
220
+ // return page.close();
221
+ });
222
+ return page;
223
+ })
224
+ .then(async (page) => {
225
+ await page.goto(`file://${`${dest}.html`}`, {});
226
+ page.evaluate(evaluation).finally(() => {
227
+ console.log("evaluation failed.", dest);
228
+ });
229
+ return page;
230
+ });
231
+ };
232
+ this.server = {};
233
+ this.configs = configs;
234
+ this.ports = {};
235
+ this.configs.ports.forEach((element) => {
236
+ this.ports[element] = "true"; // set ports as open
237
+ });
238
+ globalThis["mkdirSync"] = (fp) => {
239
+ if (!fs_1.default.existsSync(fp)) {
240
+ return fs_1.default.mkdirSync(fp, {
241
+ recursive: true,
242
+ });
243
+ }
244
+ return false;
245
+ };
246
+ globalThis["writeFileSync"] = (filepath, contents, testName) => {
247
+ // Create directories if they don't exist
248
+ const dir = path_1.default.dirname(filepath.split("/").slice(0, -1).join("/"));
249
+ fs_1.default.mkdirSync(dir, {
250
+ recursive: true,
251
+ });
252
+ if (!files[testName]) {
253
+ files[testName] = new Set();
254
+ }
255
+ files[testName].add(filepath);
256
+ return fs_1.default.writeFileSync(filepath, contents);
257
+ };
258
+ globalThis["createWriteStream"] = (filepath, testName) => {
259
+ const f = fs_1.default.createWriteStream(filepath);
260
+ fileStreams3.push(f);
261
+ // files.add(filepath);
262
+ if (!files[testName]) {
263
+ files[testName] = new Set();
264
+ }
265
+ files[testName].add(filepath);
266
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams3.length - 1 });
267
+ };
268
+ globalThis["write"] = (uid, contents) => {
269
+ fileStreams3[uid].write(contents);
270
+ };
271
+ globalThis["end"] = (uid) => {
272
+ fileStreams3[uid].end();
273
+ };
274
+ globalThis["customclose"] = (p, testName) => {
275
+ if (!files[testName]) {
276
+ files[testName] = new Set();
277
+ }
278
+ fs_1.default.writeFileSync(p + "/manifest.json", JSON.stringify(Array.from(files[testName])));
279
+ delete files[testName];
280
+ // globalThis["writeFileSync"](
281
+ // p + "/manifest.json",
282
+ // // files.entries()
283
+ // JSON.stringify(Array.from(files[testName]))
284
+ // );
285
+ // fileStreams3[uid].end();
286
+ };
287
+ // page.exposeFunction("customclose", () => {
288
+ // console.log("closing doneFileStream2", doneFileStream2);
289
+ // // console.log("closing doneFileStream2", doneFileStream2);
290
+ // Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
291
+ // page.close();
292
+ // });
293
+ // // page.close();
294
+ // // Promise.all(screenshots).then(() => {
295
+ // // page.close();
296
+ // // });
297
+ // // setTimeout(() => {
298
+ // // console.log("Delayed for 1 second.");
299
+ // // page.close();
300
+ // // }, 5000);
301
+ // // return page.close();
302
+ // });
303
+ }
304
+ async startPuppeteer(options, destfolder) {
305
+ this.browser = await puppeteer_core_1.default.launch(options);
306
+ return this.browser;
307
+ }
308
+ end(accessObject) {
309
+ throw new Error("Method not implemented.");
310
+ }
311
+ existsSync(destFolder) {
312
+ return fs_1.default.existsSync(destFolder);
313
+ }
314
+ async mkdirSync(fp) {
315
+ if (!fs_1.default.existsSync(fp)) {
316
+ return fs_1.default.mkdirSync(fp, {
317
+ recursive: true,
318
+ });
319
+ }
320
+ return false;
321
+ }
322
+ writeFileSync(fp, contents) {
323
+ fs_1.default.writeFileSync(fp, contents);
324
+ }
325
+ createWriteStream(filepath) {
326
+ return fs_1.default.createWriteStream(filepath);
327
+ }
328
+ testArtiFactoryfileWriter(tLog, callback) {
329
+ return (fPath, value) => {
330
+ callback(new Promise((res, rej) => {
331
+ tLog("testArtiFactory =>", fPath);
332
+ const cleanPath = path_1.default.resolve(fPath);
333
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
334
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
335
+ fs_1.default.mkdir(targetDir, { recursive: true }, async (error) => {
336
+ if (error) {
337
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
338
+ }
339
+ fs_1.default.writeFileSync(path_1.default.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
340
+ encoding: "utf-8",
341
+ });
342
+ if (Buffer.isBuffer(value)) {
343
+ fs_1.default.writeFileSync(fPath, value, "binary");
344
+ res();
345
+ }
346
+ else if (`string` === typeof value) {
347
+ fs_1.default.writeFileSync(fPath, value.toString(), {
348
+ encoding: "utf-8",
349
+ });
350
+ res();
351
+ }
352
+ else {
353
+ /* @ts-ignore:next-line */
354
+ const pipeStream = value;
355
+ const myFile = fs_1.default.createWriteStream(fPath);
356
+ pipeStream.pipe(myFile);
357
+ pipeStream.on("close", () => {
358
+ myFile.close();
359
+ res();
360
+ });
361
+ }
362
+ });
363
+ }));
364
+ };
365
+ }
366
+ write(accessObject, contents) {
367
+ throw new Error("Method not implemented.");
368
+ }
369
+ }
370
+ exports.PM_Main = PM_Main;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PM_Node = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const puppeteer_core_1 = __importDefault(require("puppeteer-core"));
10
+ const index_js_1 = require("./index.js");
11
+ const fPaths = [];
12
+ class PM_Node extends index_js_1.PM {
13
+ constructor(t) {
14
+ super();
15
+ this.server = {};
16
+ this.testResourceConfiguration = t;
17
+ }
18
+ existsSync(destFolder) {
19
+ return globalThis["existsSync"](this.testResourceConfiguration.fs + "/" + destFolder);
20
+ }
21
+ mkdirSync() {
22
+ return globalThis["mkdirSync"](this.testResourceConfiguration.fs + "/");
23
+ }
24
+ write(writeObject, contents) {
25
+ return globalThis["write"](writeObject.uid, contents);
26
+ }
27
+ writeFileSync(filepath, contents) {
28
+ return globalThis["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents, this.testResourceConfiguration.name);
29
+ }
30
+ createWriteStream(filepath) {
31
+ return globalThis["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath, this.testResourceConfiguration.name);
32
+ }
33
+ end(writeObject) {
34
+ return globalThis["end"](writeObject.uid);
35
+ }
36
+ customclose() {
37
+ globalThis["customclose"](this.testResourceConfiguration.fs, this.testResourceConfiguration.name);
38
+ }
39
+ testArtiFactoryfileWriter(tLog, callback) {
40
+ return (fPath, value) => {
41
+ callback(new Promise((res, rej) => {
42
+ tLog("testArtiFactory =>", fPath);
43
+ const cleanPath = path_1.default.resolve(fPath);
44
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
45
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
46
+ fs_1.default.mkdir(targetDir, { recursive: true }, async (error) => {
47
+ if (error) {
48
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
49
+ }
50
+ fs_1.default.writeFileSync(path_1.default.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
51
+ encoding: "utf-8",
52
+ });
53
+ if (Buffer.isBuffer(value)) {
54
+ fs_1.default.writeFileSync(fPath, value, "binary");
55
+ res();
56
+ }
57
+ else if (`string` === typeof value) {
58
+ fs_1.default.writeFileSync(fPath, value.toString(), {
59
+ encoding: "utf-8",
60
+ });
61
+ res();
62
+ }
63
+ else {
64
+ /* @ts-ignore:next-line */
65
+ const pipeStream = value;
66
+ const myFile = fs_1.default.createWriteStream(fPath);
67
+ pipeStream.pipe(myFile);
68
+ pipeStream.on("close", () => {
69
+ myFile.close();
70
+ res();
71
+ });
72
+ }
73
+ });
74
+ }));
75
+ };
76
+ }
77
+ // launch(options?: PuppeteerLaunchOptions): Promise<Browser>;
78
+ startPuppeteer(options) {
79
+ return puppeteer_core_1.default.connect(options).then((b) => {
80
+ this.browser = b;
81
+ });
82
+ }
83
+ }
84
+ exports.PM_Node = PM_Node;