FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
dom-testing-library/src/get-user-code-frame.js at main · testing-library/dom-testing-library · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
testing-library
/
dom-testing-library
Public
Notifications
You must be signed in to change notification settings
Fork
472
Star
3.3k
Code
Issues
92
Pull requests
39
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
dom-testing-library
/
src
/
get-user-code-frame.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (58 loc) · 1.72 KB
Breadcrumbs
dom-testing-library
/
src
/
get-user-code-frame.js
Copy path
File metadata and controls
67 lines (58 loc) · 1.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// We try to load node dependencies
let
picocolors
=
null
let
readFileSync
=
null
let
codeFrameColumns
=
null
try
{
const
nodeRequire
=
module
&&
module
.
require
readFileSync
=
nodeRequire
.
call
(
module
,
'fs'
)
.
readFileSync
codeFrameColumns
=
nodeRequire
.
call
(
module
,
'@babel/code-frame'
,
)
.
codeFrameColumns
picocolors
=
nodeRequire
.
call
(
module
,
'picocolors'
)
}
catch
{
// We're in a browser environment
}
// frame has the form "at myMethod (location/to/my/file.js:10:2)"
function
getCodeFrame
(
frame
)
{
const
locationStart
=
frame
.
indexOf
(
'('
)
+
1
const
locationEnd
=
frame
.
indexOf
(
')'
)
const
frameLocation
=
frame
.
slice
(
locationStart
,
locationEnd
)
const
frameLocationElements
=
frameLocation
.
split
(
':'
)
const
[
filename
,
line
,
column
]
=
[
frameLocationElements
[
0
]
,
parseInt
(
frameLocationElements
[
1
]
,
10
)
,
parseInt
(
frameLocationElements
[
2
]
,
10
)
,
]
let
rawFileContents
=
''
try
{
rawFileContents
=
readFileSync
(
filename
,
'utf-8'
)
}
catch
{
return
''
}
const
codeFrame
=
codeFrameColumns
(
rawFileContents
,
{
start
:
{
line
,
column
}
,
}
,
{
highlightCode
:
true
,
linesBelow
:
0
,
}
,
)
return
`
${
picocolors
.
dim
(
frameLocation
)
}
\n
${
codeFrame
}
\n`
}
function
getUserCodeFrame
(
)
{
// If we couldn't load dependencies, we can't generate the user trace
/* istanbul ignore next */
if
(
!
readFileSync
||
!
codeFrameColumns
)
{
return
''
}
const
err
=
new
Error
(
)
const
firstClientCodeFrame
=
err
.
stack
.
split
(
'\n'
)
.
slice
(
1
)
// Remove first line which has the form "Error: TypeError"
.
find
(
frame
=>
!
frame
.
includes
(
'node_modules/'
)
)
// Ignore frames from 3rd party libraries
return
getCodeFrame
(
firstClientCodeFrame
)
}
export
{
getUserCodeFrame
}
Back
|
FazBrowse Home
|
New Git URL