@lvce-editor/test-with-playwright 22.7.0 → 22.8.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 +18 -0
  2. package/dist/main.js +52 -3
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -37,7 +37,11 @@ test('sample.hello-world', async () => {
37
37
  - `--reuse-page`: run browser tests through `/tests/_all.html` on one page
38
38
  - `--timeout`: test timeout in milliseconds, defaults to `30000` or `600000` with `--reuse-page`
39
39
  - `--browser`: browser engine to launch: `chromium`, `firefox`, or `webkit`
40
+ - `--coverage`: collect JavaScript coverage with Chromium and write Istanbul reports to `coverage`
40
41
  - `--trace-focus`: add `traceFocus=true` to test URLs
42
+ - `--svg-screenshot-dir`: compare a self-contained SVG screenshot after each passing test with the browser-specific snapshot in this directory
43
+ - `--svg-screenshot-selector`: capture only the first matching element, such as `.Explorer`; defaults to the application body
44
+ - `--update-svg-screenshots`: create or update SVG screenshots in `--svg-screenshot-dir`
41
45
  - `--electron-path`: path to an existing Electron app executable
42
46
  - `--electron-version`: Lvce release version override; by default Electron uses the installed `@lvce-editor/server` version
43
47
  - `--electron-cache-dir`: directory for downloaded Electron apps, defaults to `.test-with-playwright/electron`
@@ -47,9 +51,23 @@ test('sample.hello-world', async () => {
47
51
  ## Runtime Notes
48
52
 
49
53
  - `browser` keeps the server-backed HTML test execution flow.
54
+ - JavaScript coverage is available for Chromium-based browser and Electron runs. It prints a coverage table and writes `coverage/coverage-final.json`, `coverage/coverage-summary.json`, `coverage/coverage.txt`, and `coverage/lcov.info`.
50
55
  - `--reuse-page` is browser-only. It loads `/tests/_all.html` once and reads JSON results from a hidden `.TestResults` element.
51
56
  - `electron` downloads or reuses the matching Lvce Electron app, launches it with Playwright and a temporary user data directory, and runs each test module against the first window.
52
57
  - `--electron-path` skips downloading and is useful for custom local builds.
58
+ - SVG screenshots are not supported with `--reuse-page`, because that mode exposes only the final application state.
59
+
60
+ ## SVG Screenshot Tests
61
+
62
+ Add `--svg-screenshot-dir=./snapshots` to compare each passing test's final application state with a committed SVG. Use `--svg-screenshot-selector=.Explorer` for a focused Explorer View snapshot. Snapshot names include the runtime, for example `viewlet.explorer-open.chromium.svg`, so browser-specific output does not conflict.
63
+
64
+ Create or intentionally update the snapshots with:
65
+
66
+ ```sh
67
+ npm run e2e -- --svg-screenshot-dir=./snapshots --update-svg-screenshots
68
+ ```
69
+
70
+ The screenshot converts the rendered DOM to SVG shapes with the computed visual properties already applied. Fonts and images are inlined, test result overlays are excluded, animations and carets are frozen, and no page scripts are included. A mismatch writes an adjacent `.actual` file for inspection and fails the test.
53
71
 
54
72
  ## Reuse Page Results
55
73
 
package/dist/main.js CHANGED
@@ -122,6 +122,7 @@ const getHelpMessage = () => {
122
122
 
123
123
  Options:
124
124
  --browser=<browser> Browser to run tests in: chromium, firefox, or webkit
125
+ --coverage Collect JavaScript coverage and write Istanbul reports
125
126
  --runtime=<runtime> Runtime to run tests in: browser or electron
126
127
  --electron Run tests in Electron and infer the matching Lvce version
127
128
  --filter=<pattern> Only run tests matching the filter
@@ -129,9 +130,12 @@ Options:
129
130
  --reuse-page Run browser tests through /tests/_all.html on one page
130
131
  --only-extension=<path> Path to the extension under test
131
132
  --server-path=<path> Path to the editor server entrypoint
133
+ --svg-screenshot-dir=<p> Compare SVG screenshots with snapshots in this directory
134
+ --svg-screenshot-selector=<css> Capture only the matching element
132
135
  --test-path=<path> Path to the test files
133
136
  --timeout=<ms> Test timeout in milliseconds
134
137
  --trace-focus Log focus changes while tests run
138
+ --update-svg-screenshots Create or update expected SVG screenshots
135
139
  --electron-path=<path> Path to an existing Electron app executable
136
140
  --electron-version=<ver> Override the inferred Lvce release version
137
141
  --electron-cache-dir=<p> Directory for downloaded Electron apps
@@ -411,6 +415,16 @@ const setOptionalPositiveNumber = (result, key, value, name) => {
411
415
  result[key] = toPositiveNumber(value, name);
412
416
  }
413
417
  };
418
+ const setOptionalString = (result, key, value) => {
419
+ if (value) {
420
+ result[key] = toCliString(value);
421
+ }
422
+ };
423
+ const setFlag = (result, key, value) => {
424
+ if (value) {
425
+ result[key] = true;
426
+ }
427
+ };
414
428
  const getRuntime = parsed => {
415
429
  if (parsed.electron) {
416
430
  return 'electron';
@@ -426,6 +440,7 @@ const parseCliArgs = argv => {
426
440
  if (parsed.browser) {
427
441
  result.browser = String(parsed.browser);
428
442
  }
443
+ setFlag(result, 'coverage', parsed.coverage);
429
444
  const runtime = getRuntime(parsed);
430
445
  if (runtime) {
431
446
  result.runtime = runtime;
@@ -452,6 +467,8 @@ const parseCliArgs = argv => {
452
467
  if (parsed['server-path']) {
453
468
  result.serverPath = String(parsed['server-path']);
454
469
  }
470
+ setOptionalString(result, 'svgScreenshotDir', parsed['svg-screenshot-dir']);
471
+ setOptionalString(result, 'svgScreenshotSelector', parsed['svg-screenshot-selector']);
455
472
  if (parsed['electron-path']) {
456
473
  result.electronPath = String(parsed['electron-path']);
457
474
  }
@@ -472,6 +489,7 @@ const parseCliArgs = argv => {
472
489
  if (parsed['trace-focus']) {
473
490
  result.traceFocus = true;
474
491
  }
492
+ setFlag(result, 'updateSvgScreenshots', parsed['update-svg-screenshots']);
475
493
  return result;
476
494
  };
477
495
 
@@ -491,13 +509,15 @@ const defaultTimeout = 30_000;
491
509
  const reusePageDefaultTimeout = 600_000;
492
510
  const defaultOptions = {
493
511
  browser: 'chromium',
512
+ coverage: false,
494
513
  extensionPath: '',
495
514
  headless: false,
496
515
  help: false,
497
516
  reusePage: false,
498
517
  runtime: 'browser',
499
518
  testPath: '',
500
- timeout: defaultTimeout
519
+ timeout: defaultTimeout,
520
+ updateSvgScreenshots: false
501
521
  };
502
522
  const isBrowser = value => {
503
523
  return browsers.includes(value);
@@ -519,9 +539,21 @@ const getOptions = ({
519
539
  }
520
540
  const browser = parsedArgs.browser ?? defaultOptions.browser;
521
541
  const runtime = parsedArgs.runtime ?? defaultOptions.runtime;
542
+ if (parsedArgs.coverage && runtime === 'browser' && browser !== 'chromium') {
543
+ throw new Error('[test-with-playwright] --coverage is only supported with Chromium-based browsers');
544
+ }
522
545
  if (parsedArgs.reusePage && runtime === 'electron') {
523
546
  throw new Error('[test-with-playwright] --reuse-page is only supported with --runtime=browser');
524
547
  }
548
+ if (parsedArgs.reusePage && parsedArgs.svgScreenshotDir) {
549
+ throw new Error('[test-with-playwright] --svg-screenshot-dir is not supported with --reuse-page');
550
+ }
551
+ if (parsedArgs.updateSvgScreenshots && !parsedArgs.svgScreenshotDir) {
552
+ throw new Error('[test-with-playwright] --update-svg-screenshots requires --svg-screenshot-dir');
553
+ }
554
+ if (parsedArgs.svgScreenshotSelector && !parsedArgs.svgScreenshotDir) {
555
+ throw new Error('[test-with-playwright] --svg-screenshot-selector requires --svg-screenshot-dir');
556
+ }
525
557
  const reusePage = parsedArgs.reusePage ?? defaultOptions.reusePage;
526
558
  const timeout = parsedArgs.timeout ?? (reusePage ? reusePageDefaultTimeout : defaultTimeout);
527
559
  return {
@@ -1920,12 +1952,14 @@ const RunAllTests = 'RunAllTests';
1920
1952
  const runAllTests = async ({
1921
1953
  browser,
1922
1954
  commandMap,
1955
+ coverage,
1923
1956
  cwd,
1924
1957
  filter,
1925
1958
  headless,
1926
1959
  onlyExtension,
1927
1960
  reusePage,
1928
1961
  runtimeOptions,
1962
+ svgScreenshotOptions,
1929
1963
  testPath,
1930
1964
  testWorkerUri,
1931
1965
  timeout,
@@ -1939,7 +1973,7 @@ const runAllTests = async ({
1939
1973
  path,
1940
1974
  stdio: 'inherit'
1941
1975
  });
1942
- await rpc.invoke(RunAllTests, onlyExtension, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage);
1976
+ await rpc.invoke(RunAllTests, onlyExtension, testPath, cwd, browser, headless, timeout, runtimeOptions, traceFocus, filter, reusePage, svgScreenshotOptions, coverage);
1943
1977
  await rpc.dispose();
1944
1978
  };
1945
1979
 
@@ -1955,6 +1989,7 @@ const handleCliArgs = async ({
1955
1989
  });
1956
1990
  const {
1957
1991
  browser,
1992
+ coverage,
1958
1993
  electronArgs,
1959
1994
  electronCacheDir,
1960
1995
  electronEnv,
@@ -1967,9 +2002,12 @@ const handleCliArgs = async ({
1967
2002
  reusePage,
1968
2003
  runtime,
1969
2004
  serverPath,
2005
+ svgScreenshotDir,
2006
+ svgScreenshotSelector,
1970
2007
  testPath,
1971
2008
  timeout,
1972
- traceFocus
2009
+ traceFocus,
2010
+ updateSvgScreenshots
1973
2011
  } = options;
1974
2012
  if (help) {
1975
2013
  console.info(getHelpMessage());
@@ -2001,6 +2039,7 @@ const handleCliArgs = async ({
2001
2039
  await runAllTests({
2002
2040
  browser,
2003
2041
  commandMap,
2042
+ coverage,
2004
2043
  cwd,
2005
2044
  filter,
2006
2045
  headless,
@@ -2008,6 +2047,16 @@ const handleCliArgs = async ({
2008
2047
  onlyExtension,
2009
2048
  reusePage,
2010
2049
  runtimeOptions,
2050
+ ...(svgScreenshotDir && {
2051
+ svgScreenshotOptions: {
2052
+ directory: resolve$1(cwd, svgScreenshotDir),
2053
+ name: runtime === 'electron' ? 'electron' : browser,
2054
+ ...(svgScreenshotSelector && {
2055
+ selector: svgScreenshotSelector
2056
+ }),
2057
+ update: updateSvgScreenshots
2058
+ }
2059
+ }),
2011
2060
  testPath,
2012
2061
  testWorkerUri,
2013
2062
  timeout,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-with-playwright",
3
- "version": "22.7.0",
3
+ "version": "22.8.0",
4
4
  "description": "CLI tool for running Playwright tests",
5
5
  "repository": {
6
6
  "type": "git",
@@ -12,7 +12,7 @@
12
12
  "main": "dist/main.js",
13
13
  "bin": "bin/test-with-playwright.js",
14
14
  "dependencies": {
15
- "@lvce-editor/test-with-playwright-worker": "22.7.0",
15
+ "@lvce-editor/test-with-playwright-worker": "22.8.0",
16
16
  "@lvce-editor/test-worker": "^17.2.0"
17
17
  },
18
18
  "engines": {