MCPcopy Create free account
hub / github.com/testing-library/dom-testing-library / getCodeFrame

Function getCodeFrame

src/get-user-code-frame.js:20–50  ·  view source on GitHub ↗
(frame)

Source from the content-addressed store, hash-verified

18
19// frame has the form "at myMethod (location/to/my/file.js:10:2)"
20function getCodeFrame(frame) {
21 const locationStart = frame.indexOf('(') + 1
22 const locationEnd = frame.indexOf(')')
23 const frameLocation = frame.slice(locationStart, locationEnd)
24
25 const frameLocationElements = frameLocation.split(':')
26 const [filename, line, column] = [
27 frameLocationElements[0],
28 parseInt(frameLocationElements[1], 10),
29 parseInt(frameLocationElements[2], 10),
30 ]
31
32 let rawFileContents = ''
33 try {
34 rawFileContents = readFileSync(filename, 'utf-8')
35 } catch {
36 return ''
37 }
38
39 const codeFrame = codeFrameColumns(
40 rawFileContents,
41 {
42 start: {line, column},
43 },
44 {
45 highlightCode: true,
46 linesBelow: 0,
47 },
48 )
49 return `${picocolors.dim(frameLocation)}\n${codeFrame}\n`
50}
51
52function getUserCodeFrame() {
53 // If we couldn't load dependencies, we can't generate the user trace

Callers 1

getUserCodeFrameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected