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.
- package/README.md +9 -18
- package/dist/common/Node.js +14 -34
- package/dist/common/PM/index.js +71 -0
- package/dist/common/PM/main.js +361 -0
- package/dist/common/PM/node.js +176 -0
- package/dist/common/PM/web.js +174 -0
- package/dist/common/Project.js +20 -2
- package/dist/common/Puppeteer.js +109 -0
- package/dist/common/Reporter.js +119 -0
- package/dist/common/Scheduler.js +1 -0
- package/dist/common/SubPackages/puppeteer.js +3 -1
- package/dist/common/SubPackages/react-dom/component/web.js +98 -45
- package/dist/common/SubPackages/react-test-renderer/jsx/index.js +0 -1
- package/dist/common/Web.js +24 -43
- package/dist/common/esbuildConfigs/web.js +3 -1
- package/dist/common/lib/abstractBase.js +189 -41
- package/dist/common/lib/basebuilder.js +56 -29
- package/dist/common/lib/classBuilder.js +6 -2
- package/dist/common/lib/core.js +41 -45
- package/dist/common/lib/index.js +2 -1
- package/dist/common/preload.js +14 -18
- package/dist/common/tsconfig.common.tsbuildinfo +1 -1
- package/dist/module/Node.js +14 -34
- package/dist/module/PM/index.js +67 -0
- package/dist/module/PM/main.js +331 -0
- package/dist/module/PM/node.js +168 -0
- package/dist/module/PM/web.js +167 -0
- package/dist/module/Project.js +20 -2
- package/dist/module/Puppeteer.js +104 -0
- package/dist/module/Reporter.js +114 -0
- package/dist/module/Scheduler.js +1 -0
- package/dist/module/SubPackages/puppeteer.js +3 -1
- package/dist/module/SubPackages/react/jsx/node.js +1 -1
- package/dist/module/SubPackages/react-dom/component/web.js +98 -45
- package/dist/module/SubPackages/react-test-renderer/jsx/index.js +0 -1
- package/dist/module/Web.js +24 -43
- package/dist/module/esbuildConfigs/web.js +3 -1
- package/dist/module/lib/abstractBase.js +189 -41
- package/dist/module/lib/basebuilder.js +56 -29
- package/dist/module/lib/classBuilder.js +6 -2
- package/dist/module/lib/core.js +41 -45
- package/dist/module/lib/index.js +2 -1
- package/dist/module/preload.js +15 -14
- package/dist/module/tsconfig.module.tsbuildinfo +1 -1
- package/dist/prebuild/Report.css +1616 -584
- package/dist/prebuild/Report.js +2635 -2506
- package/dist/types/PM/index.d.ts +19 -0
- package/dist/types/PM/main.d.ts +28 -0
- package/dist/types/PM/node.d.ts +26 -0
- package/dist/types/PM/web.d.ts +24 -0
- package/dist/types/Reporter.d.ts +1 -0
- package/dist/types/Scheduler.d.ts +0 -0
- package/dist/types/SubPackages/react-dom/component/web.d.ts +1 -1
- package/dist/types/lib/abstractBase.d.ts +13 -12
- package/dist/types/lib/basebuilder.d.ts +4 -2
- package/dist/types/lib/classBuilder.d.ts +2 -2
- package/dist/types/lib/core.d.ts +4 -4
- package/dist/types/lib/index.d.ts +6 -5
- package/dist/types/lib/types.d.ts +16 -24
- package/dist/types/preload.d.ts +0 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +3 -5
- package/src/Node.ts +18 -43
- package/src/PM/index.ts +102 -0
- package/src/PM/main.ts +420 -0
- package/src/PM/node.ts +515 -0
- package/src/PM/web.ts +497 -0
- package/src/Project.ts +21 -2
- package/src/Puppeteer.ts +131 -0
- package/src/Report.tsx +158 -44
- package/src/Reporter.ts +134 -0
- package/src/Scheduler.ts +0 -0
- package/src/SubPackages/puppeteer.ts +3 -3
- package/src/SubPackages/react/jsx/node.ts +5 -8
- package/src/SubPackages/react-dom/component/web.ts +126 -67
- package/src/SubPackages/react-test-renderer/jsx/index.ts +0 -1
- package/src/Web.ts +25 -67
- package/src/esbuildConfigs/web.ts +4 -2
- package/src/lib/abstractBase.ts +260 -65
- package/src/lib/basebuilder.ts +121 -100
- package/src/lib/classBuilder.ts +5 -4
- package/src/lib/core.ts +58 -59
- package/src/lib/index.ts +10 -9
- package/src/lib/types.ts +18 -27
- package/src/preload.ts +14 -14
- package/dist/common/NodeWriter.js +0 -54
- package/dist/common/electron.js +0 -266
- package/dist/module/NodeWriter.js +0 -48
- package/dist/module/electron.js +0 -261
- package/dist/types/NodeWriter.d.ts +0 -2
- package/src/NodeWriter.ts +0 -72
- package/src/electron.ts +0 -317
- package/yarn-error.log +0 -3144
- /package/dist/types/{electron.d.ts → Puppeteer.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testeranto",
|
|
3
3
|
"description": "teeny tiny tightly-typed typescript tests",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.73.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.mts",
|
|
7
7
|
"module": "dist/module/index.js",
|
|
@@ -227,10 +227,8 @@
|
|
|
227
227
|
"ipc": "^0.0.1",
|
|
228
228
|
"jsonc": "^2.0.0",
|
|
229
229
|
"npm-watch": "^0.11.0",
|
|
230
|
-
"puppeteer": "
|
|
231
|
-
"
|
|
232
|
-
"puppeteer-in-electron": "^3.0.5",
|
|
233
|
-
"react-bootstrap": "^2.7.0",
|
|
230
|
+
"puppeteer-core": "^23.6.0",
|
|
231
|
+
"react-bootstrap": "2.10.6",
|
|
234
232
|
"react-sigma": "^1.2.35",
|
|
235
233
|
"react-test-renderer": "18.2.0",
|
|
236
234
|
"selenium-webdriver": "^4.25.0",
|
package/src/Node.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import puppeteer from "puppeteer-core";
|
|
2
|
-
|
|
3
1
|
import Testeranto from "./lib/core.js";
|
|
4
2
|
import {
|
|
5
3
|
defaultTestResourceRequirement,
|
|
6
|
-
ITestJob,
|
|
7
4
|
ITTestResourceConfiguration,
|
|
8
5
|
ITTestResourceRequest,
|
|
9
6
|
} from "./lib/index.js";
|
|
10
|
-
|
|
7
|
+
|
|
11
8
|
import type {
|
|
12
9
|
IBaseTest,
|
|
13
10
|
ITestImplementation,
|
|
@@ -15,7 +12,7 @@ import type {
|
|
|
15
12
|
} from "./Types.js";
|
|
16
13
|
import { ITestInterface, INodeTestInterface } from "./lib/types.js";
|
|
17
14
|
|
|
18
|
-
import
|
|
15
|
+
import { PM_Node } from "./PM/node.js";
|
|
19
16
|
|
|
20
17
|
class NodeTesteranto<
|
|
21
18
|
TestShape extends IBaseTest
|
|
@@ -32,52 +29,30 @@ class NodeTesteranto<
|
|
|
32
29
|
testSpecification,
|
|
33
30
|
testImplementation,
|
|
34
31
|
testResourceRequirement,
|
|
35
|
-
NodeWriter,
|
|
36
32
|
testInterface
|
|
37
33
|
);
|
|
38
|
-
|
|
39
|
-
if (process.argv[2]) {
|
|
40
|
-
const testResourceArg = process.argv[2];
|
|
41
|
-
|
|
42
|
-
try {
|
|
43
|
-
const partialTestResource = JSON.parse(
|
|
44
|
-
testResourceArg
|
|
45
|
-
) as ITTestResourceConfiguration;
|
|
46
|
-
|
|
47
|
-
this.receiveTestResourceConfig(this.testJobs[0], partialTestResource);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
console.error(e);
|
|
50
|
-
// process.exit(-1);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
// no-op
|
|
54
|
-
}
|
|
55
34
|
}
|
|
56
35
|
|
|
57
36
|
async receiveTestResourceConfig(
|
|
58
|
-
t: ITestJob,
|
|
59
|
-
partialTestResource:
|
|
37
|
+
// t: ITestJob,
|
|
38
|
+
partialTestResource: string
|
|
60
39
|
) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
defaultViewport: null,
|
|
65
|
-
});
|
|
66
|
-
console.log("connected!", b.isConnected());
|
|
67
|
-
return b;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const { failed, artifacts, logPromise } = await t.receiveTestResourceConfig(
|
|
71
|
-
partialTestResource,
|
|
72
|
-
{
|
|
73
|
-
browser,
|
|
74
|
-
ipc: process.parentPort,
|
|
75
|
-
}
|
|
40
|
+
console.log(
|
|
41
|
+
"receiveTestResourceConfig!!",
|
|
42
|
+
this.testJobs[0].receiveTestResourceConfig
|
|
76
43
|
);
|
|
77
44
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
45
|
+
const t: ITTestResourceConfiguration = JSON.parse(partialTestResource);
|
|
46
|
+
const pm = new PM_Node(t);
|
|
47
|
+
const { failed, artifacts, logPromise } =
|
|
48
|
+
await this.testJobs[0].receiveTestResourceConfig(pm);
|
|
49
|
+
|
|
50
|
+
console.log("test is done, awaiting test result write to fs");
|
|
51
|
+
pm.customclose();
|
|
52
|
+
|
|
53
|
+
// Promise.all([...artifacts, logPromise]).then(async () => {
|
|
54
|
+
// // process.exit((await failed) ? 1 : 0);
|
|
55
|
+
// });
|
|
81
56
|
}
|
|
82
57
|
}
|
|
83
58
|
|
package/src/PM/index.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// import {
|
|
2
|
+
// Browser,
|
|
3
|
+
// BrowserContext,
|
|
4
|
+
// BrowserContextOptions,
|
|
5
|
+
// DebugInfo,
|
|
6
|
+
// Page,
|
|
7
|
+
// PuppeteerNode,
|
|
8
|
+
// Target,
|
|
9
|
+
// } from "puppeteer-core";
|
|
10
|
+
|
|
11
|
+
import { Browser } from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser";
|
|
12
|
+
import { ITLog, ITTestResourceConfiguration } from "../lib";
|
|
13
|
+
import { ChildProcess } from "child_process";
|
|
14
|
+
import { PuppeteerLaunchOptions } from "puppeteer-core/lib/esm/puppeteer";
|
|
15
|
+
// import { ILogWriter, ITLog } from "./lib";
|
|
16
|
+
|
|
17
|
+
type IFPaths = string[];
|
|
18
|
+
const fPaths: IFPaths = [];
|
|
19
|
+
|
|
20
|
+
export abstract class PM {
|
|
21
|
+
server: any;
|
|
22
|
+
browser: Browser;
|
|
23
|
+
testResourceConfiguration: ITTestResourceConfiguration;
|
|
24
|
+
|
|
25
|
+
// constructor(testResourceConfiguration: ITTestResourceConfiguration) {
|
|
26
|
+
// this.testResourceConfiguration = testResourceConfiguration;
|
|
27
|
+
// console.log("mkdirsync2", this.testResourceConfiguration);
|
|
28
|
+
// }
|
|
29
|
+
|
|
30
|
+
abstract startPuppeteer(options: any, destfolder: string): Promise<Browser>;
|
|
31
|
+
|
|
32
|
+
abstract testArtiFactoryfileWriter(tLog: ITLog, callback: (Promise) => void);
|
|
33
|
+
abstract createWriteStream(filepath: string): any;
|
|
34
|
+
abstract writeFileSync(fp: string, contents: string);
|
|
35
|
+
abstract mkdirSync();
|
|
36
|
+
abstract existsSync(fp: string): boolean;
|
|
37
|
+
abstract write(accessObject: { uid: number }, contents: string): boolean;
|
|
38
|
+
abstract end(accessObject: { uid: number }): boolean;
|
|
39
|
+
|
|
40
|
+
// pages(): Promise<Page[]>;
|
|
41
|
+
// pages(): Promise<Page[]> {
|
|
42
|
+
// return new Promise<Page[]>((res, rej) => {
|
|
43
|
+
// res(super.pages());
|
|
44
|
+
// });
|
|
45
|
+
// }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// export class PuppetMasterBrowser extends Browser {
|
|
49
|
+
// process(): ChildProcess | null {
|
|
50
|
+
// return super.process();
|
|
51
|
+
// }
|
|
52
|
+
// createBrowserContext(
|
|
53
|
+
// options?: BrowserContextOptions
|
|
54
|
+
// ): Promise<BrowserContext> {
|
|
55
|
+
// throw new Error("Method not implemented.");
|
|
56
|
+
// }
|
|
57
|
+
// browserContexts(): BrowserContext[] {
|
|
58
|
+
// throw new Error("Method not implemented.");
|
|
59
|
+
// }
|
|
60
|
+
// defaultBrowserContext(): BrowserContext {
|
|
61
|
+
// throw new Error("Method not implemented.");
|
|
62
|
+
// }
|
|
63
|
+
// wsEndpoint(): string {
|
|
64
|
+
// throw new Error("Method not implemented.");
|
|
65
|
+
// }
|
|
66
|
+
// newPage(): Promise<Page> {
|
|
67
|
+
// throw new Error("Method not implemented.");
|
|
68
|
+
// }
|
|
69
|
+
// targets(): Target[] {
|
|
70
|
+
// throw new Error("Method not implemented.");
|
|
71
|
+
// }
|
|
72
|
+
// target(): Target {
|
|
73
|
+
// throw new Error("Method not implemented.");
|
|
74
|
+
// }
|
|
75
|
+
// version(): Promise<string> {
|
|
76
|
+
// throw new Error("Method not implemented.");
|
|
77
|
+
// }
|
|
78
|
+
// userAgent(): Promise<string> {
|
|
79
|
+
// throw new Error("Method not implemented.");
|
|
80
|
+
// }
|
|
81
|
+
// close(): Promise<void> {
|
|
82
|
+
// throw new Error("Method not implemented.");
|
|
83
|
+
// }
|
|
84
|
+
// disconnect(): Promise<void> {
|
|
85
|
+
// throw new Error("Method not implemented.");
|
|
86
|
+
// }
|
|
87
|
+
// get connected(): boolean {
|
|
88
|
+
// throw new Error("Method not implemented.");
|
|
89
|
+
// }
|
|
90
|
+
// get debugInfo(): DebugInfo {
|
|
91
|
+
// throw new Error("Method not implemented.");
|
|
92
|
+
// }
|
|
93
|
+
// constructor(...z: []) {
|
|
94
|
+
// super(...z);
|
|
95
|
+
// }
|
|
96
|
+
// // pages(): Promise<Page[]>;
|
|
97
|
+
// pages(): Promise<Page[]> {
|
|
98
|
+
// return new Promise<Page[]>((res, rej) => {
|
|
99
|
+
// res(super.pages());
|
|
100
|
+
// });
|
|
101
|
+
// }
|
|
102
|
+
// }
|
package/src/PM/main.ts
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import puppeteer, { ScreenshotOptions } from "puppeteer-core";
|
|
4
|
+
import { PassThrough } from "stream";
|
|
5
|
+
|
|
6
|
+
import { ITLog, ITTestResourceConfiguration } from "../lib";
|
|
7
|
+
import { IBuiltConfig } from "../lib/types";
|
|
8
|
+
|
|
9
|
+
import { PM } from "./index.js";
|
|
10
|
+
|
|
11
|
+
type IFPaths = string[];
|
|
12
|
+
const fPaths: IFPaths = [];
|
|
13
|
+
|
|
14
|
+
const fileStreams3: fs.WriteStream[] = [];
|
|
15
|
+
const screenshots3: Promise<any>[] = [];
|
|
16
|
+
const doneFileStream3: Promise<any>[] = [];
|
|
17
|
+
|
|
18
|
+
export class PM_Main extends PM {
|
|
19
|
+
configs: IBuiltConfig;
|
|
20
|
+
|
|
21
|
+
ports: Record<number, boolean>;
|
|
22
|
+
queue: any[];
|
|
23
|
+
|
|
24
|
+
// testResourceConfiguration: ITTestResourceConfiguration;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
configs: IBuiltConfig
|
|
28
|
+
// testResourceConfig: ITTestResourceConfiguration
|
|
29
|
+
) {
|
|
30
|
+
super();
|
|
31
|
+
// this.testResourceConfiguration = testResourceConfig;
|
|
32
|
+
// console.log("mkdirsync4", testResourceConfig);
|
|
33
|
+
this.server = {};
|
|
34
|
+
this.configs = configs;
|
|
35
|
+
this.ports = {};
|
|
36
|
+
this.configs.ports.forEach((element) => {
|
|
37
|
+
this.ports[element] = "true"; // set ports as open
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
globalThis["mkdirSync"] = (fp: string) => {
|
|
41
|
+
if (!fs.existsSync(fp)) {
|
|
42
|
+
return fs.mkdirSync(fp, {
|
|
43
|
+
recursive: true,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
globalThis["writeFileSync"] = (fp: string, contents: string) => {
|
|
50
|
+
// Create directories if they don't exist
|
|
51
|
+
const dir = path.dirname(fp.split("/").slice(0, -1).join("/"));
|
|
52
|
+
console.log("dir", dir);
|
|
53
|
+
fs.mkdirSync(dir, {
|
|
54
|
+
recursive: true,
|
|
55
|
+
});
|
|
56
|
+
return fs.writeFileSync(fp, contents);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
globalThis["createWriteStream"] = (filepath: string) => {
|
|
60
|
+
const f = fs.createWriteStream(filepath);
|
|
61
|
+
fileStreams3.push(f);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...JSON.parse(JSON.stringify(f)),
|
|
65
|
+
uid: fileStreams3.length - 1,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
globalThis["write"] = (uid: number, contents: string) => {
|
|
70
|
+
console.log("write", uid, contents);
|
|
71
|
+
// process.exit();
|
|
72
|
+
fileStreams3[uid].write(contents);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
globalThis["end"] = (uid: number) => {
|
|
76
|
+
fileStreams3[uid].end();
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
globalThis["customclose"] = () => {
|
|
80
|
+
// fileStreams3[uid].end();
|
|
81
|
+
};
|
|
82
|
+
// page.exposeFunction("customclose", () => {
|
|
83
|
+
// console.log("closing doneFileStream2", doneFileStream2);
|
|
84
|
+
// // console.log("closing doneFileStream2", doneFileStream2);
|
|
85
|
+
// Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
|
|
86
|
+
// page.close();
|
|
87
|
+
// });
|
|
88
|
+
|
|
89
|
+
// // page.close();
|
|
90
|
+
// // Promise.all(screenshots).then(() => {
|
|
91
|
+
// // page.close();
|
|
92
|
+
// // });
|
|
93
|
+
// // setTimeout(() => {
|
|
94
|
+
// // console.log("Delayed for 1 second.");
|
|
95
|
+
// // page.close();
|
|
96
|
+
// // }, 5000);
|
|
97
|
+
|
|
98
|
+
// // return page.close();
|
|
99
|
+
// });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async startPuppeteer(options: any, destfolder: string): Promise<any> {
|
|
103
|
+
this.browser = await puppeteer.launch(options);
|
|
104
|
+
return this.browser;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
launchNode = async (src: string, dest: string) => {
|
|
108
|
+
console.log("launchNode", src);
|
|
109
|
+
// childProcesses[src] = "running";
|
|
110
|
+
const destFolder = dest.replace(".mjs", "");
|
|
111
|
+
|
|
112
|
+
let argz = "";
|
|
113
|
+
|
|
114
|
+
const testConfig = this.configs.tests.find((t) => {
|
|
115
|
+
return t[0] === src;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
if (!testConfig) {
|
|
119
|
+
console.error("missing test config");
|
|
120
|
+
process.exit(-1);
|
|
121
|
+
}
|
|
122
|
+
const testConfigResource = testConfig[2];
|
|
123
|
+
|
|
124
|
+
console.log("mark22 testConfigResource", testConfigResource);
|
|
125
|
+
let portsToUse: string[] = [];
|
|
126
|
+
if (testConfigResource.ports === 0) {
|
|
127
|
+
argz = JSON.stringify({
|
|
128
|
+
scheduled: true,
|
|
129
|
+
name: src,
|
|
130
|
+
ports: portsToUse,
|
|
131
|
+
fs: destFolder,
|
|
132
|
+
browserWSEndpoint: this.browser.wsEndpoint(),
|
|
133
|
+
});
|
|
134
|
+
} else if (testConfigResource.ports > 0) {
|
|
135
|
+
const openPorts = Object.entries(this.ports).filter(
|
|
136
|
+
([portnumber, portopen]) => portopen
|
|
137
|
+
);
|
|
138
|
+
if (openPorts.length >= testConfigResource.ports) {
|
|
139
|
+
for (let i = 0; i < testConfigResource.ports; i++) {
|
|
140
|
+
portsToUse.push(openPorts[i][0]);
|
|
141
|
+
this.ports[openPorts[i][0]] = false; // port is now closed
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
argz = JSON.stringify({
|
|
145
|
+
scheduled: true,
|
|
146
|
+
name: src,
|
|
147
|
+
// ports: [3333],
|
|
148
|
+
ports: portsToUse,
|
|
149
|
+
fs: ".",
|
|
150
|
+
browserWSEndpoint: this.browser.wsEndpoint(),
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
this.queue.push(src);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
console.error("negative port makes no sense", src);
|
|
158
|
+
process.exit(-1);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const builtfile = dest + ".mjs";
|
|
162
|
+
|
|
163
|
+
this.server[builtfile] = await import(
|
|
164
|
+
`${builtfile}?cacheBust=${Date.now()}`
|
|
165
|
+
).then((module) => {
|
|
166
|
+
return module.default.then((defaultModule) => {
|
|
167
|
+
defaultModule
|
|
168
|
+
.receiveTestResourceConfig(argz)
|
|
169
|
+
.then((x) => {
|
|
170
|
+
console.log("then", x);
|
|
171
|
+
return x;
|
|
172
|
+
})
|
|
173
|
+
.catch((e) => {
|
|
174
|
+
console.log("catch", e);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
for (let i = 0; i <= portsToUse.length; i++) {
|
|
180
|
+
this.ports[i] = true; //port is open again
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
launchWeb = (t: string, dest: string) => {
|
|
185
|
+
console.log("launchWeb", t, dest);
|
|
186
|
+
const testResourceConfiguration = this.testResourceConfiguration;
|
|
187
|
+
|
|
188
|
+
// childProcesses[t] = "running";
|
|
189
|
+
const destFolder = dest.replace(".mjs", "");
|
|
190
|
+
|
|
191
|
+
const webArgz = JSON.stringify({
|
|
192
|
+
name: dest,
|
|
193
|
+
ports: [].toString(),
|
|
194
|
+
fs: destFolder,
|
|
195
|
+
browserWSEndpoint: this.browser.wsEndpoint(),
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const evaluation = `import('${dest}.mjs').then(async (x) => {
|
|
199
|
+
console.log("imported", x, (x.default));
|
|
200
|
+
try {
|
|
201
|
+
await (await x.default).receiveTestResourceConfig(${webArgz})
|
|
202
|
+
} catch (e) {
|
|
203
|
+
console.log("fail", e)
|
|
204
|
+
}
|
|
205
|
+
})`;
|
|
206
|
+
|
|
207
|
+
const fileStreams2: fs.WriteStream[] = [];
|
|
208
|
+
|
|
209
|
+
const screenshots2: Promise<any>[] = [];
|
|
210
|
+
const doneFileStream2: Promise<any>[] = [];
|
|
211
|
+
|
|
212
|
+
this.browser
|
|
213
|
+
.newPage()
|
|
214
|
+
.then((page) => {
|
|
215
|
+
page.exposeFunction(
|
|
216
|
+
"custom-screenshot",
|
|
217
|
+
async (ssOpts: ScreenshotOptions) => {
|
|
218
|
+
const p = ssOpts.path as string;
|
|
219
|
+
console.log("custom-screenshot", ssOpts);
|
|
220
|
+
const dir = path.dirname(p);
|
|
221
|
+
console.log("dir", dir);
|
|
222
|
+
fs.mkdirSync(dir, {
|
|
223
|
+
recursive: true,
|
|
224
|
+
});
|
|
225
|
+
return page.screenshot({
|
|
226
|
+
...ssOpts,
|
|
227
|
+
path: p,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// screenshots.push(
|
|
231
|
+
// page.screenshot({
|
|
232
|
+
// ...ssOpts,
|
|
233
|
+
// path: ssOpts.path,
|
|
234
|
+
// })
|
|
235
|
+
// );
|
|
236
|
+
// const sPromise = page.screenshot({
|
|
237
|
+
// ...ssOpts,
|
|
238
|
+
// path: p,
|
|
239
|
+
// });
|
|
240
|
+
// await sPromise;
|
|
241
|
+
// page.evaluate(`window["screenshot done"]`);
|
|
242
|
+
}
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
page.exposeFunction("writeFileSync", (fp: string, contents: string) => {
|
|
246
|
+
console.log("writeFileSync", fp);
|
|
247
|
+
// Create directories if they don't exist
|
|
248
|
+
const dir = path.dirname(fp);
|
|
249
|
+
console.log("dir", dir);
|
|
250
|
+
fs.mkdirSync(dir, {
|
|
251
|
+
recursive: true,
|
|
252
|
+
});
|
|
253
|
+
// return fs.writeFileSync(fp, contents);
|
|
254
|
+
|
|
255
|
+
const p = new Promise<string>(async (res, rej) => {
|
|
256
|
+
fs.writeFileSync(fp, contents);
|
|
257
|
+
res(fp);
|
|
258
|
+
});
|
|
259
|
+
doneFileStream2.push(p);
|
|
260
|
+
return p;
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
page.exposeFunction("existsSync", (fp: string, contents: string) => {
|
|
264
|
+
return fs.existsSync(fp);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
page.exposeFunction("mkdirSync", (fp: string) => {
|
|
268
|
+
console.log("mkdirsync", fp);
|
|
269
|
+
if (!fs.existsSync(fp)) {
|
|
270
|
+
return fs.mkdirSync(fp, {
|
|
271
|
+
recursive: true,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
page.exposeFunction("createWriteStream", (fp: string) => {
|
|
278
|
+
const f = fs.createWriteStream(fp);
|
|
279
|
+
|
|
280
|
+
const p = new Promise<string>((res, rej) => {
|
|
281
|
+
res(fp);
|
|
282
|
+
});
|
|
283
|
+
doneFileStream2.push(p);
|
|
284
|
+
f.on("close", async () => {
|
|
285
|
+
await p;
|
|
286
|
+
});
|
|
287
|
+
fileStreams2.push(f);
|
|
288
|
+
return {
|
|
289
|
+
...JSON.parse(JSON.stringify(f)),
|
|
290
|
+
uid: fileStreams2.length - 1,
|
|
291
|
+
};
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
page.exposeFunction("write", async (uid: number, contents: string) => {
|
|
295
|
+
return fileStreams2[uid].write(contents);
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
page.exposeFunction("end", async (uid: number) => {
|
|
299
|
+
return fileStreams2[uid].end();
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
page.exposeFunction("customclose", () => {
|
|
303
|
+
console.log("closing doneFileStream2", doneFileStream2);
|
|
304
|
+
// console.log("closing doneFileStream2", doneFileStream2);
|
|
305
|
+
Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
|
|
306
|
+
page.close();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// page.close();
|
|
310
|
+
// Promise.all(screenshots).then(() => {
|
|
311
|
+
// page.close();
|
|
312
|
+
// });
|
|
313
|
+
// setTimeout(() => {
|
|
314
|
+
// console.log("Delayed for 1 second.");
|
|
315
|
+
// page.close();
|
|
316
|
+
// }, 5000);
|
|
317
|
+
|
|
318
|
+
// return page.close();
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
return page;
|
|
322
|
+
})
|
|
323
|
+
.then(async (page) => {
|
|
324
|
+
await page.goto(`file://${`${dest}.html`}`, {
|
|
325
|
+
// waitUntil: "load",
|
|
326
|
+
// timeout: 0,
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
page.evaluate(evaluation).finally(() => {
|
|
330
|
+
console.log("evaluation failed.", dest);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
return page;
|
|
334
|
+
})
|
|
335
|
+
.then((page) => {
|
|
336
|
+
// console.log("qwe", page);
|
|
337
|
+
// page.close();
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
end(accessObject: { uid: number }): boolean {
|
|
342
|
+
throw new Error("Method not implemented.");
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
existsSync(destFolder: string): boolean {
|
|
346
|
+
return fs.existsSync(destFolder);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async mkdirSync(fp: string) {
|
|
350
|
+
if (!fs.existsSync(fp)) {
|
|
351
|
+
return fs.mkdirSync(fp, {
|
|
352
|
+
recursive: true,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
return false;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
writeFileSync(fp: string, contents: string) {
|
|
359
|
+
fs.writeFileSync(fp, contents);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
createWriteStream(filepath: string): fs.WriteStream {
|
|
363
|
+
return fs.createWriteStream(filepath);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
testArtiFactoryfileWriter(tLog: ITLog, callback: (Promise) => void) {
|
|
367
|
+
return (fPath, value: string | Buffer | PassThrough) => {
|
|
368
|
+
callback(
|
|
369
|
+
new Promise<void>((res, rej) => {
|
|
370
|
+
tLog("testArtiFactory =>", fPath);
|
|
371
|
+
|
|
372
|
+
const cleanPath = path.resolve(fPath);
|
|
373
|
+
fPaths.push(cleanPath.replace(process.cwd(), ``));
|
|
374
|
+
|
|
375
|
+
const targetDir = cleanPath.split("/").slice(0, -1).join("/");
|
|
376
|
+
|
|
377
|
+
fs.mkdir(targetDir, { recursive: true }, async (error) => {
|
|
378
|
+
if (error) {
|
|
379
|
+
console.error(`❗️testArtiFactory failed`, targetDir, error);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
fs.writeFileSync(
|
|
383
|
+
path.resolve(
|
|
384
|
+
targetDir.split("/").slice(0, -1).join("/"),
|
|
385
|
+
"manifest"
|
|
386
|
+
),
|
|
387
|
+
fPaths.join(`\n`),
|
|
388
|
+
{
|
|
389
|
+
encoding: "utf-8",
|
|
390
|
+
}
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
if (Buffer.isBuffer(value)) {
|
|
394
|
+
fs.writeFileSync(fPath, value, "binary");
|
|
395
|
+
res();
|
|
396
|
+
} else if (`string` === typeof value) {
|
|
397
|
+
fs.writeFileSync(fPath, value.toString(), {
|
|
398
|
+
encoding: "utf-8",
|
|
399
|
+
});
|
|
400
|
+
res();
|
|
401
|
+
} else {
|
|
402
|
+
/* @ts-ignore:next-line */
|
|
403
|
+
const pipeStream: PassThrough = value;
|
|
404
|
+
const myFile = fs.createWriteStream(fPath);
|
|
405
|
+
pipeStream.pipe(myFile);
|
|
406
|
+
pipeStream.on("close", () => {
|
|
407
|
+
myFile.close();
|
|
408
|
+
res();
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
});
|
|
412
|
+
})
|
|
413
|
+
);
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
write(accessObject: { uid: number }, contents: string): boolean {
|
|
418
|
+
throw new Error("Method not implemented.");
|
|
419
|
+
}
|
|
420
|
+
}
|