testeranto 0.70.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 (94) hide show
  1. package/README.md +9 -18
  2. package/dist/common/Node.js +14 -34
  3. package/dist/common/PM/index.js +71 -0
  4. package/dist/common/PM/main.js +361 -0
  5. package/dist/common/PM/node.js +176 -0
  6. package/dist/common/PM/web.js +174 -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-dom/component/web.js +98 -45
  13. package/dist/common/SubPackages/react-test-renderer/jsx/index.js +0 -1
  14. package/dist/common/Web.js +24 -43
  15. package/dist/common/esbuildConfigs/web.js +3 -1
  16. package/dist/common/lib/abstractBase.js +189 -41
  17. package/dist/common/lib/basebuilder.js +56 -29
  18. package/dist/common/lib/classBuilder.js +6 -2
  19. package/dist/common/lib/core.js +41 -45
  20. package/dist/common/lib/index.js +2 -1
  21. package/dist/common/preload.js +14 -18
  22. package/dist/common/tsconfig.common.tsbuildinfo +1 -1
  23. package/dist/module/Node.js +14 -34
  24. package/dist/module/PM/index.js +67 -0
  25. package/dist/module/PM/main.js +331 -0
  26. package/dist/module/PM/node.js +168 -0
  27. package/dist/module/PM/web.js +167 -0
  28. package/dist/module/Project.js +20 -2
  29. package/dist/module/Puppeteer.js +104 -0
  30. package/dist/module/Reporter.js +114 -0
  31. package/dist/module/Scheduler.js +1 -0
  32. package/dist/module/SubPackages/puppeteer.js +3 -1
  33. package/dist/module/SubPackages/react/jsx/node.js +1 -1
  34. package/dist/module/SubPackages/react-dom/component/web.js +98 -45
  35. package/dist/module/SubPackages/react-test-renderer/jsx/index.js +0 -1
  36. package/dist/module/Web.js +24 -43
  37. package/dist/module/esbuildConfigs/web.js +3 -1
  38. package/dist/module/lib/abstractBase.js +189 -41
  39. package/dist/module/lib/basebuilder.js +56 -29
  40. package/dist/module/lib/classBuilder.js +6 -2
  41. package/dist/module/lib/core.js +41 -45
  42. package/dist/module/lib/index.js +2 -1
  43. package/dist/module/preload.js +15 -14
  44. package/dist/module/tsconfig.module.tsbuildinfo +1 -1
  45. package/dist/prebuild/Report.css +1616 -584
  46. package/dist/prebuild/Report.js +2635 -2506
  47. package/dist/types/PM/index.d.ts +19 -0
  48. package/dist/types/PM/main.d.ts +28 -0
  49. package/dist/types/PM/node.d.ts +26 -0
  50. package/dist/types/PM/web.d.ts +24 -0
  51. package/dist/types/Reporter.d.ts +1 -0
  52. package/dist/types/Scheduler.d.ts +0 -0
  53. package/dist/types/SubPackages/react-dom/component/web.d.ts +1 -1
  54. package/dist/types/lib/abstractBase.d.ts +13 -12
  55. package/dist/types/lib/basebuilder.d.ts +4 -2
  56. package/dist/types/lib/classBuilder.d.ts +2 -2
  57. package/dist/types/lib/core.d.ts +4 -4
  58. package/dist/types/lib/index.d.ts +6 -5
  59. package/dist/types/lib/types.d.ts +16 -24
  60. package/dist/types/preload.d.ts +0 -1
  61. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  62. package/package.json +3 -5
  63. package/src/Node.ts +18 -43
  64. package/src/PM/index.ts +102 -0
  65. package/src/PM/main.ts +420 -0
  66. package/src/PM/node.ts +515 -0
  67. package/src/PM/web.ts +497 -0
  68. package/src/Project.ts +21 -2
  69. package/src/Puppeteer.ts +131 -0
  70. package/src/Report.tsx +158 -44
  71. package/src/Reporter.ts +134 -0
  72. package/src/Scheduler.ts +0 -0
  73. package/src/SubPackages/puppeteer.ts +3 -3
  74. package/src/SubPackages/react/jsx/node.ts +5 -8
  75. package/src/SubPackages/react-dom/component/web.ts +126 -67
  76. package/src/SubPackages/react-test-renderer/jsx/index.ts +0 -1
  77. package/src/Web.ts +25 -67
  78. package/src/esbuildConfigs/web.ts +4 -2
  79. package/src/lib/abstractBase.ts +260 -65
  80. package/src/lib/basebuilder.ts +121 -100
  81. package/src/lib/classBuilder.ts +5 -4
  82. package/src/lib/core.ts +58 -59
  83. package/src/lib/index.ts +10 -9
  84. package/src/lib/types.ts +18 -27
  85. package/src/preload.ts +14 -14
  86. package/dist/common/NodeWriter.js +0 -54
  87. package/dist/common/electron.js +0 -266
  88. package/dist/module/NodeWriter.js +0 -48
  89. package/dist/module/electron.js +0 -261
  90. package/dist/types/NodeWriter.d.ts +0 -2
  91. package/src/NodeWriter.ts +0 -72
  92. package/src/electron.ts +0 -317
  93. package/yarn-error.log +0 -3144
  94. /package/dist/types/{electron.d.ts → Puppeteer.d.ts} +0 -0
@@ -1,42 +1,22 @@
1
- import puppeteer from "puppeteer-core";
2
1
  import Testeranto from "./lib/core.js";
3
2
  import { defaultTestResourceRequirement, } from "./lib/index.js";
4
- import { NodeWriter } from "./NodeWriter.js";
5
- import puppeteerConfiger from "./puppeteerConfiger.js";
3
+ import { PM_Node } from "./PM/node.js";
6
4
  class NodeTesteranto extends Testeranto {
7
5
  constructor(input, testSpecification, testImplementation, testResourceRequirement, testInterface) {
8
- super(input, testSpecification, testImplementation, testResourceRequirement, NodeWriter, testInterface);
9
- if (process.argv[2]) {
10
- const testResourceArg = process.argv[2];
11
- try {
12
- const partialTestResource = JSON.parse(testResourceArg);
13
- this.receiveTestResourceConfig(this.testJobs[0], partialTestResource);
14
- }
15
- catch (e) {
16
- console.error(e);
17
- // process.exit(-1);
18
- }
19
- }
20
- else {
21
- // no-op
22
- }
6
+ super(input, testSpecification, testImplementation, testResourceRequirement, testInterface);
23
7
  }
24
- async receiveTestResourceConfig(t, partialTestResource) {
25
- const browser = await puppeteerConfiger("2999").then(async (json) => {
26
- const b = await puppeteer.connect({
27
- browserWSEndpoint: json.webSocketDebuggerUrl,
28
- defaultViewport: null,
29
- });
30
- console.log("connected!", b.isConnected());
31
- return b;
32
- });
33
- const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(partialTestResource, {
34
- browser,
35
- ipc: process.parentPort,
36
- });
37
- Promise.all([...artifacts, logPromise]).then(async () => {
38
- process.exit((await failed) ? 1 : 0);
39
- });
8
+ async receiveTestResourceConfig(
9
+ // t: ITestJob,
10
+ partialTestResource) {
11
+ console.log("receiveTestResourceConfig!!", this.testJobs[0].receiveTestResourceConfig);
12
+ const t = JSON.parse(partialTestResource);
13
+ const pm = new PM_Node(t);
14
+ const { failed, artifacts, logPromise } = await this.testJobs[0].receiveTestResourceConfig(pm);
15
+ console.log("test is done, awaiting test result write to fs");
16
+ pm.customclose();
17
+ // Promise.all([...artifacts, logPromise]).then(async () => {
18
+ // // process.exit((await failed) ? 1 : 0);
19
+ // });
40
20
  }
41
21
  }
42
22
  export default async (input, testSpecification, testImplementation, testInterface, testResourceRequirement = defaultTestResourceRequirement) => {
@@ -0,0 +1,67 @@
1
+ // import {
2
+ // Browser,
3
+ // BrowserContext,
4
+ // BrowserContextOptions,
5
+ // DebugInfo,
6
+ // Page,
7
+ // PuppeteerNode,
8
+ // Target,
9
+ // } from "puppeteer-core";
10
+ const fPaths = [];
11
+ export class PM {
12
+ }
13
+ // export class PuppetMasterBrowser extends Browser {
14
+ // process(): ChildProcess | null {
15
+ // return super.process();
16
+ // }
17
+ // createBrowserContext(
18
+ // options?: BrowserContextOptions
19
+ // ): Promise<BrowserContext> {
20
+ // throw new Error("Method not implemented.");
21
+ // }
22
+ // browserContexts(): BrowserContext[] {
23
+ // throw new Error("Method not implemented.");
24
+ // }
25
+ // defaultBrowserContext(): BrowserContext {
26
+ // throw new Error("Method not implemented.");
27
+ // }
28
+ // wsEndpoint(): string {
29
+ // throw new Error("Method not implemented.");
30
+ // }
31
+ // newPage(): Promise<Page> {
32
+ // throw new Error("Method not implemented.");
33
+ // }
34
+ // targets(): Target[] {
35
+ // throw new Error("Method not implemented.");
36
+ // }
37
+ // target(): Target {
38
+ // throw new Error("Method not implemented.");
39
+ // }
40
+ // version(): Promise<string> {
41
+ // throw new Error("Method not implemented.");
42
+ // }
43
+ // userAgent(): Promise<string> {
44
+ // throw new Error("Method not implemented.");
45
+ // }
46
+ // close(): Promise<void> {
47
+ // throw new Error("Method not implemented.");
48
+ // }
49
+ // disconnect(): Promise<void> {
50
+ // throw new Error("Method not implemented.");
51
+ // }
52
+ // get connected(): boolean {
53
+ // throw new Error("Method not implemented.");
54
+ // }
55
+ // get debugInfo(): DebugInfo {
56
+ // throw new Error("Method not implemented.");
57
+ // }
58
+ // constructor(...z: []) {
59
+ // super(...z);
60
+ // }
61
+ // // pages(): Promise<Page[]>;
62
+ // pages(): Promise<Page[]> {
63
+ // return new Promise<Page[]>((res, rej) => {
64
+ // res(super.pages());
65
+ // });
66
+ // }
67
+ // }
@@ -0,0 +1,331 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import puppeteer from "puppeteer-core";
4
+ import { PM } from "./index.js";
5
+ const fPaths = [];
6
+ const fileStreams3 = [];
7
+ const screenshots3 = [];
8
+ const doneFileStream3 = [];
9
+ export class PM_Main extends PM {
10
+ // testResourceConfiguration: ITTestResourceConfiguration;
11
+ constructor(configs
12
+ // testResourceConfig: ITTestResourceConfiguration
13
+ ) {
14
+ super();
15
+ this.launchNode = async (src, dest) => {
16
+ console.log("launchNode", src);
17
+ // childProcesses[src] = "running";
18
+ const destFolder = dest.replace(".mjs", "");
19
+ let argz = "";
20
+ const testConfig = this.configs.tests.find((t) => {
21
+ return t[0] === src;
22
+ });
23
+ if (!testConfig) {
24
+ console.error("missing test config");
25
+ process.exit(-1);
26
+ }
27
+ const testConfigResource = testConfig[2];
28
+ console.log("mark22 testConfigResource", testConfigResource);
29
+ let portsToUse = [];
30
+ if (testConfigResource.ports === 0) {
31
+ argz = JSON.stringify({
32
+ scheduled: true,
33
+ name: src,
34
+ ports: portsToUse,
35
+ fs: destFolder,
36
+ browserWSEndpoint: this.browser.wsEndpoint(),
37
+ });
38
+ }
39
+ else if (testConfigResource.ports > 0) {
40
+ const openPorts = Object.entries(this.ports).filter(([portnumber, portopen]) => portopen);
41
+ if (openPorts.length >= testConfigResource.ports) {
42
+ for (let i = 0; i < testConfigResource.ports; i++) {
43
+ portsToUse.push(openPorts[i][0]);
44
+ this.ports[openPorts[i][0]] = false; // port is now closed
45
+ }
46
+ argz = JSON.stringify({
47
+ scheduled: true,
48
+ name: src,
49
+ // ports: [3333],
50
+ ports: portsToUse,
51
+ fs: ".",
52
+ browserWSEndpoint: this.browser.wsEndpoint(),
53
+ });
54
+ }
55
+ else {
56
+ this.queue.push(src);
57
+ return;
58
+ }
59
+ }
60
+ else {
61
+ console.error("negative port makes no sense", src);
62
+ process.exit(-1);
63
+ }
64
+ const builtfile = dest + ".mjs";
65
+ this.server[builtfile] = await import(`${builtfile}?cacheBust=${Date.now()}`).then((module) => {
66
+ return module.default.then((defaultModule) => {
67
+ defaultModule
68
+ .receiveTestResourceConfig(argz)
69
+ .then((x) => {
70
+ console.log("then", x);
71
+ return x;
72
+ })
73
+ .catch((e) => {
74
+ console.log("catch", e);
75
+ });
76
+ });
77
+ });
78
+ for (let i = 0; i <= portsToUse.length; i++) {
79
+ this.ports[i] = true; //port is open again
80
+ }
81
+ };
82
+ this.launchWeb = (t, dest) => {
83
+ console.log("launchWeb", t, dest);
84
+ const testResourceConfiguration = this.testResourceConfiguration;
85
+ // childProcesses[t] = "running";
86
+ const destFolder = dest.replace(".mjs", "");
87
+ const webArgz = JSON.stringify({
88
+ name: dest,
89
+ ports: [].toString(),
90
+ fs: destFolder,
91
+ browserWSEndpoint: this.browser.wsEndpoint(),
92
+ });
93
+ const evaluation = `import('${dest}.mjs').then(async (x) => {
94
+ console.log("imported", x, (x.default));
95
+ try {
96
+ await (await x.default).receiveTestResourceConfig(${webArgz})
97
+ } catch (e) {
98
+ console.log("fail", e)
99
+ }
100
+ })`;
101
+ const fileStreams2 = [];
102
+ const screenshots2 = [];
103
+ const doneFileStream2 = [];
104
+ this.browser
105
+ .newPage()
106
+ .then((page) => {
107
+ page.exposeFunction("custom-screenshot", async (ssOpts) => {
108
+ const p = ssOpts.path;
109
+ console.log("custom-screenshot", ssOpts);
110
+ const dir = path.dirname(p);
111
+ console.log("dir", dir);
112
+ fs.mkdirSync(dir, {
113
+ recursive: true,
114
+ });
115
+ return page.screenshot(Object.assign(Object.assign({}, ssOpts), { path: p }));
116
+ // screenshots.push(
117
+ // page.screenshot({
118
+ // ...ssOpts,
119
+ // path: ssOpts.path,
120
+ // })
121
+ // );
122
+ // const sPromise = page.screenshot({
123
+ // ...ssOpts,
124
+ // path: p,
125
+ // });
126
+ // await sPromise;
127
+ // page.evaluate(`window["screenshot done"]`);
128
+ });
129
+ page.exposeFunction("writeFileSync", (fp, contents) => {
130
+ console.log("writeFileSync", fp);
131
+ // Create directories if they don't exist
132
+ const dir = path.dirname(fp);
133
+ console.log("dir", dir);
134
+ fs.mkdirSync(dir, {
135
+ recursive: true,
136
+ });
137
+ // return fs.writeFileSync(fp, contents);
138
+ const p = new Promise(async (res, rej) => {
139
+ fs.writeFileSync(fp, contents);
140
+ res(fp);
141
+ });
142
+ doneFileStream2.push(p);
143
+ return p;
144
+ });
145
+ page.exposeFunction("existsSync", (fp, contents) => {
146
+ return fs.existsSync(fp);
147
+ });
148
+ page.exposeFunction("mkdirSync", (fp) => {
149
+ console.log("mkdirsync", fp);
150
+ if (!fs.existsSync(fp)) {
151
+ return fs.mkdirSync(fp, {
152
+ recursive: true,
153
+ });
154
+ }
155
+ return false;
156
+ });
157
+ page.exposeFunction("createWriteStream", (fp) => {
158
+ const f = fs.createWriteStream(fp);
159
+ const p = new Promise((res, rej) => {
160
+ res(fp);
161
+ });
162
+ doneFileStream2.push(p);
163
+ f.on("close", async () => {
164
+ await p;
165
+ });
166
+ fileStreams2.push(f);
167
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams2.length - 1 });
168
+ });
169
+ page.exposeFunction("write", async (uid, contents) => {
170
+ return fileStreams2[uid].write(contents);
171
+ });
172
+ page.exposeFunction("end", async (uid) => {
173
+ return fileStreams2[uid].end();
174
+ });
175
+ page.exposeFunction("customclose", () => {
176
+ console.log("closing doneFileStream2", doneFileStream2);
177
+ // console.log("closing doneFileStream2", doneFileStream2);
178
+ Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
179
+ page.close();
180
+ });
181
+ // page.close();
182
+ // Promise.all(screenshots).then(() => {
183
+ // page.close();
184
+ // });
185
+ // setTimeout(() => {
186
+ // console.log("Delayed for 1 second.");
187
+ // page.close();
188
+ // }, 5000);
189
+ // return page.close();
190
+ });
191
+ return page;
192
+ })
193
+ .then(async (page) => {
194
+ await page.goto(`file://${`${dest}.html`}`, {
195
+ // waitUntil: "load",
196
+ // timeout: 0,
197
+ });
198
+ page.evaluate(evaluation).finally(() => {
199
+ console.log("evaluation failed.", dest);
200
+ });
201
+ return page;
202
+ })
203
+ .then((page) => {
204
+ // console.log("qwe", page);
205
+ // page.close();
206
+ });
207
+ };
208
+ // this.testResourceConfiguration = testResourceConfig;
209
+ // console.log("mkdirsync4", testResourceConfig);
210
+ this.server = {};
211
+ this.configs = configs;
212
+ this.ports = {};
213
+ this.configs.ports.forEach((element) => {
214
+ this.ports[element] = "true"; // set ports as open
215
+ });
216
+ globalThis["mkdirSync"] = (fp) => {
217
+ if (!fs.existsSync(fp)) {
218
+ return fs.mkdirSync(fp, {
219
+ recursive: true,
220
+ });
221
+ }
222
+ return false;
223
+ };
224
+ globalThis["writeFileSync"] = (fp, contents) => {
225
+ // Create directories if they don't exist
226
+ const dir = path.dirname(fp.split("/").slice(0, -1).join("/"));
227
+ console.log("dir", dir);
228
+ fs.mkdirSync(dir, {
229
+ recursive: true,
230
+ });
231
+ return fs.writeFileSync(fp, contents);
232
+ };
233
+ globalThis["createWriteStream"] = (filepath) => {
234
+ const f = fs.createWriteStream(filepath);
235
+ fileStreams3.push(f);
236
+ return Object.assign(Object.assign({}, JSON.parse(JSON.stringify(f))), { uid: fileStreams3.length - 1 });
237
+ };
238
+ globalThis["write"] = (uid, contents) => {
239
+ console.log("write", uid, contents);
240
+ // process.exit();
241
+ fileStreams3[uid].write(contents);
242
+ };
243
+ globalThis["end"] = (uid) => {
244
+ fileStreams3[uid].end();
245
+ };
246
+ globalThis["customclose"] = () => {
247
+ // fileStreams3[uid].end();
248
+ };
249
+ // page.exposeFunction("customclose", () => {
250
+ // console.log("closing doneFileStream2", doneFileStream2);
251
+ // // console.log("closing doneFileStream2", doneFileStream2);
252
+ // Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
253
+ // page.close();
254
+ // });
255
+ // // page.close();
256
+ // // Promise.all(screenshots).then(() => {
257
+ // // page.close();
258
+ // // });
259
+ // // setTimeout(() => {
260
+ // // console.log("Delayed for 1 second.");
261
+ // // page.close();
262
+ // // }, 5000);
263
+ // // return page.close();
264
+ // });
265
+ }
266
+ async startPuppeteer(options, destfolder) {
267
+ this.browser = await puppeteer.launch(options);
268
+ return this.browser;
269
+ }
270
+ end(accessObject) {
271
+ throw new Error("Method not implemented.");
272
+ }
273
+ existsSync(destFolder) {
274
+ return fs.existsSync(destFolder);
275
+ }
276
+ async mkdirSync(fp) {
277
+ if (!fs.existsSync(fp)) {
278
+ return fs.mkdirSync(fp, {
279
+ recursive: true,
280
+ });
281
+ }
282
+ return false;
283
+ }
284
+ writeFileSync(fp, contents) {
285
+ fs.writeFileSync(fp, contents);
286
+ }
287
+ createWriteStream(filepath) {
288
+ return fs.createWriteStream(filepath);
289
+ }
290
+ testArtiFactoryfileWriter(tLog, callback) {
291
+ return (fPath, value) => {
292
+ callback(new Promise((res, rej) => {
293
+ tLog("testArtiFactory =>", fPath);
294
+ const cleanPath = path.resolve(fPath);
295
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
296
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
297
+ fs.mkdir(targetDir, { recursive: true }, async (error) => {
298
+ if (error) {
299
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
300
+ }
301
+ fs.writeFileSync(path.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
302
+ encoding: "utf-8",
303
+ });
304
+ if (Buffer.isBuffer(value)) {
305
+ fs.writeFileSync(fPath, value, "binary");
306
+ res();
307
+ }
308
+ else if (`string` === typeof value) {
309
+ fs.writeFileSync(fPath, value.toString(), {
310
+ encoding: "utf-8",
311
+ });
312
+ res();
313
+ }
314
+ else {
315
+ /* @ts-ignore:next-line */
316
+ const pipeStream = value;
317
+ const myFile = fs.createWriteStream(fPath);
318
+ pipeStream.pipe(myFile);
319
+ pipeStream.on("close", () => {
320
+ myFile.close();
321
+ res();
322
+ });
323
+ }
324
+ });
325
+ }));
326
+ };
327
+ }
328
+ write(accessObject, contents) {
329
+ throw new Error("Method not implemented.");
330
+ }
331
+ }
@@ -0,0 +1,168 @@
1
+ // import puppeteer from "puppeteer";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ // import puppeteer from "puppeteer-core/lib/esm/puppeteer/puppeteer-core";
5
+ import puppeteer from "puppeteer-core";
6
+ import { PM } from "./index.js";
7
+ const fPaths = [];
8
+ export function addPageBinding(type, name, prefix) {
9
+ // Depending on the frame loading state either Runtime.evaluate or
10
+ // Page.addScriptToEvaluateOnNewDocument might succeed. Let's check that we
11
+ // don't re-wrap Puppeteer's binding.
12
+ if (globalThis[name]) {
13
+ return;
14
+ }
15
+ // We replace the CDP binding with a Puppeteer binding.
16
+ Object.assign(globalThis, {
17
+ [name](...args) {
18
+ var _a, _b, _c;
19
+ // This is the Puppeteer binding.
20
+ const callPuppeteer = globalThis[name];
21
+ (_a = callPuppeteer.args) !== null && _a !== void 0 ? _a : (callPuppeteer.args = new Map());
22
+ (_b = callPuppeteer.callbacks) !== null && _b !== void 0 ? _b : (callPuppeteer.callbacks = new Map());
23
+ const seq = ((_c = callPuppeteer.lastSeq) !== null && _c !== void 0 ? _c : 0) + 1;
24
+ callPuppeteer.lastSeq = seq;
25
+ callPuppeteer.args.set(seq, args);
26
+ // Needs to be the same as CDP_BINDING_PREFIX.
27
+ globalThis[prefix + name](JSON.stringify({
28
+ type,
29
+ name,
30
+ seq,
31
+ args,
32
+ isTrivial: !args.some((value) => {
33
+ return value instanceof Node;
34
+ }),
35
+ }));
36
+ return new Promise((resolve, reject) => {
37
+ callPuppeteer.callbacks.set(seq, {
38
+ resolve(value) {
39
+ callPuppeteer.args.delete(seq);
40
+ resolve(value);
41
+ },
42
+ reject(value) {
43
+ callPuppeteer.args.delete(seq);
44
+ reject(value);
45
+ },
46
+ });
47
+ });
48
+ },
49
+ });
50
+ }
51
+ const files = new Set();
52
+ export class PM_Node extends PM {
53
+ constructor(t) {
54
+ super();
55
+ this.server = {};
56
+ this.testResourceConfiguration = t;
57
+ }
58
+ existsSync(destFolder) {
59
+ return globalThis["existsSync"](this.testResourceConfiguration.fs + "/" + destFolder);
60
+ }
61
+ mkdirSync() {
62
+ return globalThis["mkdirSync"](this.testResourceConfiguration.fs + "/");
63
+ }
64
+ write(writeObject, contents) {
65
+ return globalThis["write"](writeObject.uid, contents);
66
+ }
67
+ writeFileSync(filepath, contents) {
68
+ files.add(filepath);
69
+ return globalThis["writeFileSync"](this.testResourceConfiguration.fs + "/" + filepath, contents);
70
+ }
71
+ createWriteStream(filepath) {
72
+ files.add(filepath);
73
+ return globalThis["createWriteStream"](this.testResourceConfiguration.fs + "/" + filepath);
74
+ }
75
+ end(writeObject) {
76
+ return globalThis["end"](writeObject.uid);
77
+ }
78
+ customclose() {
79
+ console.log("node-customclose");
80
+ // globalThis["writeFileSync"](
81
+ // this.testResourceConfiguration.fs + "/manifest.json",
82
+ // // files.entries()
83
+ // JSON.stringify(Array.from(files))
84
+ // ).then(() => {
85
+ // globalThis["customclose"]();
86
+ // });
87
+ }
88
+ // write(accessObject: { uid: number; }, contents: string): boolean {
89
+ // throw new Error("Method not implemented.");
90
+ // }
91
+ // existsSync(destFolder: string): boolean {
92
+ // return fs.existsSync(destFolder);
93
+ // }
94
+ // async mkdirSync(destFolder: string) {
95
+ // if (!fs.existsSync(destFolder)) {
96
+ // return fs.mkdirSync(destFolder, { recursive: true });
97
+ // }
98
+ // return false;
99
+ // }
100
+ // writeFileSync(fp: string, contents: string) {
101
+ // fs.writeFileSync(fp, contents);
102
+ // }
103
+ // createWriteStream(filepath: string): fs.WriteStream {
104
+ // return fs.createWriteStream(filepath);
105
+ // }
106
+ testArtiFactoryfileWriter(tLog, callback) {
107
+ return (fPath, value) => {
108
+ callback(new Promise((res, rej) => {
109
+ tLog("testArtiFactory =>", fPath);
110
+ const cleanPath = path.resolve(fPath);
111
+ fPaths.push(cleanPath.replace(process.cwd(), ``));
112
+ const targetDir = cleanPath.split("/").slice(0, -1).join("/");
113
+ fs.mkdir(targetDir, { recursive: true }, async (error) => {
114
+ if (error) {
115
+ console.error(`❗️testArtiFactory failed`, targetDir, error);
116
+ }
117
+ fs.writeFileSync(path.resolve(targetDir.split("/").slice(0, -1).join("/"), "manifest"), fPaths.join(`\n`), {
118
+ encoding: "utf-8",
119
+ });
120
+ if (Buffer.isBuffer(value)) {
121
+ fs.writeFileSync(fPath, value, "binary");
122
+ res();
123
+ }
124
+ else if (`string` === typeof value) {
125
+ fs.writeFileSync(fPath, value.toString(), {
126
+ encoding: "utf-8",
127
+ });
128
+ res();
129
+ }
130
+ else {
131
+ /* @ts-ignore:next-line */
132
+ const pipeStream = value;
133
+ const myFile = fs.createWriteStream(fPath);
134
+ pipeStream.pipe(myFile);
135
+ pipeStream.on("close", () => {
136
+ myFile.close();
137
+ res();
138
+ });
139
+ }
140
+ });
141
+ }));
142
+ };
143
+ }
144
+ // launch(options?: PuppeteerLaunchOptions): Promise<Browser>;
145
+ startPuppeteer(options) {
146
+ console.log("start1");
147
+ return puppeteer.connect(options).then((b) => {
148
+ this.browser = b;
149
+ });
150
+ // return new Promise<Browser>((res, rej) => {
151
+ // // this.browser = await puppeteer.connect(options);
152
+ // // console.log("start2", this.browser);
153
+ // // console.log("mark5", this.browser);
154
+ // // res(this.browser);
155
+ // });
156
+ }
157
+ }
158
+ // class PuppetMasterServer extends AbstractPuppetMaster {
159
+ // // constructor(...z: []) {
160
+ // // super(...z);
161
+ // // }
162
+ // // // pages(): Promise<Page[]>;
163
+ // // pages(): Promise<Page[]> {
164
+ // // return new Promise<Page[]>((res, rej) => {
165
+ // // res(super.pages());
166
+ // // });
167
+ // // }
168
+ // }