|
1 | 1 | import { assertTypes, deepClone, deepMerge, isNegativeNaN, objDisplay, objectAttr, toArray } from '@vitest/utils' |
| 2 | +import { parseSingleFFOrSafariStack } from '@vitest/utils/source-map' |
2 | 3 | import { EvaluatedModules } from 'vite/module-runner' |
3 | 4 | import { beforeAll, describe, expect, test } from 'vitest' |
4 | 5 | import { deepMergeSnapshot } from '../../../packages/snapshot/src/port/utils' |
@@ -306,3 +307,88 @@ describe('isNegativeNaN', () => { |
306 | 307 | expect(isNegativeNaN(value)).toBe(expected) |
307 | 308 | }) |
308 | 309 | }) |
| 310 | + |
| 311 | +describe('parseSingleFFOrSafariStack', () => { |
| 312 | + test('should parse valid Firefox/Safari stack traces with file protocol', () => { |
| 313 | + const validStackLine = 'functionName@file:///path/to/file.js:123:45' |
| 314 | + |
| 315 | + const result = parseSingleFFOrSafariStack(validStackLine) |
| 316 | + |
| 317 | + expect(result).toEqual({ |
| 318 | + file: 'file:///path/to/file.js', |
| 319 | + method: 'functionName', |
| 320 | + line: 123, |
| 321 | + column: 45, |
| 322 | + }) |
| 323 | + }) |
| 324 | + |
| 325 | + test('should parse valid Firefox/Safari stack traces with https protocol', () => { |
| 326 | + const validStackLine = 'functionName@https://example.com/path/to/file.js:123:45' |
| 327 | + |
| 328 | + const result = parseSingleFFOrSafariStack(validStackLine) |
| 329 | + |
| 330 | + expect(result).toEqual({ |
| 331 | + file: '/path/to/file.js', |
| 332 | + method: 'functionName', |
| 333 | + line: 123, |
| 334 | + column: 45, |
| 335 | + }) |
| 336 | + }) |
| 337 | + |
| 338 | + test('should handle stack lines without function names', () => { |
| 339 | + const stackLineWithoutFunction = '@file:///path/to/file.js:123:45' |
| 340 | + |
| 341 | + const result = parseSingleFFOrSafariStack(stackLineWithoutFunction) |
| 342 | + |
| 343 | + expect(result).toEqual({ |
| 344 | + file: 'file:///path/to/file.js', |
| 345 | + method: '', |
| 346 | + line: 123, |
| 347 | + column: 45, |
| 348 | + }) |
| 349 | + }) |
| 350 | + |
| 351 | + test('should parse https URLs with @fs prefix without function name', () => { |
| 352 | + const stackLine = '@https://@fs/path/to/file.js:123:4' |
| 353 | + |
| 354 | + const result = parseSingleFFOrSafariStack(stackLine) |
| 355 | + |
| 356 | + expect(result).toEqual({ |
| 357 | + file: '/path/to/file.js', |
| 358 | + method: '', |
| 359 | + line: 123, |
| 360 | + column: 4, |
| 361 | + }) |
| 362 | + }) |
| 363 | + |
| 364 | + test('should parse https URLs with @fs prefix with function name', () => { |
| 365 | + const stackLine = 'functionName@https://@fs/path/to/file.js:123:4' |
| 366 | + |
| 367 | + const result = parseSingleFFOrSafariStack(stackLine) |
| 368 | + |
| 369 | + expect(result).toEqual({ |
| 370 | + file: '/path/to/file.js', |
| 371 | + method: 'functionName', |
| 372 | + line: 123, |
| 373 | + column: 4, |
| 374 | + }) |
| 375 | + }) |
| 376 | + |
| 377 | + test('should not hang when `Error.stackTraceLimit = 0` (#6039)', { timeout: 5_000 }, async () => { |
| 378 | + // 40 takes ~30s on M2 CPU when fix is reverted |
| 379 | + const size = 40 |
| 380 | + |
| 381 | + const obj = Object.fromEntries( |
| 382 | + [...Array.from({ length: size }).keys()].map(i => [`prop${i}`, i]), |
| 383 | + ) |
| 384 | + |
| 385 | + class PrettyError extends globalThis.Error { |
| 386 | + constructor(e: unknown) { |
| 387 | + Error.stackTraceLimit = 0 |
| 388 | + super(JSON.stringify(e)) |
| 389 | + } |
| 390 | + } |
| 391 | + |
| 392 | + parseSingleFFOrSafariStack(new PrettyError(obj).stack!) |
| 393 | + }) |
| 394 | +}) |
0 commit comments