testeranto 0.62.0 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -26
- package/dist/cjs-shim.js +2 -2
- package/dist/common/Node.js +14 -51
- 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 +121 -266
- 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-dom/jsx/web.js +15 -7
- package/dist/common/SubPackages/react-test-renderer/MemoExoticComponent/node.js +1 -1
- package/dist/common/SubPackages/react-test-renderer/component/index.js +0 -1
- package/dist/common/SubPackages/react-test-renderer/fc/web.js +1 -1
- package/dist/common/SubPackages/react-test-renderer/jsx/index.js +1 -3
- package/dist/common/SubPackages/react-test-renderer/jsx/web.js +1 -1
- package/dist/common/SubPackages/react-test-renderer/jsx-promised/index.js +1 -1
- package/dist/common/Types.js +2 -32
- package/dist/common/Web.js +25 -37
- package/dist/common/esbuildConfigs/index.js +5 -5
- package/dist/common/esbuildConfigs/node.js +17 -15
- package/dist/common/esbuildConfigs/report.js +12 -47
- package/dist/common/esbuildConfigs/tests.js +0 -1
- package/dist/common/esbuildConfigs/web.js +17 -12
- package/dist/common/lib/abstractBase.js +190 -35
- package/dist/common/lib/basebuilder.js +56 -29
- package/dist/common/lib/classBuilder.js +8 -5
- package/dist/common/lib/core.js +42 -17
- package/dist/common/lib/index.js +11 -8
- package/dist/common/lib/types.js +2 -0
- package/dist/common/preload.js +14 -28
- package/dist/common/puppeteerConfiger.js +24 -0
- package/dist/common/tsconfig.common.tsbuildinfo +1 -1
- package/dist/module/Node.js +14 -51
- 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 +122 -267
- 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/jsx/web.js +1 -1
- package/dist/module/SubPackages/react-dom/component/node.js +2 -2
- package/dist/module/SubPackages/react-dom/component/web.js +98 -45
- package/dist/module/SubPackages/react-dom/jsx/web.js +17 -9
- package/dist/module/SubPackages/react-test-renderer/MemoExoticComponent/node.js +1 -1
- package/dist/module/SubPackages/react-test-renderer/component/index.js +0 -1
- package/dist/module/SubPackages/react-test-renderer/fc/web.js +1 -1
- package/dist/module/SubPackages/react-test-renderer/jsx/index.js +1 -3
- package/dist/module/SubPackages/react-test-renderer/jsx/web.js +1 -1
- package/dist/module/SubPackages/react-test-renderer/jsx-promised/index.js +1 -1
- package/dist/module/Types.js +3 -30
- package/dist/module/Web.js +26 -38
- package/dist/module/esbuildConfigs/index.js +5 -5
- package/dist/module/esbuildConfigs/node.js +17 -15
- package/dist/module/esbuildConfigs/report.js +11 -48
- package/dist/module/esbuildConfigs/tests.js +0 -1
- package/dist/module/esbuildConfigs/web.js +17 -12
- package/dist/module/lib/abstractBase.js +190 -35
- package/dist/module/lib/basebuilder.js +56 -29
- package/dist/module/lib/classBuilder.js +8 -5
- package/dist/module/lib/core.js +44 -19
- package/dist/module/lib/index.js +11 -8
- package/dist/module/preload.js +15 -27
- package/dist/module/puppeteerConfiger.js +19 -0
- 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/Node.d.ts +3 -2
- 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/Project.d.ts +1 -2
- package/dist/types/Puppeteer.d.ts +1 -0
- package/dist/types/Reporter.d.ts +1 -0
- package/dist/types/Scheduler.d.ts +0 -0
- package/dist/types/SubPackages/puppeteer.d.ts +3 -3
- package/dist/types/SubPackages/react/component/node.d.ts +1 -1
- package/dist/types/SubPackages/react/component/web.d.ts +1 -1
- package/dist/types/SubPackages/react/jsx/index.d.ts +1 -1
- package/dist/types/SubPackages/react/jsx/node.d.ts +1 -1
- package/dist/types/SubPackages/react/jsx/web.d.ts +2 -2
- package/dist/types/SubPackages/react-dom/component/node.d.ts +2 -2
- package/dist/types/SubPackages/react-dom/component/web.d.ts +1 -1
- package/dist/types/SubPackages/react-dom/jsx/node.d.ts +1 -1
- package/dist/types/SubPackages/react-dom/jsx/web.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/MemoExoticComponent/node.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/component/index.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/component/node.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/component/web.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/fc/node.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/fc/web.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/jsx/node.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/jsx/web.d.ts +3 -3
- package/dist/types/SubPackages/react-test-renderer/jsx-promised/index.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/jsx-promised/node.d.ts +1 -1
- package/dist/types/SubPackages/react-test-renderer/jsx-promised/web.d.ts +1 -1
- package/dist/types/Types.d.ts +19 -100
- package/dist/types/Web.d.ts +3 -2
- package/dist/types/esbuildConfigs/features.d.ts +1 -1
- package/dist/types/esbuildConfigs/index.d.ts +1 -1
- package/dist/types/esbuildConfigs/node.d.ts +1 -1
- package/dist/types/esbuildConfigs/report.d.ts +4 -0
- package/dist/types/esbuildConfigs/tests.d.ts +1 -1
- package/dist/types/esbuildConfigs/web.d.ts +1 -1
- package/dist/types/lib/abstractBase.d.ts +26 -24
- package/dist/types/lib/basebuilder.d.ts +10 -7
- package/dist/types/lib/classBuilder.d.ts +4 -3
- package/dist/types/lib/core.d.ts +5 -4
- package/dist/types/lib/index.d.ts +7 -5
- package/dist/types/lib/types.d.ts +62 -0
- package/dist/types/preload.d.ts +0 -1
- package/dist/types/puppeteerConfiger.d.ts +4 -0
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +6 -7
- package/src/Node.ts +30 -85
- 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 +183 -619
- 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 +19 -14
- package/src/SubPackages/react/component/node.ts +20 -32
- package/src/SubPackages/react/component/web.ts +20 -30
- package/src/SubPackages/react/jsx/index.ts +13 -24
- package/src/SubPackages/react/jsx/node.ts +5 -8
- package/src/SubPackages/react/jsx/web.ts +10 -8
- package/src/SubPackages/react-dom/component/node.ts +17 -23
- package/src/SubPackages/react-dom/component/web.ts +134 -95
- package/src/SubPackages/react-dom/jsx/web.ts +41 -48
- package/src/SubPackages/react-test-renderer/MemoExoticComponent/node.ts +27 -37
- package/src/SubPackages/react-test-renderer/component/index.ts +16 -30
- package/src/SubPackages/react-test-renderer/component/node.ts +5 -11
- package/src/SubPackages/react-test-renderer/component/web.ts +5 -11
- package/src/SubPackages/react-test-renderer/fc/node.ts +36 -50
- package/src/SubPackages/react-test-renderer/fc/web.ts +37 -50
- package/src/SubPackages/react-test-renderer/jsx/index.ts +15 -21
- package/src/SubPackages/react-test-renderer/jsx/node.ts +6 -10
- package/src/SubPackages/react-test-renderer/jsx/web.ts +7 -7
- package/src/SubPackages/react-test-renderer/jsx-promised/index.ts +13 -16
- package/src/Types.ts +73 -307
- package/src/Web.ts +40 -81
- package/src/cjs-shim.js +2 -2
- package/src/esbuildConfigs/features.ts +3 -4
- package/src/esbuildConfigs/index.ts +8 -8
- package/src/esbuildConfigs/node.ts +21 -20
- package/src/esbuildConfigs/report.ts +15 -51
- package/src/esbuildConfigs/tests.ts +3 -9
- package/src/esbuildConfigs/web.ts +22 -20
- package/src/lib/abstractBase.ts +312 -164
- package/src/lib/basebuilder.ts +123 -127
- package/src/lib/classBuilder.ts +30 -48
- package/src/lib/core.ts +115 -84
- package/src/lib/index.ts +58 -56
- package/src/lib/types.ts +197 -0
- package/src/preload.ts +14 -30
- package/src/puppeteerConfiger.ts +26 -0
- package/src/web.html.ts +1 -1
- package/dist/common/NodeWriter.js +0 -56
- package/dist/common/electron.js +0 -196
- package/dist/common/lib/browser.js +0 -26
- package/dist/common/nodeWriterElectron.js +0 -55
- package/dist/module/NodeWriter.js +0 -50
- package/dist/module/electron.js +0 -191
- package/dist/module/lib/browser.js +0 -22
- package/dist/module/nodeWriterElectron.js +0 -52
- package/dist/types/NodeWriter.d.ts +0 -2
- package/dist/types/lib/browser.d.ts +0 -6
- package/dist/types/nodeWriterElectron.d.ts +0 -2
- package/src/NodeWriter.ts +0 -69
- package/src/electron.ts +0 -250
- package/src/lib/browser.ts +0 -34
- package/src/nodeWriterElectron.ts +0 -71
- package/yarn-error.log +0 -3144
- /package/dist/{types/electron.d.ts → module/lib/types.js} +0 -0
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
|
+
}
|