File size: 28,855 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 |
/* eslint-env jest */
import { createSandbox } from 'development-sandbox'
import { FileRef, nextTestSetup } from 'e2e-utils'
import { check } from 'next-test-utils'
import path from 'path'
import { outdent } from 'outdent'
const isRspack = !!process.env.NEXT_RSPACK
describe('Error recovery app', () => {
const { next, isTurbopack } = nextTestSetup({
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
skipStart: true,
})
test('can recover from a syntax error without losing state', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
await session.patch(
'index.js',
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
const increment = useCallback(() => setCount(c => c + 1), [setCount])
return (
<main>
<p>{count}</p>
<button onClick={increment}>Increment</button>
</main>
)
}
`
)
await browser.elementByCss('button').click()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('1')
await session.patch('index.js', `export default () => <div/`)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (1:27)
Parsing ecmascript source code failed
> 1 | export default () => <div/
| ^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " Γ Module build failed:",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Γ Module build failed:
β°ββΆ Γ Error: x Unexpected eof
β ,----
β 1 | export default () => <div/
β \`----
β
β
β Caused by:
β Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Unexpected eof",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Error: x Unexpected eof
,----
1 | export default () => <div/
\`----
Caused by:
Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
}
await session.patch(
'index.js',
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
const increment = useCallback(() => setCount(c => c + 1), [setCount])
return (
<main>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</main>
)
}
`
)
await session.assertNoRedbox()
await check(
() => session.evaluate(() => document.querySelector('p').textContent),
/Count: 1/
)
})
test('server component can recover from syntax error', async () => {
const type = 'server'
await using sandbox = await createSandbox(next, undefined, '/' + type)
const { browser, session } = sandbox
// Add syntax error
await session.patch(
`app/${type}/page.js`,
outdent`
export default function Page() {
return <p>Hello world</p>
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/server/page.js (2:26)
Parsing ecmascript source code failed
> 2 | return <p>Hello world</p>
| ^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '}', got '<eof>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/server/page.js
Error: x Expected '}', got '<eof>'
,-[2:1]
1 | export default function Page() {
2 | return <p>Hello world</p>
: ^
\`----
Caused by:
Syntax Error
Import trace for requested module:
./app/server/page.js",
"stack": [],
}
`)
}
// Fix syntax error
await session.patch(
`app/${type}/page.js`,
outdent`
export default function Page() {
return <p>Hello world 2</p>
}
`
)
await check(
() => session.evaluate(() => document.querySelector('p').textContent),
'Hello world 2'
)
})
test('client component can recover from syntax error', async () => {
const type = 'client'
await using sandbox = await createSandbox(next, undefined, '/' + type)
const { browser, session } = sandbox
// Add syntax error
await session.patch(
`app/${type}/page.js`,
outdent`
export default function Page() {
return <p>Hello world</p>
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/client/page.js (2:26)
Parsing ecmascript source code failed
> 2 | return <p>Hello world</p>
| ^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '}', got '<eof>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/client/page.js
Error: x Expected '}', got '<eof>'
,-[2:1]
1 | export default function Page() {
2 | return <p>Hello world</p>
: ^
\`----
Caused by:
Syntax Error
Import trace for requested module:
./app/client/page.js",
"stack": [],
}
`)
}
// Fix syntax error
await session.patch(
`app/${type}/page.js`,
outdent`
export default function Page() {
return <p>Hello world 2</p>
}
`
)
await check(
() => session.evaluate(() => document.querySelector('p').textContent),
'Hello world 2'
)
})
test('can recover from a event handler error', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
await session.patch(
'index.js',
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
const increment = useCallback(() => {
setCount(c => c + 1)
throw new Error('oops')
}, [setCount])
return (
<main>
<p>{count}</p>
<button onClick={increment}>Increment</button>
</main>
)
}
`
)
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('0')
await browser.elementByCss('button').click()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('1')
if (isTurbopack) {
// TODO(veil): Location of Page should be app/page.js
// TODO(sokra): The location is wrong because of an bug with HMR and source maps.
// When the code `index.js` changes, this also moves the locations of `app/page.js` in the bundled file.
// So the SourceMap is updated to reflect that. But the browser still has the old bundled file loaded.
// So we look up locations from the old bundle in the new source maps, which leads to mismatched locations.
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "oops",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (7:11) @ Index.useCallback[increment]
> 7 | throw new Error('oops')
| ^",
"stack": [
"Index.useCallback[increment] index.js (7:11)",
"button <anonymous>",
"Index index.js (12:7)",
"Page index.js (8:16)",
],
}
`)
} else {
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "oops",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (7:11) @ Index.useCallback[increment]
> 7 | throw new Error('oops')
| ^",
"stack": [
"Index.useCallback[increment] index.js (7:11)",
"button <anonymous>",
"Index index.js (12:7)",
"Page app/page.js (4:10)",
],
}
`)
}
await session.patch(
'index.js',
outdent`
import { useCallback, useState } from 'react'
export default function Index() {
const [count, setCount] = useState(0)
const increment = useCallback(() => setCount(c => c + 1), [setCount])
return (
<main>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
</main>
)
}
`
)
await session.assertNoRedbox()
expect(await session.hasErrorToast()).toBe(false)
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('Count: 1')
await browser.elementByCss('button').click()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('Count: 2')
await session.assertNoRedbox()
expect(await session.hasErrorToast()).toBe(false)
})
test('server component can recover from a component error', async () => {
const type = 'server'
await using sandbox = await createSandbox(next, undefined, '/' + type)
const { session, browser } = sandbox
await session.write(
'child.js',
outdent`
export default function Child() {
return <p>Hello</p>;
}
`
)
await session.patch(
'index.js',
outdent`
import Child from './child'
export default function Index() {
return (
<main>
<Child />
</main>
)
}
`
)
expect(await browser.elementByCss('p').text()).toBe('Hello')
await session.patch(
'child.js',
outdent`
// hello
export default function Child() {
throw new Error('oops')
}
`
)
await expect(browser).toDisplayRedbox(
`
{
"description": "oops",
"environmentLabel": "Server",
"label": "<FIXME-excluded-label>",
"source": "child.js (3:9) @ Child
> 3 | throw new Error('oops')
| ^",
"stack": [
"Child child.js (3:9)",
"Page app/server/page.js (3:10)",
],
}
`,
// FIXME: `label` is flaking between "Runtime Error" and "Recoverable Error"
{ label: false }
)
// TODO-APP: re-enable when error recovery doesn't reload the page.
/* const didNotReload = */ await session.patch(
'child.js',
outdent`
export default function Child() {
return <p>Hello</p>;
}
`
)
// TODO-APP: re-enable when error recovery doesn't reload the page.
// expect(didNotReload).toBe(true)
await session.assertNoRedbox()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('Hello')
})
test('client component can recover from a component error', async () => {
const type = 'client'
await using sandbox = await createSandbox(next, undefined, '/' + type)
const { session, browser } = sandbox
await session.write(
'child.js',
outdent`
export default function Child() {
return <p>Hello</p>;
}
`
)
await session.patch(
'index.js',
outdent`
import Child from './child'
export default function Index() {
return (
<main>
<Child />
</main>
)
}
`
)
expect(await browser.elementByCss('p').text()).toBe('Hello')
await session.patch(
'child.js',
outdent`
// hello
export default function Child() {
throw new Error('oops')
}
`
)
if (isTurbopack) {
// <FIXME-file-protocol>: https://linear.app/vercel/issue/NDX-920/
await expect(browser).toDisplayRedbox(`
{
"description": "oops",
"environmentLabel": null,
"label": "Runtime Error",
"source": "child.js (3:9) @ Child
> 3 | throw new Error('oops')
| ^",
"stack": [
"Child child.js (3:9)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"Index index.js (6:7)",
"<FIXME-file-protocol>",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": "oops",
"environmentLabel": null,
"label": "Runtime Error",
"source": "child.js (3:9) @ Child
> 3 | throw new Error('oops')
| ^",
"stack": [
"Child child.js (3:9)",
"Index index.js (6:7)",
"Page app/client/page.js (4:10)",
],
}
`)
}
// TODO-APP: re-enable when error recovery doesn't reload the page.
/* const didNotReload = */ await session.patch(
'child.js',
outdent`
export default function Child() {
return <p>Hello</p>;
}
`
)
// TODO-APP: re-enable when error recovery doesn't reload the page.
// expect(didNotReload).toBe(true)
await session.assertNoRedbox()
expect(
await session.evaluate(() => document.querySelector('p').textContent)
).toBe('Hello')
})
// https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554150098
test('syntax > runtime error', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
// Start here.
await session.patch(
'index.js',
outdent`
import * as React from 'react';
export default function FunctionNamed() {
return <div />
}
`
)
// TODO: this acts weird without above step
await session.patch(
'index.js',
outdent`
import * as React from 'react';
let i = 0
window.triggerError = () => {
// TODO(veil): sync thrown errors do not trigger Redbox.
setTimeout(() => {
i++
throw Error('no ' + i)
}, 0)
}
export default function FunctionNamed() {
return <div />
}
`
)
await browser.eval('window.triggerError()')
if (isRspack) {
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "no 1",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (7:11) @ eval
> 7 | throw Error('no ' + i)
| ^",
"stack": [
"eval index.js (7:11)",
],
}
`)
} else {
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "no 1",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (7:11) @ eval
> 7 | throw Error('no ' + i)
| ^",
"stack": [
"eval index.js (7:11)",
],
}
`)
}
// Make a syntax error.
await session.patch(
'index.js',
outdent`
import * as React from 'react';
let i = 0
window.triggerError = () => {
// TODO(veil): sync thrown errors do not trigger Redbox.
setTimeout(() => {
i++
throw Error('no ' + i)
}, 0)
}
export default function FunctionNamed() {
`
)
await new Promise((resolve) => setTimeout(resolve, 1000))
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (10:39)
Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() {
| ^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '}', got '<eof>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Error: x Expected '}', got '<eof>'
,-[10:1]
10 | export default function FunctionNamed() {
: ^
\`----
Caused by:
Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
}
// Test that runtime error does not take over:
await browser.eval('window.triggerError()')
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (10:39)
Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() {
| ^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '}', got '<eof>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Error: x Expected '}', got '<eof>'
,-[10:1]
10 | export default function FunctionNamed() {
: ^
\`----
Caused by:
Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
}
})
// https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554144016
test('stuck error', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
// We start here.
await session.patch(
'index.js',
outdent`
import * as React from 'react';
function FunctionDefault() {
return <h1>Default Export Function</h1>;
}
export default FunctionDefault;
`
)
// We add a new file. Let's call it Foo.js.
await session.write(
'Foo.js',
outdent`
// intentionally skips export
export default function Foo() {
return React.createElement('h1', null, 'Foo');
}
`
)
// We edit our first file to use it.
await session.patch(
'index.js',
outdent`
import * as React from 'react';
import Foo from './Foo';
function FunctionDefault() {
return <Foo />;
}
export default FunctionDefault;
`
)
// We get an error because Foo didn't import React. Fair.
if (isTurbopack) {
// <FIXME-file-protocol>: https://linear.app/vercel/issue/NDX-920/
await expect(browser).toDisplayRedbox(`
{
"description": "React is not defined",
"environmentLabel": null,
"label": "Runtime ReferenceError",
"source": "Foo.js (3:3) @ Foo
> 3 | return React.createElement('h1', null, 'Foo');
| ^",
"stack": [
"Foo Foo.js (3:3)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"FunctionDefault index.js (4:10)",
"<FIXME-file-protocol>",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": "React is not defined",
"environmentLabel": null,
"label": "Runtime ReferenceError",
"source": "Foo.js (3:3) @ Foo
> 3 | return React.createElement('h1', null, 'Foo');
| ^",
"stack": [
"Foo Foo.js (3:3)",
"FunctionDefault index.js (4:10)",
"Page app/page.js (4:10)",
],
}
`)
}
// Let's add that to Foo.
await session.patch(
'Foo.js',
outdent`
import * as React from 'react';
export default function Foo() {
return React.createElement('h1', null, 'Foo');
}
`
)
// Expected: this fixes the problem
await session.assertNoRedbox()
})
// https://github.com/pmmmwh/react-refresh-webpack-plugin/pull/3#issuecomment-554137262
test('render error not shown right after syntax error', async () => {
await using sandbox = await createSandbox(next)
const { browser, session } = sandbox
// Starting here:
await session.patch(
'index.js',
outdent`
import * as React from 'react';
class ClassDefault extends React.Component {
render() {
return <h1>Default Export</h1>;
}
}
export default ClassDefault;
`
)
expect(
await session.evaluate(() => document.querySelector('h1').textContent)
).toBe('Default Export')
// Break it with a syntax error:
await session.patch(
'index.js',
outdent`
import * as React from 'react';
class ClassDefault extends React.Component {
render()
return <h1>Default Export</h1>;
}
}
export default ClassDefault;
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (5:5)
Parsing ecmascript source code failed
> 5 | return <h1>Default Export</h1>;
| ^^^^^^",
"stack": [],
}
`)
} else if (isRspack) {
await expect({ browser, next }).toDisplayRedbox(`
{
"description": " Γ Module build failed:",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Γ Module build failed:
β°ββΆ Γ Error: x Expected '{', got 'return'
β ,-[5:1]
β 2 |
β 3 | class ClassDefault extends React.Component {
β 4 | render()
β 5 | return <h1>Default Export</h1>;
β : ^^^^^^
β 6 | }
β 7 | }
β \`----
β
β
β Caused by:
β Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '{', got 'return'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Error: x Expected '{', got 'return'
,-[5:1]
2 |
3 | class ClassDefault extends React.Component {
4 | render()
5 | return <h1>Default Export</h1>;
: ^^^^^^
6 | }
7 | }
\`----
Caused by:
Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
}
// Now change the code to introduce a runtime error without fixing the syntax error:
await session.patch(
'index.js',
outdent`
import * as React from 'react';
class ClassDefault extends React.Component {
render()
throw new Error('nooo');
return <h1>Default Export</h1>;
}
}
export default ClassDefault;
`
)
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js (5:5)
Parsing ecmascript source code failed
> 5 | throw new Error('nooo');
| ^^^^^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '{', got 'throw'",
"environmentLabel": null,
"label": "Build Error",
"source": "./index.js
Error: x Expected '{', got 'throw'
,-[5:1]
2 |
3 | class ClassDefault extends React.Component {
4 | render()
5 | throw new Error('nooo');
: ^^^^^
6 | return <h1>Default Export</h1>;
7 | }
8 | }
\`----
Caused by:
Syntax Error
Import trace for requested module:
./index.js
./app/page.js",
"stack": [],
}
`)
}
// Now fix the syntax error:
await session.patch(
'index.js',
outdent`
import * as React from 'react';
class ClassDefault extends React.Component {
render() {
throw new Error('nooo');
return <h1>Default Export</h1>;
}
}
export default ClassDefault;
`
)
if (isTurbopack) {
// TODO(veil): Location of Page should be app/page.js
// <FIXME-file-protocol>: https://linear.app/vercel/issue/NDX-920/
await expect(browser).toDisplayRedbox(`
{
"description": "nooo",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (5:11) @ ClassDefault.render
> 5 | throw new Error('nooo');
| ^",
"stack": [
"ClassDefault.render index.js (5:11)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"Page index.js (10:16)",
],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": "nooo",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (5:11) @ ClassDefault.render
> 5 | throw new Error('nooo');
| ^",
"stack": [
"ClassDefault.render index.js (5:11)",
"Page app/page.js (4:10)",
],
}
`)
}
})
test('displays build error on initial page load', async () => {
await using sandbox = await createSandbox(
next,
new Map([['app/page.js', '{{{']])
)
const { browser } = sandbox
if (isTurbopack) {
await expect(browser).toDisplayRedbox(`
{
"description": "Parsing ecmascript source code failed",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js (1:2)
Parsing ecmascript source code failed
> 1 | {{{
| ^",
"stack": [],
}
`)
} else {
await expect(browser).toDisplayRedbox(`
{
"description": " x Expected '}', got '<eof>'",
"environmentLabel": null,
"label": "Build Error",
"source": "./app/page.js
Error: x Expected '}', got '<eof>'
,----
1 | {{{
: ^
\`----
Caused by:
Syntax Error",
"stack": [],
}
`)
}
})
})
|