testeranto 0.82.0 → 0.84.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/dist/common/package.json +3 -0
- package/dist/common/src/Node.js +2 -0
- package/dist/common/src/PM/main.js +182 -79
- package/dist/common/src/PM/node.js +32 -6
- package/dist/common/src/PM/web.js +28 -54
- package/dist/common/src/Project.js +0 -3
- package/dist/common/src/Puppeteer.js +9 -51
- package/dist/common/src/SubPackages/react-dom/jsx/web.js +11 -11
- package/dist/common/src/Web.js +2 -0
- package/dist/common/src/esbuildConfigs/featuresPlugin.js +39 -0
- package/dist/common/src/esbuildConfigs/inputFilesPlugin.js +62 -41
- package/dist/common/src/esbuildConfigs/node.js +10 -3
- package/dist/common/src/esbuildConfigs/web.js +6 -2
- package/dist/common/src/lib/abstractBase.js +343 -335
- package/dist/common/src/lib/basebuilder.js +7 -3
- package/dist/common/src/lib/core.js +1 -1
- package/dist/common/tsconfig.common.tsbuildinfo +1 -1
- package/dist/module/package.json +3 -0
- package/dist/module/src/Node.js +1 -1
- package/dist/module/src/PM/main.js +182 -79
- package/dist/module/src/PM/node.js +32 -6
- package/dist/module/src/PM/web.js +28 -51
- package/dist/module/src/Project.js +0 -3
- package/dist/module/src/Puppeteer.js +9 -51
- package/dist/module/src/SubPackages/react-dom/jsx/web.js +10 -10
- package/dist/module/src/Web.js +1 -1
- package/dist/module/src/esbuildConfigs/featuresPlugin.js +34 -0
- package/dist/module/src/esbuildConfigs/inputFilesPlugin.js +62 -41
- package/dist/module/src/esbuildConfigs/node.js +10 -3
- package/dist/module/src/esbuildConfigs/web.js +6 -2
- package/dist/module/src/lib/abstractBase.js +343 -335
- package/dist/module/src/lib/basebuilder.js +7 -3
- package/dist/module/src/lib/core.js +1 -1
- package/dist/module/tsconfig.module.tsbuildinfo +1 -1
- package/dist/prebuild/Puppeteer.mjs +82033 -0
- package/dist/types/src/Node.d.ts +5 -1
- package/dist/types/src/PM/index.d.ts +10 -4
- package/dist/types/src/PM/main.d.ts +21 -9
- package/dist/types/src/PM/node.d.ts +11 -3
- package/dist/types/src/PM/web.d.ts +11 -2
- package/dist/types/src/SubPackages/react-dom/jsx/index.d.ts +1 -0
- package/dist/types/src/SubPackages/react-test-renderer/jsx/index.d.ts +1 -0
- package/dist/types/src/SubPackages/react-test-renderer/jsx-promised/index.d.ts +1 -0
- package/dist/types/src/Types.d.ts +2 -2
- package/dist/types/src/Web.d.ts +5 -1
- package/dist/types/src/esbuildConfigs/featuresPlugin.d.ts +5 -0
- package/dist/types/src/esbuildConfigs/inputFilesPlugin.d.ts +4 -2
- package/dist/types/src/lib/abstractBase.d.ts +5 -5
- package/dist/types/src/lib/types.d.ts +7 -5
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +18 -41
- package/pupBuild.js +18 -0
- package/src/Node.ts +1 -3
- package/src/PM/index.ts +12 -3
- package/src/PM/main.ts +300 -164
- package/src/PM/node.ts +40 -6
- package/src/PM/web.ts +108 -58
- package/src/Project.ts +0 -8
- package/src/Puppeteer.ts +11 -57
- package/src/SubPackages/react-dom/jsx/web.ts +15 -10
- package/src/Types.ts +5 -2
- package/src/Web.ts +1 -1
- package/src/esbuildConfigs/featuresPlugin.ts +43 -0
- package/src/esbuildConfigs/inputFilesPlugin.ts +98 -66
- package/src/esbuildConfigs/node.ts +18 -3
- package/src/esbuildConfigs/web.ts +14 -2
- package/src/lib/abstractBase.ts +381 -364
- package/src/lib/basebuilder.ts +7 -7
- package/src/lib/core.ts +1 -1
- package/src/lib/types.ts +13 -5
package/src/PM/main.ts
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import fs from "fs";
|
|
2
2
|
import path from "path";
|
|
3
|
-
import puppeteer, {
|
|
3
|
+
import puppeteer, { Browser, ScreenshotOptions } from "puppeteer-core";
|
|
4
4
|
import { PassThrough } from "stream";
|
|
5
|
+
import crypto from "crypto";
|
|
5
6
|
|
|
6
7
|
import { IBuiltConfig, ITestTypes } from "../lib/types";
|
|
7
8
|
|
|
8
9
|
import { PM } from "./index.js";
|
|
9
10
|
import { destinationOfRuntime } from "../utils.js";
|
|
10
11
|
import { ITLog } from "../lib/index.js";
|
|
12
|
+
import { Page } from "puppeteer-core/lib/esm/puppeteer";
|
|
11
13
|
|
|
12
14
|
type IFPaths = string[];
|
|
13
15
|
|
|
14
16
|
const fPaths: IFPaths = [];
|
|
15
17
|
const fileStreams3: fs.WriteStream[] = [];
|
|
16
|
-
const files: Record<string, Set<string>> = {};
|
|
18
|
+
const files: Record<string, Set<string>> = {};
|
|
17
19
|
const screenshots: Record<string, Promise<Uint8Array>[]> = {};
|
|
18
20
|
|
|
19
21
|
export class PM_Main extends PM {
|
|
22
|
+
browser: Browser;
|
|
23
|
+
|
|
20
24
|
shutdownMode = false;
|
|
21
25
|
configs: IBuiltConfig;
|
|
22
26
|
ports: Record<number, boolean>;
|
|
@@ -125,19 +129,128 @@ export class PM_Main extends PM {
|
|
|
125
129
|
};
|
|
126
130
|
}
|
|
127
131
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
$(selector: string): boolean {
|
|
133
|
+
throw new Error("Method not implemented.");
|
|
134
|
+
}
|
|
135
|
+
screencast(opts: object) {
|
|
136
|
+
throw new Error("Method not implemented.");
|
|
132
137
|
}
|
|
133
|
-
|
|
134
138
|
customScreenShot(opts: object) {
|
|
135
139
|
throw new Error("Method not implemented.");
|
|
136
140
|
}
|
|
137
141
|
|
|
142
|
+
end(accessObject: { uid: number }): boolean {
|
|
143
|
+
throw new Error("Method not implemented.");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
existsSync(destFolder: string): boolean {
|
|
147
|
+
return fs.existsSync(destFolder);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
async mkdirSync(fp: string) {
|
|
151
|
+
if (!fs.existsSync(fp)) {
|
|
152
|
+
return fs.mkdirSync(fp, {
|
|
153
|
+
recursive: true,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
writeFileSync(fp: string, contents: string) {
|
|
160
|
+
fs.writeFileSync(fp, contents);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
createWriteStream(filepath: string): fs.WriteStream {
|
|
164
|
+
return fs.createWriteStream(filepath);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
testArtiFactoryfileWriter(tLog: ITLog, callback: (Promise) => void) {
|
|
168
|
+
return (fPath, value: string | Buffer | PassThrough) => {
|
|
169
|
+
callback(
|
|
170
|
+
new Promise<void>((res, rej) => {
|
|
171
|
+
tLog("testArtiFactory =>", fPath);
|
|
172
|
+
|
|
173
|
+
const cleanPath = path.resolve(fPath);
|
|
174
|
+
fPaths.push(cleanPath.replace(process.cwd(), ``));
|
|
175
|
+
|
|
176
|
+
const targetDir = cleanPath.split("/").slice(0, -1).join("/");
|
|
177
|
+
|
|
178
|
+
fs.mkdir(targetDir, { recursive: true }, async (error) => {
|
|
179
|
+
if (error) {
|
|
180
|
+
console.error(`❗️testArtiFactory failed`, targetDir, error);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
fs.writeFileSync(
|
|
184
|
+
path.resolve(
|
|
185
|
+
targetDir.split("/").slice(0, -1).join("/"),
|
|
186
|
+
"manifest"
|
|
187
|
+
),
|
|
188
|
+
fPaths.join(`\n`),
|
|
189
|
+
{
|
|
190
|
+
encoding: "utf-8",
|
|
191
|
+
}
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (Buffer.isBuffer(value)) {
|
|
195
|
+
fs.writeFileSync(fPath, value, "binary");
|
|
196
|
+
res();
|
|
197
|
+
} else if (`string` === typeof value) {
|
|
198
|
+
fs.writeFileSync(fPath, value.toString(), {
|
|
199
|
+
encoding: "utf-8",
|
|
200
|
+
});
|
|
201
|
+
res();
|
|
202
|
+
} else {
|
|
203
|
+
/* @ts-ignore:next-line */
|
|
204
|
+
const pipeStream: PassThrough = value;
|
|
205
|
+
const myFile = fs.createWriteStream(fPath);
|
|
206
|
+
pipeStream.pipe(myFile);
|
|
207
|
+
pipeStream.on("close", () => {
|
|
208
|
+
myFile.close();
|
|
209
|
+
res();
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
})
|
|
214
|
+
);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
write(accessObject: { uid: number }, contents: string): boolean {
|
|
219
|
+
throw new Error("Method not implemented.");
|
|
220
|
+
}
|
|
221
|
+
page(): string | undefined {
|
|
222
|
+
throw new Error("Method not implemented.");
|
|
223
|
+
}
|
|
224
|
+
click(selector: string): string | undefined {
|
|
225
|
+
throw new Error("Method not implemented.");
|
|
226
|
+
}
|
|
227
|
+
focusOn(selector: string) {
|
|
228
|
+
throw new Error("Method not implemented.");
|
|
229
|
+
}
|
|
230
|
+
typeInto(value: string) {
|
|
231
|
+
throw new Error("Method not implemented.");
|
|
232
|
+
}
|
|
233
|
+
getValue(value: string) {
|
|
234
|
+
throw new Error("Method not implemented.");
|
|
235
|
+
}
|
|
236
|
+
getAttribute(selector: string, attribute: string) {
|
|
237
|
+
throw new Error("Method not implemented.");
|
|
238
|
+
}
|
|
239
|
+
isDisabled(selector: string): boolean {
|
|
240
|
+
throw new Error("Method not implemented.");
|
|
241
|
+
}
|
|
242
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
243
|
+
|
|
138
244
|
async startPuppeteer(options: any, destfolder: string): Promise<any> {
|
|
139
245
|
this.browser = (await puppeteer.launch(options)) as any;
|
|
140
|
-
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
249
|
+
|
|
250
|
+
shutDown() {
|
|
251
|
+
console.log("shutting down...");
|
|
252
|
+
this.shutdownMode = true;
|
|
253
|
+
this.checkForShutdown();
|
|
141
254
|
}
|
|
142
255
|
|
|
143
256
|
checkForShutdown = () => {
|
|
@@ -153,14 +266,11 @@ export class PM_Main extends PM {
|
|
|
153
266
|
};
|
|
154
267
|
|
|
155
268
|
register = (src: string) => {
|
|
156
|
-
// console.log("register", src);
|
|
157
269
|
this.registry[src] = false;
|
|
158
270
|
};
|
|
159
271
|
|
|
160
272
|
deregister = (src: string) => {
|
|
161
|
-
// console.log("deregister", src, this.shutdownMode);
|
|
162
273
|
this.registry[src] = true;
|
|
163
|
-
|
|
164
274
|
if (this.shutdownMode) {
|
|
165
275
|
this.checkForShutdown();
|
|
166
276
|
}
|
|
@@ -251,19 +361,7 @@ export class PM_Main extends PM {
|
|
|
251
361
|
defaultModule
|
|
252
362
|
.receiveTestResourceConfig(argz)
|
|
253
363
|
.then(async (features: string[]) => {
|
|
254
|
-
|
|
255
|
-
.reduce(async (mm, lm) => {
|
|
256
|
-
const accum = await mm;
|
|
257
|
-
const x = await this.configs.featureIngestor(features[lm]);
|
|
258
|
-
accum[lm] = x;
|
|
259
|
-
return accum;
|
|
260
|
-
}, Promise.resolve({}))
|
|
261
|
-
.then((x) => {
|
|
262
|
-
fs.writeFileSync(
|
|
263
|
-
`${destFolder}/features.json`,
|
|
264
|
-
JSON.stringify(x, null, 2)
|
|
265
|
-
);
|
|
266
|
-
});
|
|
364
|
+
this.receiveFeatures(features, destFolder);
|
|
267
365
|
})
|
|
268
366
|
.catch((e) => {
|
|
269
367
|
console.log("catch", e);
|
|
@@ -297,11 +395,11 @@ export class PM_Main extends PM {
|
|
|
297
395
|
browserWSEndpoint: this.browser.wsEndpoint(),
|
|
298
396
|
});
|
|
299
397
|
|
|
300
|
-
const evaluation = `
|
|
301
|
-
console.log("importing ${dest}.mjs");
|
|
302
|
-
import('${dest}.mjs').then(async (x) => {
|
|
303
|
-
|
|
304
|
-
})`;
|
|
398
|
+
// const evaluation = `
|
|
399
|
+
// console.log("importing ${dest}.mjs");
|
|
400
|
+
// import('${dest}.mjs').then(async (x) => {
|
|
401
|
+
// console.log("imported", x.default);
|
|
402
|
+
// })`;
|
|
305
403
|
|
|
306
404
|
const fileStreams2: fs.WriteStream[] = [];
|
|
307
405
|
const doneFileStream2: Promise<any>[] = [];
|
|
@@ -310,11 +408,11 @@ export class PM_Main extends PM {
|
|
|
310
408
|
this.browser
|
|
311
409
|
.newPage()
|
|
312
410
|
.then((page) => {
|
|
313
|
-
page.on("console", (msg) => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
});
|
|
411
|
+
// page.on("console", (msg) => {
|
|
412
|
+
// console.log("web > ", msg.args(), msg.text());
|
|
413
|
+
// // for (let i = 0; i < msg._args.length; ++i)
|
|
414
|
+
// // console.log(`${i}: ${msg._args[i]}`);
|
|
415
|
+
// });
|
|
318
416
|
|
|
319
417
|
page.exposeFunction(
|
|
320
418
|
"custom-screenshot",
|
|
@@ -426,44 +524,13 @@ export class PM_Main extends PM {
|
|
|
426
524
|
delete screenshots[testName];
|
|
427
525
|
// page.close();
|
|
428
526
|
});
|
|
429
|
-
|
|
430
|
-
// globalThis["writeFileSync"](
|
|
431
|
-
// p + "/manifest.json",
|
|
432
|
-
// // files.entries()
|
|
433
|
-
// JSON.stringify(Array.from(files[testName]))
|
|
434
|
-
// );
|
|
435
|
-
|
|
436
|
-
// console.log("closing doneFileStream2", doneFileStream2);
|
|
437
|
-
// console.log("closing doneFileStream2", doneFileStream2);
|
|
438
|
-
// Promise.all([...doneFileStream2, ...screenshots2]).then(() => {
|
|
439
|
-
// page.close();
|
|
440
|
-
// });
|
|
441
|
-
|
|
442
|
-
// Promise.all(screenshots).then(() => {
|
|
443
|
-
// page.close();
|
|
444
|
-
// });
|
|
445
|
-
// setTimeout(() => {
|
|
446
|
-
// console.log("Delayed for 1 second.");
|
|
447
|
-
// page.close();
|
|
448
|
-
// }, 5000);
|
|
449
|
-
|
|
450
|
-
// return page.close();
|
|
451
527
|
});
|
|
452
528
|
|
|
453
529
|
return page;
|
|
454
530
|
})
|
|
455
531
|
.then(async (page) => {
|
|
456
|
-
page.on("console", (log) =>
|
|
457
|
-
console.debug(`Log from client: [${log.text()}] `)
|
|
458
|
-
);
|
|
459
532
|
await page.goto(`file://${`${dest}.html`}`, {});
|
|
460
533
|
res(page);
|
|
461
|
-
|
|
462
|
-
// page.evaluate(evaluation).finally(() => {
|
|
463
|
-
// console.log("evaluation failed.", dest);
|
|
464
|
-
// });
|
|
465
|
-
|
|
466
|
-
// return page;
|
|
467
534
|
});
|
|
468
535
|
});
|
|
469
536
|
};
|
|
@@ -480,14 +547,6 @@ export class PM_Main extends PM {
|
|
|
480
547
|
|
|
481
548
|
let argz = "";
|
|
482
549
|
|
|
483
|
-
// const testConfig = this.configs.tests.find((t) => {
|
|
484
|
-
// return t[0] === src;
|
|
485
|
-
// });
|
|
486
|
-
|
|
487
|
-
// if (!testConfig) {
|
|
488
|
-
// console.error("missing test config");
|
|
489
|
-
// process.exit(-1);
|
|
490
|
-
// }
|
|
491
550
|
const testConfigResource = testConfig[2];
|
|
492
551
|
|
|
493
552
|
let portsToUse: string[] = [];
|
|
@@ -589,7 +648,7 @@ export class PM_Main extends PM {
|
|
|
589
648
|
const evaluation = `
|
|
590
649
|
console.log("importing ${dest}.mjs");
|
|
591
650
|
import('${dest}.mjs').then(async (x) => {
|
|
592
|
-
console.log("imported", x.default);
|
|
651
|
+
console.log("imported", (await x.default));
|
|
593
652
|
try {
|
|
594
653
|
return await (await x.default).receiveTestResourceConfig(${webArgz})
|
|
595
654
|
} catch (e) {
|
|
@@ -603,16 +662,42 @@ export class PM_Main extends PM {
|
|
|
603
662
|
this.browser
|
|
604
663
|
.newPage()
|
|
605
664
|
.then((page) => {
|
|
606
|
-
page.on("console", (msg) => {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
665
|
+
// page.on("console", (msg) => {
|
|
666
|
+
// // console.log("web > ", msg.args(), msg.text());
|
|
667
|
+
// });
|
|
668
|
+
|
|
669
|
+
page.exposeFunction(
|
|
670
|
+
"screencast",
|
|
671
|
+
async (ssOpts: ScreenshotOptions, testName: string) => {
|
|
672
|
+
const p = ssOpts.path as string;
|
|
673
|
+
const dir = path.dirname(p);
|
|
674
|
+
fs.mkdirSync(dir, {
|
|
675
|
+
recursive: true,
|
|
676
|
+
});
|
|
677
|
+
if (!files[testName]) {
|
|
678
|
+
files[testName] = new Set();
|
|
679
|
+
}
|
|
680
|
+
files[testName].add(ssOpts.path as string);
|
|
681
|
+
|
|
682
|
+
const sPromise = page.screenshot({
|
|
683
|
+
...ssOpts,
|
|
684
|
+
path: p,
|
|
685
|
+
});
|
|
686
|
+
|
|
687
|
+
if (!screenshots[testName]) {
|
|
688
|
+
screenshots[testName] = [];
|
|
689
|
+
}
|
|
690
|
+
screenshots[testName].push(sPromise);
|
|
691
|
+
// sPromise.then(())
|
|
692
|
+
await sPromise;
|
|
693
|
+
return sPromise;
|
|
694
|
+
// page.evaluate(`window["screenshot done"]`);
|
|
695
|
+
}
|
|
696
|
+
);
|
|
611
697
|
|
|
612
698
|
page.exposeFunction(
|
|
613
699
|
"customScreenShot",
|
|
614
700
|
async (ssOpts: ScreenshotOptions, testName: string) => {
|
|
615
|
-
// console.log("main.ts browser custom-screenshot", testName);
|
|
616
701
|
const p = ssOpts.path as string;
|
|
617
702
|
const dir = path.dirname(p);
|
|
618
703
|
fs.mkdirSync(dir, {
|
|
@@ -748,30 +833,66 @@ export class PM_Main extends PM {
|
|
|
748
833
|
// return page.close();
|
|
749
834
|
});
|
|
750
835
|
|
|
836
|
+
page.exposeFunction("page", () => {
|
|
837
|
+
return page.mainFrame()._id;
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
page.exposeFunction("click", (sel) => {
|
|
841
|
+
return page.click(sel);
|
|
842
|
+
});
|
|
843
|
+
|
|
844
|
+
page.exposeFunction("focusOn", (sel) => {
|
|
845
|
+
return page.focus(sel);
|
|
846
|
+
});
|
|
847
|
+
|
|
848
|
+
page.exposeFunction(
|
|
849
|
+
"typeInto",
|
|
850
|
+
async (value) => await page.keyboard.type(value)
|
|
851
|
+
);
|
|
852
|
+
|
|
853
|
+
page.exposeFunction("getValue", (selector) =>
|
|
854
|
+
page.$eval(selector, (input) => input.getAttribute("value"))
|
|
855
|
+
);
|
|
856
|
+
|
|
857
|
+
page.exposeFunction(
|
|
858
|
+
"getAttribute",
|
|
859
|
+
async (selector: string, attribute: string) => {
|
|
860
|
+
const attributeValue = await page.$eval(selector, (input) => {
|
|
861
|
+
return input.getAttribute(attribute);
|
|
862
|
+
});
|
|
863
|
+
return attributeValue;
|
|
864
|
+
}
|
|
865
|
+
);
|
|
866
|
+
|
|
867
|
+
page.exposeFunction("isDisabled", async (selector: string) => {
|
|
868
|
+
const attributeValue = await page.$eval(
|
|
869
|
+
selector,
|
|
870
|
+
(input: HTMLButtonElement) => {
|
|
871
|
+
return input.disabled;
|
|
872
|
+
}
|
|
873
|
+
);
|
|
874
|
+
return attributeValue;
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
page.exposeFunction("$", async (selector: string) => {
|
|
878
|
+
const x = page.$(selector);
|
|
879
|
+
const y = await x;
|
|
880
|
+
|
|
881
|
+
return y;
|
|
882
|
+
});
|
|
883
|
+
|
|
751
884
|
return page;
|
|
752
885
|
})
|
|
753
886
|
.then(async (page) => {
|
|
754
|
-
page.on("console", (log) =>
|
|
755
|
-
|
|
756
|
-
);
|
|
887
|
+
// page.on("console", (log) =>
|
|
888
|
+
// console.debug(`Log from client: [${log.text()}] `)
|
|
889
|
+
// );
|
|
757
890
|
await page.goto(`file://${`${dest}.html`}`, {});
|
|
758
891
|
|
|
759
892
|
await page
|
|
760
893
|
.evaluate(evaluation)
|
|
761
894
|
.then(async (features: string[]) => {
|
|
762
|
-
|
|
763
|
-
.reduce(async (mm, lm) => {
|
|
764
|
-
const accum = await mm;
|
|
765
|
-
const x = await this.configs.featureIngestor(features[lm]);
|
|
766
|
-
accum[lm] = x;
|
|
767
|
-
return accum;
|
|
768
|
-
}, Promise.resolve({}))
|
|
769
|
-
.then((x) => {
|
|
770
|
-
fs.writeFileSync(
|
|
771
|
-
`${destFolder}/features.json`,
|
|
772
|
-
JSON.stringify(x, null, 2)
|
|
773
|
-
);
|
|
774
|
-
});
|
|
895
|
+
this.receiveFeatures(features, destFolder);
|
|
775
896
|
})
|
|
776
897
|
.catch((e) => {
|
|
777
898
|
console.log("evaluation failed.", dest);
|
|
@@ -781,90 +902,105 @@ export class PM_Main extends PM {
|
|
|
781
902
|
console.log("evaluation complete.", dest);
|
|
782
903
|
// page.close();
|
|
783
904
|
this.deregister(t);
|
|
784
|
-
// whyIsNodeRunning();
|
|
785
905
|
});
|
|
786
906
|
|
|
787
907
|
return page;
|
|
788
908
|
});
|
|
789
909
|
};
|
|
790
910
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
return fs.existsSync(destFolder);
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
async mkdirSync(fp: string) {
|
|
800
|
-
if (!fs.existsSync(fp)) {
|
|
801
|
-
return fs.mkdirSync(fp, {
|
|
802
|
-
recursive: true,
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
return false;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
writeFileSync(fp: string, contents: string) {
|
|
809
|
-
fs.writeFileSync(fp, contents);
|
|
810
|
-
}
|
|
911
|
+
receiveFeatures = (features: string[], destFolder: string) => {
|
|
912
|
+
console.log("this.receiveFeatures", features);
|
|
913
|
+
features
|
|
914
|
+
.reduce(async (mm, featureStringKey) => {
|
|
915
|
+
const accum = await mm;
|
|
811
916
|
|
|
812
|
-
|
|
813
|
-
return fs.createWriteStream(filepath);
|
|
814
|
-
}
|
|
917
|
+
const isUrl = isValidUrl(featureStringKey);
|
|
815
918
|
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
callback(
|
|
819
|
-
new Promise<void>((res, rej) => {
|
|
820
|
-
tLog("testArtiFactory =>", fPath);
|
|
919
|
+
if (isUrl) {
|
|
920
|
+
const u = new URL(featureStringKey);
|
|
821
921
|
|
|
822
|
-
|
|
823
|
-
|
|
922
|
+
if (u.protocol === "file:") {
|
|
923
|
+
const newPath = `${process.cwd()}/docs/features/internal/${path.relative(
|
|
924
|
+
process.cwd(),
|
|
925
|
+
u.pathname
|
|
926
|
+
)}`;
|
|
824
927
|
|
|
825
|
-
|
|
928
|
+
await fs.promises.mkdir(path.dirname(newPath), { recursive: true });
|
|
826
929
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
console.
|
|
930
|
+
try {
|
|
931
|
+
await fs.unlinkSync(newPath);
|
|
932
|
+
// console.log(`Removed existing link at ${newPath}`);
|
|
933
|
+
} catch (error) {
|
|
934
|
+
if (error.code !== "ENOENT") {
|
|
935
|
+
// throw error;
|
|
936
|
+
}
|
|
830
937
|
}
|
|
831
938
|
|
|
832
|
-
fs.
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
fPaths.join(`\n`),
|
|
838
|
-
{
|
|
839
|
-
encoding: "utf-8",
|
|
939
|
+
fs.symlink(u.pathname, newPath, (err) => {
|
|
940
|
+
if (err) {
|
|
941
|
+
// console.error("Error creating symlink:", err);
|
|
942
|
+
} else {
|
|
943
|
+
// console.log("Symlink created successfully");
|
|
840
944
|
}
|
|
841
|
-
);
|
|
945
|
+
});
|
|
946
|
+
accum.push(newPath);
|
|
947
|
+
} else if (u.protocol === "http:" || u.protocol === "https:") {
|
|
948
|
+
const newPath = `${process.cwd()}/docs/features/external${
|
|
949
|
+
u.hostname
|
|
950
|
+
}${u.pathname}`;
|
|
951
|
+
const body = await this.configs.featureIngestor(featureStringKey);
|
|
952
|
+
writeFileAndCreateDir(newPath, body);
|
|
953
|
+
accum.push(newPath);
|
|
954
|
+
}
|
|
955
|
+
} else {
|
|
956
|
+
const newPath = `${process.cwd()}/docs/features/plain/${await sha256(
|
|
957
|
+
featureStringKey
|
|
958
|
+
)}`;
|
|
959
|
+
writeFileAndCreateDir(newPath, featureStringKey);
|
|
960
|
+
accum.push(newPath);
|
|
961
|
+
}
|
|
842
962
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
963
|
+
return accum;
|
|
964
|
+
}, Promise.resolve([] as string[]))
|
|
965
|
+
.then((features: string[]) => {
|
|
966
|
+
fs.writeFileSync(
|
|
967
|
+
`${destFolder}/featurePrompt.txt`,
|
|
968
|
+
features
|
|
969
|
+
.map((f) => {
|
|
970
|
+
return `/read ${f}`;
|
|
971
|
+
})
|
|
972
|
+
.join("\n")
|
|
973
|
+
);
|
|
974
|
+
});
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
async function writeFileAndCreateDir(filePath, data) {
|
|
979
|
+
const dirPath = path.dirname(filePath);
|
|
980
|
+
|
|
981
|
+
try {
|
|
982
|
+
await fs.promises.mkdir(dirPath, { recursive: true });
|
|
983
|
+
await fs.promises.writeFile(filePath, data);
|
|
984
|
+
} catch (error) {
|
|
985
|
+
console.error(`Error writing file: ${error}`);
|
|
865
986
|
}
|
|
987
|
+
}
|
|
866
988
|
|
|
867
|
-
|
|
868
|
-
|
|
989
|
+
async function sha256(rawData) {
|
|
990
|
+
const data =
|
|
991
|
+
typeof rawData === "object" ? JSON.stringify(rawData) : String(rawData);
|
|
992
|
+
|
|
993
|
+
const msgBuffer = new TextEncoder().encode(data);
|
|
994
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", msgBuffer);
|
|
995
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
996
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
function isValidUrl(string) {
|
|
1000
|
+
try {
|
|
1001
|
+
new URL(string);
|
|
1002
|
+
return true;
|
|
1003
|
+
} catch (err) {
|
|
1004
|
+
return false;
|
|
869
1005
|
}
|
|
870
1006
|
}
|
package/src/PM/node.ts
CHANGED
|
@@ -23,8 +23,42 @@ export class PM_Node extends PM {
|
|
|
23
23
|
this.testResourceConfiguration = t;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
$(selector: string): boolean {
|
|
27
|
+
throw new Error("Method not implemented.");
|
|
28
|
+
}
|
|
29
|
+
screencast(opts: object) {
|
|
30
|
+
throw new Error("Method not implemented.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
isDisabled(selector: string): boolean {
|
|
34
|
+
throw new Error("Method not implemented.");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getAttribute(selector: string, attribute: string) {
|
|
38
|
+
throw new Error("Method not implemented.");
|
|
39
|
+
}
|
|
40
|
+
getValue(selector: string) {
|
|
41
|
+
throw new Error("Method not implemented.");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
focusOn(selector: string) {
|
|
45
|
+
throw new Error("Method not implemented.");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
typeInto(value: string) {
|
|
49
|
+
throw new Error("Method not implemented.");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
page() {
|
|
53
|
+
return globalThis["page"]();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
click(selector: string): string | undefined {
|
|
57
|
+
return globalThis["click"](selector);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
customScreenShot(opts: object) {
|
|
61
|
+
return globalThis["customScreenShot"](opts);
|
|
28
62
|
}
|
|
29
63
|
|
|
30
64
|
existsSync(destFolder: string): boolean {
|
|
@@ -119,9 +153,9 @@ export class PM_Node extends PM {
|
|
|
119
153
|
}
|
|
120
154
|
|
|
121
155
|
// launch(options?: PuppeteerLaunchOptions): Promise<Browser>;
|
|
122
|
-
startPuppeteer(options?: any):
|
|
123
|
-
return puppeteer.connect(options).then((b) => {
|
|
124
|
-
|
|
125
|
-
});
|
|
156
|
+
startPuppeteer(options?: any): any {
|
|
157
|
+
// return puppeteer.connect(options).then((b) => {
|
|
158
|
+
// this.browser = b;
|
|
159
|
+
// });
|
|
126
160
|
}
|
|
127
161
|
}
|