@lvce-editor/test-with-playwright-worker 21.0.0 → 22.1.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 +188 -8
- package/package.json +1 -1
package/dist/workerMain.js
CHANGED
|
@@ -117,7 +117,7 @@ class AssertionError extends Error {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
const Object$1 = 1;
|
|
120
|
-
const Number = 2;
|
|
120
|
+
const Number$1 = 2;
|
|
121
121
|
const Array$1 = 3;
|
|
122
122
|
const String$1 = 4;
|
|
123
123
|
const Boolean = 5;
|
|
@@ -127,7 +127,7 @@ const Unknown = 8;
|
|
|
127
127
|
const getType = value => {
|
|
128
128
|
switch (typeof value) {
|
|
129
129
|
case 'number':
|
|
130
|
-
return Number;
|
|
130
|
+
return Number$1;
|
|
131
131
|
case 'function':
|
|
132
132
|
return Function;
|
|
133
133
|
case 'string':
|
|
@@ -154,7 +154,7 @@ const object = value => {
|
|
|
154
154
|
};
|
|
155
155
|
const number = value => {
|
|
156
156
|
const type = getType(value);
|
|
157
|
-
if (type !== Number) {
|
|
157
|
+
if (type !== Number$1) {
|
|
158
158
|
throw new AssertionError('expected value to be of type number');
|
|
159
159
|
}
|
|
160
160
|
};
|
|
@@ -1034,7 +1034,7 @@ const runElectronTest = async ({
|
|
|
1034
1034
|
}
|
|
1035
1035
|
};
|
|
1036
1036
|
|
|
1037
|
-
const getResultCounts$
|
|
1037
|
+
const getResultCounts$2 = status => {
|
|
1038
1038
|
switch (status) {
|
|
1039
1039
|
case Fail$1:
|
|
1040
1040
|
return {
|
|
@@ -1086,7 +1086,7 @@ const runElectronTests = async ({
|
|
|
1086
1086
|
timeout
|
|
1087
1087
|
});
|
|
1088
1088
|
await onResult(result);
|
|
1089
|
-
const resultCounts = getResultCounts$
|
|
1089
|
+
const resultCounts = getResultCounts$2(result.status);
|
|
1090
1090
|
failed += resultCounts.failed;
|
|
1091
1091
|
passed += resultCounts.passed;
|
|
1092
1092
|
skipped += resultCounts.skipped;
|
|
@@ -1191,7 +1191,7 @@ const runTest = async ({
|
|
|
1191
1191
|
}
|
|
1192
1192
|
};
|
|
1193
1193
|
|
|
1194
|
-
const getResultCounts = status => {
|
|
1194
|
+
const getResultCounts$1 = status => {
|
|
1195
1195
|
switch (status) {
|
|
1196
1196
|
case Fail$1:
|
|
1197
1197
|
return {
|
|
@@ -1253,6 +1253,167 @@ const runTests = async ({
|
|
|
1253
1253
|
});
|
|
1254
1254
|
await onResult(result);
|
|
1255
1255
|
// @ts-ignore
|
|
1256
|
+
const resultCounts = getResultCounts$1(result.status);
|
|
1257
|
+
failed += resultCounts.failed;
|
|
1258
|
+
passed += resultCounts.passed;
|
|
1259
|
+
skipped += resultCounts.skipped;
|
|
1260
|
+
}
|
|
1261
|
+
const end = performance.now();
|
|
1262
|
+
await onFinalResult({
|
|
1263
|
+
end,
|
|
1264
|
+
failed,
|
|
1265
|
+
passed,
|
|
1266
|
+
skipped,
|
|
1267
|
+
start
|
|
1268
|
+
});
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
const testResultsSelector = '.TestResults';
|
|
1272
|
+
const getResultCounts = status => {
|
|
1273
|
+
switch (status) {
|
|
1274
|
+
case Fail$1:
|
|
1275
|
+
return {
|
|
1276
|
+
failed: 1,
|
|
1277
|
+
passed: 0,
|
|
1278
|
+
skipped: 0
|
|
1279
|
+
};
|
|
1280
|
+
case Pass$1:
|
|
1281
|
+
return {
|
|
1282
|
+
failed: 0,
|
|
1283
|
+
passed: 1,
|
|
1284
|
+
skipped: 0
|
|
1285
|
+
};
|
|
1286
|
+
case Skip$1:
|
|
1287
|
+
return {
|
|
1288
|
+
failed: 0,
|
|
1289
|
+
passed: 0,
|
|
1290
|
+
skipped: 1
|
|
1291
|
+
};
|
|
1292
|
+
default:
|
|
1293
|
+
return {
|
|
1294
|
+
failed: 0,
|
|
1295
|
+
passed: 0,
|
|
1296
|
+
skipped: 0
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
const getAllTestsUrl = (port, filter, traceFocus) => {
|
|
1301
|
+
const url = new URL(`http://localhost:${port}/tests/_all.html`);
|
|
1302
|
+
if (traceFocus) {
|
|
1303
|
+
url.searchParams.set('traceFocus', 'true');
|
|
1304
|
+
}
|
|
1305
|
+
if (filter) {
|
|
1306
|
+
url.searchParams.set('filter', filter);
|
|
1307
|
+
}
|
|
1308
|
+
return url.href;
|
|
1309
|
+
};
|
|
1310
|
+
const isObject = value => {
|
|
1311
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
1312
|
+
};
|
|
1313
|
+
const parseStatus = value => {
|
|
1314
|
+
switch (value) {
|
|
1315
|
+
case 'fail':
|
|
1316
|
+
return Fail$1;
|
|
1317
|
+
case 'pass':
|
|
1318
|
+
return Pass$1;
|
|
1319
|
+
case 'skip':
|
|
1320
|
+
return Skip$1;
|
|
1321
|
+
default:
|
|
1322
|
+
throw new Error(`expected status to be pass, skip, or fail`);
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
const parseString = (value, field) => {
|
|
1326
|
+
if (typeof value !== 'string') {
|
|
1327
|
+
throw new TypeError(`expected ${field} to be a string`);
|
|
1328
|
+
}
|
|
1329
|
+
return value;
|
|
1330
|
+
};
|
|
1331
|
+
const parseOptionalString = (value, field) => {
|
|
1332
|
+
if (value === undefined) {
|
|
1333
|
+
return '';
|
|
1334
|
+
}
|
|
1335
|
+
return parseString(value, field);
|
|
1336
|
+
};
|
|
1337
|
+
const parseNumber = (value, field) => {
|
|
1338
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
1339
|
+
throw new TypeError(`expected ${field} to be a finite number`);
|
|
1340
|
+
}
|
|
1341
|
+
return value;
|
|
1342
|
+
};
|
|
1343
|
+
const parseTestResult = value => {
|
|
1344
|
+
if (!isObject(value)) {
|
|
1345
|
+
throw new TypeError(`expected test result to be an object`);
|
|
1346
|
+
}
|
|
1347
|
+
return {
|
|
1348
|
+
end: parseNumber(value.end, 'end'),
|
|
1349
|
+
error: parseOptionalString(value.error, 'error'),
|
|
1350
|
+
name: parseString(value.name, 'name'),
|
|
1351
|
+
start: parseNumber(value.start, 'start'),
|
|
1352
|
+
status: parseStatus(value.status)
|
|
1353
|
+
};
|
|
1354
|
+
};
|
|
1355
|
+
const parseTestResults = text => {
|
|
1356
|
+
const parsed = JSON.parse(text);
|
|
1357
|
+
if (!Array.isArray(parsed)) {
|
|
1358
|
+
throw new TypeError(`expected TestResults JSON to be an array`);
|
|
1359
|
+
}
|
|
1360
|
+
return parsed.map(parseTestResult);
|
|
1361
|
+
};
|
|
1362
|
+
const getFailedAllTestsResult = (error, start) => {
|
|
1363
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1364
|
+
return {
|
|
1365
|
+
end: performance.now(),
|
|
1366
|
+
error: message,
|
|
1367
|
+
name: '_all.html',
|
|
1368
|
+
start,
|
|
1369
|
+
status: Fail$1
|
|
1370
|
+
};
|
|
1371
|
+
};
|
|
1372
|
+
const readTestResultsText = async (page, timeout) => {
|
|
1373
|
+
const testResults = page.locator(testResultsSelector);
|
|
1374
|
+
await testResults.waitFor({
|
|
1375
|
+
state: 'attached',
|
|
1376
|
+
timeout
|
|
1377
|
+
});
|
|
1378
|
+
await page.waitForFunction(selector => {
|
|
1379
|
+
const element = document.querySelector(selector);
|
|
1380
|
+
const text = element?.textContent;
|
|
1381
|
+
return typeof text === 'string' && text.trim().length > 0;
|
|
1382
|
+
}, testResultsSelector, {
|
|
1383
|
+
timeout
|
|
1384
|
+
});
|
|
1385
|
+
const text = await testResults.textContent();
|
|
1386
|
+
if (!text || text.trim().length === 0) {
|
|
1387
|
+
throw new Error(`TestResults is empty`);
|
|
1388
|
+
}
|
|
1389
|
+
return text;
|
|
1390
|
+
};
|
|
1391
|
+
const runTestsWithReusedPage = async ({
|
|
1392
|
+
filter,
|
|
1393
|
+
onFinalResult,
|
|
1394
|
+
onResult,
|
|
1395
|
+
page,
|
|
1396
|
+
port,
|
|
1397
|
+
timeout,
|
|
1398
|
+
traceFocus
|
|
1399
|
+
}) => {
|
|
1400
|
+
const start = performance.now();
|
|
1401
|
+
let results;
|
|
1402
|
+
try {
|
|
1403
|
+
const url = getAllTestsUrl(port, filter, traceFocus ?? false);
|
|
1404
|
+
await page.goto(url, {
|
|
1405
|
+
waitUntil: 'networkidle'
|
|
1406
|
+
});
|
|
1407
|
+
const text = await readTestResultsText(page, timeout);
|
|
1408
|
+
results = parseTestResults(text);
|
|
1409
|
+
} catch (error) {
|
|
1410
|
+
results = [getFailedAllTestsResult(error, start)];
|
|
1411
|
+
}
|
|
1412
|
+
let failed = 0;
|
|
1413
|
+
let passed = 0;
|
|
1414
|
+
let skipped = 0;
|
|
1415
|
+
for (const result of results) {
|
|
1416
|
+
await onResult(result);
|
|
1256
1417
|
const resultCounts = getResultCounts(result.status);
|
|
1257
1418
|
failed += resultCounts.failed;
|
|
1258
1419
|
passed += resultCounts.passed;
|
|
@@ -1741,8 +1902,9 @@ const tearDownTests = async ({
|
|
|
1741
1902
|
* @param {string} serverPath
|
|
1742
1903
|
* @param {boolean} traceFocus
|
|
1743
1904
|
* @param {string} filter
|
|
1905
|
+
* @param {boolean} reusePage
|
|
1744
1906
|
*/
|
|
1745
|
-
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter) => {
|
|
1907
|
+
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage) => {
|
|
1746
1908
|
string(extensionPath);
|
|
1747
1909
|
string(testPath);
|
|
1748
1910
|
string(cwd);
|
|
@@ -1750,13 +1912,13 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
1750
1912
|
boolean(headless);
|
|
1751
1913
|
number(timeout);
|
|
1752
1914
|
object(runtimeOptions);
|
|
1915
|
+
boolean(reusePage);
|
|
1753
1916
|
const rpc = get(Cli);
|
|
1754
1917
|
const controller = new AbortController();
|
|
1755
1918
|
const {
|
|
1756
1919
|
signal
|
|
1757
1920
|
} = controller;
|
|
1758
1921
|
const testSrc = join(testPath, 'src');
|
|
1759
|
-
const tests = await getTests(testSrc);
|
|
1760
1922
|
const onResult = async result => {
|
|
1761
1923
|
await rpc.invoke(HandleResult, result);
|
|
1762
1924
|
};
|
|
@@ -1767,6 +1929,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
1767
1929
|
filter
|
|
1768
1930
|
};
|
|
1769
1931
|
if (runtimeOptions.type === 'electron') {
|
|
1932
|
+
const tests = await getTests(testSrc);
|
|
1770
1933
|
await using electron = await startElectron({
|
|
1771
1934
|
runtimeOptions,
|
|
1772
1935
|
signal
|
|
@@ -1797,6 +1960,23 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
1797
1960
|
signal,
|
|
1798
1961
|
testPath
|
|
1799
1962
|
});
|
|
1963
|
+
if (reusePage) {
|
|
1964
|
+
await runTestsWithReusedPage({
|
|
1965
|
+
...filterOption,
|
|
1966
|
+
onFinalResult,
|
|
1967
|
+
onResult,
|
|
1968
|
+
page,
|
|
1969
|
+
port,
|
|
1970
|
+
timeout,
|
|
1971
|
+
traceFocus
|
|
1972
|
+
});
|
|
1973
|
+
await tearDownTests({
|
|
1974
|
+
child,
|
|
1975
|
+
controller
|
|
1976
|
+
});
|
|
1977
|
+
return;
|
|
1978
|
+
}
|
|
1979
|
+
const tests = await getTests(testSrc);
|
|
1800
1980
|
await runTests({
|
|
1801
1981
|
...filterOption,
|
|
1802
1982
|
headless,
|