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.
- package/README.md +9 -18
- package/dist/common/Node.js +7 -34
- package/dist/common/PM/index.js +71 -0
- package/dist/common/PM/main.js +370 -0
- package/dist/common/PM/node.js +84 -0
- package/dist/common/PM/web.js +129 -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/jsx/index.js +14 -2
- 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 -44
- 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 +7 -34
- package/dist/module/PM/index.js +67 -0
- package/dist/module/PM/main.js +340 -0
- package/dist/module/PM/node.js +77 -0
- package/dist/module/PM/web.js +122 -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/index.js +11 -2
- 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 -44
- 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 +26 -0
- package/dist/types/PM/node.d.ts +25 -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/jsx/index.d.ts +2 -5
- 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 +8 -47
- package/src/PM/index.ts +102 -0
- package/src/PM/main.ts +452 -0
- package/src/PM/node.ts +122 -0
- package/src/PM/web.ts +162 -0
- package/src/Project.ts +21 -2
- package/src/Puppeteer.ts +131 -0
- package/src/Report.tsx +160 -46
- package/src/Reporter.ts +134 -0
- package/src/Scheduler.ts +0 -0
- package/src/SubPackages/puppeteer.ts +3 -3
- package/src/SubPackages/react/jsx/index.ts +13 -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 -69
- 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/dist/module/electron.js
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import readline from "readline";
|
|
2
|
-
import { app, BrowserWindow, utilityProcess, ipcMain } from "electron";
|
|
3
|
-
import pie from "puppeteer-in-electron";
|
|
4
|
-
import puppeteer from "puppeteer-core";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { jsonc } from "jsonc";
|
|
8
|
-
import { v4 as uuidv4 } from "uuid";
|
|
9
|
-
var mode = process.argv[2] === "-dev" ? "DEV" : "PROD";
|
|
10
|
-
console.log("hello electron", mode);
|
|
11
|
-
const nodeChildren = {};
|
|
12
|
-
const webChildren = {};
|
|
13
|
-
const node2web = {};
|
|
14
|
-
const web2node = {};
|
|
15
|
-
const childProcesses = {};
|
|
16
|
-
readline.emitKeypressEvents(process.stdin);
|
|
17
|
-
if (process.stdin.isTTY)
|
|
18
|
-
process.stdin.setRawMode(true);
|
|
19
|
-
console.log("\n Electron is running. Press 'q' to quit\n");
|
|
20
|
-
process.stdin.on("keypress", (str, key) => {
|
|
21
|
-
if (key.name === "q") {
|
|
22
|
-
mode = "PROD";
|
|
23
|
-
// process.exit();
|
|
24
|
-
console.log("Switching to prod mode. Begin shutdown sequence...");
|
|
25
|
-
// process.exit(-1);
|
|
26
|
-
const allDone = Object.values(childProcesses).every((v) => v === "done");
|
|
27
|
-
if (allDone && mode === "PROD") {
|
|
28
|
-
console.log("Goodbye Testeranto by manual shutdown");
|
|
29
|
-
process.exit();
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
console.log(childProcesses);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const onDone = (test) => {
|
|
37
|
-
console.log("onDone", test);
|
|
38
|
-
childProcesses[test] = "done";
|
|
39
|
-
const allDone = Object.values(childProcesses).every((v) => v === "done");
|
|
40
|
-
if (allDone && mode === "PROD") {
|
|
41
|
-
console.log("Goodbye Testeranto by auto shutdown");
|
|
42
|
-
process.exit();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log(childProcesses);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
process.on("message", function (message) {
|
|
49
|
-
console.log("message: " + message);
|
|
50
|
-
process.exit();
|
|
51
|
-
});
|
|
52
|
-
const remoteMain = require("@electron/remote/main");
|
|
53
|
-
remoteMain.initialize();
|
|
54
|
-
const main = async () => {
|
|
55
|
-
const configs = jsonc.parse((await fs.readFileSync("./docs/testeranto.json")).toString());
|
|
56
|
-
const loadReport = (configs) => {
|
|
57
|
-
const win = new BrowserWindow({
|
|
58
|
-
show: true,
|
|
59
|
-
webPreferences: {
|
|
60
|
-
offscreen: false,
|
|
61
|
-
devTools: true,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
win.loadFile(`/${configs.buildDir}/report.html`).then(async (x) => {
|
|
65
|
-
// pie.connect(app, puppeteer).then(async (browser) => {
|
|
66
|
-
// pie.getPage(browser, win).then(async (page) => {
|
|
67
|
-
// await page.screenshot({
|
|
68
|
-
// path: 'electron-puppeteer-screenshot1.jpg'
|
|
69
|
-
// });
|
|
70
|
-
// })
|
|
71
|
-
// })
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
const launchNode = (src, dest) => {
|
|
75
|
-
var _a, _b;
|
|
76
|
-
console.log("launchNode", src);
|
|
77
|
-
childProcesses[src] = "running";
|
|
78
|
-
const destFolder = dest.replace(".mjs", "");
|
|
79
|
-
const argz = JSON.stringify({
|
|
80
|
-
scheduled: true,
|
|
81
|
-
name: src,
|
|
82
|
-
ports: [3333],
|
|
83
|
-
// fs: path.resolve(configs.buildDir, "web", destFolder + "/"),
|
|
84
|
-
// fs: destFolder,
|
|
85
|
-
fs: ".",
|
|
86
|
-
});
|
|
87
|
-
// console.log("launchNode", src, dest, " -> ", destFolder, argz);
|
|
88
|
-
const child = utilityProcess.fork(dest + ".mjs", [argz], {
|
|
89
|
-
cwd: destFolder,
|
|
90
|
-
stdio: "pipe",
|
|
91
|
-
});
|
|
92
|
-
const nodeGuid = uuidv4();
|
|
93
|
-
nodeChildren[nodeGuid] = child;
|
|
94
|
-
if (!fs.existsSync(destFolder)) {
|
|
95
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
96
|
-
}
|
|
97
|
-
fs.rmSync(`${destFolder}/stdout.log`, { force: true });
|
|
98
|
-
fs.rmSync(`${destFolder}/stderr.log`, { force: true });
|
|
99
|
-
const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
|
|
100
|
-
const stderr = fs.createWriteStream(`${destFolder}/stderr.log`);
|
|
101
|
-
child
|
|
102
|
-
.on("message", (data) => {
|
|
103
|
-
console.log("from child", JSON.stringify(data));
|
|
104
|
-
if (data.launchWeb) {
|
|
105
|
-
const guid = uuidv4();
|
|
106
|
-
const webChild = launchWebSecondary(process.cwd() + data.launchWeb);
|
|
107
|
-
// child.postMessage({ webLaunched: guid });
|
|
108
|
-
webChild.webContents.on("did-finish-load", () => {
|
|
109
|
-
// webChild.webContents.send("message", "hello world");
|
|
110
|
-
child.postMessage({ webLaunched: guid });
|
|
111
|
-
webChildren[guid] = webChild;
|
|
112
|
-
node2web[nodeGuid] = [...(node2web[nodeGuid] || []), guid];
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
if (data.teardown) {
|
|
116
|
-
webChildren[data.teardown].close();
|
|
117
|
-
delete webChildren[data.teardown];
|
|
118
|
-
node2web[nodeGuid] = node2web[nodeGuid].filter((x) => x !== data.teardown);
|
|
119
|
-
}
|
|
120
|
-
})
|
|
121
|
-
.on("exit", (data) => {
|
|
122
|
-
stdout.close();
|
|
123
|
-
stderr.close();
|
|
124
|
-
console.log(`ending node ${src}`);
|
|
125
|
-
onDone(src);
|
|
126
|
-
});
|
|
127
|
-
(_a = child.stdout) === null || _a === void 0 ? void 0 : _a.pipe(stdout);
|
|
128
|
-
(_b = child.stderr) === null || _b === void 0 ? void 0 : _b.pipe(stderr);
|
|
129
|
-
};
|
|
130
|
-
const launchWebSecondary = (htmlFile) => {
|
|
131
|
-
console.log("launchWebSecondary", htmlFile);
|
|
132
|
-
const subWin = new BrowserWindow({
|
|
133
|
-
show: false,
|
|
134
|
-
webPreferences: {
|
|
135
|
-
nodeIntegration: true,
|
|
136
|
-
nodeIntegrationInWorker: true,
|
|
137
|
-
contextIsolation: false,
|
|
138
|
-
preload: path.join(app.getAppPath(), "preload.js"),
|
|
139
|
-
offscreen: false,
|
|
140
|
-
devTools: true,
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
remoteMain.enable(subWin.webContents);
|
|
144
|
-
subWin.webContents.openDevTools();
|
|
145
|
-
subWin.loadFile(htmlFile);
|
|
146
|
-
return subWin;
|
|
147
|
-
// const uuid = uuidv4();
|
|
148
|
-
// windows[uuid] = subWin;
|
|
149
|
-
// return uuid;
|
|
150
|
-
};
|
|
151
|
-
const launchWeb = (t, dest) => {
|
|
152
|
-
console.log("launchWeb", t);
|
|
153
|
-
childProcesses[t] = "running";
|
|
154
|
-
const destFolder = dest.replace(".mjs", "");
|
|
155
|
-
const subWin = new BrowserWindow({
|
|
156
|
-
show: true,
|
|
157
|
-
webPreferences: {
|
|
158
|
-
nodeIntegration: true,
|
|
159
|
-
nodeIntegrationInWorker: true,
|
|
160
|
-
contextIsolation: false,
|
|
161
|
-
preload: path.join(app.getAppPath(), "preload.js"),
|
|
162
|
-
offscreen: false,
|
|
163
|
-
devTools: true,
|
|
164
|
-
},
|
|
165
|
-
});
|
|
166
|
-
webChildren[uuidv4()] = subWin;
|
|
167
|
-
remoteMain.enable(subWin.webContents);
|
|
168
|
-
const webArgz = JSON.stringify({
|
|
169
|
-
name: dest,
|
|
170
|
-
ports: [].toString(),
|
|
171
|
-
fs: destFolder,
|
|
172
|
-
});
|
|
173
|
-
// console.log("webArgz", webArgz);
|
|
174
|
-
subWin.loadFile(`${dest}.html`, {
|
|
175
|
-
query: {
|
|
176
|
-
requesting: encodeURIComponent(webArgz),
|
|
177
|
-
},
|
|
178
|
-
});
|
|
179
|
-
if (!fs.existsSync(destFolder)) {
|
|
180
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
181
|
-
}
|
|
182
|
-
const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
|
|
183
|
-
subWin.webContents.on("console-message", (event, level, message, line, sourceId) => {
|
|
184
|
-
stdout.write(JSON.stringify({
|
|
185
|
-
event,
|
|
186
|
-
level,
|
|
187
|
-
message: JSON.stringify(message),
|
|
188
|
-
line,
|
|
189
|
-
sourceId,
|
|
190
|
-
}, null, 2));
|
|
191
|
-
stdout.write("\n");
|
|
192
|
-
});
|
|
193
|
-
subWin.on("closed", () => {
|
|
194
|
-
stdout.close();
|
|
195
|
-
console.log(`ending web ${t}`);
|
|
196
|
-
// childProcesses[t] = "done";
|
|
197
|
-
onDone(t);
|
|
198
|
-
});
|
|
199
|
-
ipcMain.on("message", (message, data) => {
|
|
200
|
-
console.log("ipcMain message: " + JSON.stringify(data));
|
|
201
|
-
// process.exit();
|
|
202
|
-
});
|
|
203
|
-
};
|
|
204
|
-
const destinationOfRuntime = (f, r) => {
|
|
205
|
-
return path
|
|
206
|
-
.normalize(`${configs.buildDir}/${r}/${f}`)
|
|
207
|
-
.split(".")
|
|
208
|
-
.slice(0, -1)
|
|
209
|
-
.join(".");
|
|
210
|
-
};
|
|
211
|
-
pie.initialize(app, 2999).then(async () => {
|
|
212
|
-
app.on("ready", () => {
|
|
213
|
-
loadReport(configs);
|
|
214
|
-
console.log("running all the tests once initially");
|
|
215
|
-
configs.tests.forEach(([test, runtime, secondaryArtifacts]) => {
|
|
216
|
-
childProcesses[test] = "loaded";
|
|
217
|
-
if (runtime === "node") {
|
|
218
|
-
launchNode(test, destinationOfRuntime(test, "node"));
|
|
219
|
-
}
|
|
220
|
-
else if (runtime === "web") {
|
|
221
|
-
launchWeb(test, destinationOfRuntime(test, "web"));
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
console.error("runtime makes no sense", runtime);
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
console.log("ready and watching for changes...", configs.buildDir);
|
|
228
|
-
fs.watch(configs.buildDir, {
|
|
229
|
-
recursive: true,
|
|
230
|
-
}, (eventType, changedFile) => {
|
|
231
|
-
// console.log(eventType);
|
|
232
|
-
if (changedFile) {
|
|
233
|
-
configs.tests.forEach(([test, runtime, secondaryArtifacts]) => {
|
|
234
|
-
if (eventType === "change" || eventType === "rename") {
|
|
235
|
-
if (changedFile ===
|
|
236
|
-
test
|
|
237
|
-
.replace("./", "node/")
|
|
238
|
-
.split(".")
|
|
239
|
-
.slice(0, -1)
|
|
240
|
-
.concat("mjs")
|
|
241
|
-
.join(".")) {
|
|
242
|
-
launchNode(test, destinationOfRuntime(test, "node"));
|
|
243
|
-
}
|
|
244
|
-
if (changedFile ===
|
|
245
|
-
test
|
|
246
|
-
.replace("./", "web/")
|
|
247
|
-
.split(".")
|
|
248
|
-
.slice(0, -1)
|
|
249
|
-
.concat("mjs")
|
|
250
|
-
.join(".")) {
|
|
251
|
-
launchWeb(test, destinationOfRuntime(test, "web"));
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
await pie.connect(app, puppeteer);
|
|
260
|
-
};
|
|
261
|
-
main();
|
package/src/NodeWriter.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { PassThrough } from "stream";
|
|
4
|
-
|
|
5
|
-
import { ILogWriter, ITLog } from "./lib/index.js";
|
|
6
|
-
|
|
7
|
-
type IFPaths = string[];
|
|
8
|
-
const fPaths: IFPaths = [];
|
|
9
|
-
|
|
10
|
-
export const NodeWriter: ILogWriter = {
|
|
11
|
-
createWriteStream: (filepath: string): fs.WriteStream =>
|
|
12
|
-
fs.createWriteStream(filepath),
|
|
13
|
-
|
|
14
|
-
writeFileSync: (fp: string, contents: string) =>
|
|
15
|
-
fs.writeFileSync(fp, contents),
|
|
16
|
-
|
|
17
|
-
mkdirSync: async (destFolder: string) => {
|
|
18
|
-
if (!fs.existsSync(destFolder)) {
|
|
19
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
testArtiFactoryfileWriter:
|
|
23
|
-
(tLog: ITLog, callback: (Promise) => void) =>
|
|
24
|
-
(fPath, value: string | Buffer | PassThrough) => {
|
|
25
|
-
callback(
|
|
26
|
-
new Promise<void>((res, rej) => {
|
|
27
|
-
tLog("testArtiFactory =>", fPath);
|
|
28
|
-
|
|
29
|
-
const cleanPath = path.resolve(fPath);
|
|
30
|
-
fPaths.push(cleanPath.replace(process.cwd(), ``));
|
|
31
|
-
|
|
32
|
-
const targetDir = cleanPath.split("/").slice(0, -1).join("/");
|
|
33
|
-
|
|
34
|
-
fs.mkdir(targetDir, { recursive: true }, async (error) => {
|
|
35
|
-
if (error) {
|
|
36
|
-
console.error(`❗️testArtiFactory failed`, targetDir, error);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
fs.writeFileSync(
|
|
40
|
-
path.resolve(
|
|
41
|
-
targetDir.split("/").slice(0, -1).join("/"),
|
|
42
|
-
"manifest"
|
|
43
|
-
),
|
|
44
|
-
fPaths.join(`\n`),
|
|
45
|
-
{
|
|
46
|
-
encoding: "utf-8",
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
if (Buffer.isBuffer(value)) {
|
|
51
|
-
fs.writeFileSync(fPath, value, "binary");
|
|
52
|
-
res();
|
|
53
|
-
} else if (`string` === typeof value) {
|
|
54
|
-
fs.writeFileSync(fPath, value.toString(), {
|
|
55
|
-
encoding: "utf-8",
|
|
56
|
-
});
|
|
57
|
-
res();
|
|
58
|
-
} else {
|
|
59
|
-
/* @ts-ignore:next-line */
|
|
60
|
-
const pipeStream: PassThrough = value;
|
|
61
|
-
const myFile = fs.createWriteStream(fPath);
|
|
62
|
-
pipeStream.pipe(myFile);
|
|
63
|
-
pipeStream.on("close", () => {
|
|
64
|
-
myFile.close();
|
|
65
|
-
res();
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
},
|
|
72
|
-
};
|
package/src/electron.ts
DELETED
|
@@ -1,317 +0,0 @@
|
|
|
1
|
-
import readline from "readline";
|
|
2
|
-
import { app, BrowserWindow, utilityProcess, ipcMain } from "electron";
|
|
3
|
-
import pie from "puppeteer-in-electron";
|
|
4
|
-
import puppeteer from "puppeteer-core";
|
|
5
|
-
import fs from "fs";
|
|
6
|
-
import path from "path";
|
|
7
|
-
import { jsonc } from "jsonc";
|
|
8
|
-
import { v4 as uuidv4 } from "uuid";
|
|
9
|
-
|
|
10
|
-
import { IBuiltConfig, IRunTime } from "./lib/types";
|
|
11
|
-
|
|
12
|
-
var mode: "DEV" | "PROD" = process.argv[2] === "-dev" ? "DEV" : "PROD";
|
|
13
|
-
|
|
14
|
-
console.log("hello electron", mode);
|
|
15
|
-
|
|
16
|
-
const nodeChildren: Record<string, Electron.UtilityProcess> = {};
|
|
17
|
-
const webChildren: Record<string, BrowserWindow> = {};
|
|
18
|
-
const node2web: Record<string, string[]> = {};
|
|
19
|
-
const web2node: Record<string, string[]> = {};
|
|
20
|
-
const childProcesses: Record<string, "loaded" | "running" | "done"> = {};
|
|
21
|
-
|
|
22
|
-
readline.emitKeypressEvents(process.stdin);
|
|
23
|
-
if (process.stdin.isTTY) process.stdin.setRawMode(true);
|
|
24
|
-
|
|
25
|
-
console.log("\n Electron is running. Press 'q' to quit\n");
|
|
26
|
-
process.stdin.on("keypress", (str, key) => {
|
|
27
|
-
if (key.name === "q") {
|
|
28
|
-
mode = "PROD";
|
|
29
|
-
// process.exit();
|
|
30
|
-
console.log("Switching to prod mode. Begin shutdown sequence...");
|
|
31
|
-
// process.exit(-1);
|
|
32
|
-
const allDone = Object.values(childProcesses).every((v) => v === "done");
|
|
33
|
-
if (allDone && mode === "PROD") {
|
|
34
|
-
console.log("Goodbye Testeranto by manual shutdown");
|
|
35
|
-
process.exit();
|
|
36
|
-
} else {
|
|
37
|
-
console.log(childProcesses);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
const onDone = (test: string) => {
|
|
43
|
-
console.log("onDone", test);
|
|
44
|
-
childProcesses[test] = "done";
|
|
45
|
-
|
|
46
|
-
const allDone = Object.values(childProcesses).every((v) => v === "done");
|
|
47
|
-
if (allDone && mode === "PROD") {
|
|
48
|
-
console.log("Goodbye Testeranto by auto shutdown");
|
|
49
|
-
process.exit();
|
|
50
|
-
} else {
|
|
51
|
-
console.log(childProcesses);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
process.on("message", function (message) {
|
|
56
|
-
console.log("message: " + message);
|
|
57
|
-
process.exit();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const remoteMain = require("@electron/remote/main");
|
|
61
|
-
|
|
62
|
-
remoteMain.initialize();
|
|
63
|
-
|
|
64
|
-
const main = async () => {
|
|
65
|
-
const configs = jsonc.parse(
|
|
66
|
-
(await fs.readFileSync("./docs/testeranto.json")).toString()
|
|
67
|
-
) as IBuiltConfig;
|
|
68
|
-
|
|
69
|
-
const loadReport = (configs: IBuiltConfig) => {
|
|
70
|
-
const win = new BrowserWindow({
|
|
71
|
-
show: true,
|
|
72
|
-
webPreferences: {
|
|
73
|
-
offscreen: false,
|
|
74
|
-
devTools: true,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
win.loadFile(`/${configs.buildDir}/report.html`).then(async (x) => {
|
|
79
|
-
// pie.connect(app, puppeteer).then(async (browser) => {
|
|
80
|
-
// pie.getPage(browser, win).then(async (page) => {
|
|
81
|
-
// await page.screenshot({
|
|
82
|
-
// path: 'electron-puppeteer-screenshot1.jpg'
|
|
83
|
-
// });
|
|
84
|
-
// })
|
|
85
|
-
// })
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const launchNode = (src: string, dest: string) => {
|
|
90
|
-
console.log("launchNode", src);
|
|
91
|
-
childProcesses[src] = "running";
|
|
92
|
-
const destFolder = dest.replace(".mjs", "");
|
|
93
|
-
|
|
94
|
-
const argz = JSON.stringify({
|
|
95
|
-
scheduled: true,
|
|
96
|
-
name: src,
|
|
97
|
-
ports: [3333],
|
|
98
|
-
// fs: path.resolve(configs.buildDir, "web", destFolder + "/"),
|
|
99
|
-
// fs: destFolder,
|
|
100
|
-
fs: ".",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// console.log("launchNode", src, dest, " -> ", destFolder, argz);
|
|
104
|
-
|
|
105
|
-
const child = utilityProcess.fork(dest + ".mjs", [argz], {
|
|
106
|
-
cwd: destFolder,
|
|
107
|
-
stdio: "pipe",
|
|
108
|
-
});
|
|
109
|
-
const nodeGuid = uuidv4();
|
|
110
|
-
nodeChildren[nodeGuid] = child;
|
|
111
|
-
|
|
112
|
-
if (!fs.existsSync(destFolder)) {
|
|
113
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
fs.rmSync(`${destFolder}/stdout.log`, { force: true });
|
|
117
|
-
fs.rmSync(`${destFolder}/stderr.log`, { force: true });
|
|
118
|
-
const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
|
|
119
|
-
const stderr = fs.createWriteStream(`${destFolder}/stderr.log`);
|
|
120
|
-
|
|
121
|
-
child
|
|
122
|
-
.on("message", (data) => {
|
|
123
|
-
console.log("from child", JSON.stringify(data));
|
|
124
|
-
if (data.launchWeb) {
|
|
125
|
-
const guid = uuidv4();
|
|
126
|
-
const webChild = launchWebSecondary(process.cwd() + data.launchWeb);
|
|
127
|
-
// child.postMessage({ webLaunched: guid });
|
|
128
|
-
|
|
129
|
-
webChild.webContents.on("did-finish-load", () => {
|
|
130
|
-
// webChild.webContents.send("message", "hello world");
|
|
131
|
-
child.postMessage({ webLaunched: guid });
|
|
132
|
-
webChildren[guid] = webChild;
|
|
133
|
-
node2web[nodeGuid] = [...(node2web[nodeGuid] || []), guid];
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
if (data.teardown) {
|
|
137
|
-
webChildren[data.teardown].close();
|
|
138
|
-
delete webChildren[data.teardown];
|
|
139
|
-
node2web[nodeGuid] = node2web[nodeGuid].filter(
|
|
140
|
-
(x) => x !== data.teardown
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
})
|
|
144
|
-
.on("exit", (data) => {
|
|
145
|
-
stdout.close();
|
|
146
|
-
stderr.close();
|
|
147
|
-
console.log(`ending node ${src}`);
|
|
148
|
-
onDone(src);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
child.stdout?.pipe(stdout);
|
|
152
|
-
child.stderr?.pipe(stderr);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const launchWebSecondary = (htmlFile: string): BrowserWindow => {
|
|
156
|
-
console.log("launchWebSecondary", htmlFile);
|
|
157
|
-
const subWin = new BrowserWindow({
|
|
158
|
-
show: false,
|
|
159
|
-
|
|
160
|
-
webPreferences: {
|
|
161
|
-
nodeIntegration: true,
|
|
162
|
-
nodeIntegrationInWorker: true,
|
|
163
|
-
contextIsolation: false,
|
|
164
|
-
preload: path.join(app.getAppPath(), "preload.js"),
|
|
165
|
-
offscreen: false,
|
|
166
|
-
devTools: true,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
remoteMain.enable(subWin.webContents);
|
|
170
|
-
subWin.webContents.openDevTools();
|
|
171
|
-
subWin.loadFile(htmlFile);
|
|
172
|
-
return subWin;
|
|
173
|
-
|
|
174
|
-
// const uuid = uuidv4();
|
|
175
|
-
// windows[uuid] = subWin;
|
|
176
|
-
// return uuid;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const launchWeb = (t: string, dest: string) => {
|
|
180
|
-
console.log("launchWeb", t);
|
|
181
|
-
childProcesses[t] = "running";
|
|
182
|
-
const destFolder = dest.replace(".mjs", "");
|
|
183
|
-
|
|
184
|
-
const subWin = new BrowserWindow({
|
|
185
|
-
show: true,
|
|
186
|
-
webPreferences: {
|
|
187
|
-
nodeIntegration: true,
|
|
188
|
-
nodeIntegrationInWorker: true,
|
|
189
|
-
contextIsolation: false,
|
|
190
|
-
preload: path.join(app.getAppPath(), "preload.js"),
|
|
191
|
-
offscreen: false,
|
|
192
|
-
devTools: true,
|
|
193
|
-
},
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
webChildren[uuidv4()] = subWin;
|
|
197
|
-
|
|
198
|
-
remoteMain.enable(subWin.webContents);
|
|
199
|
-
|
|
200
|
-
const webArgz = JSON.stringify({
|
|
201
|
-
name: dest,
|
|
202
|
-
ports: [].toString(),
|
|
203
|
-
fs: destFolder,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// console.log("webArgz", webArgz);
|
|
207
|
-
subWin.loadFile(`${dest}.html`, {
|
|
208
|
-
query: {
|
|
209
|
-
requesting: encodeURIComponent(webArgz),
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
if (!fs.existsSync(destFolder)) {
|
|
214
|
-
fs.mkdirSync(destFolder, { recursive: true });
|
|
215
|
-
}
|
|
216
|
-
const stdout = fs.createWriteStream(`${destFolder}/stdout.log`);
|
|
217
|
-
|
|
218
|
-
subWin.webContents.on(
|
|
219
|
-
"console-message",
|
|
220
|
-
(event, level, message, line, sourceId) => {
|
|
221
|
-
stdout.write(
|
|
222
|
-
JSON.stringify(
|
|
223
|
-
{
|
|
224
|
-
event,
|
|
225
|
-
level,
|
|
226
|
-
message: JSON.stringify(message),
|
|
227
|
-
line,
|
|
228
|
-
sourceId,
|
|
229
|
-
},
|
|
230
|
-
null,
|
|
231
|
-
2
|
|
232
|
-
)
|
|
233
|
-
);
|
|
234
|
-
stdout.write("\n");
|
|
235
|
-
}
|
|
236
|
-
);
|
|
237
|
-
subWin.on("closed", () => {
|
|
238
|
-
stdout.close();
|
|
239
|
-
console.log(`ending web ${t}`);
|
|
240
|
-
// childProcesses[t] = "done";
|
|
241
|
-
onDone(t);
|
|
242
|
-
});
|
|
243
|
-
ipcMain.on("message", (message, data) => {
|
|
244
|
-
console.log("ipcMain message: " + JSON.stringify(data));
|
|
245
|
-
// process.exit();
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const destinationOfRuntime = (f: string, r: IRunTime) => {
|
|
250
|
-
return path
|
|
251
|
-
.normalize(`${configs.buildDir}/${r}/${f}`)
|
|
252
|
-
.split(".")
|
|
253
|
-
.slice(0, -1)
|
|
254
|
-
.join(".");
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
pie.initialize(app, 2999).then(async () => {
|
|
258
|
-
app.on("ready", () => {
|
|
259
|
-
loadReport(configs);
|
|
260
|
-
|
|
261
|
-
console.log("running all the tests once initially");
|
|
262
|
-
configs.tests.forEach(([test, runtime, secondaryArtifacts]) => {
|
|
263
|
-
childProcesses[test] = "loaded";
|
|
264
|
-
if (runtime === "node") {
|
|
265
|
-
launchNode(test, destinationOfRuntime(test, "node"));
|
|
266
|
-
} else if (runtime === "web") {
|
|
267
|
-
launchWeb(test, destinationOfRuntime(test, "web"));
|
|
268
|
-
} else {
|
|
269
|
-
console.error("runtime makes no sense", runtime);
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
console.log("ready and watching for changes...", configs.buildDir);
|
|
274
|
-
fs.watch(
|
|
275
|
-
configs.buildDir,
|
|
276
|
-
{
|
|
277
|
-
recursive: true,
|
|
278
|
-
},
|
|
279
|
-
(eventType, changedFile) => {
|
|
280
|
-
// console.log(eventType);
|
|
281
|
-
if (changedFile) {
|
|
282
|
-
configs.tests.forEach(([test, runtime, secondaryArtifacts]) => {
|
|
283
|
-
if (eventType === "change" || eventType === "rename") {
|
|
284
|
-
if (
|
|
285
|
-
changedFile ===
|
|
286
|
-
test
|
|
287
|
-
.replace("./", "node/")
|
|
288
|
-
.split(".")
|
|
289
|
-
.slice(0, -1)
|
|
290
|
-
.concat("mjs")
|
|
291
|
-
.join(".")
|
|
292
|
-
) {
|
|
293
|
-
launchNode(test, destinationOfRuntime(test, "node"));
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (
|
|
297
|
-
changedFile ===
|
|
298
|
-
test
|
|
299
|
-
.replace("./", "web/")
|
|
300
|
-
.split(".")
|
|
301
|
-
.slice(0, -1)
|
|
302
|
-
.concat("mjs")
|
|
303
|
-
.join(".")
|
|
304
|
-
) {
|
|
305
|
-
launchWeb(test, destinationOfRuntime(test, "web"));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
});
|
|
313
|
-
});
|
|
314
|
-
await pie.connect(app, puppeteer);
|
|
315
|
-
};
|
|
316
|
-
|
|
317
|
-
main();
|