@lvce-editor/test-with-playwright-worker 22.7.0 → 22.7.1
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 +30 -114
- package/package.json +1 -1
package/dist/workerMain.js
CHANGED
|
@@ -3,8 +3,7 @@ import { readFile, writeFile, readdir, mkdtemp, rm } from 'node:fs/promises';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import net from 'node:net';
|
|
5
5
|
import os, { tmpdir } from 'node:os';
|
|
6
|
-
import { fork
|
|
7
|
-
import { createInterface } from 'node:readline';
|
|
6
|
+
import { fork } from 'node:child_process';
|
|
8
7
|
import { createRequire } from 'node:module';
|
|
9
8
|
|
|
10
9
|
const require$1 = createRequire(import.meta.url);
|
|
@@ -1760,101 +1759,26 @@ const getElectronProcessArgs = ({
|
|
|
1760
1759
|
platform = process.platform,
|
|
1761
1760
|
userDataDir
|
|
1762
1761
|
}) => {
|
|
1763
|
-
return [
|
|
1762
|
+
return [...(platform === 'linux' ? ['--no-sandbox'] : []), ...args, `--user-data-dir=${userDataDir}`];
|
|
1764
1763
|
};
|
|
1765
1764
|
|
|
1766
|
-
const
|
|
1767
|
-
|
|
1768
|
-
const electronConnectionTimeout = 120_000;
|
|
1769
|
-
const devtoolsRegex = /^DevTools listening on (ws:\/\/.*)$/;
|
|
1770
|
-
const waitForDevtoolsEndpoint = async child => {
|
|
1771
|
-
const {
|
|
1772
|
-
stderr
|
|
1773
|
-
} = child;
|
|
1774
|
-
if (!stderr) {
|
|
1775
|
-
throw new Error('Electron stderr is unavailable');
|
|
1776
|
-
}
|
|
1777
|
-
const lines = createInterface({
|
|
1778
|
-
input: stderr
|
|
1779
|
-
});
|
|
1780
|
-
const {
|
|
1781
|
-
promise,
|
|
1782
|
-
reject,
|
|
1783
|
-
resolve
|
|
1784
|
-
} = Promise.withResolvers();
|
|
1785
|
-
const stderrLines = [];
|
|
1786
|
-
const onExit = () => {
|
|
1787
|
-
const details = stderrLines.length > 0 ? `: ${stderrLines.join('\n')}` : '';
|
|
1788
|
-
reject(new Error(`Electron exited before DevTools endpoint was available${details}`));
|
|
1789
|
-
};
|
|
1790
|
-
const onLine = line => {
|
|
1791
|
-
stderrLines.push(line);
|
|
1792
|
-
const match = line.match(devtoolsRegex);
|
|
1793
|
-
if (match) {
|
|
1794
|
-
resolve(match[1]);
|
|
1795
|
-
}
|
|
1796
|
-
};
|
|
1797
|
-
child.once('exit', onExit);
|
|
1798
|
-
lines.on('line', onLine);
|
|
1799
|
-
try {
|
|
1800
|
-
return await promise;
|
|
1801
|
-
} finally {
|
|
1802
|
-
child.off('exit', onExit);
|
|
1803
|
-
lines.off('line', onLine);
|
|
1804
|
-
lines.close();
|
|
1805
|
-
}
|
|
1806
|
-
};
|
|
1807
|
-
const getFirstPage = async browser => {
|
|
1808
|
-
const context = browser.contexts()[0];
|
|
1809
|
-
const pages = context.pages();
|
|
1810
|
-
if (pages.length > 0) {
|
|
1811
|
-
return pages[0];
|
|
1812
|
-
}
|
|
1813
|
-
return context.waitForEvent('page', {
|
|
1814
|
-
timeout: 15_000
|
|
1815
|
-
});
|
|
1816
|
-
};
|
|
1817
|
-
const waitForChildExit = async child => {
|
|
1818
|
-
if (child.exitCode !== null || child.signalCode !== null) {
|
|
1819
|
-
return;
|
|
1820
|
-
}
|
|
1821
|
-
await new Promise(resolve => {
|
|
1822
|
-
const timeout = setTimeout(resolve, 5000);
|
|
1823
|
-
child.once('exit', () => {
|
|
1824
|
-
clearTimeout(timeout);
|
|
1825
|
-
resolve();
|
|
1826
|
-
});
|
|
1827
|
-
});
|
|
1828
|
-
};
|
|
1829
|
-
const stopElectronProcess = async child => {
|
|
1830
|
-
if (child.exitCode === null && child.signalCode === null) {
|
|
1831
|
-
child.kill(SIGINT);
|
|
1832
|
-
await waitForChildExit(child);
|
|
1833
|
-
}
|
|
1834
|
-
if (child.exitCode === null && child.signalCode === null) {
|
|
1835
|
-
child.kill('SIGKILL');
|
|
1836
|
-
await waitForChildExit(child);
|
|
1837
|
-
}
|
|
1838
|
-
};
|
|
1765
|
+
const electronLaunchTimeout = 120_000;
|
|
1839
1766
|
const closeElectron = async ({
|
|
1840
|
-
|
|
1841
|
-
child,
|
|
1767
|
+
electronApp,
|
|
1842
1768
|
userDataDir
|
|
1843
1769
|
}) => {
|
|
1844
1770
|
try {
|
|
1845
|
-
await
|
|
1771
|
+
await electronApp.close();
|
|
1846
1772
|
} catch {
|
|
1847
1773
|
// ignore close errors during cleanup
|
|
1848
1774
|
}
|
|
1849
|
-
await stopElectronProcess(child);
|
|
1850
1775
|
await rm(userDataDir, {
|
|
1851
1776
|
force: true,
|
|
1852
1777
|
recursive: true
|
|
1853
1778
|
});
|
|
1854
1779
|
};
|
|
1855
1780
|
const createElectronLaunch = ({
|
|
1856
|
-
|
|
1857
|
-
child,
|
|
1781
|
+
electronApp,
|
|
1858
1782
|
page,
|
|
1859
1783
|
signal,
|
|
1860
1784
|
userDataDir
|
|
@@ -1869,8 +1793,7 @@ const createElectronLaunch = ({
|
|
|
1869
1793
|
process.off('SIGINT', handleSigint);
|
|
1870
1794
|
process.off('SIGTERM', handleSigterm);
|
|
1871
1795
|
await closeElectron({
|
|
1872
|
-
|
|
1873
|
-
child,
|
|
1796
|
+
electronApp,
|
|
1874
1797
|
userDataDir
|
|
1875
1798
|
});
|
|
1876
1799
|
};
|
|
@@ -1895,13 +1818,6 @@ const createElectronLaunch = ({
|
|
|
1895
1818
|
signal.addEventListener('abort', handleAbort);
|
|
1896
1819
|
process.once('SIGINT', handleSigint);
|
|
1897
1820
|
process.once('SIGTERM', handleSigterm);
|
|
1898
|
-
const electronApp = {
|
|
1899
|
-
close: dispose,
|
|
1900
|
-
process: () => {
|
|
1901
|
-
return child;
|
|
1902
|
-
},
|
|
1903
|
-
[Symbol.asyncDispose]: dispose
|
|
1904
|
-
};
|
|
1905
1821
|
return {
|
|
1906
1822
|
electronApp,
|
|
1907
1823
|
page,
|
|
@@ -1918,44 +1834,44 @@ const startElectron = async ({
|
|
|
1918
1834
|
args: launchOptions.args,
|
|
1919
1835
|
userDataDir
|
|
1920
1836
|
});
|
|
1921
|
-
|
|
1922
|
-
env: launchOptions.env,
|
|
1923
|
-
stdio: ['ignore', 'ignore', 'pipe']
|
|
1924
|
-
});
|
|
1925
|
-
let browser;
|
|
1837
|
+
let electronApp;
|
|
1926
1838
|
try {
|
|
1927
|
-
const endpoint = await waitForDevtoolsEndpoint(child);
|
|
1928
1839
|
const {
|
|
1929
|
-
|
|
1840
|
+
_electron
|
|
1930
1841
|
} = await import('@playwright/test');
|
|
1931
|
-
|
|
1932
|
-
|
|
1842
|
+
electronApp = await _electron.launch({
|
|
1843
|
+
args: [...args],
|
|
1844
|
+
env: launchOptions.env,
|
|
1845
|
+
executablePath: launchOptions.executablePath,
|
|
1846
|
+
timeout: electronLaunchTimeout
|
|
1847
|
+
});
|
|
1848
|
+
const page = await electronApp.firstWindow({
|
|
1849
|
+
timeout: electronLaunchTimeout
|
|
1933
1850
|
});
|
|
1934
|
-
const page = await getFirstPage(browser);
|
|
1935
1851
|
return createElectronLaunch({
|
|
1936
|
-
|
|
1937
|
-
child,
|
|
1852
|
+
electronApp,
|
|
1938
1853
|
page,
|
|
1939
1854
|
signal,
|
|
1940
1855
|
userDataDir
|
|
1941
1856
|
});
|
|
1942
1857
|
} catch (error) {
|
|
1943
|
-
if (
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1858
|
+
if (electronApp) {
|
|
1859
|
+
await closeElectron({
|
|
1860
|
+
electronApp,
|
|
1861
|
+
userDataDir
|
|
1862
|
+
});
|
|
1863
|
+
} else {
|
|
1864
|
+
await rm(userDataDir, {
|
|
1865
|
+
force: true,
|
|
1866
|
+
recursive: true
|
|
1867
|
+
});
|
|
1949
1868
|
}
|
|
1950
|
-
await stopElectronProcess(child);
|
|
1951
|
-
await rm(userDataDir, {
|
|
1952
|
-
force: true,
|
|
1953
|
-
recursive: true
|
|
1954
|
-
});
|
|
1955
1869
|
throw error;
|
|
1956
1870
|
}
|
|
1957
1871
|
};
|
|
1958
1872
|
|
|
1873
|
+
const SIGINT = 'SIGINT';
|
|
1874
|
+
|
|
1959
1875
|
const tearDownTests = async ({
|
|
1960
1876
|
child,
|
|
1961
1877
|
controller,
|