This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Record test failure details in mocha
Fixes #231
- Loading branch information
1 parent
25bb77d
commit 5400c82
Showing
10 changed files
with
400 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,54 @@ | ||
import { InternalAppmapError } from "../../error/index.mjs"; | ||
import { assert } from "../../util/index.mjs"; | ||
|
||
const { String, parseInt, undefined } = globalThis; | ||
const { parseInt, undefined } = globalThis; | ||
|
||
const regexp = /^([A-Za-z0-9+/=]+\|)?([\s\S]+):([0-9]+):([0-9]+)$/u; | ||
const regexp = /^(?:([A-Za-z0-9+/=]+)\|)?(.+)$/u; | ||
|
||
export const stringifyLocation = ({ | ||
url, | ||
hash, | ||
position: { line, column }, | ||
}) => { | ||
const position = [line, column].filter((x) => x !== undefined).join(":"); | ||
if (hash === null) { | ||
return `${url}:${String(line)}:${String(column)}`; | ||
return `${url}:${position}`; | ||
} else { | ||
return `${hash}|${url}:${String(line)}:${String(column)}`; | ||
return `${hash}|${url}:${position}`; | ||
} | ||
}; | ||
|
||
const popInt = (arr) => { | ||
const last = arr.pop(); | ||
if (last.match(/\d+/u)) { | ||
return parseInt(last); | ||
} | ||
arr.push(last); | ||
return undefined; | ||
}; | ||
|
||
export const parseLocation = (string) => { | ||
const parts = regexp.exec(string); | ||
assert(parts !== null, "invalid location format", InternalAppmapError); | ||
const [, hash, rest] = regexp.exec(string); | ||
assert( | ||
rest !== null, | ||
`invalid location format: ${string}`, | ||
InternalAppmapError, | ||
); | ||
|
||
const parts = rest.split(":"); | ||
const loc2 = popInt(parts); | ||
const loc1 = popInt(parts); | ||
let line, column; | ||
if (loc1 !== undefined) { | ||
line = parseInt(loc1); | ||
column = parseInt(loc2); | ||
} else if (loc2 !== undefined) { | ||
line = parseInt(loc2); | ||
} | ||
|
||
return { | ||
hash: | ||
parts[1] === undefined | ||
? null | ||
: parts[1].substring(0, parts[1].length - 1), | ||
url: parts[2], | ||
position: { | ||
line: parseInt(parts[3]), | ||
column: parseInt(parts[4]), | ||
}, | ||
hash: hash ?? null, | ||
url: parts.join(":"), | ||
position: { line, column }, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.