File size: 4,869 Bytes
1e92f2d |
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 169 170 171 172 173 |
import { check, retry } from 'next-test-utils'
import { FileRef, nextTestSetup } from 'e2e-utils'
import path from 'path'
import { createSandbox } 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')),
skipStart: true,
})
it('should be possible to open source file on build error', async () => {
let editorRequestsCount = 0
await using sandbox = await createSandbox(
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()
})
},
}
)
const { session, browser } = sandbox
await session.patch(
'index.js',
outdent`
import { useState } from 'react'
export default () => 'hello world'
`
)
// Ensure the Next Logo is not loading. This is to assert that the build did stop.
await retry(async () => {
const loaded = await browser.eval(() => {
return Boolean(
[].slice
.call(document.querySelectorAll('nextjs-portal'))
.find((p) =>
p.shadowRoot.querySelector('[data-next-mark-loading="false"]')
)
)
})
expect(loaded).toBe(true)
})
await session.assertHasRedbox()
await clickSourceFile(browser)
await check(() => editorRequestsCount, /1/)
})
;(process.env.IS_TURBOPACK_TEST ? 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
await using sandbox = await createSandbox(
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()
})
},
}
)
const { session, browser } = sandbox
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
await session.assertHasRedbox()
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /4/)
})
it('should be possible to open import trace files on module not found error', async () => {
let editorRequestsCount = 0
await using sandbox = await createSandbox(
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()
})
},
}
)
const { session, browser } = sandbox
await session.patch(
'index.js',
outdent`
import './mod1'
export default () => 'hello world'
`
)
await session.assertHasRedbox()
await clickImportTraceFiles(browser)
await check(() => editorRequestsCount, /3/)
})
}
)
})
|