@vitest/browser-playwright 5.0.0-beta.5 → 5.0.0-beta.6

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 (2) hide show
  1. package/dist/index.js +22 -6
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parseKeyDef, resolveScreenshotPath, defineBrowserProvider } from '@vitest/browser';
1
+ import { parseKeyDef, resolveScreenshotPath, assertBrowserApiWrite, assertBrowserFileAccess, defineBrowserProvider } from '@vitest/browser';
2
2
  export { defineBrowserCommand } from '@vitest/browser';
3
3
  import { createManualModuleSource } from '@vitest/mocker/node';
4
4
  import c from 'tinyrainbow';
@@ -522,6 +522,8 @@ async function takeScreenshot(context, name, options) {
522
522
  let savePath;
523
523
  if (options.save) {
524
524
  savePath = normalize(path);
525
+ assertBrowserApiWrite(context.project, savePath);
526
+ assertBrowserFileAccess(context.project, savePath);
525
527
  await mkdir(dirname(savePath), { recursive: true });
526
528
  }
527
529
  const mask = options.mask?.map((selector) => getDescribedLocator(context, selector));
@@ -622,6 +624,8 @@ const startChunkTrace = async (command, { name, title }) => {
622
624
  const stopChunkTrace = async (context, { name }) => {
623
625
  if (isPlaywrightProvider(context.provider)) {
624
626
  const path = resolveTracesPath(context, name);
627
+ assertBrowserApiWrite(context.project, path);
628
+ assertBrowserFileAccess(context.project, path);
625
629
  context.provider.pendingTraces.delete(path);
626
630
  await context.context.tracing.stopChunk({ path });
627
631
  return { tracePath: path };
@@ -708,6 +712,10 @@ const deleteTracing = async (context, { traces }) => {
708
712
  throw new Error(`stopChunkTrace cannot be called outside of the test file.`);
709
713
  }
710
714
  if (isPlaywrightProvider(context.provider)) {
715
+ for (const trace of traces) {
716
+ assertBrowserApiWrite(context.project, trace);
717
+ assertBrowserFileAccess(context.project, trace);
718
+ }
711
719
  return Promise.all(traces.map((trace) => unlink(trace).catch((err) => {
712
720
  if (err.code === "ENOENT") {
713
721
  // Ignore the error if the file doesn't exist
@@ -722,6 +730,8 @@ const deleteTracing = async (context, { traces }) => {
722
730
  const annotateTraces = async ({ project }, { testId, traces }) => {
723
731
  const vitest = project.vitest;
724
732
  await Promise.all(traces.map((trace) => {
733
+ assertBrowserApiWrite(project, trace);
734
+ assertBrowserFileAccess(project, trace);
725
735
  const entity = vitest.state.getReportedEntityById(testId);
726
736
  const location = entity?.location ? {
727
737
  file: entity.module.moduleId,
@@ -766,7 +776,9 @@ const upload = async (context, selector, files, options) => {
766
776
  const root = context.project.config.root;
767
777
  const playwrightFiles = files.map((file) => {
768
778
  if (typeof file === "string") {
769
- return resolve(root, file);
779
+ const filepath = resolve(root, file);
780
+ assertBrowserFileAccess(context.project, filepath);
781
+ return filepath;
770
782
  }
771
783
  return {
772
784
  name: file.name,
@@ -1069,7 +1081,7 @@ class PlaywrightBrowserProvider {
1069
1081
  clear: async (sessionId) => {
1070
1082
  const page = this.getPage(sessionId);
1071
1083
  const ids = sessionIds.get(sessionId) ?? new Set();
1072
- const promises = [...ids].map((id) => {
1084
+ const promises = Array.from(ids, (id) => {
1073
1085
  const key = predicateKey(sessionId, id);
1074
1086
  const predicate = idPredicates.get(key);
1075
1087
  if (predicate) {
@@ -1111,7 +1123,11 @@ class PlaywrightBrowserProvider {
1111
1123
  ...contextOptions,
1112
1124
  ignoreHTTPSErrors: true
1113
1125
  };
1114
- if (this.project.config.browser.ui) {
1126
+ // A `null` viewport lets the page adopt the real window size, which is only
1127
+ // meaningful for a headed UI. In headless mode there is no real window, so it
1128
+ // would inherit the host's device scale factor and produce screenshots that
1129
+ // differ from non-UI runs on the same machine.
1130
+ if (this.project.config.browser.ui && !this.project.config.browser.headless) {
1115
1131
  options.viewport = null;
1116
1132
  }
1117
1133
  return options;
@@ -1207,12 +1223,12 @@ class PlaywrightBrowserProvider {
1207
1223
  }
1208
1224
  const browser = this.browser;
1209
1225
  this.browser = null;
1210
- await Promise.all([...this.pages.values()].map((p) => p.close()));
1226
+ await Promise.all(Array.from(this.pages.values(), (p) => p.close()));
1211
1227
  this.pages.clear();
1212
1228
  if (this.persistentContext) {
1213
1229
  await this.persistentContext.close();
1214
1230
  } else {
1215
- await Promise.all([...this.contexts.values()].map((c) => c.close()));
1231
+ await Promise.all(Array.from(this.contexts.values(), (c) => c.close()));
1216
1232
  }
1217
1233
  this.contexts.clear();
1218
1234
  await browser?.close();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/browser-playwright",
3
3
  "type": "module",
4
- "version": "5.0.0-beta.5",
4
+ "version": "5.0.0-beta.6",
5
5
  "description": "Browser running for Vitest using playwright",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -42,7 +42,7 @@
42
42
  ],
43
43
  "peerDependencies": {
44
44
  "playwright": "*",
45
- "vitest": "5.0.0-beta.5"
45
+ "vitest": "5.0.0-beta.6"
46
46
  },
47
47
  "peerDependenciesMeta": {
48
48
  "playwright": {
@@ -51,12 +51,12 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "tinyrainbow": "^3.1.0",
54
- "@vitest/browser": "5.0.0-beta.5",
55
- "@vitest/mocker": "5.0.0-beta.5"
54
+ "@vitest/browser": "5.0.0-beta.6",
55
+ "@vitest/mocker": "5.0.0-beta.6"
56
56
  },
57
57
  "devDependencies": {
58
- "playwright": "^1.60.0",
59
- "vitest": "5.0.0-beta.5"
58
+ "playwright": "^1.61.0",
59
+ "vitest": "5.0.0-beta.6"
60
60
  },
61
61
  "scripts": {
62
62
  "build": "premove dist && pnpm rollup -c",