@lvce-editor/test-with-playwright-worker 20.2.0 → 21.0.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/workerMain.js +79 -6
- package/package.json +1 -1
package/dist/workerMain.js
CHANGED
|
@@ -1,11 +1,58 @@
|
|
|
1
|
-
import { join, basename } from 'node:path';
|
|
2
|
-
import { readdir } from 'node:fs/promises';
|
|
3
|
-
import { expect, webkit, firefox, chromium } from '@playwright/test';
|
|
1
|
+
import { join, dirname, basename } from 'node:path';
|
|
2
|
+
import { readFile, writeFile, readdir } from 'node:fs/promises';
|
|
4
3
|
import { pathToFileURL } from 'node:url';
|
|
5
4
|
import net from 'node:net';
|
|
6
5
|
import os from 'node:os';
|
|
7
6
|
import { fork, spawn } from 'node:child_process';
|
|
8
7
|
import { createInterface } from 'node:readline';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
|
|
10
|
+
const require$1 = createRequire(import.meta.url);
|
|
11
|
+
const before = ` _onWebSocketOpened(event) {
|
|
12
|
+
const request2 = this._webSocketRequests.get(event.requestId);
|
|
13
|
+
assert(request2);
|
|
14
|
+
const response2 = this._webSocketResponses.get(event.requestId);
|
|
15
|
+
assert(response2);
|
|
16
|
+
this._webSocketRequests.delete(event.requestId);
|
|
17
|
+
this._webSocketResponses.delete(event.requestId);
|
|
18
|
+
this._page.frameManager.onWebSocketRequest(webSocketId(event.frameId, event.wsid), request2.headers);
|
|
19
|
+
this._page.frameManager.onWebSocketResponse(webSocketId(event.frameId, event.wsid), response2.status, response2.statusText, response2.headers);
|
|
20
|
+
}`;
|
|
21
|
+
const after = ` _onWebSocketOpened(event) {
|
|
22
|
+
const request2 = this._webSocketRequests.get(event.requestId);
|
|
23
|
+
const response2 = this._webSocketResponses.get(event.requestId);
|
|
24
|
+
if (!request2 || !response2) {
|
|
25
|
+
this._webSocketRequests.delete(event.requestId);
|
|
26
|
+
this._webSocketResponses.delete(event.requestId);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this._webSocketRequests.delete(event.requestId);
|
|
30
|
+
this._webSocketResponses.delete(event.requestId);
|
|
31
|
+
this._page.frameManager.onWebSocketRequest(webSocketId(event.frameId, event.wsid), request2.headers);
|
|
32
|
+
this._page.frameManager.onWebSocketResponse(webSocketId(event.frameId, event.wsid), response2.status, response2.statusText, response2.headers);
|
|
33
|
+
}`;
|
|
34
|
+
const patchCoreBundleContent = content => {
|
|
35
|
+
if (content.includes(after)) {
|
|
36
|
+
return content;
|
|
37
|
+
}
|
|
38
|
+
if (!content.includes(before)) {
|
|
39
|
+
throw new Error('Could not patch Playwright Firefox worker WebSocket handler');
|
|
40
|
+
}
|
|
41
|
+
return content.split(before).join(after);
|
|
42
|
+
};
|
|
43
|
+
const getCoreBundlePath = () => {
|
|
44
|
+
const packageJsonPath = require$1.resolve('playwright-core/package.json');
|
|
45
|
+
return join(dirname(packageJsonPath), 'lib', 'coreBundle.js');
|
|
46
|
+
};
|
|
47
|
+
const patchPlaywrightFirefoxWorkerWebSocket = async () => {
|
|
48
|
+
const file = getCoreBundlePath();
|
|
49
|
+
const content = await readFile(file, 'utf8');
|
|
50
|
+
const patched = patchCoreBundleContent(content);
|
|
51
|
+
if (patched === content) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await writeFile(file, patched);
|
|
55
|
+
};
|
|
9
56
|
|
|
10
57
|
const normalizeLine = line => {
|
|
11
58
|
if (line.startsWith('Error: ')) {
|
|
@@ -957,6 +1004,9 @@ const runElectronTest = async ({
|
|
|
957
1004
|
status: Skip$1
|
|
958
1005
|
};
|
|
959
1006
|
}
|
|
1007
|
+
const {
|
|
1008
|
+
expect
|
|
1009
|
+
} = await import('@playwright/test');
|
|
960
1010
|
await withTimeout(testModule.test({
|
|
961
1011
|
electronApp,
|
|
962
1012
|
expect,
|
|
@@ -1104,6 +1154,9 @@ const runTest = async ({
|
|
|
1104
1154
|
}) => {
|
|
1105
1155
|
const start = performance.now();
|
|
1106
1156
|
try {
|
|
1157
|
+
const {
|
|
1158
|
+
expect
|
|
1159
|
+
} = await import('@playwright/test');
|
|
1107
1160
|
const url = getUrlFromTestFile(test, port, traceFocus);
|
|
1108
1161
|
await page.goto(url, {
|
|
1109
1162
|
waitUntil: 'networkidle'
|
|
@@ -1370,7 +1423,12 @@ const getServerPath = async serverPath => {
|
|
|
1370
1423
|
* @param {{browser:'chromium'|'firefox'|'webkit', signal:AbortSignal, headless:boolean}} options
|
|
1371
1424
|
* @returns
|
|
1372
1425
|
*/
|
|
1373
|
-
const getLauncher = browser => {
|
|
1426
|
+
const getLauncher = async browser => {
|
|
1427
|
+
const {
|
|
1428
|
+
chromium,
|
|
1429
|
+
firefox,
|
|
1430
|
+
webkit
|
|
1431
|
+
} = await import('@playwright/test');
|
|
1374
1432
|
switch (browser) {
|
|
1375
1433
|
case 'chromium':
|
|
1376
1434
|
return chromium;
|
|
@@ -1385,7 +1443,10 @@ const startBrowser = async ({
|
|
|
1385
1443
|
headless,
|
|
1386
1444
|
signal
|
|
1387
1445
|
}) => {
|
|
1388
|
-
|
|
1446
|
+
if (browser === 'firefox') {
|
|
1447
|
+
await patchPlaywrightFirefoxWorkerWebSocket();
|
|
1448
|
+
}
|
|
1449
|
+
const launcher = await getLauncher(browser);
|
|
1389
1450
|
const browserInstance = await launcher.launch({
|
|
1390
1451
|
headless
|
|
1391
1452
|
});
|
|
@@ -1629,6 +1690,9 @@ const startElectron = async ({
|
|
|
1629
1690
|
let browser;
|
|
1630
1691
|
try {
|
|
1631
1692
|
const endpoint = await waitForDevtoolsEndpoint(child);
|
|
1693
|
+
const {
|
|
1694
|
+
chromium
|
|
1695
|
+
} = await import('@playwright/test');
|
|
1632
1696
|
browser = await chromium.connectOverCDP(endpoint);
|
|
1633
1697
|
const page = await getFirstPage(browser);
|
|
1634
1698
|
return createElectronLaunch({
|
|
@@ -1789,4 +1853,13 @@ const main = async () => {
|
|
|
1789
1853
|
set(Cli, rpc);
|
|
1790
1854
|
};
|
|
1791
1855
|
|
|
1792
|
-
|
|
1856
|
+
const Main$1 = {
|
|
1857
|
+
__proto__: null,
|
|
1858
|
+
main
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
if (process.argv.includes('--browser=firefox')) {
|
|
1862
|
+
await patchPlaywrightFirefoxWorkerWebSocket();
|
|
1863
|
+
}
|
|
1864
|
+
const Main = await Promise.resolve().then(function () { return Main$1; });
|
|
1865
|
+
await Main.main();
|