@lvce-editor/test-with-playwright-worker 22.42.0 → 22.43.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/svgScreenshot.js +2 -2
- package/dist/workerMain.js +137 -10
- package/package.json +1 -1
package/dist/svgScreenshot.js
CHANGED
|
@@ -7108,9 +7108,9 @@ var SvgScreenshot = (function (exports) {
|
|
|
7108
7108
|
}`;
|
|
7109
7109
|
document.head.append(freezeStyle);
|
|
7110
7110
|
try {
|
|
7111
|
-
const target = selector ? document.querySelector(selector) : document.body;
|
|
7111
|
+
const target = typeof selector === 'string' ? document.querySelector(selector) : selector || document.body;
|
|
7112
7112
|
if (!target) {
|
|
7113
|
-
throw new Error(`SVG screenshot selector did not match an element: ${selector}`);
|
|
7113
|
+
throw new Error(`SVG screenshot selector did not match an element: ${typeof selector === 'string' ? selector : '(detached target)'}`);
|
|
7114
7114
|
}
|
|
7115
7115
|
const root = document.documentElement;
|
|
7116
7116
|
const captureArea = selector ? target.getBoundingClientRect() : new DOMRect(0, 0, root.clientWidth, root.clientHeight);
|
package/dist/workerMain.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { join, dirname, basename, extname } from 'node:path';
|
|
2
|
-
import { readFile, writeFile, readdir, rm, mkdir, access, mkdtemp } from 'node:fs/promises';
|
|
1
|
+
import { join, dirname, basename, extname, resolve as resolve$1, isAbsolute } from 'node:path';
|
|
2
|
+
import { readFile, writeFile, readdir, rm, mkdir, access, lstat, mkdtemp } from 'node:fs/promises';
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
4
|
import net from 'node:net';
|
|
5
5
|
import os, { tmpdir } from 'node:os';
|
|
@@ -1219,7 +1219,7 @@ const get = id => {
|
|
|
1219
1219
|
};
|
|
1220
1220
|
|
|
1221
1221
|
// This function is serialized by Playwright and must not close over module bindings.
|
|
1222
|
-
const install = () => {
|
|
1222
|
+
const install$1 = () => {
|
|
1223
1223
|
const limit = 5000;
|
|
1224
1224
|
const payloadLimit = 8192;
|
|
1225
1225
|
const entries = [];
|
|
@@ -1528,12 +1528,13 @@ const captureSvgScreenshot = async ({
|
|
|
1528
1528
|
});
|
|
1529
1529
|
};
|
|
1530
1530
|
const compareSvgScreenshot = async ({
|
|
1531
|
+
fixturePath,
|
|
1531
1532
|
options,
|
|
1532
1533
|
svg,
|
|
1533
1534
|
test
|
|
1534
1535
|
}) => {
|
|
1535
1536
|
const formattedSvg = formatSvg(svg);
|
|
1536
|
-
const snapshotPath = join(options.directory, getSnapshotName(test, options.name));
|
|
1537
|
+
const snapshotPath = fixturePath || join(options.directory, getSnapshotName(test, options.name));
|
|
1537
1538
|
const actualPath = `${snapshotPath}.actual`;
|
|
1538
1539
|
if (options.update) {
|
|
1539
1540
|
await mkdir(options.directory, {
|
|
@@ -1799,6 +1800,122 @@ const getTestState = (testOverlayState, text) => {
|
|
|
1799
1800
|
}
|
|
1800
1801
|
};
|
|
1801
1802
|
|
|
1803
|
+
const compare = async (path, actual, update) => {
|
|
1804
|
+
const actualPath = `${path}.actual.png`;
|
|
1805
|
+
if (update) {
|
|
1806
|
+
await mkdir(dirname(path), {
|
|
1807
|
+
recursive: true
|
|
1808
|
+
});
|
|
1809
|
+
await writeFile(path, actual);
|
|
1810
|
+
await rm(actualPath, {
|
|
1811
|
+
force: true
|
|
1812
|
+
});
|
|
1813
|
+
return;
|
|
1814
|
+
}
|
|
1815
|
+
let expected;
|
|
1816
|
+
try {
|
|
1817
|
+
expected = await readFile(path);
|
|
1818
|
+
} catch (error) {
|
|
1819
|
+
if (isEnoentError(error)) {
|
|
1820
|
+
await mkdir(dirname(path), {
|
|
1821
|
+
recursive: true
|
|
1822
|
+
});
|
|
1823
|
+
await writeFile(actualPath, actual);
|
|
1824
|
+
throw new Error(`[SCREENSHOT_MISSING] PNG screenshot is missing: ${path}. Actual output: ${actualPath}. Run with --update-screenshots to create it.`);
|
|
1825
|
+
}
|
|
1826
|
+
throw error;
|
|
1827
|
+
}
|
|
1828
|
+
if (!actual.equals(expected)) {
|
|
1829
|
+
await writeFile(actualPath, actual);
|
|
1830
|
+
throw new Error(`[SCREENSHOT_MISMATCH] PNG screenshot differs: ${path}. Actual output: ${actualPath}`);
|
|
1831
|
+
}
|
|
1832
|
+
await rm(actualPath, {
|
|
1833
|
+
force: true
|
|
1834
|
+
});
|
|
1835
|
+
};
|
|
1836
|
+
|
|
1837
|
+
const installed = new WeakSet();
|
|
1838
|
+
const resolveFixture = async (directory, uri) => {
|
|
1839
|
+
if (typeof uri !== 'string' || !uri.endsWith('.svg') && !uri.endsWith('.png') || isAbsolute(uri) || uri.includes('\\') || uri.includes(':') || uri.includes('\0') || uri.split('/').some(part => !part || part === '.' || part === '..')) {
|
|
1840
|
+
throw new Error(`[SCREENSHOT_INVALID_URI] Expected a relative .svg or .png path inside e2e/fixtures: ${String(uri)}`);
|
|
1841
|
+
}
|
|
1842
|
+
let current = resolve$1(directory);
|
|
1843
|
+
for (const part of ['', ...uri.split('/')]) {
|
|
1844
|
+
current = join(current, part);
|
|
1845
|
+
try {
|
|
1846
|
+
const stat = await lstat(current);
|
|
1847
|
+
if (stat.isSymbolicLink()) {
|
|
1848
|
+
throw new Error(`[SCREENSHOT_INVALID_URI] Symbolic links are not supported: ${uri}`);
|
|
1849
|
+
}
|
|
1850
|
+
} catch (error) {
|
|
1851
|
+
if (!isEnoentError(error)) {
|
|
1852
|
+
throw error;
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return current;
|
|
1857
|
+
};
|
|
1858
|
+
const install = async (page, testPath, update) => {
|
|
1859
|
+
if (installed.has(page)) {
|
|
1860
|
+
return;
|
|
1861
|
+
}
|
|
1862
|
+
const directory = resolve$1(testPath, 'fixtures');
|
|
1863
|
+
let previous = Promise.resolve();
|
|
1864
|
+
await page.exposeBinding('lvceMatchScreenshot', async ({
|
|
1865
|
+
frame
|
|
1866
|
+
}, uri, token) => {
|
|
1867
|
+
const run = async () => {
|
|
1868
|
+
const fixturePath = await resolveFixture(directory, uri);
|
|
1869
|
+
const element = await frame.evaluateHandle(token => {
|
|
1870
|
+
const host = globalThis;
|
|
1871
|
+
return host.lvceScreenshotTargets?.get(token) || null;
|
|
1872
|
+
}, token);
|
|
1873
|
+
try {
|
|
1874
|
+
if (!element.asElement()) {
|
|
1875
|
+
throw new Error(`[SCREENSHOT_ELEMENT_NOT_FOUND] ${String(uri)}`);
|
|
1876
|
+
}
|
|
1877
|
+
if (fixturePath.endsWith('.png')) {
|
|
1878
|
+
await resolveFixture(directory, `${String(uri)}.actual.png`);
|
|
1879
|
+
const png = await element.asElement().screenshot({
|
|
1880
|
+
animations: 'disabled',
|
|
1881
|
+
caret: 'hide'
|
|
1882
|
+
});
|
|
1883
|
+
await compare(fixturePath, png, update);
|
|
1884
|
+
} else {
|
|
1885
|
+
const svg = await capture(frame, element.asElement());
|
|
1886
|
+
await compareSvgScreenshot({
|
|
1887
|
+
fixturePath,
|
|
1888
|
+
options: {
|
|
1889
|
+
directory: dirname(fixturePath),
|
|
1890
|
+
name: '',
|
|
1891
|
+
update
|
|
1892
|
+
},
|
|
1893
|
+
svg,
|
|
1894
|
+
test: ''
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
} finally {
|
|
1898
|
+
await element.dispose();
|
|
1899
|
+
}
|
|
1900
|
+
};
|
|
1901
|
+
// Capture changes document styles temporarily; serialize concurrent assertions on this page.
|
|
1902
|
+
const prior = previous;
|
|
1903
|
+
const result = (async () => {
|
|
1904
|
+
await prior;
|
|
1905
|
+
await run();
|
|
1906
|
+
})();
|
|
1907
|
+
previous = (async () => {
|
|
1908
|
+
try {
|
|
1909
|
+
await result;
|
|
1910
|
+
} catch {
|
|
1911
|
+
// A failed assertion must not prevent later requests from being handled.
|
|
1912
|
+
}
|
|
1913
|
+
})();
|
|
1914
|
+
return result;
|
|
1915
|
+
});
|
|
1916
|
+
installed.add(page);
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1802
1919
|
// Keep the server bind address and browser URLs on the same address family.
|
|
1803
1920
|
// Chromium can fall back to IPv4 even when Node resolved localhost to ::1.
|
|
1804
1921
|
const testServerHost = '127.0.0.1';
|
|
@@ -1835,12 +1952,14 @@ const runTest = async ({
|
|
|
1835
1952
|
testSrc,
|
|
1836
1953
|
timeout,
|
|
1837
1954
|
traceFocus,
|
|
1838
|
-
traceRendererWorker
|
|
1955
|
+
traceRendererWorker,
|
|
1956
|
+
updateSvgScreenshots = false
|
|
1839
1957
|
}) => {
|
|
1840
1958
|
const start = performance.now();
|
|
1841
1959
|
const pageMessages = failOnConsoleMessages ? createPageMessages(page) : undefined;
|
|
1842
1960
|
let result;
|
|
1843
1961
|
try {
|
|
1962
|
+
await install(page, dirname(testSrc), updateSvgScreenshots);
|
|
1844
1963
|
const url = getUrlFromTestFile(test, port, traceFocus ?? false, traceRendererWorker ?? false);
|
|
1845
1964
|
await navigateToTest(page, url, browser);
|
|
1846
1965
|
const testOverlay = page.locator('#TestOverlay');
|
|
@@ -1940,7 +2059,8 @@ const runTests = async ({
|
|
|
1940
2059
|
tests,
|
|
1941
2060
|
testSrc,
|
|
1942
2061
|
timeout,
|
|
1943
|
-
traceFocus
|
|
2062
|
+
traceFocus,
|
|
2063
|
+
updateSvgScreenshots = false
|
|
1944
2064
|
}) => {
|
|
1945
2065
|
let failed = 0;
|
|
1946
2066
|
let skipped = 0;
|
|
@@ -1962,6 +2082,7 @@ const runTests = async ({
|
|
|
1962
2082
|
timeout,
|
|
1963
2083
|
traceFocus: traceFocus ?? false,
|
|
1964
2084
|
traceRendererWorker: rendererWorkerTraceDirectory !== undefined,
|
|
2085
|
+
updateSvgScreenshots,
|
|
1965
2086
|
...(svgScreenshotOptions && {
|
|
1966
2087
|
svgScreenshotOptions
|
|
1967
2088
|
})
|
|
@@ -2125,13 +2246,16 @@ const runTestsWithReusedPage = async ({
|
|
|
2125
2246
|
page,
|
|
2126
2247
|
port,
|
|
2127
2248
|
rendererWorkerTraceDirectory,
|
|
2249
|
+
testPath,
|
|
2128
2250
|
timeout,
|
|
2129
|
-
traceFocus
|
|
2251
|
+
traceFocus,
|
|
2252
|
+
updateSvgScreenshots = false
|
|
2130
2253
|
}) => {
|
|
2131
2254
|
const start = performance.now();
|
|
2132
2255
|
const pageMessages = failOnConsoleMessages ? createPageMessages(page) : undefined;
|
|
2133
2256
|
let results;
|
|
2134
2257
|
try {
|
|
2258
|
+
await install(page, testPath, updateSvgScreenshots);
|
|
2135
2259
|
const url = getAllTestsUrl(port, filter, traceFocus ?? false, rendererWorkerTraceDirectory !== undefined);
|
|
2136
2260
|
await page.goto(url, {
|
|
2137
2261
|
timeout,
|
|
@@ -3014,7 +3138,7 @@ const assertCoverageOptions = (coverageTarget, coverageInclude, coverageThreshol
|
|
|
3014
3138
|
* @param {boolean} coverage
|
|
3015
3139
|
* @param {boolean} traceRendererWorker
|
|
3016
3140
|
*/
|
|
3017
|
-
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage, svgScreenshotOptions, coverage, coverageInclude, coverageTarget, coverageThreshold, traceRendererWorker, failOnConsoleMessages) => {
|
|
3141
|
+
const runAllTests = async (extensionPath, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage, svgScreenshotOptions, coverage, coverageInclude, coverageTarget, coverageThreshold, traceRendererWorker, failOnConsoleMessages, updateSvgScreenshots = false) => {
|
|
3018
3142
|
string(extensionPath);
|
|
3019
3143
|
string(testPath);
|
|
3020
3144
|
string(cwd);
|
|
@@ -3107,7 +3231,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3107
3231
|
});
|
|
3108
3232
|
try {
|
|
3109
3233
|
if (traceRendererWorker) {
|
|
3110
|
-
await page.addInitScript(install);
|
|
3234
|
+
await page.addInitScript(install$1);
|
|
3111
3235
|
}
|
|
3112
3236
|
if (reusePage) {
|
|
3113
3237
|
await runWithJavascriptCoverage({
|
|
@@ -3126,6 +3250,8 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3126
3250
|
run: async () => {
|
|
3127
3251
|
await runTestsWithReusedPage({
|
|
3128
3252
|
browser,
|
|
3253
|
+
testPath,
|
|
3254
|
+
updateSvgScreenshots,
|
|
3129
3255
|
...filterOption,
|
|
3130
3256
|
failOnConsoleMessages,
|
|
3131
3257
|
onFinalResult,
|
|
@@ -3160,7 +3286,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3160
3286
|
});
|
|
3161
3287
|
try {
|
|
3162
3288
|
if (traceRendererWorker) {
|
|
3163
|
-
await nextBrowser.page.addInitScript(install);
|
|
3289
|
+
await nextBrowser.page.addInitScript(install$1);
|
|
3164
3290
|
}
|
|
3165
3291
|
return nextBrowser;
|
|
3166
3292
|
} catch (error) {
|
|
@@ -3176,6 +3302,7 @@ const runAllTests = async (extensionPath, testPath, cwd, browser, headless, time
|
|
|
3176
3302
|
await runTests({
|
|
3177
3303
|
browser,
|
|
3178
3304
|
failOnConsoleMessages,
|
|
3305
|
+
updateSvgScreenshots,
|
|
3179
3306
|
...(createPage && {
|
|
3180
3307
|
createPage
|
|
3181
3308
|
}),
|