Skip to content

Commit 48ee23e

Browse files
committed
test: shorten paths used as test data for get user code frame
1 parent 220caa5 commit 48ee23e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/__tests__/get-user-code-frame.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jest.mock('fs', () => ({
1717
),
1818
}))
1919

20-
const userStackFrame =
21-
'at somethingWrong (/home/john/projects/sample-error/error-example.js:7:14)'
20+
const userStackFrame = 'at somethingWrong (/sample-error/error-example.js:7:14)'
2221

2322
let globalErrorMock
2423

@@ -31,16 +30,16 @@ afterEach(() => {
3130
global.Error.mockRestore()
3231
})
3332

34-
test('it returns only client code frame when code frames from node_modules are first', () => {
33+
test('it returns only user code frame when code frames from node_modules are first', () => {
3534
const stack = `Error: Kaboom
36-
at Object.<anonymous> (/home/john/projects/projects/sample-error/node_modules/@es2050/console/build/index.js:4:10)
35+
at Object.<anonymous> (/sample-error/node_modules/@es2050/console/build/index.js:4:10)
3736
${userStackFrame}
3837
`
3938
globalErrorMock.mockImplementationOnce(() => ({stack}))
4039
const userTrace = getUserCodeFrame(stack)
4140

4241
expect(userTrace).toMatchInlineSnapshot(`
43-
"/home/john/projects/sample-error/error-example.js:7:14
42+
"/sample-error/error-example.js:7:14
4443
5 | document.createTextNode('Hello world')
4544
6 | )
4645
> 7 | screen.debug()
@@ -49,18 +48,18 @@ test('it returns only client code frame when code frames from node_modules are f
4948
`)
5049
})
5150

52-
test('it returns only client code frame when node code frames are present afterwards', () => {
51+
test('it returns only user code frame when node code frames are present afterwards', () => {
5352
const stack = `Error: Kaboom
54-
at Object.<anonymous> (/home/john/projects/projects/sample-error/node_modules/@es2050/console/build/index.js:4:10)
53+
at Object.<anonymous> (/sample-error/node_modules/@es2050/console/build/index.js:4:10)
5554
${userStackFrame}
56-
at Object.<anonymous> (/home/user/Documents/projects/sample-error/error-example.js:14:1)
55+
at Object.<anonymous> (/sample-error/error-example.js:14:1)
5756
at internal/main/run_main_module.js:17:47
5857
`
5958
globalErrorMock.mockImplementationOnce(() => ({stack}))
6059
const userTrace = getUserCodeFrame()
6160

6261
expect(userTrace).toMatchInlineSnapshot(`
63-
"/home/john/projects/sample-error/error-example.js:7:14
62+
"/sample-error/error-example.js:7:14
6463
5 | document.createTextNode('Hello world')
6564
6 | )
6665
> 7 | screen.debug()
@@ -86,6 +85,6 @@ test("it returns empty string if file from code frame can't be read", () => {
8685
expect(getUserCodeFrame(stack)).toEqual('')
8786
expect(consoleWarnSpy).toHaveBeenCalledTimes(1)
8887
expect(consoleWarnSpy).toHaveBeenCalledWith(
89-
`Couldn't read file /home/john/projects/sample-error/error-example.js for displaying the code frame`,
88+
`Couldn't read file /sample-error/error-example.js for displaying the code frame`,
9089
)
9190
})

0 commit comments

Comments
 (0)