mirror of
https://github.com/dorny/test-reporter.git
synced 2025-12-19 07:27:09 +01:00
* Fix tests on non us-EN local env Different locale might result in different alphabetical order of tests in report. Tests using snapshot comparison then fails * Fix code style
32 lines
845 B
TypeScript
32 lines
845 B
TypeScript
import {normalizeFilePath} from './path-utils'
|
|
|
|
export const DEFAULT_LOCALE = 'en-US'
|
|
|
|
export function getExceptionSource(
|
|
stackTrace: string,
|
|
trackedFiles: string[],
|
|
getRelativePath: (str: string) => string
|
|
): {path: string; line: number} | undefined {
|
|
const lines = stackTrace.split(/\r?\n/)
|
|
const re = /\((.*):(\d+):\d+\)$/
|
|
|
|
for (const str of lines) {
|
|
const match = str.match(re)
|
|
if (match !== null) {
|
|
const [_, fileStr, lineStr] = match
|
|
const filePath = normalizeFilePath(fileStr)
|
|
if (filePath.startsWith('internal/') || filePath.includes('/node_modules/')) {
|
|
continue
|
|
}
|
|
const path = getRelativePath(filePath)
|
|
if (!path) {
|
|
continue
|
|
}
|
|
if (trackedFiles.includes(path)) {
|
|
const line = parseInt(lineStr)
|
|
|
|
return {path, line}
|
|
}
|
|
}
|
|
}
|
|
}
|