@vitest/browser 5.0.0-beta.2 → 5.0.0-beta.3

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 (31) hide show
  1. package/context.d.ts +8 -0
  2. package/dist/client/.vite/manifest.json +8 -8
  3. package/dist/client/__vitest__/assets/index-BlLo6Q_D.css +1 -0
  4. package/dist/client/__vitest__/assets/index-O8gheoYf.js +89 -0
  5. package/dist/client/__vitest__/index.html +2 -2
  6. package/dist/client/__vitest_browser__/defineProperty-C3k2g8Sk.js +267 -0
  7. package/dist/client/__vitest_browser__/orchestrator-B44yH1M4.js +343 -0
  8. package/dist/client/__vitest_browser__/rrweb-snapshot-iZCFA2to.js +4388 -0
  9. package/dist/client/__vitest_browser__/tester-Byk-s_d6.js +5088 -0
  10. package/dist/client/orchestrator.html +2 -2
  11. package/dist/client/tester/tester.html +2 -2
  12. package/dist/client/tester/trace.d.ts +9 -6
  13. package/dist/client.js +10 -1
  14. package/dist/context.js +53 -23
  15. package/dist/expect-element.js +30 -30
  16. package/dist/index.js +92 -23
  17. package/dist/locators-DUkyvRhY.js +5 -0
  18. package/dist/locators.js +1 -1
  19. package/dist/shared/screenshotMatcher/types.d.ts +2 -1
  20. package/dist/state.js +64 -14
  21. package/dist/types.d.ts +2 -0
  22. package/jest-dom.d.ts +1 -0
  23. package/matchers.d.ts +2 -1
  24. package/package.json +6 -6
  25. package/dist/client/__vitest__/assets/index-Cd6On2Pm.js +0 -136
  26. package/dist/client/__vitest__/assets/index-Dw9P28Qt.css +0 -1
  27. package/dist/client/__vitest_browser__/orchestrator-BfoS0x4w.js +0 -411
  28. package/dist/client/__vitest_browser__/rrweb-snapshot-xhvrgOHx.js +0 -5476
  29. package/dist/client/__vitest_browser__/tester-BJtW9QqZ.js +0 -5588
  30. package/dist/client/__vitest_browser__/utils-Nd8hqrhP.js +0 -189
  31. package/dist/locators-CesZ2RSY.js +0 -5
package/dist/state.js CHANGED
@@ -3,7 +3,12 @@
3
3
 
4
4
  let SOURCEMAPPING_URL = "sourceMa";
5
5
  SOURCEMAPPING_URL += "ppingURL";
6
+ //#endregion
7
+ //#region src/shared/utils.ts
6
8
  const isWindows = typeof process < "u" && process.platform === "win32";
9
+ /**
10
+ * Undo {@link wrapId}'s `/@id/` and null byte replacements.
11
+ */
7
12
  function unwrapId(id) {
8
13
  return id.startsWith("/@id/") ? id.slice(5).replace("__x00__", "\0") : id;
9
14
  }
@@ -15,11 +20,13 @@
15
20
  function cleanUrl(url) {
16
21
  return url.replace(postfixRE, "");
17
22
  }
23
+ //#endregion
24
+ //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
18
25
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
19
26
  function normalizeWindowsPath(input = "") {
20
27
  return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
21
28
  }
22
- const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
29
+ const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
23
30
  function cwd() {
24
31
  return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
25
32
  }
@@ -59,25 +66,35 @@
59
66
  }
60
67
  const isAbsolute = function(p) {
61
68
  return _IS_ABSOLUTE_RE.test(p);
62
- }, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8");
63
- const posixResolve = resolve;
64
- const intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
65
- for (let i = 0; i < 64; i++) {
66
- let c = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(i);
69
+ }, dirname = function(p) {
70
+ let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
71
+ return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
72
+ }, textDecoder = new TextDecoder(), decodeBase64 = typeof Buffer == "function" && typeof Buffer.from == "function" ? (base64) => Buffer.from(base64, "base64").toString("utf-8") : (base64) => textDecoder.decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)));
73
+ const posixDirname = dirname, posixResolve = resolve;
74
+ //#endregion
75
+ //#region ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
76
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
77
+ for (let i = 0; i < chars.length; i++) {
78
+ let c = chars.charCodeAt(i);
67
79
  intToChar[i] = c, charToInt[c] = i;
68
80
  }
81
+ //#endregion
82
+ //#region src/module-runner/sourcemap/decoder.ts
69
83
  var DecodedMap = class {
70
84
  _encoded;
71
85
  _decoded;
72
86
  _decodedMemo;
73
87
  url;
88
+ file;
74
89
  version;
75
90
  names = [];
76
91
  resolvedSources;
77
92
  constructor(map, from) {
78
93
  this.map = map;
79
94
  let { mappings, names, sources } = map;
80
- this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
95
+ this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.file = from;
96
+ let originDir = posixDirname(from);
97
+ this.resolvedSources = (sources || []).map((s) => posixResolve(originDir, s || ""));
81
98
  }
82
99
  };
83
100
  function memoizedState() {
@@ -87,7 +104,9 @@
87
104
  lastIndex: -1
88
105
  };
89
106
  }
90
- const MODULE_RUNNER_SOURCEMAPPING_REGEXP = /* @__PURE__ */ RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
107
+ //#endregion
108
+ //#region src/module-runner/evaluatedModules.ts
109
+ const MODULE_RUNNER_SOURCEMAPPING_REGEXP = RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
91
110
  var EvaluatedModuleNode = class {
92
111
  importers = /* @__PURE__ */ new Set();
93
112
  imports = /* @__PURE__ */ new Set();
@@ -104,19 +123,44 @@
104
123
  idToModuleMap = /* @__PURE__ */ new Map();
105
124
  fileToModulesMap = /* @__PURE__ */ new Map();
106
125
  urlToIdModuleMap = /* @__PURE__ */ new Map();
126
+ /**
127
+ * Returns the module node by the resolved module ID. Usually, module ID is
128
+ * the file system path with query and/or hash. It can also be a virtual module.
129
+ *
130
+ * Module runner graph will have 1 to 1 mapping with the server module graph.
131
+ * @param id Resolved module ID
132
+ */
107
133
  getModuleById(id) {
108
134
  return this.idToModuleMap.get(id);
109
135
  }
136
+ /**
137
+ * Returns all modules related to the file system path. Different modules
138
+ * might have different query parameters or hash, so it's possible to have
139
+ * multiple modules for the same file.
140
+ * @param file The file system path of the module
141
+ */
110
142
  getModulesByFile(file) {
111
143
  return this.fileToModulesMap.get(file);
112
144
  }
145
+ /**
146
+ * Returns the module node by the URL that was used in the import statement.
147
+ * Unlike module graph on the server, the URL is not resolved and is used as is.
148
+ * @param url Server URL that was used in the import statement
149
+ */
113
150
  getModuleByUrl(url) {
114
151
  return this.urlToIdModuleMap.get(unwrapId(url));
115
152
  }
153
+ /**
154
+ * Ensure that module is in the graph. If the module is already in the graph,
155
+ * it will return the existing module node. Otherwise, it will create a new
156
+ * module node and add it to the graph.
157
+ * @param id Resolved module ID
158
+ * @param url URL that was used in the import statement
159
+ */
116
160
  ensureModule(id, url) {
117
161
  if (id = normalizeModuleId(id), this.idToModuleMap.has(id)) {
118
- let moduleNode$1 = this.idToModuleMap.get(id);
119
- return this.urlToIdModuleMap.set(url, moduleNode$1), moduleNode$1;
162
+ let moduleNode = this.idToModuleMap.get(id);
163
+ return this.urlToIdModuleMap.set(url, moduleNode), moduleNode;
120
164
  }
121
165
  let moduleNode = new EvaluatedModuleNode(id, url);
122
166
  this.idToModuleMap.set(id, moduleNode), this.urlToIdModuleMap.set(url, moduleNode);
@@ -126,6 +170,11 @@
126
170
  invalidateModule(node) {
127
171
  node.evaluated = false, node.meta = void 0, node.map = void 0, node.promise = void 0, node.exports = void 0, node.imports.clear();
128
172
  }
173
+ /**
174
+ * Extracts the inlined source map from the module code and returns the decoded
175
+ * source map. If the source map is not inlined, it will return null.
176
+ * @param id Resolved module ID
177
+ */
129
178
  getModuleSourceMapById(id) {
130
179
  let mod = this.getModuleById(id);
131
180
  if (!mod) return null;
@@ -147,10 +196,10 @@
147
196
  "node:test/reporters"
148
197
  ]);
149
198
  function normalizeModuleId(file) {
150
- if (prefixedBuiltins.has(file)) return file;
151
- let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
152
- return unixFile.replace(/^file:\/+/, isWindows ? "" : "/");
199
+ return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\/+/, isWindows ? "" : "/");
153
200
  }
201
+ //#endregion
202
+ //#region src/module-runner/importMetaResolver.ts
154
203
  const customizationHookNamespace = "vite-module-runner:import-meta-resolve/v1/"; `
155
204
 
156
205
  export async function resolve(specifier, context, nextResolve) {
@@ -160,11 +209,12 @@ export async function resolve(specifier, context, nextResolve) {
160
209
  specifier = parsedSpecifier
161
210
  context.parentURL = parsedImporter
162
211
  }
163
-
164
212
  return nextResolve(specifier, context)
165
213
  }
166
214
 
167
215
  `;
216
+ //#endregion
217
+ //#region src/module-runner/createImportMeta.ts
168
218
  new Proxy({}, { get(_, p) {
169
219
  throw Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
170
220
  } });
package/dist/types.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { MockedModuleSerialized, ServerIdResolution, ServerMockResolution }
2
2
  import type { TaskEventPack, TaskResultPack, TestArtifact } from "@vitest/runner";
3
3
  import type { BirpcReturn } from "birpc";
4
4
  import type { AfterSuiteRunMeta, BrowserTesterOptions, CancelReason, RunnerTestFile, SerializedTestSpecification, SnapshotResult, TestExecutionMethod, UserConsoleLog } from "vitest";
5
+ import type { MarkOptions } from "vitest/browser";
5
6
  export interface WebSocketBrowserHandlers {
6
7
  resolveSnapshotPath: (testPath: string) => string;
7
8
  resolveSnapshotRawPath: (testPath: string, rawPath: string) => string;
@@ -49,6 +50,7 @@ export interface WebSocketBrowserEvents {
49
50
  createTesters: (options: BrowserTesterOptions) => Promise<void>;
50
51
  cleanupTesters: () => Promise<void>;
51
52
  cdpEvent: (event: string, payload: unknown) => void;
53
+ pageMark: (name: string, options?: MarkOptions) => Promise<void>;
52
54
  resolveManualMock: (url: string) => Promise<{
53
55
  url: string;
54
56
  keys: string[];
package/jest-dom.d.ts CHANGED
@@ -692,6 +692,7 @@ export interface TestingLibraryMatchers<E, R> {
692
692
  *
693
693
  * // basic usage, auto-generates screenshot name
694
694
  * await expect.element(getByTestId('button')).toMatchScreenshot()
695
+ * await expect(page).toMatchScreenshot()
695
696
  *
696
697
  * // with custom name
697
698
  * await expect.element(getByTestId('button')).toMatchScreenshot('fancy-button')
package/matchers.d.ts CHANGED
@@ -18,7 +18,8 @@ declare module 'vitest' {
18
18
 
19
19
  interface ExpectStatic {
20
20
  /**
21
- * `expect.element(locator)` is a shorthand for `expect.poll(() => locator.element())`.
21
+ * `expect.element(locator)` retries locator resolution and DOM assertions
22
+ * using the `expect.poll` timeout options.
22
23
  * You can set default timeout via `expect.poll.timeout` option in the config.
23
24
  * @see {@link https://vitest.dev/api/expect#poll}
24
25
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/browser",
3
3
  "type": "module",
4
- "version": "5.0.0-beta.2",
4
+ "version": "5.0.0-beta.3",
5
5
  "description": "Browser running for Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -63,7 +63,7 @@
63
63
  "providers"
64
64
  ],
65
65
  "peerDependencies": {
66
- "vitest": "5.0.0-beta.2"
66
+ "vitest": "5.0.0-beta.3"
67
67
  },
68
68
  "dependencies": {
69
69
  "@blazediff/core": "1.9.1",
@@ -72,8 +72,8 @@
72
72
  "sirv": "^3.0.2",
73
73
  "tinyrainbow": "^3.1.0",
74
74
  "ws": "^8.19.0",
75
- "@vitest/mocker": "5.0.0-beta.2",
76
- "@vitest/utils": "5.0.0-beta.2"
75
+ "@vitest/mocker": "5.0.0-beta.3",
76
+ "@vitest/utils": "5.0.0-beta.3"
77
77
  },
78
78
  "devDependencies": {
79
79
  "@opentelemetry/api": "^1.9.0",
@@ -87,8 +87,8 @@
87
87
  "mime": "^4.1.0",
88
88
  "pathe": "^2.0.3",
89
89
  "rrweb-snapshot": "2.0.0-alpha.20",
90
- "@vitest/runner": "5.0.0-beta.2",
91
- "vitest": "5.0.0-beta.2"
90
+ "@vitest/runner": "5.0.0-beta.3",
91
+ "vitest": "5.0.0-beta.3"
92
92
  },
93
93
  "scripts": {
94
94
  "typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",