forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor-links.test.ts
More file actions
168 lines (154 loc) · 4.39 KB
/
editor-links.test.ts
File metadata and controls
168 lines (154 loc) · 4.39 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import { check } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { sandbox } from 'development-sandbox'
import { outdent } from 'outdent'
async function clickSourceFile(browser: any) {
await browser.waitForElementByCss(
'[data-with-open-in-editor-link-source-file]'
)
await browser
.elementByCss('[data-with-open-in-editor-link-source-file]')
.click()
}
async function clickImportTraceFiles(browser: any) {
await browser.waitForElementByCss(
'[data-with-open-in-editor-link-import-trace]'
)
const collapsedFrameworkGroups = await browser.elementsByCss(
'[data-with-open-in-editor-link-import-trace]'
)
for (const collapsedFrameworkButton of collapsedFrameworkGroups) {
await collapsedFrameworkButton.click()
}
}
describe('Error overlay - editor links', () => {
const { next } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
})
it('should be possible to open source file on build error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
outdent`
import { useState } from 'react'
export default () => 'hello world'
`
)
expect(await session.hasRedbox()).toBe(true)
await clickSourceFile(browser)
await check(() => editorRequestsCount, /1/)
await cleanup()
})
;(process.env.TURBOPACK ? describe.skip : describe)(
'opening links in import traces',
() => {
it('should be possible to open import trace files on RSC parse error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', '{{{{{'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
expect(await session.hasRedbox()).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /4/)
await cleanup()
})
it('should be possible to open import trace files on module not found error', async () => {
let editorRequestsCount = 0
const { session, browser, cleanup } = await sandbox(
next,
new Map([
[
'app/page.js',
outdent`
import Component from '../index'
export default function Page() {
return <Component />
}
`,
],
['mod1.js', "import './mod2.js'"],
['mod2.js', 'import "boom"'],
]),
undefined,
{
beforePageLoad(page) {
page.route('**/__nextjs_launch-editor**', (route) => {
editorRequestsCount += 1
route.fulfill()
})
},
}
)
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
expect(await session.hasRedbox()).toBe(true)
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /3/)
await cleanup()
})
}
)
})