rsnext/test/development/acceptance-app/version-staleness.test.ts
Balázs Orbán c16e28715f
feat: show version staleness in error overlay (#44234)Co-authored-by: Sukka <isukkaw@gmail.com> Co-authored-by: Steven <steven@ceriously.com> Co-authored-by: Hannes Bornö <hannes.borno@vercel.com> Co-authored-by: Hannes Bornö <borno.hannes@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Supersedes #37750 as the overlay has been refactored and moved into the
Next.js package itself.

If it detects an older major version, it will show "outdated". Older
minor shows "out of date". Old canary will show "out of date", with a
different message. Matching latest canary or latest will show "up to
date". It will show nothing if we could not detect the versions due to
some error.

<details>
<summary>States: Fresh, stale, outdated</summary>

Fresh:

![image](https://user-images.githubusercontent.com/18369201/208972067-8f2bd8d5-bb92-440a-a3aa-0685b18b4871.png)


Stale:

![image](https://user-images.githubusercontent.com/18369201/208971789-baec0b90-718a-4cdc-bb15-ed23ce5efcbc.png)


Outdated:

![image](https://user-images.githubusercontent.com/18369201/208972153-923ab865-e0f7-405d-9411-45ad1f545d0e.png)

</details>

Fixes NEXT-316

---------

Co-authored-by: Sukka <isukkaw@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Hannes Bornö <hannes.borno@vercel.com>
Co-authored-by: Hannes Bornö <borno.hannes@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-02-17 16:18:28 +01:00

118 lines
3 KiB
TypeScript

/* eslint-env jest */
import { sandbox } from './helpers'
import { createNextDescribe, FileRef } from 'e2e-utils'
import path from 'path'
createNextDescribe(
'Error Overlay version staleness',
{
files: new FileRef(path.join(__dirname, 'fixtures', 'default-template')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
},
skipStart: true,
},
({ next }) => {
it('should show version staleness in runtime error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '1.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
"use client"
import Component from '../index'
export default function Page() {
setTimeout(() => {
throw new Error("runtime error")
}, 0)
return null
}
`
)
await session.waitForAndOpenRuntimeError()
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (1.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in render error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '2.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
export default function Page() {
throw new Error("render error")
return null
}
`
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (2.0.0) is outdated (learn more)"`)
await cleanup()
})
it('should show version staleness in build error', async () => {
// Set next to outdated version
const nextPackageJson = JSON.parse(
await next.readFile('node_modules/next/package.json')
)
nextPackageJson.version = '3.0.0'
const { browser, session, cleanup } = await sandbox(
next,
new Map([
['node_modules/next/package.json', JSON.stringify(nextPackageJson)],
])
)
await session.patch(
'app/page.js',
`
{{{
`
)
expect(
await browser
.waitForElementByCss('.nextjs-container-build-error-version-status')
.text()
).toMatchInlineSnapshot(`"Next.js (3.0.0) is outdated (learn more)"`)
await cleanup()
})
}
)