@lvce-editor/test-with-playwright-worker 22.40.5 → 22.40.7
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 +181 -59
- package/package.json +3 -3
package/dist/workerMain.js
CHANGED
|
@@ -1566,6 +1566,41 @@ const compareSvgScreenshot = async ({
|
|
|
1566
1566
|
});
|
|
1567
1567
|
};
|
|
1568
1568
|
|
|
1569
|
+
const formatConsoleMessage = (type, message) => {
|
|
1570
|
+
const {
|
|
1571
|
+
columnNumber,
|
|
1572
|
+
lineNumber,
|
|
1573
|
+
url
|
|
1574
|
+
} = message.location();
|
|
1575
|
+
const location = url ? ` (${url}:${lineNumber}:${columnNumber})` : '';
|
|
1576
|
+
return `console ${type}: ${message.text()}${location}`;
|
|
1577
|
+
};
|
|
1578
|
+
const createPageMessages = page => {
|
|
1579
|
+
const messages = [];
|
|
1580
|
+
const onConsole = message => {
|
|
1581
|
+
const type = message.type();
|
|
1582
|
+
if (type === 'warning' || type === 'error') {
|
|
1583
|
+
messages.push(formatConsoleMessage(type, message));
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1586
|
+
const onPageError = error => {
|
|
1587
|
+
messages.push('uncaught page error: ' + (error.stack || error.message));
|
|
1588
|
+
};
|
|
1589
|
+
page.on('console', onConsole);
|
|
1590
|
+
page.on('pageerror', onPageError);
|
|
1591
|
+
return {
|
|
1592
|
+
dispose: () => {
|
|
1593
|
+
page.off('console', onConsole);
|
|
1594
|
+
page.off('pageerror', onPageError);
|
|
1595
|
+
},
|
|
1596
|
+
messages
|
|
1597
|
+
};
|
|
1598
|
+
};
|
|
1599
|
+
const formatPageMessages = messages => {
|
|
1600
|
+
const formattedMessages = messages.map(message => ' ' + message).join('\n');
|
|
1601
|
+
return `Browser console messages:\n${formattedMessages}`;
|
|
1602
|
+
};
|
|
1603
|
+
|
|
1569
1604
|
const Pass$1 = 1;
|
|
1570
1605
|
const Skip$1 = 2;
|
|
1571
1606
|
const Fail$1 = 3;
|
|
@@ -1594,6 +1629,7 @@ const withTimeout = async (promise, timeout) => {
|
|
|
1594
1629
|
};
|
|
1595
1630
|
const runElectronTest = async ({
|
|
1596
1631
|
electronApp,
|
|
1632
|
+
failOnConsoleMessages,
|
|
1597
1633
|
page,
|
|
1598
1634
|
svgScreenshotOptions,
|
|
1599
1635
|
test,
|
|
@@ -1601,53 +1637,67 @@ const runElectronTest = async ({
|
|
|
1601
1637
|
timeout
|
|
1602
1638
|
}) => {
|
|
1603
1639
|
const start = performance.now();
|
|
1640
|
+
const pageMessages = failOnConsoleMessages ? createPageMessages(page) : undefined;
|
|
1641
|
+
let result;
|
|
1604
1642
|
try {
|
|
1605
1643
|
const testModule = await importTestModule(testSrc, test);
|
|
1606
1644
|
if (testModule.skip) {
|
|
1607
1645
|
const end = performance.now();
|
|
1608
|
-
|
|
1646
|
+
result = {
|
|
1609
1647
|
end,
|
|
1610
1648
|
error: '',
|
|
1611
1649
|
name: test,
|
|
1612
1650
|
start,
|
|
1613
1651
|
status: Skip$1
|
|
1614
1652
|
};
|
|
1653
|
+
} else {
|
|
1654
|
+
const {
|
|
1655
|
+
expect
|
|
1656
|
+
} = await import('@playwright/test');
|
|
1657
|
+
await withTimeout(testModule.test({
|
|
1658
|
+
electronApp,
|
|
1659
|
+
expect,
|
|
1660
|
+
Locator: page.locator.bind(page),
|
|
1661
|
+
page
|
|
1662
|
+
}), timeout);
|
|
1663
|
+
if (svgScreenshotOptions) {
|
|
1664
|
+
await captureSvgScreenshot({
|
|
1665
|
+
options: svgScreenshotOptions,
|
|
1666
|
+
page,
|
|
1667
|
+
test
|
|
1668
|
+
});
|
|
1669
|
+
}
|
|
1670
|
+
const end = performance.now();
|
|
1671
|
+
result = {
|
|
1672
|
+
end,
|
|
1673
|
+
error: '',
|
|
1674
|
+
name: test,
|
|
1675
|
+
start,
|
|
1676
|
+
status: Pass$1
|
|
1677
|
+
};
|
|
1615
1678
|
}
|
|
1616
|
-
const {
|
|
1617
|
-
expect
|
|
1618
|
-
} = await import('@playwright/test');
|
|
1619
|
-
await withTimeout(testModule.test({
|
|
1620
|
-
electronApp,
|
|
1621
|
-
expect,
|
|
1622
|
-
Locator: page.locator.bind(page),
|
|
1623
|
-
page
|
|
1624
|
-
}), timeout);
|
|
1625
|
-
if (svgScreenshotOptions) {
|
|
1626
|
-
await captureSvgScreenshot({
|
|
1627
|
-
options: svgScreenshotOptions,
|
|
1628
|
-
page,
|
|
1629
|
-
test
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
const end = performance.now();
|
|
1633
|
-
return {
|
|
1634
|
-
end,
|
|
1635
|
-
error: '',
|
|
1636
|
-
name: test,
|
|
1637
|
-
start,
|
|
1638
|
-
status: Pass$1
|
|
1639
|
-
};
|
|
1640
1679
|
} catch (error) {
|
|
1641
1680
|
const end = performance.now();
|
|
1642
1681
|
const message = error instanceof Error ? error.message : String(error);
|
|
1643
|
-
|
|
1682
|
+
result = {
|
|
1644
1683
|
end,
|
|
1645
1684
|
error: message,
|
|
1646
1685
|
name: test,
|
|
1647
1686
|
start,
|
|
1648
1687
|
status: Fail$1
|
|
1649
1688
|
};
|
|
1689
|
+
} finally {
|
|
1690
|
+
pageMessages?.dispose();
|
|
1691
|
+
}
|
|
1692
|
+
if (pageMessages && pageMessages.messages.length > 0) {
|
|
1693
|
+
const messages = formatPageMessages(pageMessages.messages);
|
|
1694
|
+
result = {
|
|
1695
|
+
...result,
|
|
1696
|
+
error: result.error ? `${result.error}\n${messages}` : messages,
|
|
1697
|
+
status: Fail$1
|
|
1698
|
+
};
|
|
1650
1699
|
}
|
|
1700
|
+
return result;
|
|
1651
1701
|
};
|
|
1652
1702
|
|
|
1653
1703
|
const getResultCounts$2 = status => {
|
|
@@ -1680,6 +1730,7 @@ const getResultCounts$2 = status => {
|
|
|
1680
1730
|
};
|
|
1681
1731
|
const runElectronTests = async ({
|
|
1682
1732
|
electronApp,
|
|
1733
|
+
failOnConsoleMessages,
|
|
1683
1734
|
filter,
|
|
1684
1735
|
onFinalResult,
|
|
1685
1736
|
onResult,
|
|
@@ -1697,6 +1748,7 @@ const runElectronTests = async ({
|
|
|
1697
1748
|
for (const test of filteredTests) {
|
|
1698
1749
|
const result = await runElectronTest({
|
|
1699
1750
|
electronApp,
|
|
1751
|
+
failOnConsoleMessages,
|
|
1700
1752
|
page,
|
|
1701
1753
|
test,
|
|
1702
1754
|
testSrc,
|
|
@@ -1775,6 +1827,7 @@ const navigateToTest = async (page, url, browser) => {
|
|
|
1775
1827
|
};
|
|
1776
1828
|
const runTest = async ({
|
|
1777
1829
|
browser,
|
|
1830
|
+
failOnConsoleMessages,
|
|
1778
1831
|
page,
|
|
1779
1832
|
port,
|
|
1780
1833
|
svgScreenshotOptions,
|
|
@@ -1785,6 +1838,8 @@ const runTest = async ({
|
|
|
1785
1838
|
traceRendererWorker
|
|
1786
1839
|
}) => {
|
|
1787
1840
|
const start = performance.now();
|
|
1841
|
+
const pageMessages = failOnConsoleMessages ? createPageMessages(page) : undefined;
|
|
1842
|
+
let result;
|
|
1788
1843
|
try {
|
|
1789
1844
|
const url = getUrlFromTestFile(test, port, traceFocus ?? false, traceRendererWorker ?? false);
|
|
1790
1845
|
await navigateToTest(page, url, browser);
|
|
@@ -1805,7 +1860,7 @@ const runTest = async ({
|
|
|
1805
1860
|
});
|
|
1806
1861
|
}
|
|
1807
1862
|
const end = performance.now();
|
|
1808
|
-
|
|
1863
|
+
result = {
|
|
1809
1864
|
// @ts-ignore
|
|
1810
1865
|
...testState,
|
|
1811
1866
|
end,
|
|
@@ -1816,14 +1871,25 @@ const runTest = async ({
|
|
|
1816
1871
|
} catch (error) {
|
|
1817
1872
|
const end = performance.now();
|
|
1818
1873
|
const message = error instanceof Error ? error.message : String(error);
|
|
1819
|
-
|
|
1874
|
+
result = {
|
|
1820
1875
|
end,
|
|
1821
1876
|
error: message,
|
|
1822
1877
|
name: test,
|
|
1823
1878
|
start,
|
|
1824
1879
|
status: Fail$1
|
|
1825
1880
|
};
|
|
1881
|
+
} finally {
|
|
1882
|
+
pageMessages?.dispose();
|
|
1883
|
+
}
|
|
1884
|
+
if (pageMessages && pageMessages.messages.length > 0) {
|
|
1885
|
+
const messages = formatPageMessages(pageMessages.messages);
|
|
1886
|
+
result = {
|
|
1887
|
+
...result,
|
|
1888
|
+
error: result.error ? `${result.error}\n${messages}` : messages,
|
|
1889
|
+
status: Fail$1
|
|
1890
|
+
};
|
|
1826
1891
|
}
|
|
1892
|
+
return result;
|
|
1827
1893
|
};
|
|
1828
1894
|
|
|
1829
1895
|
const getResultCounts$1 = status => {
|
|
@@ -1861,6 +1927,8 @@ const getResultCounts$1 = status => {
|
|
|
1861
1927
|
*/
|
|
1862
1928
|
const runTests = async ({
|
|
1863
1929
|
browser = 'chromium',
|
|
1930
|
+
createPage,
|
|
1931
|
+
failOnConsoleMessages,
|
|
1864
1932
|
filter,
|
|
1865
1933
|
headless,
|
|
1866
1934
|
onFinalResult,
|
|
@@ -1881,32 +1949,39 @@ const runTests = async ({
|
|
|
1881
1949
|
// Filter tests if a filter is provided
|
|
1882
1950
|
const filteredTests = filter ? tests.filter(test => test.includes(filter)) : tests;
|
|
1883
1951
|
for (const test of filteredTests) {
|
|
1884
|
-
const
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
page,
|
|
1901
|
-
test
|
|
1952
|
+
const testPage = await createPage?.();
|
|
1953
|
+
const currentPage = testPage?.page ?? page;
|
|
1954
|
+
try {
|
|
1955
|
+
const result = await runTest({
|
|
1956
|
+
browser,
|
|
1957
|
+
failOnConsoleMessages,
|
|
1958
|
+
page: currentPage,
|
|
1959
|
+
port,
|
|
1960
|
+
test,
|
|
1961
|
+
testSrc,
|
|
1962
|
+
timeout,
|
|
1963
|
+
traceFocus: traceFocus ?? false,
|
|
1964
|
+
traceRendererWorker: rendererWorkerTraceDirectory !== undefined,
|
|
1965
|
+
...(svgScreenshotOptions && {
|
|
1966
|
+
svgScreenshotOptions
|
|
1967
|
+
})
|
|
1902
1968
|
});
|
|
1969
|
+
if (rendererWorkerTraceDirectory) {
|
|
1970
|
+
await exportTrace({
|
|
1971
|
+
directory: rendererWorkerTraceDirectory,
|
|
1972
|
+
page: currentPage,
|
|
1973
|
+
test
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
await onResult(result);
|
|
1977
|
+
// @ts-ignore
|
|
1978
|
+
const resultCounts = getResultCounts$1(result.status);
|
|
1979
|
+
failed += resultCounts.failed;
|
|
1980
|
+
passed += resultCounts.passed;
|
|
1981
|
+
skipped += resultCounts.skipped;
|
|
1982
|
+
} finally {
|
|
1983
|
+
await testPage?.dispose();
|
|
1903
1984
|
}
|
|
1904
|
-
await onResult(result);
|
|
1905
|
-
// @ts-ignore
|
|
1906
|
-
const resultCounts = getResultCounts$1(result.status);
|
|
1907
|
-
failed += resultCounts.failed;
|
|
1908
|
-
passed += resultCounts.passed;
|
|
1909
|
-
skipped += resultCounts.skipped;
|
|
1910
1985
|
}
|
|
1911
1986
|
const end = performance.now();
|
|
1912
1987
|
await onFinalResult({
|
|
@@ -2043,6 +2118,7 @@ const readTestResultsText = async (page, timeout) => {
|
|
|
2043
2118
|
};
|
|
2044
2119
|
const runTestsWithReusedPage = async ({
|
|
2045
2120
|
browser,
|
|
2121
|
+
failOnConsoleMessages,
|
|
2046
2122
|
filter,
|
|
2047
2123
|
onFinalResult,
|
|
2048
2124
|
onResult,
|
|
@@ -2053,6 +2129,7 @@ const runTestsWithReusedPage = async ({
|
|
|
2053
2129
|
traceFocus
|
|
2054
2130
|
}) => {
|
|
2055
2131
|
const start = performance.now();
|
|
2132
|
+
const pageMessages = failOnConsoleMessages ? createPageMessages(page) : undefined;
|
|
2056
2133
|
let results;
|
|
2057
2134
|
try {
|
|
2058
2135
|
const url = getAllTestsUrl(port, filter, traceFocus ?? false, rendererWorkerTraceDirectory !== undefined);
|
|
@@ -2065,12 +2142,25 @@ const runTestsWithReusedPage = async ({
|
|
|
2065
2142
|
} catch (error) {
|
|
2066
2143
|
results = [getFailedAllTestsResult(error, start)];
|
|
2067
2144
|
}
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2145
|
+
try {
|
|
2146
|
+
if (rendererWorkerTraceDirectory) {
|
|
2147
|
+
await exportTrace({
|
|
2148
|
+
directory: rendererWorkerTraceDirectory,
|
|
2149
|
+
page,
|
|
2150
|
+
test: '_all.html'
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
} finally {
|
|
2154
|
+
pageMessages?.dispose();
|
|
2155
|
+
}
|
|
2156
|
+
if (pageMessages && pageMessages.messages.length > 0) {
|
|
2157
|
+
results = [...results, {
|
|
2158
|
+
end: performance.now(),
|
|
2159
|
+
error: formatPageMessages(pageMessages.messages),
|
|
2160
|
+
name: '_all.html (console messages)',
|
|
2161
|
+
start,
|
|
2162
|
+
status: Fail$1
|
|
2163
|
+
}];
|
|
2074
2164
|
}
|
|
2075
2165
|
let failed = 0;
|
|
2076
2166
|
let passed = 0;
|
|
@@ -2924,7 +3014,7 @@ const assertCoverageOptions = (coverageTarget, coverageInclude, coverageThreshol
|
|
|
2924
3014
|
* @param {boolean} coverage
|
|
2925
3015
|
* @param {boolean} traceRendererWorker
|
|
2926
3016
|
*/
|
|
2927
|
-
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage, svgScreenshotOptions, coverage, coverageInclude, coverageTarget, coverageThreshold, traceRendererWorker) => {
|
|
3017
|
+
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage, svgScreenshotOptions, coverage, coverageInclude, coverageTarget, coverageThreshold, traceRendererWorker, failOnConsoleMessages) => {
|
|
2928
3018
|
string(extensionPath);
|
|
2929
3019
|
string(testPath);
|
|
2930
3020
|
string(cwd);
|
|
@@ -2936,6 +3026,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
2936
3026
|
boolean(coverage);
|
|
2937
3027
|
assertCoverageOptions(coverageTarget, coverageInclude, coverageThreshold);
|
|
2938
3028
|
boolean(traceRendererWorker);
|
|
3029
|
+
boolean(failOnConsoleMessages);
|
|
2939
3030
|
if (svgScreenshotOptions !== undefined) {
|
|
2940
3031
|
object(svgScreenshotOptions);
|
|
2941
3032
|
}
|
|
@@ -2981,6 +3072,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
2981
3072
|
await runElectronTests({
|
|
2982
3073
|
...filterOption,
|
|
2983
3074
|
electronApp: electron.electronApp,
|
|
3075
|
+
failOnConsoleMessages,
|
|
2984
3076
|
onFinalResult,
|
|
2985
3077
|
onResult,
|
|
2986
3078
|
page: electron.page,
|
|
@@ -3035,6 +3127,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3035
3127
|
await runTestsWithReusedPage({
|
|
3036
3128
|
browser,
|
|
3037
3129
|
...filterOption,
|
|
3130
|
+
failOnConsoleMessages,
|
|
3038
3131
|
onFinalResult,
|
|
3039
3132
|
onResult,
|
|
3040
3133
|
page,
|
|
@@ -3050,6 +3143,31 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3050
3143
|
return;
|
|
3051
3144
|
}
|
|
3052
3145
|
const tests = await getTests(testSrc);
|
|
3146
|
+
let initialBrowserAvailable = true;
|
|
3147
|
+
const createPage = browser === 'webkit' ? async () => {
|
|
3148
|
+
signal.throwIfAborted();
|
|
3149
|
+
if (initialBrowserAvailable) {
|
|
3150
|
+
initialBrowserAvailable = false;
|
|
3151
|
+
return {
|
|
3152
|
+
dispose,
|
|
3153
|
+
page
|
|
3154
|
+
};
|
|
3155
|
+
}
|
|
3156
|
+
const nextBrowser = await startBrowser({
|
|
3157
|
+
browser,
|
|
3158
|
+
headless,
|
|
3159
|
+
signal
|
|
3160
|
+
});
|
|
3161
|
+
try {
|
|
3162
|
+
if (traceRendererWorker) {
|
|
3163
|
+
await nextBrowser.page.addInitScript(install);
|
|
3164
|
+
}
|
|
3165
|
+
return nextBrowser;
|
|
3166
|
+
} catch (error) {
|
|
3167
|
+
await nextBrowser.dispose();
|
|
3168
|
+
throw error;
|
|
3169
|
+
}
|
|
3170
|
+
} : undefined;
|
|
3053
3171
|
await runWithJavascriptCoverage({
|
|
3054
3172
|
coverage,
|
|
3055
3173
|
cwd,
|
|
@@ -3057,6 +3175,10 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3057
3175
|
run: async () => {
|
|
3058
3176
|
await runTests({
|
|
3059
3177
|
browser,
|
|
3178
|
+
failOnConsoleMessages,
|
|
3179
|
+
...(createPage && {
|
|
3180
|
+
createPage
|
|
3181
|
+
}),
|
|
3060
3182
|
...filterOption,
|
|
3061
3183
|
headless,
|
|
3062
3184
|
onFinalResult,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/test-with-playwright-worker",
|
|
3
|
-
"version": "22.40.
|
|
3
|
+
"version": "22.40.7",
|
|
4
4
|
"description": "Worker package for test-with-playwright",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"type": "module",
|
|
13
13
|
"main": "dist/workerMain.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@playwright/test": "1.
|
|
15
|
+
"@playwright/test": "1.64.0",
|
|
16
16
|
"get-port": "^7.2.0",
|
|
17
|
-
"playwright-core": "^1.
|
|
17
|
+
"playwright-core": "^1.64.0"
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=24"
|