testeranto 0.73.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.
package/src/PM/node.ts CHANGED
@@ -1,76 +1,17 @@
1
- // import puppeteer from "puppeteer";
2
1
  import fs from "fs";
3
2
  import path from "path";
4
- // import puppeteer from "puppeteer-core/lib/esm/puppeteer/puppeteer-core";
5
3
  import puppeteer from "puppeteer-core";
6
-
7
- // import { Browser } from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser";
8
- import { Browser } from "puppeteer-core";
9
4
  import { PassThrough } from "stream";
5
+
10
6
  import { ITLog, ITTestResourceConfiguration } from "../lib";
7
+
11
8
  import { PM } from "./index.js";
12
- import { PuppeteerLaunchOptions } from "puppeteer-core/lib/esm/puppeteer";
13
9
 
14
10
  type IFPaths = string[];
15
11
  const fPaths: IFPaths = [];
16
12
 
17
13
  type PuppetMasterServer = Record<string, Promise<any>>;
18
14
 
19
- export function addPageBinding(
20
- type: string,
21
- name: string,
22
- prefix: string
23
- ): void {
24
- // Depending on the frame loading state either Runtime.evaluate or
25
- // Page.addScriptToEvaluateOnNewDocument might succeed. Let's check that we
26
- // don't re-wrap Puppeteer's binding.
27
- if (globalThis[name]) {
28
- return;
29
- }
30
-
31
- // We replace the CDP binding with a Puppeteer binding.
32
- Object.assign(globalThis, {
33
- [name](...args: unknown[]): Promise<unknown> {
34
- // This is the Puppeteer binding.
35
- const callPuppeteer = globalThis[name];
36
- callPuppeteer.args ??= new Map();
37
- callPuppeteer.callbacks ??= new Map();
38
-
39
- const seq = (callPuppeteer.lastSeq ?? 0) + 1;
40
- callPuppeteer.lastSeq = seq;
41
- callPuppeteer.args.set(seq, args);
42
-
43
- // Needs to be the same as CDP_BINDING_PREFIX.
44
- globalThis[prefix + name](
45
- JSON.stringify({
46
- type,
47
- name,
48
- seq,
49
- args,
50
- isTrivial: !args.some((value) => {
51
- return value instanceof Node;
52
- }),
53
- })
54
- );
55
-
56
- return new Promise((resolve, reject) => {
57
- callPuppeteer.callbacks.set(seq, {
58
- resolve(value: unknown) {
59
- callPuppeteer.args.delete(seq);
60
- resolve(value);
61
- },
62
- reject(value?: unknown) {
63
- callPuppeteer.args.delete(seq);
64
- reject(value);
65
- },
66
- });
67
- });
68
- },
69
- });
70
- }
71
-
72
- const files = new Set<string>();
73
-
74
15
  export class PM_Node extends PM {
75
16
  server: PuppetMasterServer;
76
17
  testResourceConfiguration: ITTestResourceConfiguration;
@@ -96,17 +37,17 @@ export class PM_Node extends PM {
96
37
  }
97
38
 
98
39
  writeFileSync(filepath: string, contents: string) {
99
- files.add(filepath);
100
40
  return globalThis["writeFileSync"](
101
41
  this.testResourceConfiguration.fs + "/" + filepath,
102
- contents
42
+ contents,
43
+ this.testResourceConfiguration.name
103
44
  );
104
45
  }
105
46
 
106
47
  createWriteStream(filepath: string): any {
107
- files.add(filepath);
108
48
  return globalThis["createWriteStream"](
109
- this.testResourceConfiguration.fs + "/" + filepath
49
+ this.testResourceConfiguration.fs + "/" + filepath,
50
+ this.testResourceConfiguration.name
110
51
  );
111
52
  }
112
53
 
@@ -115,36 +56,11 @@ export class PM_Node extends PM {
115
56
  }
116
57
 
117
58
  customclose() {
118
- console.log("node-customclose");
119
- // globalThis["writeFileSync"](
120
- // this.testResourceConfiguration.fs + "/manifest.json",
121
- // // files.entries()
122
- // JSON.stringify(Array.from(files))
123
- // ).then(() => {
124
- // globalThis["customclose"]();
125
- // });
59
+ globalThis["customclose"](
60
+ this.testResourceConfiguration.fs,
61
+ this.testResourceConfiguration.name
62
+ );
126
63
  }
127
- // write(accessObject: { uid: number; }, contents: string): boolean {
128
- // throw new Error("Method not implemented.");
129
- // }
130
- // existsSync(destFolder: string): boolean {
131
- // return fs.existsSync(destFolder);
132
- // }
133
-
134
- // async mkdirSync(destFolder: string) {
135
- // if (!fs.existsSync(destFolder)) {
136
- // return fs.mkdirSync(destFolder, { recursive: true });
137
- // }
138
- // return false;
139
- // }
140
-
141
- // writeFileSync(fp: string, contents: string) {
142
- // fs.writeFileSync(fp, contents);
143
- // }
144
-
145
- // createWriteStream(filepath: string): fs.WriteStream {
146
- // return fs.createWriteStream(filepath);
147
- // }
148
64
 
149
65
  testArtiFactoryfileWriter(tLog: ITLog, callback: (Promise) => void) {
150
66
  return (fPath, value: string | Buffer | PassThrough) => {
@@ -199,317 +115,8 @@ export class PM_Node extends PM {
199
115
 
200
116
  // launch(options?: PuppeteerLaunchOptions): Promise<Browser>;
201
117
  startPuppeteer(options?: any): Promise<any> {
202
- console.log("start1");
203
118
  return puppeteer.connect(options).then((b) => {
204
119
  this.browser = b;
205
120
  });
206
- // return new Promise<Browser>((res, rej) => {
207
- // // this.browser = await puppeteer.connect(options);
208
- // // console.log("start2", this.browser);
209
- // // console.log("mark5", this.browser);
210
- // // res(this.browser);
211
- // });
212
121
  }
213
-
214
- // launchNode = (src: string, dest: string) => {
215
- // console.log("launchNode", src);
216
- // // childProcesses[src] = "running";
217
- // const destFolder = dest.replace(".mjs", "");
218
-
219
- // const argz = JSON.stringify({
220
- // scheduled: true,
221
- // name: src,
222
- // ports: [3333],
223
- // // fs: path.resolve(configs.buildDir, "web", destFolder + "/"),
224
- // // fs: destFolder,
225
- // fs: ".",
226
- // });
227
-
228
- // const builtfile = dest + ".mjs";
229
- // console.log("importing and running ", builtfile);
230
- // // import(builtfile).then(async (v) => {
231
- // // console.log("v", (await v.default).receiveTestResourceConfig(argz));
232
- // // });
233
-
234
- // // console.log("launchNode", src, dest, " -> ", destFolder, argz);
235
-
236
- // // const child = utilityProcess.fork(dest + ".mjs", [argz], {
237
- // // cwd: destFolder,
238
- // // stdio: "pipe",
239
- // // });
240
- // // const nodeGuid = uuidv4();
241
- // // nodeChildren[nodeGuid] = child;
242
-
243
- // // if (!fs.existsSync(destFolder)) {
244
- // // fs.mkdirSync(destFolder, { recursive: true });
245
- // // }
246
-
247
- // // fs.rmSync(`${destFolder}/stdout.log`, { force: true });
248
- // // fs.rmSync(`${destFolder}/stderr.log`, { force: true });
249
- // // const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
250
- // // const stderr = fs.createWriteStream(`${destFolder}/stderr.log`);
251
-
252
- // // child
253
- // // .on("message", (data) => {
254
- // // console.log("from child", JSON.stringify(data));
255
- // // if (data.launchWeb) {
256
- // // const guid = uuidv4();
257
- // // const webChild = launchWebSecondary(process.cwd() + data.launchWeb);
258
- // // // child.postMessage({ webLaunched: guid });
259
-
260
- // // webChild.webContents.on("did-finish-load", () => {
261
- // // // webChild.webContents.send("message", "hello world");
262
- // // child.postMessage({ webLaunched: guid });
263
- // // webChildren[guid] = webChild;
264
- // // node2web[nodeGuid] = [...(node2web[nodeGuid] || []), guid];
265
- // // });
266
- // // }
267
- // // if (data.teardown) {
268
- // // webChildren[data.teardown].close();
269
- // // delete webChildren[data.teardown];
270
- // // node2web[nodeGuid] = node2web[nodeGuid].filter(
271
- // // (x) => x !== data.teardown
272
- // // );
273
- // // }
274
- // // })
275
- // // .on("exit", (data) => {
276
- // // stdout.close();
277
- // // stderr.close();
278
- // // console.log(`ending node ${src}`);
279
- // // onDone(src);
280
- // // });
281
-
282
- // // child.stdout?.pipe(stdout);
283
- // // child.stderr?.pipe(stderr);
284
- // };
285
-
286
- // const launchWebSecondary = (htmlFile: string): BrowserWindow => {
287
- // console.log("launchWebSecondary", htmlFile);
288
- // const subWin = new BrowserWindow({
289
- // show: false,
290
-
291
- // webPreferences: {
292
- // nodeIntegration: true,
293
- // nodeIntegrationInWorker: true,
294
- // contextIsolation: false,
295
- // preload: path.join(app.getAppPath(), "preload.js"),
296
- // offscreen: false,
297
- // devTools: true,
298
- // },
299
- // });
300
- // remoteMain.enable(subWin.webContents);
301
- // subWin.webContents.openDevTools();
302
- // subWin.loadFile(htmlFile);
303
- // return subWin;
304
-
305
- // // const uuid = uuidv4();
306
- // // windows[uuid] = subWin;
307
- // // return uuid;
308
- // };
309
-
310
- // const launchWeb = (t: string, dest: string) => {
311
- // console.log("launchWeb", t);
312
- // childProcesses[t] = "running";
313
- // const destFolder = dest.replace(".mjs", "");
314
-
315
- // const subWin = new BrowserWindow({
316
- // show: true,
317
- // webPreferences: {
318
- // nodeIntegration: true,
319
- // nodeIntegrationInWorker: true,
320
- // contextIsolation: false,
321
- // preload: path.join(app.getAppPath(), "preload.js"),
322
- // offscreen: false,
323
- // devTools: true,
324
- // },
325
- // });
326
-
327
- // webChildren[uuidv4()] = subWin;
328
-
329
- // remoteMain.enable(subWin.webContents);
330
-
331
- // const webArgz = JSON.stringify({
332
- // name: dest,
333
- // ports: [].toString(),
334
- // fs: destFolder,
335
- // });
336
-
337
- // // console.log("webArgz", webArgz);
338
- // subWin.loadFile(`${dest}.html`, {
339
- // query: {
340
- // requesting: encodeURIComponent(webArgz),
341
- // },
342
- // });
343
-
344
- // if (!fs.existsSync(destFolder)) {
345
- // fs.mkdirSync(destFolder, { recursive: true });
346
- // }
347
- // const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
348
-
349
- // subWin.webContents.on(
350
- // "console-message",
351
- // (event, level, message, line, sourceId) => {
352
- // stdout.write(
353
- // JSON.stringify(
354
- // {
355
- // event,
356
- // level,
357
- // message: JSON.stringify(message),
358
- // line,
359
- // sourceId,
360
- // },
361
- // null,
362
- // 2
363
- // )
364
- // );
365
- // stdout.write("\n");
366
- // }
367
- // );
368
- // subWin.on("closed", () => {
369
- // stdout.close();
370
- // console.log(`ending web ${t}`);
371
- // // childProcesses[t] = "done";
372
- // onDone(t);
373
- // });
374
- // ipcMain.on("message", (message, data) => {
375
- // console.log("ipcMain message: " + JSON.stringify(data));
376
- // // process.exit();
377
- // });
378
- // };
379
-
380
- // return await import("${dest}.mjs");
381
-
382
- // launchWeb = (t: string, dest: string) => {
383
- // console.log("launchWeb", t);
384
- // // // childProcesses[t] = "running";
385
- // // const destFolder = dest.replace(".mjs", "");
386
-
387
- // // const webArgz = JSON.stringify({
388
- // // name: dest,
389
- // // ports: [].toString(),
390
- // // fs: destFolder,
391
- // // });
392
-
393
- // // const evaluation = `import('file:///Users/adam/Code/kokomoBay/docs/web/src/LoginPage/react/web.test.mjs').then(async (x) => {
394
- // // return (await x.default).receiveTestResourceConfig(${webArgz})
395
- // // })`;
396
-
397
- // // // console.log("evaluation", evaluation);
398
-
399
- // // const y = browser
400
- // // .newPage()
401
- // // .then(async (page) => {
402
- // // // const codeString = "1 + 1";
403
- // // await page.goto(
404
- // // // "file:///Users/adam/Code/kokomoBay/docs/web/src/LoginPage/react/web.test.html"
405
- // // `file://${`${dest}.html`}`
406
- // // );
407
- // // // page.url
408
- // // // page.setContent(`
409
-
410
- // // // <!DOCTYPE html>
411
- // // // <html lang="en">
412
-
413
- // // // <head>
414
-
415
- // // // </head>
416
-
417
- // // // <body>
418
- // // // <h1>/Users/adam/Code/kokomoBay/docs/web/src/LoginPage/react/web.test.html</h1>
419
- // // // <div id="root">
420
-
421
- // // // </div>
422
- // // // </body>
423
-
424
- // // // <footer></footer>
425
-
426
- // // // </html>
427
- // // // `);
428
- // // // return await page.evaluate((code) => eval(code), evaluation);
429
-
430
- // // return await page.evaluate(evaluation);
431
- // // // return await page.evaluate(async () => {
432
- // // // return await import(dest);
433
- // // // });
434
- // // })
435
- // // .then((x) => {
436
- // // console.log("mark1", x);
437
- // // });
438
- // // .then((x) => {
439
- // // console.log("mark0", x);
440
- // // })
441
- // // .catch((z) => {
442
- // // console.log("mark2", z);
443
- // // });
444
-
445
- // // const subWin = new BrowserWindow({
446
- // // show: true,
447
- // // webPreferences: {
448
- // // nodeIntegration: true,
449
- // // nodeIntegrationInWorker: true,
450
- // // contextIsolation: false,
451
- // // preload: path.join(app.getAppPath(), "preload.js"),
452
- // // offscreen: false,
453
- // // devTools: true,
454
- // // },
455
- // // });
456
-
457
- // // webChildren[uuidv4()] = subWin;
458
-
459
- // // remoteMain.enable(subWin.webContents);
460
-
461
- // // // console.log("webArgz", webArgz);
462
- // // subWin.loadFile(`${dest}.html`, {
463
- // // query: {
464
- // // requesting: encodeURIComponent(webArgz),
465
- // // },
466
- // // });
467
-
468
- // // if (!fs.existsSync(destFolder)) {
469
- // // fs.mkdirSync(destFolder, { recursive: true });
470
- // // }
471
- // // const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
472
-
473
- // // subWin.webContents.on(
474
- // // "console-message",
475
- // // (event, level, message, line, sourceId) => {
476
- // // stdout.write(
477
- // // JSON.stringify(
478
- // // {
479
- // // event,
480
- // // level,
481
- // // message: JSON.stringify(message),
482
- // // line,
483
- // // sourceId,
484
- // // },
485
- // // null,
486
- // // 2
487
- // // )
488
- // // );
489
- // // stdout.write("\n");
490
- // // }
491
- // // );
492
- // // subWin.on("closed", () => {
493
- // // stdout.close();
494
- // // console.log(`ending web ${t}`);
495
- // // // childProcesses[t] = "done";
496
- // // onDone(t);
497
- // // });
498
- // // ipcMain.on("message", (message, data) => {
499
- // // console.log("ipcMain message: " + JSON.stringify(data));
500
- // // // process.exit();
501
- // // });
502
- // };
503
122
  }
504
-
505
- // class PuppetMasterServer extends AbstractPuppetMaster {
506
- // // constructor(...z: []) {
507
- // // super(...z);
508
- // // }
509
- // // // pages(): Promise<Page[]>;
510
- // // pages(): Promise<Page[]> {
511
- // // return new Promise<Page[]>((res, rej) => {
512
- // // res(super.pages());
513
- // // });
514
- // // }
515
- // }