@lvce-editor/test-with-playwright 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.
Files changed (3) hide show
  1. package/README.md +21 -0
  2. package/dist/main.js +36 -4
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -33,6 +33,8 @@ test('sample.hello-world', async () => {
33
33
  - `--server-path`: explicit server entry point
34
34
  - `--filter`: run only matching tests
35
35
  - `--headless`: run Playwright in headless mode
36
+ - `--reuse-page`: run browser tests through `/tests/_all.html` on one page
37
+ - `--timeout`: test timeout in milliseconds, defaults to `30000` or `600000` with `--reuse-page`
36
38
  - `--browser`: browser engine to launch: `chromium`, `firefox`, or `webkit`
37
39
  - `--trace-focus`: add `traceFocus=true` to test URLs
38
40
  - `--electron-path`: path to an existing Electron app executable
@@ -44,9 +46,28 @@ test('sample.hello-world', async () => {
44
46
  ## Runtime Notes
45
47
 
46
48
  - `browser` keeps the server-backed HTML test execution flow.
49
+ - `--reuse-page` is browser-only. It loads `/tests/_all.html` once and reads JSON results from a hidden `.TestResults` element.
47
50
  - `electron` downloads or reuses a Lvce Electron app, launches it with Playwright, and runs each test module against the first window.
48
51
  - `--electron-path` skips downloading and is useful for custom local builds.
49
52
 
53
+ ## Reuse Page Results
54
+
55
+ When `--reuse-page` is enabled, `/tests/_all.html` should run the tests and write a JSON array into `.TestResults`:
56
+
57
+ ```json
58
+ [
59
+ {
60
+ "name": "sample.hello-world.js",
61
+ "status": "pass",
62
+ "error": "",
63
+ "start": 0,
64
+ "end": 12.5
65
+ }
66
+ ]
67
+ ```
68
+
69
+ `status` must be `pass`, `skip`, or `fail`. `error` is optional and defaults to an empty string.
70
+
50
71
  ## Environment Variables
51
72
 
52
73
  - `ONLY_EXTENSION`
package/dist/main.js CHANGED
@@ -124,9 +124,11 @@ Options:
124
124
  --runtime=<runtime> Runtime to run tests in: browser or electron
125
125
  --filter=<pattern> Only run tests matching the filter
126
126
  --headless Run the browser in headless mode
127
+ --reuse-page Run browser tests through /tests/_all.html on one page
127
128
  --only-extension=<path> Path to the extension under test
128
129
  --server-path=<path> Path to the editor server entrypoint
129
130
  --test-path=<path> Path to the test files
131
+ --timeout=<ms> Test timeout in milliseconds
130
132
  --trace-focus Log focus changes while tests run
131
133
  --electron-path=<path> Path to an existing Electron app executable
132
134
  --electron-version=<ver> Lvce release version to download, for example v0.84.0
@@ -395,6 +397,18 @@ const toStringArray = value => {
395
397
  }
396
398
  return [toCliString(value)];
397
399
  };
400
+ const toPositiveNumber = (value, name) => {
401
+ const number = Number(toCliString(value));
402
+ if (!Number.isFinite(number) || number <= 0) {
403
+ throw new TypeError(`expected ${name} to be a positive number`);
404
+ }
405
+ return number;
406
+ };
407
+ const setOptionalPositiveNumber = (result, key, value, name) => {
408
+ if (value !== undefined) {
409
+ result[key] = toPositiveNumber(value, name);
410
+ }
411
+ };
398
412
  const parseCliArgs = argv => {
399
413
  const parsed = parseArgv(argv);
400
414
  const result = Object.create(null);
@@ -416,9 +430,13 @@ const parseCliArgs = argv => {
416
430
  if (parsed['only-extension']) {
417
431
  result.onlyExtension = String(parsed['only-extension']);
418
432
  }
433
+ if (parsed['reuse-page']) {
434
+ result.reusePage = true;
435
+ }
419
436
  if (parsed['test-path']) {
420
437
  result.testPath = String(parsed['test-path']);
421
438
  }
439
+ setOptionalPositiveNumber(result, 'timeout', parsed.timeout, '--timeout');
422
440
  if (parsed['server-path']) {
423
441
  result.serverPath = String(parsed['server-path']);
424
442
  }
@@ -457,13 +475,17 @@ const parseEnv = env => {
457
475
  };
458
476
 
459
477
  const browsers = ['chromium', 'firefox', 'webkit'];
478
+ const defaultTimeout = 30_000;
479
+ const reusePageDefaultTimeout = 600_000;
460
480
  const defaultOptions = {
461
481
  browser: 'chromium',
462
482
  extensionPath: '',
463
483
  headless: false,
464
484
  help: false,
485
+ reusePage: false,
465
486
  runtime: 'browser',
466
- testPath: ''
487
+ testPath: '',
488
+ timeout: defaultTimeout
467
489
  };
468
490
  const isBrowser = value => {
469
491
  return browsers.includes(value);
@@ -485,12 +507,19 @@ const getOptions = ({
485
507
  }
486
508
  const browser = parsedArgs.browser ?? defaultOptions.browser;
487
509
  const runtime = parsedArgs.runtime ?? defaultOptions.runtime;
510
+ if (parsedArgs.reusePage && runtime === 'electron') {
511
+ throw new Error('[test-with-playwright] --reuse-page is only supported with --runtime=browser');
512
+ }
513
+ const reusePage = parsedArgs.reusePage ?? defaultOptions.reusePage;
514
+ const timeout = parsedArgs.timeout ?? (reusePage ? reusePageDefaultTimeout : defaultTimeout);
488
515
  return {
489
516
  ...defaultOptions,
490
517
  ...parsedEnv,
491
518
  ...parsedArgs,
492
519
  browser,
493
- runtime
520
+ reusePage,
521
+ runtime,
522
+ timeout
494
523
  };
495
524
  };
496
525
 
@@ -1789,6 +1818,7 @@ const runAllTests = async ({
1789
1818
  filter,
1790
1819
  headless,
1791
1820
  onlyExtension,
1821
+ reusePage,
1792
1822
  runtimeOptions,
1793
1823
  testPath,
1794
1824
  testWorkerUri,
@@ -1803,7 +1833,7 @@ const runAllTests = async ({
1803
1833
  path,
1804
1834
  stdio: 'inherit'
1805
1835
  });
1806
- await rpc.invoke(RunAllTests, onlyExtension, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter);
1836
+ await rpc.invoke(RunAllTests, onlyExtension, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage);
1807
1837
  await rpc.dispose();
1808
1838
  };
1809
1839
 
@@ -1828,16 +1858,17 @@ const handleCliArgs = async ({
1828
1858
  headless,
1829
1859
  help,
1830
1860
  onlyExtension,
1861
+ reusePage,
1831
1862
  runtime,
1832
1863
  serverPath,
1833
1864
  testPath,
1865
+ timeout,
1834
1866
  traceFocus
1835
1867
  } = options;
1836
1868
  if (help) {
1837
1869
  console.info(getHelpMessage());
1838
1870
  return;
1839
1871
  }
1840
- const timeout = 30_000;
1841
1872
  const testWorkerUri = getTestWorkerUrl();
1842
1873
  const runtimeOptions = await getRuntimeOptions({
1843
1874
  cwd,
@@ -1869,6 +1900,7 @@ const handleCliArgs = async ({
1869
1900
  headless,
1870
1901
  // @ts-ignore
1871
1902
  onlyExtension,
1903
+ reusePage,
1872
1904
  runtimeOptions,
1873
1905
  testPath,
1874
1906
  testWorkerUri,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-with-playwright",
3
- "version": "21.0.0",
3
+ "version": "22.1.0",
4
4
  "description": "CLI tool for running Playwright tests",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,8 +12,8 @@
12
12
  "main": "dist/main.js",
13
13
  "bin": "bin/test-with-playwright.js",
14
14
  "dependencies": {
15
- "@lvce-editor/test-with-playwright-worker": "21.0.0",
16
- "@lvce-editor/test-worker": "^16.4.0"
15
+ "@lvce-editor/test-with-playwright-worker": "22.1.0",
16
+ "@lvce-editor/test-worker": "^16.5.0"
17
17
  },
18
18
  "engines": {
19
19
  "node": ">=24"