@vitest/browser 4.0.9 → 4.0.11

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.
@@ -23,7 +23,7 @@
23
23
  })();
24
24
  </script>
25
25
  <!-- !LOAD_METADATA! -->
26
- <script type="module" src="./assets/index-zBMt7UWw.js"></script>
26
+ <script type="module" src="./assets/index-TGTX-jRo.js"></script>
27
27
  <link rel="stylesheet" href="./assets/index-VPnwgb7M.css">
28
28
  </head>
29
29
  <body>
@@ -25,7 +25,7 @@ class IframeOrchestrator {
25
25
  const startTime = performance.now();
26
26
  this.cancelled = false;
27
27
  const config = getConfig();
28
- debug("create testers", options.files.join(", "));
28
+ debug("create testers", ...options.files.join(", "));
29
29
  const container = await getContainer(config);
30
30
  if (config.browser.ui) {
31
31
  container.className = "absolute origin-top mt-[8px]";
@@ -45,7 +45,7 @@ class IframeOrchestrator {
45
45
  return;
46
46
  }
47
47
  const file = options.files[i];
48
- debug("create iframe", file);
48
+ debug("create iframe", file.filepath);
49
49
  await this.runIsolatedTestInIframe(
50
50
  container,
51
51
  file,
@@ -971,25 +971,32 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
971
971
  return rpc$2().onCollected(this.method, files);
972
972
  };
973
973
  onTestAnnotate = (test, annotation) => {
974
- if (annotation.location) {
975
- const map = this.sourceMapCache.get(annotation.location.file);
974
+ const artifact = { type: "internal:annotation", annotation, location: annotation.location };
975
+ return this.onTestArtifactRecord(test, artifact).then(({ annotation: annotation2 }) => annotation2);
976
+ };
977
+ onTestArtifactRecord = (test, artifact) => {
978
+ if (artifact.location) {
979
+ const map = this.sourceMapCache.get(artifact.location.file);
976
980
  if (!map) {
977
- return rpc$2().onTaskAnnotate(test.id, annotation);
981
+ return rpc$2().onTaskArtifactRecord(test.id, artifact);
978
982
  }
979
- const traceMap = new DecodedMap$1(map, annotation.location.file);
980
- const position = getOriginalPosition$1(traceMap, annotation.location);
983
+ const traceMap = new DecodedMap$1(map, artifact.location.file);
984
+ const position = getOriginalPosition$1(traceMap, artifact.location);
981
985
  if (position) {
982
986
  const { source, column, line } = position;
983
- const file = source || annotation.location.file;
984
- annotation.location = {
987
+ const file = source || artifact.location.file;
988
+ artifact.location = {
985
989
  line,
986
990
  column: column + 1,
987
991
  // if the file path is on windows, we need to remove the starting slash
988
992
  file: file.match(/\/\w:\//) ? file.slice(1) : file
989
993
  };
994
+ if (artifact.type === "internal:annotation") {
995
+ artifact.annotation.location = artifact.location;
996
+ }
990
997
  }
991
998
  }
992
- return rpc$2().onTaskAnnotate(test.id, annotation);
999
+ return rpc$2().onTaskArtifactRecord(test.id, artifact);
993
1000
  };
994
1001
  onTaskUpdate = (task, events) => {
995
1002
  return rpc$2().onTaskUpdate(this.method, task, events);
@@ -1016,6 +1023,9 @@ function createBrowserRunner(runnerClass, mocker, state, coverageModule) {
1016
1023
  throw new Error(`Failed to import test file ${filepath}`, { cause: err });
1017
1024
  }
1018
1025
  };
1026
+ // disable tracing in the browser for now
1027
+ trace = void 0;
1028
+ __setTraces = void 0;
1019
1029
  };
1020
1030
  }
1021
1031
  let cachedRunner = null;
@@ -2051,24 +2061,24 @@ async function prepareTestEnvironment(options) {
2051
2061
  };
2052
2062
  }
2053
2063
  let preparedData;
2054
- async function executeTests(method, files) {
2064
+ async function executeTests(method, specifications) {
2055
2065
  if (!preparedData) {
2056
2066
  throw new Error(`Data was not properly initialized. This is a bug in Vitest. Please, open a new issue with reproduction.`);
2057
2067
  }
2058
2068
  debug == null ? void 0 : debug("runner resolved successfully");
2059
2069
  const { runner, state } = preparedData;
2060
- state.ctx.files = files;
2070
+ state.ctx.files = specifications;
2061
2071
  runner.setMethod(method);
2062
2072
  const version = url.searchParams.get("browserv") || "";
2063
- files.forEach(({ filepath }) => {
2073
+ specifications.forEach(({ filepath }) => {
2064
2074
  const currentVersion = browserHashMap.get(filepath);
2065
2075
  if (!currentVersion || currentVersion[1] !== version) {
2066
2076
  browserHashMap.set(filepath, version);
2067
2077
  }
2068
2078
  });
2069
- debug == null ? void 0 : debug("prepare time", state.durations.prepare, "ms");
2070
- for (const file of files) {
2079
+ for (const file of specifications) {
2071
2080
  state.filepath = file.filepath;
2081
+ debug == null ? void 0 : debug("running test file", file.filepath);
2072
2082
  if (method === "run") {
2073
2083
  await startTests([file], runner);
2074
2084
  } else {
@@ -26,7 +26,7 @@
26
26
  {__VITEST_INJECTOR__}
27
27
  {__VITEST_ERROR_CATCHER__}
28
28
  {__VITEST_SCRIPTS__}
29
- <script type="module" crossorigin src="/__vitest_browser__/orchestrator-CFVVvVT1.js"></script>
29
+ <script type="module" crossorigin src="/__vitest_browser__/orchestrator-8U3FyXSU.js"></script>
30
30
  <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
31
31
  </head>
32
32
  <body>
@@ -5,7 +5,7 @@
5
5
  <link rel="icon" href="{__VITEST_FAVICON__}" type="image/svg+xml">
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>Vitest Browser Tester</title>
8
- <script type="module" crossorigin src="/__vitest_browser__/tester-BLe1dg8x.js"></script>
8
+ <script type="module" crossorigin src="/__vitest_browser__/tester-gw0ZBXrK.js"></script>
9
9
  <link rel="modulepreload" crossorigin href="/__vitest_browser__/utils-uxqdqUz8.js">
10
10
  </head>
11
11
  <body>
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import { PNG } from 'pngjs';
18
18
  import pm from 'pixelmatch';
19
19
  import { WebSocketServer } from 'ws';
20
20
 
21
- var version = "4.0.9";
21
+ var version = "4.0.11";
22
22
 
23
23
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
24
24
  function normalizeWindowsPath(input = "") {
@@ -2027,7 +2027,7 @@ const defaultOptions$1 = {
2027
2027
  diffColorAlt: undefined,
2028
2028
  diffMask: false
2029
2029
  };
2030
- const pixelmatch = (reference, actual, { createDiff,...options }) => {
2030
+ const pixelmatch = (reference, actual, { createDiff, ...options }) => {
2031
2031
  if (reference.metadata.height !== actual.metadata.height || reference.metadata.width !== actual.metadata.width) {
2032
2032
  return {
2033
2033
  pass: false,
@@ -2979,8 +2979,8 @@ function setupBrowserRpc(globalServer, defaultMockerRegistry) {
2979
2979
  await vitest._testRun.collected(project, files);
2980
2980
  }
2981
2981
  },
2982
- async onTaskAnnotate(id, annotation) {
2983
- return vitest._testRun.annotate(id, annotation);
2982
+ async onTaskArtifactRecord(id, artifact) {
2983
+ return vitest._testRun.recordArtifact(id, artifact);
2984
2984
  },
2985
2985
  async onTaskUpdate(method, packs, events) {
2986
2986
  if (method === "collect") {
@@ -3029,7 +3029,23 @@ function setupBrowserRpc(globalServer, defaultMockerRegistry) {
3029
3029
  },
3030
3030
  getBrowserFileSourceMap(id) {
3031
3031
  const mod = globalServer.vite.moduleGraph.getModuleById(id);
3032
- return mod?.transformResult?.map;
3032
+ const result = mod?.transformResult;
3033
+ // this can happen for bundled dependencies in node_modules/.vite
3034
+ if (result && !result.map) {
3035
+ const sourceMapUrl = retrieveSourceMapURL(result.code);
3036
+ if (!sourceMapUrl) {
3037
+ return null;
3038
+ }
3039
+ const filepathDir = dirname(id);
3040
+ const sourceMapPath = resolve(filepathDir, sourceMapUrl);
3041
+ try {
3042
+ const map = JSON.parse(readFileSync(sourceMapPath, "utf-8"));
3043
+ return map;
3044
+ } catch {
3045
+ return null;
3046
+ }
3047
+ }
3048
+ return result?.map;
3033
3049
  },
3034
3050
  cancelCurrentRun(reason) {
3035
3051
  vitest.cancelCurrentRun(reason);
@@ -3152,6 +3168,20 @@ function setupBrowserRpc(globalServer, defaultMockerRegistry) {
3152
3168
  return rpc;
3153
3169
  }
3154
3170
  }
3171
+ function retrieveSourceMapURL(source) {
3172
+ const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
3173
+ // keep executing the search to find the *last* sourceMappingURL to avoid
3174
+ // picking up sourceMappingURLs from comments, strings, etc.
3175
+ let lastMatch, match;
3176
+ // eslint-disable-next-line no-cond-assign
3177
+ while (match = re.exec(source)) {
3178
+ lastMatch = match;
3179
+ }
3180
+ if (!lastMatch) {
3181
+ return null;
3182
+ }
3183
+ return lastMatch[1];
3184
+ }
3155
3185
  // Serialization support utils.
3156
3186
  function cloneByOwnProperties(value) {
3157
3187
  // Clones the value's properties into a new Object. The simpler approach of
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { MockedModuleSerialized, ServerIdResolution, ServerMockResolution } from "@vitest/mocker";
2
- import type { TaskEventPack, TaskResultPack, TestAnnotation } from "@vitest/runner";
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
5
  export interface WebSocketBrowserHandlers {
@@ -8,7 +8,7 @@ export interface WebSocketBrowserHandlers {
8
8
  onUnhandledError: (error: unknown, type: string) => Promise<void>;
9
9
  onQueued: (method: TestExecutionMethod, file: RunnerTestFile) => void;
10
10
  onCollected: (method: TestExecutionMethod, files: RunnerTestFile[]) => Promise<void>;
11
- onTaskAnnotate: (testId: string, annotation: TestAnnotation) => Promise<TestAnnotation>;
11
+ onTaskArtifactRecord: <Artifact extends TestArtifact>(testId: string, artifact: Artifact) => Promise<Artifact>;
12
12
  onTaskUpdate: (method: TestExecutionMethod, packs: TaskResultPack[], events: TaskEventPack[]) => void;
13
13
  onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void;
14
14
  cancelCurrentRun: (reason: CancelReason) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/browser",
3
3
  "type": "module",
4
- "version": "4.0.9",
4
+ "version": "4.0.11",
5
5
  "description": "Browser running for Vitest",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -51,7 +51,7 @@
51
51
  "providers"
52
52
  ],
53
53
  "peerDependencies": {
54
- "vitest": "4.0.9"
54
+ "vitest": "4.0.11"
55
55
  },
56
56
  "dependencies": {
57
57
  "magic-string": "^0.30.21",
@@ -60,8 +60,8 @@
60
60
  "sirv": "^3.0.2",
61
61
  "tinyrainbow": "^3.0.3",
62
62
  "ws": "^8.18.3",
63
- "@vitest/mocker": "4.0.9",
64
- "@vitest/utils": "4.0.9"
63
+ "@vitest/mocker": "4.0.11",
64
+ "@vitest/utils": "4.0.11"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@testing-library/user-event": "^14.6.1",
@@ -72,8 +72,8 @@
72
72
  "ivya": "^1.7.0",
73
73
  "mime": "^4.1.0",
74
74
  "pathe": "^2.0.3",
75
- "vitest": "4.0.9",
76
- "@vitest/runner": "4.0.9"
75
+ "@vitest/runner": "4.0.11",
76
+ "vitest": "4.0.11"
77
77
  },
78
78
  "scripts": {
79
79
  "typecheck": "tsc -p ./src/client/tsconfig.json --noEmit",