Unverified Commit 49933c2e authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Move all files to .ts (1/6) (#85634)

parent 60c0a9df
...@@ -183,7 +183,7 @@ ...@@ -183,7 +183,7 @@
"test/e2e/app-dir/graceful-shutdown-next-after/next-start/index.test.ts", "test/e2e/app-dir/graceful-shutdown-next-after/next-start/index.test.ts",
"test/e2e/app-dir/headers-static-bailout/headers-static-bailout.test.ts", "test/e2e/app-dir/headers-static-bailout/headers-static-bailout.test.ts",
"test/e2e/app-dir/hooks/hooks.test.ts", "test/e2e/app-dir/hooks/hooks.test.ts",
"test/e2e/app-dir/i18n-hybrid/i18n-hybrid.test.js", "test/e2e/app-dir/i18n-hybrid/i18n-hybrid.test.ts",
"test/e2e/app-dir/instrumentation-order/instrumentation-order.test.ts", "test/e2e/app-dir/instrumentation-order/instrumentation-order.test.ts",
"test/e2e/app-dir/interception-dynamic-segment-middleware/interception-dynamic-segment-middleware.test.ts", "test/e2e/app-dir/interception-dynamic-segment-middleware/interception-dynamic-segment-middleware.test.ts",
"test/e2e/app-dir/interception-middleware-rewrite/interception-middleware-rewrite.test.ts", "test/e2e/app-dir/interception-middleware-rewrite/interception-middleware-rewrite.test.ts",
...@@ -335,7 +335,7 @@ ...@@ -335,7 +335,7 @@
"test/e2e/url/url.test.ts", "test/e2e/url/url.test.ts",
"test/integration/app-dir-export/**/*", "test/integration/app-dir-export/**/*",
"test/integration/app-dynamic-error/test/index.test.ts", "test/integration/app-dynamic-error/test/index.test.ts",
"test/integration/app-types/app-types.test.js", "test/integration/app-types/app-types.test.ts",
"test/production/app-dir-edge-runtime-with-wasm/index.test.ts", "test/production/app-dir-edge-runtime-with-wasm/index.test.ts",
"test/production/app-dir-prevent-304-caching/index.test.ts", "test/production/app-dir-prevent-304-caching/index.test.ts",
"test/production/app-dir/actions-tree-shaking/reexport/reexport-edge.test.ts", "test/production/app-dir/actions-tree-shaking/reexport/reexport-edge.test.ts",
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
"test/e2e/new-link-behavior/stitches.test.ts", "test/e2e/new-link-behavior/stitches.test.ts",
"test/e2e/next-image-forward-ref/index.test.ts", "test/e2e/next-image-forward-ref/index.test.ts",
"test/e2e/react-compiler/react-compiler.test.ts", "test/e2e/react-compiler/react-compiler.test.ts",
"test/e2e/app-dir/i18n-hybrid/i18n-hybrid.test.js", "test/e2e/app-dir/i18n-hybrid/i18n-hybrid.test.ts",
"test/e2e/app-dir/metadata/metadata.test.ts", "test/e2e/app-dir/metadata/metadata.test.ts",
"test/e2e/app-dir/rsc-basic/rsc-basic.test.ts", "test/e2e/app-dir/rsc-basic/rsc-basic.test.ts",
"test/e2e/basepath/basepath.test.ts", "test/e2e/basepath/basepath.test.ts",
......
...@@ -22,7 +22,7 @@ let buildId ...@@ -22,7 +22,7 @@ let buildId
let appPort let appPort
let app let app
const runTests = (isDev) => { const runTests = (isDev: boolean) => {
it('should respond to 404 correctly', async () => { it('should respond to 404 correctly', async () => {
const res = await fetchViaHTTP(appPort, '/404') const res = await fetchViaHTTP(appPort, '/404')
expect(res.status).toBe(404) expect(res.status).toBe(404)
...@@ -118,7 +118,7 @@ describe('404 Page Support SSG', () => { ...@@ -118,7 +118,7 @@ describe('404 Page Support SSG', () => {
buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8') buildId = await fs.readFile(join(appDir, '.next/BUILD_ID'), 'utf8')
}) })
runTests() runTests(false)
} }
) )
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)( ;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
......
...@@ -11,12 +11,12 @@ import { ...@@ -11,12 +11,12 @@ import {
import getPort from 'get-port' import getPort from 'get-port'
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
let appPort let appPort: number
let app let app
let server let server
const context = {} const context: { appPort?: number } = {}
function runTests() { function runTests() {
it('should parse JSON body', async () => { it('should parse JSON body', async () => {
...@@ -66,7 +66,7 @@ async function makeRequestWithInvalidContentType() { ...@@ -66,7 +66,7 @@ async function makeRequestWithInvalidContentType() {
return status return status
} }
const startServer = async (optEnv = {}, opts) => { const startServer = async (optEnv = {}, opts?: any) => {
const scriptPath = join(appDir, 'server.js') const scriptPath = join(appDir, 'server.js')
context.appPort = appPort = await getPort() context.appPort = appPort = await getPort()
const env = Object.assign( const env = Object.assign(
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
import { join } from 'path' import { join } from 'path'
import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils' import { renderViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'
let appPort
let app
const context = { const context = {
output: '', output: '',
} }
...@@ -13,19 +15,19 @@ const collectOutput = (message) => { ...@@ -13,19 +15,19 @@ const collectOutput = (message) => {
describe('Document and App', () => { describe('Document and App', () => {
beforeAll(async () => { beforeAll(async () => {
context.appPort = await findPort() appPort = await findPort()
context.server = await launchApp(join(__dirname, '../'), context.appPort, { app = await launchApp(join(__dirname, '../'), appPort, {
onStdout: collectOutput, onStdout: collectOutput,
onStderr: collectOutput, onStderr: collectOutput,
}) })
// pre-build all pages at the start // pre-build all pages at the start
await Promise.all([renderViaHTTP(context.appPort, '/')]) await Promise.all([renderViaHTTP(appPort, '/')])
}) })
afterAll(() => killApp(context.server)) afterAll(() => killApp(app))
it('should not have any missing key warnings', async () => { it('should not have any missing key warnings', async () => {
const html = await renderViaHTTP(context.appPort, '/') const html = await renderViaHTTP(appPort, '/')
expect(html).toMatch(/<div>Hello World!!!<\/div>/) expect(html).toMatch(/<div>Hello World!!!<\/div>/)
}) })
}) })
...@@ -17,7 +17,6 @@ let app ...@@ -17,7 +17,6 @@ let app
beforeAll(async () => { beforeAll(async () => {
appPort = await findPort() appPort = await findPort()
app = await launchApp(appDir, appPort, { app = await launchApp(appDir, appPort, {
stderr: true,
nextStart: true, nextStart: true,
onStderr(text) { onStderr(text) {
stderr += text stderr += text
......
...@@ -12,6 +12,7 @@ import { ...@@ -12,6 +12,7 @@ import {
} from 'next-test-utils' } from 'next-test-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import path, { join } from 'path' import path, { join } from 'path'
// @ts-expect-error
import pkg from 'next/package' import pkg from 'next/package'
import http from 'http' import http from 'http'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
...@@ -31,15 +32,13 @@ const runAndCaptureOutput = async ({ port }) => { ...@@ -31,15 +32,13 @@ const runAndCaptureOutput = async ({ port }) => {
res.end('OK') res.end('OK')
}) })
await new Promise((resolve, reject) => { await new Promise<void>((resolve, reject) => {
app.on('error', reject) app.on('error', reject)
app.on('listening', () => resolve()) app.on('listening', () => resolve())
app.listen(port) app.listen(port)
}) })
await launchApp(dirBasic, port, { await launchApp(dirBasic, port, {
stdout: true,
stderr: true,
onStdout(msg) { onStdout(msg) {
stdout += msg stdout += msg
}, },
...@@ -147,7 +146,7 @@ describe('CLI Usage', () => { ...@@ -147,7 +146,7 @@ describe('CLI Usage', () => {
let stdout = '' let stdout = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
['start', dirBasic, '--hostname', '::', '--port', port], ['start', dirBasic, '--hostname', '::', '--port', '' + port],
undefined, undefined,
{ {
nextStart: true, nextStart: true,
...@@ -158,7 +157,7 @@ describe('CLI Usage', () => { ...@@ -158,7 +157,7 @@ describe('CLI Usage', () => {
) )
try { try {
await check(() => { await retry(() => {
// Only display when hostname is provided // Only display when hostname is provided
expect(stdout).toMatch( expect(stdout).toMatch(
new RegExp(`Network:\\s*http://\\[::\\]:${port}`) new RegExp(`Network:\\s*http://\\[::\\]:${port}`)
...@@ -188,7 +187,6 @@ describe('CLI Usage', () => { ...@@ -188,7 +187,6 @@ describe('CLI Usage', () => {
let stderr = '' let stderr = ''
let instance = await launchApp(dirDuplicateSass, port, { let instance = await launchApp(dirDuplicateSass, port, {
stderr: true,
onStderr(msg) { onStderr(msg) {
stderr += msg stderr += msg
}, },
...@@ -451,7 +449,7 @@ describe('CLI Usage', () => { ...@@ -451,7 +449,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -470,7 +468,7 @@ describe('CLI Usage', () => { ...@@ -470,7 +468,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -493,7 +491,7 @@ describe('CLI Usage', () => { ...@@ -493,7 +491,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -523,7 +521,7 @@ describe('CLI Usage', () => { ...@@ -523,7 +521,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
const app = await runNextCommandDev([dirBasic], undefined, { const app = await runNextCommandDev([dirBasic], undefined, {
env: { env: {
PORT: 0, PORT: '0',
}, },
onStdout(msg) { onStdout(msg) {
output += stripAnsi(msg) output += stripAnsi(msg)
...@@ -533,7 +531,7 @@ describe('CLI Usage', () => { ...@@ -533,7 +531,7 @@ describe('CLI Usage', () => {
await check(() => output, /- Local:/) await check(() => output, /- Local:/)
// without --hostname, do not log Network: xxx // without --hostname, do not log Network: xxx
const matches = /Network:\s*http:\/\/\[::\]:(\d+)/.exec(output) const matches = /Network:\s*http:\/\/\[::\]:(\d+)/.exec(output)
const _port = parseInt(matches) const _port = parseInt('' + matches)
expect(matches).toBe(null) expect(matches).toBe(null)
// Regression test: port 0 was interpreted as if no port had been // Regression test: port 0 was interpreted as if no port had been
// provided, falling back to 3000. // provided, falling back to 3000.
...@@ -548,7 +546,7 @@ describe('CLI Usage', () => { ...@@ -548,7 +546,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -575,7 +573,7 @@ describe('CLI Usage', () => { ...@@ -575,7 +573,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port, '--inspect'], [dirBasic, '--port', '' + port, '--inspect'],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -601,7 +599,7 @@ describe('CLI Usage', () => { ...@@ -601,7 +599,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port, '--inspect', '0'], [dirBasic, '--port', '' + port, '--inspect', '0'],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -627,7 +625,7 @@ describe('CLI Usage', () => { ...@@ -627,7 +625,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port, '--inspect', '9230'], [dirBasic, '--port', '' + port, '--inspect', '9230'],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -653,7 +651,7 @@ describe('CLI Usage', () => { ...@@ -653,7 +651,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -682,7 +680,7 @@ describe('CLI Usage', () => { ...@@ -682,7 +680,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
cwd: dirBasic, cwd: dirBasic,
...@@ -715,7 +713,7 @@ describe('CLI Usage', () => { ...@@ -715,7 +713,7 @@ describe('CLI Usage', () => {
let output = '' let output = ''
let errOutput = '' let errOutput = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--port', port], [dirBasic, '--port', '' + port],
undefined, undefined,
{ {
cwd: dirBasic, cwd: dirBasic,
...@@ -744,12 +742,16 @@ describe('CLI Usage', () => { ...@@ -744,12 +742,16 @@ describe('CLI Usage', () => {
test('-p', async () => { test('-p', async () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev([dirBasic, '-p', port], undefined, { const app = await runNextCommandDev(
[dirBasic, '-p', '' + port],
undefined,
{
onStdout(msg) { onStdout(msg) {
output += stripAnsi(msg) output += stripAnsi(msg)
}, },
env: { NODE_OPTIONS: '--inspect' }, env: { NODE_OPTIONS: '--inspect' },
}) }
)
try { try {
await check(() => output, new RegExp(`http://localhost:${port}`)) await check(() => output, new RegExp(`http://localhost:${port}`))
} finally { } finally {
...@@ -806,7 +808,7 @@ describe('CLI Usage', () => { ...@@ -806,7 +808,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--hostname', '0.0.0.0', '--port', port], [dirBasic, '--hostname', '0.0.0.0', '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -829,7 +831,7 @@ describe('CLI Usage', () => { ...@@ -829,7 +831,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '-H', '0.0.0.0', '--port', port], [dirBasic, '-H', '0.0.0.0', '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -860,7 +862,7 @@ describe('CLI Usage', () => { ...@@ -860,7 +862,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--experimental-https', '--port', port], [dirBasic, '--experimental-https', '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
...@@ -896,7 +898,7 @@ describe('CLI Usage', () => { ...@@ -896,7 +898,7 @@ describe('CLI Usage', () => {
'--experimental-https-cert', '--experimental-https-cert',
certFile, certFile,
'--port', '--port',
port, '' + port,
], ],
undefined, undefined,
{ {
...@@ -916,7 +918,7 @@ describe('CLI Usage', () => { ...@@ -916,7 +918,7 @@ describe('CLI Usage', () => {
const port = await findPort() const port = await findPort()
let output = '' let output = ''
const app = await runNextCommandDev( const app = await runNextCommandDev(
[dirBasic, '--hostname', '::', '--port', port], [dirBasic, '--hostname', '::', '--port', '' + port],
undefined, undefined,
{ {
onStdout(msg) { onStdout(msg) {
......
...@@ -38,10 +38,10 @@ const clientNavigation = (context, isProd = false) => { ...@@ -38,10 +38,10 @@ const clientNavigation = (context, isProd = false) => {
it('should hard navigate to URL on failing to load bundle', async () => { it('should hard navigate to URL on failing to load bundle', async () => {
const browser = await webdriver(context.appPort, '/invalid-link') const browser = await webdriver(context.appPort, '/invalid-link')
await browser.eval(() => (window.beforeNav = 'hi')) await browser.eval(() => ((window as any).beforeNav = 'hi'))
await browser.elementByCss('#to-nonexistent').click() await browser.elementByCss('#to-nonexistent').click()
await check(() => browser.elementByCss('#errorStatusCode').text(), /404/) await check(() => browser.elementByCss('#errorStatusCode').text(), /404/)
expect(await browser.eval(() => window.beforeNav)).not.toBe('hi') expect(await browser.eval(() => (window as any).beforeNav)).not.toBe('hi')
}) })
if (isProd) { if (isProd) {
...@@ -54,20 +54,22 @@ const clientNavigation = (context, isProd = false) => { ...@@ -54,20 +54,22 @@ const clientNavigation = (context, isProd = false) => {
}) })
}, },
}) })
await browser.eval(() => (window.beforeNav = 'hi')) await browser.eval(() => ((window as any).beforeNav = 'hi'))
await browser.elementByCss('#to-missing').click() await browser.elementByCss('#to-missing').click()
await retry(async () => { await retry(async () => {
expect(await browser.url()).toContain('/missing') expect(await browser.url()).toContain('/missing')
}) })
expect(await browser.elementByCss('#missing').text()).toBe('poof') expect(await browser.elementByCss('#missing').text()).toBe('poof')
expect(await browser.eval(() => window.beforeNav)).not.toBe('hi') expect(await browser.eval(() => (window as any).beforeNav)).not.toBe(
'hi'
)
}) })
} }
}) })
} }
const context = {} const context: any = {}
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const runTests = (isProd = false) => { const runTests = (isProd = false) => {
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { join } from 'path' import { join } from 'path'
const context = {} const context: Record<string, any> = {}
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const navigateTo = async (browser, selector) => const navigateTo = async (browser, selector) =>
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
killApp, killApp,
} from 'next-test-utils' } from 'next-test-utils'
const context = {} const context: Record<string, any> = {}
describe('Compression', () => { describe('Compression', () => {
beforeAll(async () => { beforeAll(async () => {
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
File, File,
nextBuild, nextBuild,
nextStart, nextStart,
check, retry,
} from 'next-test-utils' } from 'next-test-utils'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
...@@ -242,7 +242,7 @@ describe('Config Experimental Warning', () => { ...@@ -242,7 +242,7 @@ describe('Config Experimental Warning', () => {
}, },
}) })
await check(() => { await retry(() => {
const cliOutput = stripAnsi(stdout) const cliOutput = stripAnsi(stdout)
const cliOutputErr = stripAnsi(stderr) const cliOutputErr = stripAnsi(stderr)
expect(cliOutput).not.toContain(experimentalHeader) expect(cliOutput).not.toContain(experimentalHeader)
......
...@@ -6,7 +6,7 @@ import webdriver from 'next-webdriver' ...@@ -6,7 +6,7 @@ import webdriver from 'next-webdriver'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { join } from 'path' import { join } from 'path'
const context = {} const context: Record<string, any> = {}
describe('Configuration', () => { describe('Configuration', () => {
beforeAll(async () => { beforeAll(async () => {
...@@ -33,7 +33,7 @@ describe('Configuration', () => { ...@@ -33,7 +33,7 @@ describe('Configuration', () => {
await killApp(context.server) await killApp(context.server)
}) })
async function get$(path, query) { async function get$(path, query?: any) {
const html = await renderViaHTTP(context.appPort, path, query) const html = await renderViaHTTP(context.appPort, path, query)
return cheerio.load(html) return cheerio.load(html)
} }
......
This diff is collapsed.
This diff is collapsed.
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