Unverified Commit 7a2ec416 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Refactor more tests to createNextDescribe (#44104)

parent b8ae447b
...@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base' ...@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path' import path from 'path'
describe('ReactRefresh app', () => { describe('ReactRefresh app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -5,11 +5,6 @@ import path from 'path' ...@@ -5,11 +5,6 @@ import path from 'path'
// TODO-APP: Investigate snapshot mismatch // TODO-APP: Investigate snapshot mismatch
describe('ReactRefreshLogBox app', () => { describe('ReactRefreshLogBox app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -7,11 +7,6 @@ import path from 'path' ...@@ -7,11 +7,6 @@ import path from 'path'
// TODO: figure out why snapshots mismatch on GitHub actions // TODO: figure out why snapshots mismatch on GitHub actions
// specifically but work in docker and locally // specifically but work in docker and locally
describe.skip('ReactRefreshLogBox app', () => { describe.skip('ReactRefreshLogBox app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -6,11 +6,6 @@ import { check } from 'next-test-utils' ...@@ -6,11 +6,6 @@ import { check } from 'next-test-utils'
import path from 'path' import path from 'path'
describe('ReactRefreshLogBox app', () => { describe('ReactRefreshLogBox app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -6,11 +6,6 @@ import path from 'path' ...@@ -6,11 +6,6 @@ import path from 'path'
// TODO: re-enable these tests after figuring out what is causing // TODO: re-enable these tests after figuring out what is causing
// them to be so unreliable in CI // them to be so unreliable in CI
describe.skip('ReactRefreshLogBox app', () => { describe.skip('ReactRefreshLogBox app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -4,11 +4,6 @@ import { NextInstance } from 'test/lib/next-modes/base' ...@@ -4,11 +4,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import { sandbox } from './helpers' import { sandbox } from './helpers'
describe('ReactRefreshModule app', () => { describe('ReactRefreshModule app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base' ...@@ -5,11 +5,6 @@ import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path' import path from 'path'
describe('ReactRefreshRegression app', () => { describe('ReactRefreshRegression app', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -6,11 +6,6 @@ import path from 'path' ...@@ -6,11 +6,6 @@ import path from 'path'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
describe('Error Overlay for server components', () => { describe('Error Overlay for server components', () => {
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
beforeAll(async () => { beforeAll(async () => {
......
...@@ -532,14 +532,10 @@ describe('basic HMR', () => { ...@@ -532,14 +532,10 @@ describe('basic HMR', () => {
) )
) )
const isReact17 = process.env.NEXT_TEST_REACT_VERSION === '^17'
expect(await hasRedbox(browser)).toBe(true) expect(await hasRedbox(browser)).toBe(true)
// TODO: Replace this when webpack 5 is the default // TODO: Replace this when webpack 5 is the default
expect(await getRedboxHeader(browser)).toMatch( expect(await getRedboxHeader(browser)).toMatch(
`Objects are not valid as a React child (found: ${ `Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
isReact17 ? '/search/' : '[object RegExp]'
}). If you meant to render a collection of children, use an array instead.`
) )
await next.patchFile(aboutPage, aboutContent) await next.patchFile(aboutPage, aboutContent)
......
...@@ -597,14 +597,10 @@ describe('basic HMR', () => { ...@@ -597,14 +597,10 @@ describe('basic HMR', () => {
) )
) )
const isReact17 = process.env.NEXT_TEST_REACT_VERSION === '^17'
expect(await hasRedbox(browser)).toBe(true) expect(await hasRedbox(browser)).toBe(true)
// TODO: Replace this when webpack 5 is the default // TODO: Replace this when webpack 5 is the default
expect(await getRedboxHeader(browser)).toMatch( expect(await getRedboxHeader(browser)).toMatch(
`Objects are not valid as a React child (found: ${ `Objects are not valid as a React child (found: [object RegExp]). If you meant to render a collection of children, use an array instead.`
isReact17 ? '/search/' : '[object RegExp]'
}). If you meant to render a collection of children, use an array instead.`
) )
await next.patchFile(aboutPage, aboutContent) await next.patchFile(aboutPage, aboutContent)
......
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import webdriver from 'next-webdriver'
import path from 'path' import path from 'path'
import { readJSON } from 'fs-extra'
describe('app-dir alias handling', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'app-dir alias handling',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'app-alias'),
} dependencies: {
react: 'latest',
let next: NextInstance 'react-dom': 'latest',
typescript: 'latest',
beforeAll(async () => { '@types/react': 'latest',
next = await createNext({ '@types/node': 'latest',
files: new FileRef(path.join(__dirname, 'app-alias')), },
dependencies: { packageJson: {
react: 'latest', type: 'module',
'react-dom': 'latest', },
typescript: 'latest', skipDeployment: true,
'@types/react': 'latest', },
'@types/node': 'latest', ({ next, isNextDev }) => {
}, it('should handle typescript paths alias correctly', async () => {
packageJson: { const html = await next.render('/button')
type: 'module', expect(html).toContain('click</button>')
},
}) })
})
afterAll(() => next.destroy())
it('should handle typescript paths alias correctly', async () => { it('should resolve css imports from outside with src folder presented', async () => {
const html = await renderViaHTTP(next.url, '/button') const browser = await next.browser('/button')
expect(html).toContain('click</button>') const fontSize = await browser
}) .elementByCss('button')
.getComputedCss('font-size')
it('should resolve css imports from outside with src folder presented', async () => { expect(fontSize).toBe('50px')
const browser = await webdriver(next.url, '/button') })
const fontSize = await browser
.elementByCss('button')
.getComputedCss('font-size')
expect(fontSize).toBe('50px')
})
if (!(global as any).isNextDev) { if (!isNextDev) {
it('should generate app-build-manifest correctly', async () => { it('should generate app-build-manifest correctly', async () => {
// Remove other page CSS files: // Remove other page CSS files:
const manifest = await readJSON( const manifest = await next.readJSON(
path.join(next.testDir, '.next', 'app-build-manifest.json') path.join('.next', 'app-build-manifest.json')
) )
expect(manifest.pages).not.toBeEmptyObject() expect(manifest.pages).not.toBeEmptyObject()
}) })
}
} }
}) )
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
describe('app-dir global edge configuration', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'app-dir global edge configuration',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'app-edge-global'),
} dependencies: {
react: 'latest',
let next: NextInstance 'react-dom': 'latest',
typescript: 'latest',
beforeAll(async () => { '@types/react': 'latest',
next = await createNext({ '@types/node': 'latest',
files: new FileRef(path.join(__dirname, 'app-edge-global')), },
dependencies: { skipDeployment: true,
react: 'latest', },
'react-dom': 'latest', ({ next }) => {
typescript: 'latest', it('should handle edge only routes', async () => {
'@types/react': 'latest', const html = await next.render('/app-edge')
'@types/node': 'latest', expect(html).toContain('<p>Edge!</p>')
},
}) })
}) }
afterAll(() => next.destroy()) )
it('should handle edge only routes', async () => {
const appHtml = await renderViaHTTP(next.url, '/app-edge')
expect(appHtml).toContain('<p>Edge!</p>')
})
})
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { check } from 'next-test-utils'
import { check, renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
describe('app-dir edge SSR', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'app-dir edge SSR',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'app-edge'),
} dependencies: {
react: 'latest',
let next: NextInstance 'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
skipDeployment: true,
},
({ next }) => {
it('should handle edge only routes', async () => {
const appHtml = await next.render('/app-edge')
expect(appHtml).toContain('<p>Edge!</p>')
beforeAll(async () => { const pageHtml = await next.render('/pages-edge')
next = await createNext({ expect(pageHtml).toContain('<p>pages-edge-ssr</p>')
files: new FileRef(path.join(__dirname, 'app-edge')),
dependencies: {
react: 'latest',
'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
}) })
})
afterAll(() => next.destroy())
it('should handle edge only routes', async () => {
const appHtml = await renderViaHTTP(next.url, '/app-edge')
expect(appHtml).toContain('<p>Edge!</p>')
const pageHtml = await renderViaHTTP(next.url, '/pages-edge') if ((globalThis as any).isNextDev) {
expect(pageHtml).toContain('<p>pages-edge-ssr</p>') it('should resolve module without error in edge runtime', async () => {
}) const logs = []
next.on('stderr', (log) => {
if ((globalThis as any).isNextDev) { logs.push(log)
it('should resolve module without error in edge runtime', async () => { })
const logs = [] await next.render('app-edge')
next.on('stderr', (log) => { expect(
logs.push(log) logs.some((log) => log.includes(`Attempted import error:`))
).toBe(false)
}) })
await renderViaHTTP(next.url, 'app-edge')
expect(logs.some((log) => log.includes(`Attempted import error:`))).toBe(
false
)
})
it('should handle edge rsc hmr', async () => { it('should handle edge rsc hmr', async () => {
const pageFile = 'app/app-edge/page.tsx' const pageFile = 'app/app-edge/page.tsx'
const content = await next.readFile(pageFile) const content = await next.readFile(pageFile)
// Update rendered content // Update rendered content
const updatedContent = content.replace('Edge!', 'edge-hmr') const updatedContent = content.replace('Edge!', 'edge-hmr')
await next.patchFile(pageFile, updatedContent) await next.patchFile(pageFile, updatedContent)
await check(async () => { await check(async () => {
const html = await renderViaHTTP(next.url, '/app-edge') const html = await next.render('/app-edge')
return html return html
}, /edge-hmr/) }, /edge-hmr/)
// Revert // Revert
await next.patchFile(pageFile, content) await next.patchFile(pageFile, content)
await check(async () => { await check(async () => {
const html = await renderViaHTTP(next.url, '/app-edge') const html = await next.render('/app-edge')
return html return html
}, /Edge!/) }, /Edge!/)
}) })
} else { } else {
// Production tests // Production tests
it('should generate matchers correctly in middleware manifest', async () => { it('should generate matchers correctly in middleware manifest', async () => {
const manifest = JSON.parse( const manifest = JSON.parse(
await next.readFile('.next/server/middleware-manifest.json') await next.readFile('.next/server/middleware-manifest.json')
) )
expect(manifest.functions['/(group)/group/page'].matchers).toEqual([ expect(manifest.functions['/(group)/group/page'].matchers).toEqual([
{ {
regexp: '^/group$', regexp: '^/group$',
}, },
]) ])
}) })
}
} }
}) )
This diff is collapsed.
/* eslint-env jest */ /* eslint-env jest */
import { createNextDescribe, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import path from 'path' import path from 'path'
describe('app-dir with middleware', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'app-dir with middleware',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'app-middleware'),
} skipDeployment: true,
},
let next: NextInstance ({ next }) => {
describe.each([
afterAll(() => next.destroy()) {
beforeAll(async () => { title: 'Serverless Functions',
next = await createNext({ path: '/api/dump-headers-serverless',
files: new FileRef(path.join(__dirname, 'app-middleware')), toJson: (res: Response) => res.json(),
})
})
describe.each([
{
title: 'Serverless Functions',
path: '/api/dump-headers-serverless',
toJson: (res: Response) => res.json(),
},
{
title: 'Edge Functions',
path: '/api/dump-headers-edge',
toJson: (res: Response) => res.json(),
},
{
title: 'next/headers',
path: '/headers',
toJson: async (res: Response) => {
const $ = cheerio.load(await res.text())
return JSON.parse($('#headers').text())
}, },
}, {
])('Mutate request headers for $title', ({ path, toJson }) => { title: 'Edge Functions',
it(`Adds new headers`, async () => { path: '/api/dump-headers-edge',
const res = await fetchViaHTTP(next.url, path, null, { toJson: (res: Response) => res.json(),
headers: { },
'x-from-client': 'hello-from-client', {
}, title: 'next/headers',
}) path: '/headers',
expect(await toJson(res)).toMatchObject({ toJson: async (res: Response) => {
'x-from-client': 'hello-from-client', const $ = cheerio.load(await res.text())
'x-from-middleware': 'hello-from-middleware', return JSON.parse($('#headers').text())
})
})
it(`Deletes headers`, async () => {
const res = await fetchViaHTTP(
next.url,
path,
{
'remove-headers': 'x-from-client1,x-from-client2',
}, },
{ },
])('Mutate request headers for $title', ({ path, toJson }) => {
it(`Adds new headers`, async () => {
const res = await next.fetch(path, null, {
headers: { headers: {
'x-from-client1': 'hello-from-client', 'x-from-client': 'hello-from-client',
'X-From-Client2': 'hello-from-client',
}, },
} })
) expect(await toJson(res)).toMatchObject({
'x-from-client': 'hello-from-client',
const json = await toJson(res) 'x-from-middleware': 'hello-from-middleware',
expect(json).not.toHaveProperty('x-from-client1') })
expect(json).not.toHaveProperty('X-From-Client2')
expect(json).toMatchObject({
'x-from-middleware': 'hello-from-middleware',
}) })
// Should not be included in response headers. it(`Deletes headers`, async () => {
expect(res.headers.get('x-middleware-override-headers')).toBeNull() const res = await next.fetch(
expect( path,
res.headers.get('x-middleware-request-x-from-middleware') {
).toBeNull() 'remove-headers': 'x-from-client1,x-from-client2',
expect(res.headers.get('x-middleware-request-x-from-client1')).toBeNull()
expect(res.headers.get('x-middleware-request-x-from-client2')).toBeNull()
})
it(`Updates headers`, async () => {
const res = await fetchViaHTTP(
next.url,
path,
{
'update-headers':
'x-from-client1=new-value1,x-from-client2=new-value2',
},
{
headers: {
'x-from-client1': 'old-value1',
'X-From-Client2': 'old-value2',
'x-from-client3': 'old-value3',
}, },
} {
) headers: {
expect(await toJson(res)).toMatchObject({ 'x-from-client1': 'hello-from-client',
'x-from-client1': 'new-value1', 'X-From-Client2': 'hello-from-client',
'x-from-client2': 'new-value2', },
'x-from-client3': 'old-value3', }
'x-from-middleware': 'hello-from-middleware', )
const json = await toJson(res)
expect(json).not.toHaveProperty('x-from-client1')
expect(json).not.toHaveProperty('X-From-Client2')
expect(json).toMatchObject({
'x-from-middleware': 'hello-from-middleware',
})
// Should not be included in response headers.
expect(res.headers.get('x-middleware-override-headers')).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-middleware')
).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-client1')
).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-client2')
).toBeNull()
}) })
// Should not be included in response headers. it(`Updates headers`, async () => {
expect(res.headers.get('x-middleware-override-headers')).toBeNull() const res = await next.fetch(
expect( path,
res.headers.get('x-middleware-request-x-from-middleware') {
).toBeNull() 'update-headers':
expect(res.headers.get('x-middleware-request-x-from-client1')).toBeNull() 'x-from-client1=new-value1,x-from-client2=new-value2',
expect(res.headers.get('x-middleware-request-x-from-client2')).toBeNull() },
expect(res.headers.get('x-middleware-request-x-from-client3')).toBeNull() {
headers: {
'x-from-client1': 'old-value1',
'X-From-Client2': 'old-value2',
'x-from-client3': 'old-value3',
},
}
)
expect(await toJson(res)).toMatchObject({
'x-from-client1': 'new-value1',
'x-from-client2': 'new-value2',
'x-from-client3': 'old-value3',
'x-from-middleware': 'hello-from-middleware',
})
// Should not be included in response headers.
expect(res.headers.get('x-middleware-override-headers')).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-middleware')
).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-client1')
).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-client2')
).toBeNull()
expect(
res.headers.get('x-middleware-request-x-from-client3')
).toBeNull()
})
}) })
})
})
describe('app dir middleware without pages dir', () => {
if ((global as any).isNextDeploy) {
it('should skip next deploy for now', () => {})
return
} }
)
let next: NextInstance
createNextDescribe(
afterAll(() => next.destroy()) 'app dir middleware without pages dir',
beforeAll(async () => { {
next = await createNext({ files: {
files: { app: new FileRef(path.join(__dirname, 'app-middleware/app')),
app: new FileRef(path.join(__dirname, 'app-middleware/app')), 'next.config.js': new FileRef(
'next.config.js': new FileRef( path.join(__dirname, 'app-middleware/next.config.js')
path.join(__dirname, 'app-middleware/next.config.js') ),
), 'middleware.js': `
'middleware.js': ` import { NextResponse } from 'next/server'
import { NextResponse } from 'next/server'
export async function middleware(request) {
export async function middleware(request) { return new NextResponse('redirected')
return new NextResponse('redirected') }
}
export const config = {
export const config = { matcher: '/headers'
matcher: '/headers' }
} `,
`, },
}, skipDeployment: true,
},
({ next }) => {
// eslint-disable-next-line jest/no-identical-title
it('Updates headers', async () => {
const html = await next.render('/headers')
expect(html).toContain('redirected')
}) })
}) }
)
it(`Updates headers`, async () => {
const html = await renderViaHTTP(next.url, '/headers')
expect(html).toContain('redirected')
})
})
This diff is collapsed.
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import path from 'path' import path from 'path'
import cheerio from 'cheerio'
import webdriver from 'next-webdriver'
describe('app-dir assetPrefix handling', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'app-dir assetPrefix handling',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'asset-prefix'),
} skipDeployment: true,
},
let next: NextInstance ({ next }) => {
it('should redirect route when requesting it directly', async () => {
beforeAll(async () => { const res = await next.fetch(
next = await createNext({ '/a/',
files: new FileRef(path.join(__dirname, 'asset-prefix')), {},
dependencies: { {
react: 'latest', redirect: 'manual',
'react-dom': 'latest', }
}, )
skipStart: true, expect(res.status).toBe(308)
expect(res.headers.get('location')).toBe(next.url + '/a')
}) })
await next.start() it('should render link', async () => {
}) const $ = await next.render$('/')
afterAll(() => next.destroy()) expect($('#to-a-trailing-slash').attr('href')).toBe('/a')
})
it('should redirect route when requesting it directly', async () => {
const res = await fetchViaHTTP(
next.url,
'/a/',
{},
{
redirect: 'manual',
}
)
expect(res.status).toBe(308)
expect(res.headers.get('location')).toBe(next.url + '/a')
})
it('should render link', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
expect($('#to-a-trailing-slash').attr('href')).toBe('/a')
})
it('should redirect route when requesting it directly by browser', async () => { it('should redirect route when requesting it directly by browser', async () => {
const browser = await webdriver(next.url, '/a') const browser = await next.browser('/a')
expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page') expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page')
}) })
it('should redirect route when clicking link', async () => { it('should redirect route when clicking link', async () => {
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
await browser await browser
.elementByCss('#to-a-trailing-slash') .elementByCss('#to-a-trailing-slash')
.click() .click()
.waitForElementByCss('#a-page') .waitForElementByCss('#a-page')
expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page') expect(await browser.waitForElementByCss('#a-page').text()).toBe('A page')
}) })
}) }
)
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import path from 'path' import path from 'path'
describe('async-component-preload', () => { createNextDescribe(
if ((global as any).isNextDeploy) { 'async-component-preload',
it('should skip next deploy for now', () => {}) {
return files: path.join(__dirname, 'async-component-preload'),
} skipDeployment: true,
},
let next: NextInstance ({ next }) => {
it('should handle redirect in an async page', async () => {
beforeAll(async () => { const browser = await next.browser('/')
next = await createNext({ expect(await browser.waitForElementByCss('#success').text()).toBe(
files: new FileRef(path.join(__dirname, 'async-component-preload')), 'Success'
dependencies: { )
react: 'latest',
'react-dom': 'latest',
},
}) })
}) }
afterAll(() => next.destroy()) )
it('should handle redirect in an async page', async () => {
const browser = await webdriver(next.url, '/')
expect(await browser.waitForElementByCss('#success').text()).toBe('Success')
})
})
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import path from 'path' import path from 'path'
import webdriver from 'next-webdriver'
// TODO-APP: fix test as it's failing randomly // TODO-APP: fix test as it's failing randomly
describe.skip('app-dir back button download bug', () => { describe.skip('app-dir back button download bug', () => {
if ((global as any).isNextDeploy) { createNextDescribe(
it('should skip next deploy for now', () => {}) 'app-dir back button download bug',
return {
} files: path.join(__dirname, 'back-button-download-bug'),
skipDeployment: true,
},
({ next }) => {
it('should redirect route when clicking link', async () => {
const browser = await next.browser('/')
const text = await browser
.elementByCss('#to-post-1')
.click()
.waitForElementByCss('#post-page')
.text()
expect(text).toBe('This is the post page')
let next: NextInstance await browser.back()
beforeAll(async () => { expect(await browser.waitForElementByCss('#home-page').text()).toBe(
next = await createNext({ 'Home!'
files: new FileRef(path.join(__dirname, 'back-button-download-bug')), )
dependencies: { })
react: 'latest', }
'react-dom': 'latest', )
},
skipStart: true,
})
await next.start()
})
afterAll(() => next.destroy())
it('should redirect route when clicking link', async () => {
const browser = await webdriver(next.url, '/')
const text = await browser
.elementByCss('#to-post-1')
.click()
.waitForElementByCss('#post-page')
.text()
expect(text).toBe('This is the post page')
await browser.back()
expect(await browser.waitForElementByCss('#home-page').text()).toBe('Home!')
})
}) })
import path from 'path' import path from 'path'
import { createNext, FileRef } from 'e2e-utils' import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
import { check } from 'next-test-utils' import { check } from 'next-test-utils'
describe('app-dir create root layout', () => { describe('app-dir create root layout', () => {
...@@ -12,10 +11,6 @@ describe('app-dir create root layout', () => { ...@@ -12,10 +11,6 @@ describe('app-dir create root layout', () => {
return return
} }
if (process.env.NEXT_TEST_REACT_VERSION === '^17') {
it('should skip for react v17', () => {})
return
}
let next: NextInstance let next: NextInstance
if (isDev) { if (isDev) {
...@@ -39,7 +34,7 @@ describe('app-dir create root layout', () => { ...@@ -39,7 +34,7 @@ describe('app-dir create root layout', () => {
it('create root layout', async () => { it('create root layout', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/route') const browser = await next.browser('/route')
expect(await browser.elementById('page-text').text()).toBe( expect(await browser.elementById('page-text').text()).toBe(
'Hello world!' 'Hello world!'
...@@ -101,7 +96,7 @@ describe('app-dir create root layout', () => { ...@@ -101,7 +96,7 @@ describe('app-dir create root layout', () => {
it('create root layout', async () => { it('create root layout', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
expect(await browser.elementById('page-text').text()).toBe( expect(await browser.elementById('page-text').text()).toBe(
'Hello world' 'Hello world'
...@@ -168,7 +163,7 @@ describe('app-dir create root layout', () => { ...@@ -168,7 +163,7 @@ describe('app-dir create root layout', () => {
it('create root layout', async () => { it('create root layout', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/route/second/inner') const browser = await next.browser('/route/second/inner')
expect(await browser.elementById('page-text').text()).toBe( expect(await browser.elementById('page-text').text()).toBe(
'Hello world' 'Hello world'
...@@ -236,7 +231,7 @@ describe('app-dir create root layout', () => { ...@@ -236,7 +231,7 @@ describe('app-dir create root layout', () => {
it('create root layout', async () => { it('create root layout', async () => {
const outputIndex = next.cliOutput.length const outputIndex = next.cliOutput.length
const browser = await webdriver(next.url, '/') const browser = await next.browser('/')
expect(await browser.elementById('page-text').text()).toBe( expect(await browser.elementById('page-text').text()).toBe(
'Hello world!' 'Hello world!'
......
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { getRedboxDescription, hasRedbox } from 'next-test-utils' import { getRedboxDescription, hasRedbox } from 'next-test-utils'
import path from 'path' import path from 'path'
import webdriver from 'next-webdriver'
describe('dynamic-href', () => { createNextDescribe(
const isDev = (global as any).isNextDev 'dynamic-href',
if ((global as any).isNextDeploy) { {
it('should skip next deploy for now', () => {}) files: path.join(__dirname, 'dynamic-href'),
return skipDeployment: true,
} },
({ isNextDev: isDev, next }) => {
let next: NextInstance if (isDev) {
it('should error when using dynamic href.pathname in app dir', async () => {
beforeAll(async () => { const browser = await next.browser('/object')
next = await createNext({
files: new FileRef(path.join(__dirname, 'dynamic-href')), // Error should show up
dependencies: { expect(await hasRedbox(browser, true)).toBeTrue()
react: 'latest', expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
'react-dom': 'latest', `"Error: Dynamic href \`/object/[slug]\` found in <Link> while using the \`/app\` router, this is not supported. Read more: https://nextjs.org/docs/messages/app-dir-dynamic-href"`
}, )
})
})
afterAll(() => next.destroy())
if (isDev) {
it('should error when using dynamic href.pathname in app dir', async () => {
const browser = await webdriver(next.url, '/object')
// Error should show up
expect(await hasRedbox(browser, true)).toBeTrue()
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"Error: Dynamic href \`/object/[slug]\` found in <Link> while using the \`/app\` router, this is not supported. Read more: https://nextjs.org/docs/messages/app-dir-dynamic-href"`
)
// Fix error // Fix error
const pageContent = await next.readFile('app/object/page.js') const pageContent = await next.readFile('app/object/page.js')
await next.patchFile( await next.patchFile(
'app/object/page.js', 'app/object/page.js',
pageContent.replace( pageContent.replace(
"pathname: '/object/[slug]'", "pathname: '/object/[slug]'",
"pathname: '/object/slug'" "pathname: '/object/slug'"
)
)
expect(await browser.waitForElementByCss('#link').text()).toBe(
'to slug'
) )
)
expect(await browser.waitForElementByCss('#link').text()).toBe('to slug')
// Navigate to new page // Navigate to new page
await browser.elementByCss('#link').click() await browser.elementByCss('#link').click()
expect(await browser.waitForElementByCss('#pathname').text()).toBe( expect(await browser.waitForElementByCss('#pathname').text()).toBe(
'/object/slug' '/object/slug'
) )
expect(await browser.elementByCss('#slug').text()).toBe('1') expect(await browser.elementByCss('#slug').text()).toBe('1')
}) })
it('should error when using dynamic href in app dir', async () => { it('should error when using dynamic href in app dir', async () => {
const browser = await webdriver(next.url, '/string') const browser = await next.browser('/string')
// Error should show up // Error should show up
expect(await hasRedbox(browser, true)).toBeTrue() expect(await hasRedbox(browser, true)).toBeTrue()
expect(await getRedboxDescription(browser)).toMatchInlineSnapshot( expect(await getRedboxDescription(browser)).toMatchInlineSnapshot(
`"Error: Dynamic href \`/object/[slug]\` found in <Link> while using the \`/app\` router, this is not supported. Read more: https://nextjs.org/docs/messages/app-dir-dynamic-href"` `"Error: Dynamic href \`/object/[slug]\` found in <Link> while using the \`/app\` router, this is not supported. Read more: https://nextjs.org/docs/messages/app-dir-dynamic-href"`
) )
}) })
} else { } else {
it('should not error on /object in prod', async () => { it('should not error on /object in prod', async () => {
const browser = await webdriver(next.url, '/object') const browser = await next.browser('/object')
expect(await browser.elementByCss('#link').text()).toBe('to slug') expect(await browser.elementByCss('#link').text()).toBe('to slug')
}) })
it('should not error on /string in prod', async () => { it('should not error on /string in prod', async () => {
const browser = await webdriver(next.url, '/string') const browser = await next.browser('/string')
expect(await browser.elementByCss('#link').text()).toBe('to slug') expect(await browser.elementByCss('#link').text()).toBe('to slug')
}) })
}
} }
}) )
import path from 'path' import path from 'path'
import { getRedboxHeader, hasRedbox } from 'next-test-utils' import { getRedboxHeader, hasRedbox } from 'next-test-utils'
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import webdriver from 'next-webdriver'
describe('app dir - global error', () => { createNextDescribe(
let next: NextInstance 'app dir - global error',
const isDev = (global as any).isNextDev {
files: path.join(__dirname, './global-error'),
},
({ next, isNextDev }) => {
it('should trigger error component when an error happens during rendering', async () => {
const browser = await next.browser('/throw')
await browser
.waitForElementByCss('#error-trigger-button')
.elementByCss('#error-trigger-button')
.click()
beforeAll(async () => { if (isNextDev) {
next = await createNext({ expect(await hasRedbox(browser)).toBe(true)
files: new FileRef(path.join(__dirname, './global-error')), expect(await getRedboxHeader(browser)).toMatch(/Error: Client error/)
} else {
await browser
expect(await browser.elementByCss('#error').text()).toBe(
'Error message: Client error'
)
}
}) })
}) }
afterAll(() => next.destroy()) )
it('should trigger error component when an error happens during rendering', async () => {
const browser = await webdriver(next.url, '/throw')
await browser
.waitForElementByCss('#error-trigger-button')
.elementByCss('#error-trigger-button')
.click()
if (isDev) {
expect(await hasRedbox(browser)).toBe(true)
expect(await getRedboxHeader(browser)).toMatch(/Error: Client error/)
} else {
await browser
expect(await browser.elementByCss('#error').text()).toBe(
'Error message: Client error'
)
}
})
})
import path from 'path' import path from 'path'
import cheerio from 'cheerio' import { createNextDescribe } from 'e2e-utils'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { renderViaHTTP } from 'next-test-utils'
describe('app dir imports', () => { createNextDescribe(
if (process.env.NEXT_TEST_REACT_VERSION === '^17') { 'app dir imports',
it('should skip for react v17', () => {}) {
return files: path.join(__dirname, 'import'),
} dependencies: {
let next: NextInstance react: 'latest',
'react-dom': 'latest',
function runTests() { typescript: 'latest',
beforeAll(async () => { '@types/react': 'latest',
next = await createNext({ '@types/node': 'latest',
files: new FileRef(path.join(__dirname, 'import')), },
dependencies: { },
react: 'latest', ({ next }) => {
'react-dom': 'latest',
typescript: 'latest',
'@types/react': 'latest',
'@types/node': 'latest',
},
})
})
afterAll(() => next.destroy())
;['js', 'jsx', 'ts', 'tsx'].forEach((ext) => { ;['js', 'jsx', 'ts', 'tsx'].forEach((ext) => {
it(`we can import all components from .${ext}`, async () => { it(`we can import all components from .${ext}`, async () => {
const html = await renderViaHTTP(next.url, `/${ext}`) const $ = await next.render$(`/${ext}`)
const $ = cheerio.load(html)
expect($('#js').text()).toBe('CompJs') expect($('#js').text()).toBe('CompJs')
}) })
}) })
} }
)
runTests()
})
This diff is collapsed.
import path from 'path' import path from 'path'
import { renderViaHTTP } from 'next-test-utils' import { createNextDescribe } from 'e2e-utils'
import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base' createNextDescribe(
import cheerio from 'cheerio' 'app dir - layout params',
{
describe('app dir - layout params', () => { files: path.join(__dirname, './layout-params'),
let next: NextInstance dependencies: {
react: 'latest',
beforeAll(async () => { 'react-dom': 'latest',
next = await createNext({ typescript: 'latest',
files: new FileRef(path.join(__dirname, './layout-params')), '@types/react': 'latest',
dependencies: { '@types/node': 'latest',
react: 'latest', },
'react-dom': 'latest', },
typescript: 'latest', ({ next }) => {
'@types/react': 'latest', describe('basic params', () => {
'@types/node': 'latest', it('check layout without params get no params', async () => {
}, const $ = await next.render$('/base/something/another')
}) const ids = ['#root-layout', '#lvl1-layout']
}) ids.forEach((divId) => {
afterAll(() => next.destroy()) const params = $(`${divId} > div`)
expect(params.length).toBe(0)
const isReact17 = process.env.NEXT_TEST_REACT_VERSION === '^17' })
if (isReact17) {
it('should skip tests for react 17', () => {})
return
}
describe('basic params', () => {
it('check layout without params get no params', async () => {
const html = await renderViaHTTP(next.url, '/base/something/another')
const $ = cheerio.load(html)
const ids = ['#root-layout', '#lvl1-layout']
ids.forEach((divId) => {
const params = $(`${divId} > div`)
expect(params.length).toBe(0)
}) })
})
it("check layout renders just it's params", async () => { it("check layout renders just it's params", async () => {
const html = await renderViaHTTP(next.url, '/base/something/another') const $ = await next.render$('/base/something/another')
const $ = cheerio.load(html)
expect($('#lvl2-layout > div').length).toBe(1)
expect($('#lvl2-param1').text()).toBe('"something"')
})
it('check topmost layout renders all params', async () => { expect($('#lvl2-layout > div').length).toBe(1)
const html = await renderViaHTTP(next.url, '/base/something/another') expect($('#lvl2-param1').text()).toBe('"something"')
})
const $ = cheerio.load(html)
expect($('#lvl3-layout > div').length).toBe(2)
expect($('#lvl3-param1').text()).toBe('"something"')
expect($('#lvl3-param2').text()).toBe('"another"')
})
})
describe('catchall params', () => {
it('should give catchall params just to last layout', async () => {
const html = await renderViaHTTP(next.url, '/catchall/something/another')
const $ = cheerio.load(html)
expect($(`#root-layout > div`).length).toBe(0) it('check topmost layout renders all params', async () => {
const $ = await next.render$('/base/something/another')
expect($('#lvl2-layout > div').length).toBe(1) expect($('#lvl3-layout > div').length).toBe(2)
expect($('#lvl2-params').text()).toBe('["something","another"]') expect($('#lvl3-param1').text()).toBe('"something"')
expect($('#lvl3-param2').text()).toBe('"another"')
})
}) })
it('should give optional catchall params just to last layout', async () => { describe('catchall params', () => {
const html = await renderViaHTTP( it('should give catchall params just to last layout', async () => {
next.url, const $ = await next.render$('/catchall/something/another')
'/optional-catchall/something/another'
)
const $ = cheerio.load(html) expect($(`#root-layout > div`).length).toBe(0)
expect($('#lvl2-layout > div').length).toBe(1)
expect($('#lvl2-params').text()).toBe('["something","another"]')
})
expect($(`#root-layout > div`).length).toBe(0) it('should give optional catchall params just to last layout', async () => {
const $ = await next.render$('/optional-catchall/something/another')
expect($('#lvl2-layout > div').length).toBe(1) expect($(`#root-layout > div`).length).toBe(0)
expect($('#lvl2-params').text()).toBe('["something","another"]')
})
it("should give empty optional catchall params won't give params to any layout", async () => { expect($('#lvl2-layout > div').length).toBe(1)
const html = await renderViaHTTP(next.url, '/optional-catchall') expect($('#lvl2-params').text()).toBe('["something","another"]')
})
const $ = cheerio.load(html) it("should give empty optional catchall params won't give params to any layout", async () => {
const $ = await next.render$('/optional-catchall')
expect($(`#root-layout > div`).length).toBe(0) expect($(`#root-layout > div`).length).toBe(0)
expect($('#lvl2-layout > div').length).toBe(0) expect($('#lvl2-layout > div').length).toBe(0)
})
}) })
}) }
}) )
This diff is collapsed.
This diff is collapsed.
import { createNext, FileRef } from 'e2e-utils' import { createNextDescribe } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { waitFor } from 'next-test-utils' import { waitFor } from 'next-test-utils'
import path from 'path' import path from 'path'
import webdriver from 'next-webdriver'
describe('app dir prefetching', () => { createNextDescribe(
// TODO: re-enable for dev after https://vercel.slack.com/archives/C035J346QQL/p1663822388387959 is resolved (Sep 22nd 2022) 'app dir prefetching',
if ((global as any).isNextDeploy || (global as any).isNextDev) { {
it('should skip next deploy for now', () => {}) files: path.join(__dirname, 'app-prefetch'),
return skipDeployment: true,
} },
({ next, isNextDev }) => {
let next: NextInstance // TODO: re-enable for dev after https://vercel.slack.com/archives/C035J346QQL/p1663822388387959 is resolved (Sep 22nd 2022)
if (isNextDev) {
it('should skip next deploy for now', () => {})
return
}
it('should show layout eagerly when prefetched with loading one level down', async () => {
const browser = await next.browser('/')
// Ensure the page is prefetched
await waitFor(1000)
const before = Date.now()
await browser
.elementByCss('#to-dashboard')
.click()
.waitForElementByCss('#dashboard-layout')
const after = Date.now()
const timeToComplete = after - before
expect(timeToComplete < 1000).toBe(true)
expect(await browser.elementByCss('#dashboard-layout').text()).toBe(
'Dashboard Hello World'
)
await browser.waitForElementByCss('#dashboard-page')
expect(await browser.waitForElementByCss('#dashboard-page').text()).toBe(
'Welcome to the dashboard'
)
})
beforeAll(async () => { it('should not have prefetch error for static path', async () => {
next = await createNext({ const browser = await next.browser('/')
files: new FileRef(path.join(__dirname, 'app-prefetch')), await browser.eval('window.nd.router.prefetch("/dashboard/123")')
dependencies: { await waitFor(3000)
react: 'latest', await browser.eval('window.nd.router.push("/dashboard/123")')
'react-dom': 'latest', expect(next.cliOutput).not.toContain('ReferenceError')
}, expect(next.cliOutput).not.toContain('is not defined')
skipStart: true,
}) })
await next.start() }
}) )
afterAll(() => next.destroy())
it('should show layout eagerly when prefetched with loading one level down', async () => {
const browser = await webdriver(next.url, '/')
// Ensure the page is prefetched
await waitFor(1000)
const before = Date.now()
await browser
.elementByCss('#to-dashboard')
.click()
.waitForElementByCss('#dashboard-layout')
const after = Date.now()
const timeToComplete = after - before
expect(timeToComplete < 1000).toBe(true)
expect(await browser.elementByCss('#dashboard-layout').text()).toBe(
'Dashboard Hello World'
)
await browser.waitForElementByCss('#dashboard-page')
expect(await browser.waitForElementByCss('#dashboard-page').text()).toBe(
'Welcome to the dashboard'
)
})
it('should not have prefetch error for static path', async () => {
const browser = await webdriver(next.url, '/')
await browser.eval('window.nd.router.prefetch("/dashboard/123")')
await waitFor(3000)
await browser.eval('window.nd.router.push("/dashboard/123")')
expect(next.cliOutput).not.toContain('ReferenceError')
expect(next.cliOutput).not.toContain('is not defined')
})
})
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -35,8 +35,7 @@ describe('transpile packages', () => { ...@@ -35,8 +35,7 @@ describe('transpile packages', () => {
afterAll(() => next.destroy()) afterAll(() => next.destroy())
const { isNextDeploy } = global as any const { isNextDeploy } = global as any
const isReact17 = process.env.NEXT_TEST_REACT_VERSION === '^17' if (isNextDeploy) {
if (isNextDeploy || isReact17) {
it('should skip tests for next-deploy and react 17', () => {}) it('should skip tests for next-deploy and react 17', () => {})
return return
} }
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment