Unverified Commit 60c0a9df authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Move all files to .ts (2/6) (#85637)

parent 1b87ebd4
......@@ -790,7 +790,7 @@ jobs:
node run-tests.js \
--concurrency 4 \
test/production/pages-dir/production/test/index.test.ts \
test/integration/css-client-nav/test/index.test.js \
test/integration/css-client-nav/test/index.test.ts \
test/integration/rewrites-has-condition/test/index.test.js \
test/integration/create-next-app/index.test.ts \
test/integration/create-next-app/package-manager/pnpm.test.ts
......
......@@ -23,7 +23,7 @@ let stallCss
let appPort
let app
function runTests(dev) {
function runTests(dev: boolean) {
it('should be able to client-side navigate from red to blue', async () => {
let browser
try {
......@@ -176,7 +176,7 @@ describe('CSS Module client-side navigation', () => {
console.warn('Failed to proxy', err)
})
await new Promise((resolve) => {
await new Promise<void>((resolve) => {
proxyServer.listen(appPort, () => resolve())
})
})
......@@ -219,7 +219,7 @@ describe('CSS Module client-side navigation', () => {
}
})
runTests()
runTests(false)
}
)
......
......@@ -274,8 +274,7 @@ module.exports = {
await browser.waitForElementByCss('#link-other').click()
await check(
() => browser.eval(`document.body.innerText`),
'Application error: a client-side exception has occurred while loading localhost (see the browser console for more information).',
true
'Application error: a client-side exception has occurred while loading localhost (see the browser console for more information).'
)
const newPageStyles = await browser.eval(
......
......@@ -53,7 +53,7 @@ describe('Custom routes', () => {
buildId = 'development'
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -53,7 +53,7 @@ describe('Custom routes i18n with index redirect', () => {
res.statusCode = 200
res.end()
})
await new Promise((res, rej) => {
await new Promise<void>((res, rej) => {
server.listen(externalPort, (err) => (err ? rej(err) : res()))
})
})
......@@ -68,7 +68,7 @@ describe('Custom routes i18n with index redirect', () => {
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -31,7 +31,7 @@ const runTests = () => {
['/fr/redirect-1', '/fr/destination-1'],
['/nl-NL/redirect-2', '/destination-2'],
['/fr/redirect-2', false],
]) {
] as const) {
const res = await fetchViaHTTP(appPort, path, undefined, {
redirect: 'manual',
})
......@@ -158,7 +158,7 @@ describe('Custom routes i18n', () => {
})}</p>`
)
})
await new Promise((res, rej) => {
await new Promise<void>((res, rej) => {
server.listen(externalPort, (err) => (err ? rej(err) : res()))
})
nextConfig.replace(/__EXTERNAL_PORT__/g, '' + externalPort)
......@@ -175,7 +175,7 @@ describe('Custom routes i18n', () => {
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -28,7 +28,7 @@ import {
let appDir = join(__dirname, '..')
const nextConfig = new File(join(appDir, 'next.config.js'))
const nextConfigPath = join(appDir, 'next.config.js')
let externalServerHits = new Set()
let externalServerHits = new Set<string>()
let nextConfigRestoreContent
let nextConfigContent
let externalServerPort
......@@ -80,7 +80,7 @@ const runTests = (isDev = false) => {
it('should successfully rewrite a WebSocket request', async () => {
const messages = []
const ws = await new Promise((resolve, reject) => {
const ws = await new Promise<WebSocket>((resolve, reject) => {
let socket = new WebSocket(`ws://localhost:${appPort}/to-websocket`)
socket.on('message', (data) => {
messages.push(data.toString())
......@@ -104,7 +104,7 @@ const runTests = (isDev = false) => {
it('should successfully rewrite a WebSocket request to a page', async () => {
const messages = []
try {
const ws = await new Promise((resolve, reject) => {
const ws = await new Promise<WebSocket>((resolve, reject) => {
let socket = new WebSocket(
`ws://localhost:${appPort}/websocket-to-page`
)
......@@ -160,7 +160,7 @@ const runTests = (isDev = false) => {
slug: ['hello', 'world'],
},
]) {
const { status = 200, post } = expected
const { post } = expected
const res = await fetchViaHTTP(
appPort,
'/has-rewrite-8',
......@@ -170,16 +170,14 @@ const runTests = (isDev = false) => {
}
)
expect(res.status).toBe(status)
expect(res.status).toBe(200)
if (status === 200) {
const $ = cheerio.load(await res.text())
expect(JSON.parse($('#props').text())).toEqual({
params: {
slug: expected.slug,
},
})
}
const $ = cheerio.load(await res.text())
expect(JSON.parse($('#props').text())).toEqual({
params: {
slug: expected.slug,
},
})
}
})
......@@ -2562,7 +2560,7 @@ describe('Custom routes', () => {
client.send('hello world')
})
})
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
externalServer.listen(externalServerPort, (error) => {
if (error) return reject(error)
resolve()
......@@ -2661,7 +2659,7 @@ describe('Custom routes', () => {
)
describe('should load custom routes when only one type is used', () => {
const runSoloTests = (isDev) => {
const runSoloTests = (isDev: boolean) => {
const buildAndStart = async () => {
if (isDev) {
appPort = await findPort()
......@@ -2764,7 +2762,7 @@ describe('Custom routes', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
runSoloTests()
runSoloTests(false)
}
)
})
......
......@@ -21,7 +21,7 @@ const indexPg = new File(join(appDir, 'pages/index.js'))
let appPort
let server
const context = {}
const context: Record<string, any> = {}
describe.each([
{ title: 'using HTTP', useHttps: false },
......@@ -35,7 +35,7 @@ describe.each([
})
: undefined
const startServer = async (optEnv = {}, opts) => {
const startServer = async (optEnv = {}, opts?: any) => {
const scriptPath = join(appDir, 'server.js')
context.appPort = appPort = await getPort()
nextUrl = `http${useHttps ? 's' : ''}://localhost:${context.appPort}`
......@@ -306,7 +306,7 @@ describe.each([
})
describe('with middleware $title', () => {
beforeAll(() => startServer(undefined, undefined, useHttps))
beforeAll(() => startServer(undefined, undefined))
afterAll(() => killApp(server))
it('should read the expected url protocol in middleware', async () => {
......
......@@ -15,7 +15,7 @@ const appDir = join(__dirname, '../')
let appPort
let app
const context = {}
const context: Record<string, any> = {}
describe('disabled runtime JS', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -39,12 +39,12 @@ describe('distDir', () => {
it('should build the app within the given `dist` directory', async () => {
expect(
await fs.exists(join(__dirname, `/../dist/${BUILD_ID_FILE}`))
fs.existsSync(join(__dirname, `/../dist/${BUILD_ID_FILE}`))
).toBeTruthy()
})
it('should not build the app within the default `.next` directory', async () => {
expect(
await fs.exists(join(__dirname, `/../${getDistDir()}`))
fs.existsSync(join(__dirname, `/../${getDistDir()}`))
).toBeFalsy()
})
}
......@@ -69,12 +69,12 @@ describe('distDir', () => {
it('should build the app within the given `dist` directory', async () => {
// In isolated dev build, the distDir for development is `distDir/dev`
expect(
await fs.exists(join(__dirname, `/../dist/dev/${BUILD_MANIFEST}`))
fs.existsSync(join(__dirname, `/../dist/dev/${BUILD_MANIFEST}`))
).toBeTruthy()
})
it('should not build the app within the default `.next` directory', async () => {
expect(
await fs.exists(join(__dirname, `/../${getDistDir()}`))
fs.existsSync(join(__dirname, `/../${getDistDir()}`))
).toBeFalsy()
})
}
......
......@@ -9,7 +9,7 @@ const Comment = ({ gipQuery }) => {
<p id="asdf">
I am {query.comment} on {query.name}
</p>
<span>gip {gipQuery && gipQuery.name}</span>
<span data-testid="gip-query">gip {gipQuery && gipQuery.name}</span>
</>
)
}
......
......@@ -147,7 +147,7 @@ function runTests({ dev }) {
return newFrames.some((frame) => {
try {
const data = JSON.parse(frame.payload)
const data = JSON.parse('' + frame.payload)
return data.event === 'pong'
} catch (_) {}
return false
......@@ -313,7 +313,7 @@ function runTests({ dev }) {
.back()
.waitForElementByCss('#view-post-1-hash-1-interpolated')
.elementByCss('#view-post-1-hash-1-interpolated')
.click('#view-post-1-hash-1-interpolated')
.click()
.waitForElementByCss('#asdf')
expect(await browser.eval('window.beforeNav')).toBe(1)
......@@ -329,7 +329,7 @@ function runTests({ dev }) {
.back()
.waitForElementByCss('#view-post-1-hash-1-href-only')
.elementByCss('#view-post-1-hash-1-href-only')
.click('#view-post-1-hash-1-href-only')
.click()
.waitForElementByCss('#asdf')
expect(await browser.eval('window.beforeNav')).toBe(1)
......@@ -695,10 +695,12 @@ function runTests({ dev }) {
let browser
try {
browser = await webdriver(appPort, '/')
await browser.elementByCss('#view-post-1-comment-1').click()
await browser.waitForElementByCss('span')
const text = await browser
.elementByCss('[data-testid="gip-query"]')
.text()
const text = await browser.elementByCss('span').text()
expect(text).toMatch(/gip.*post-1/i)
} finally {
if (browser) await browser.close()
......@@ -1162,6 +1164,7 @@ function runTests({ dev }) {
'/_next/static/development/_devPagesManifest.json',
undefined,
{
// @ts-expect-error -- node-fetch doesn't have this as a top-level but whatwg fetch does.
credentials: 'same-origin',
}
)
......
......@@ -16,7 +16,7 @@ import { remove } from 'fs-extra'
jest.setTimeout(1000 * 60 * 2)
const context = {
const context: Record<string, any> = {
appDir: join(__dirname, '../'),
logs: { output: '', stdout: '', stderr: '' },
api: new File(join(__dirname, '../pages/api/route.js')),
......@@ -116,7 +116,7 @@ describe('Edge runtime configurable guards', () => {
stderr: true,
env: process.env.IS_TURBOPACK_TEST
? {}
: { NEXT_TELEMETRY_DEBUG: 1 },
: { NEXT_TELEMETRY_DEBUG: '1' },
})
expect(output.code).toBe(1)
......@@ -334,7 +334,7 @@ describe('Edge runtime configurable guards', () => {
stderr: true,
env: process.env.IS_TURBOPACK_TEST
? {}
: { NEXT_TELEMETRY_DEBUG: 1 },
: { NEXT_TELEMETRY_DEBUG: '1' },
})
// eslint-disable-next-line jest/no-standalone-expect
expect(output.stderr).not.toContain(`Build failed`)
......@@ -436,7 +436,7 @@ describe('Edge runtime configurable guards', () => {
stderr: true,
env: process.env.IS_TURBOPACK_TEST
? {}
: { NEXT_TELEMETRY_DEBUG: 1 },
: { NEXT_TELEMETRY_DEBUG: '1' },
})
expect(output.stderr).toContain(
`Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
......
......@@ -18,7 +18,7 @@ const WASM_COMPILE_ERROR = `Dynamic WASM code generation (e. g. 'WebAssembly.com
const WASM_INSTANTIATE_ERROR = `Dynamic WASM code generation ('WebAssembly.instantiate' with a buffer parameter) not allowed in Edge Runtime`
jest.setTimeout(1000 * 60 * 2)
const context = {
const context: Record<string, any> = {
appDir: join(__dirname, '../'),
}
......
......@@ -295,7 +295,7 @@ describe('Edge runtime code with imports', () => {
})
expect(stderr).toContain(getUnsupportedModuleWarning(moduleName))
let logs = { stdout: '', stderr: '' }
let logs = { stdout: '', stderr: '', output: '' }
const port = await findPort()
const options = {
......
......@@ -14,7 +14,7 @@ import {
jest.setTimeout(1000 * 60 * 2)
const context = {
const context: Record<string, any> = {
appDir: join(__dirname, '../'),
logs: { output: '', stdout: '', stderr: '' },
api: new File(join(__dirname, '../pages/api/route.js')),
......
......@@ -4,7 +4,7 @@ import { join } from 'path'
import fs from 'fs'
import { fetchViaHTTP, findPort, launchApp, killApp } from 'next-test-utils'
const context = {}
const context: Record<string, any> = {}
describe('Empty Project', () => {
beforeAll(async () => {
......@@ -13,7 +13,7 @@ describe('Empty Project', () => {
context.server = await launchApp(join(__dirname, '../'), context.appPort)
})
const fetch = (p, q) =>
const fetch = (p, q?: any) =>
fetchViaHTTP(context.appPort, p, q, { timeout: 10_000 })
it('Should not time out and return 404', async () => {
......
......@@ -12780,7 +12780,7 @@
"flakey": [],
"runtimeError": false
},
"test/integration/dynamic-routing/test/index.test.js": {
"test/integration/dynamic-routing/test/index.test.ts": {
"passed": [
"Dynamic Routing production mode [catch all] should not decode slashes (end)",
"Dynamic Routing production mode [catch all] should not decode slashes (middle)",
......@@ -14748,7 +14748,7 @@
"flakey": [],
"runtimeError": false
},
"test/integration/dynamic-routing/test/index.test.js": {
"test/integration/dynamic-routing/test/index.test.ts": {
"passed": [
"Dynamic Routing development mode [catch all] should not decode slashes (end)",
"Dynamic Routing development mode [catch all] should not decode slashes (middle)",
......@@ -11040,7 +11040,7 @@
"flakey": [],
"runtimeError": false
},
"test/integration/dynamic-routing/test/index.test.js": {
"test/integration/dynamic-routing/test/index.test.ts": {
"passed": [
"Dynamic Routing production mode [catch all] should not decode slashes (end)",
"Dynamic Routing production mode [catch all] should not decode slashes (middle)",
......@@ -14565,7 +14565,7 @@
"flakey": [],
"runtimeError": false
},
"test/integration/dynamic-routing/test/index.test.js": {
"test/integration/dynamic-routing/test/index.test.ts": {
"passed": [
"Dynamic Routing development mode [catch all] should not decode slashes (end)",
"Dynamic Routing development mode [catch all] should not decode slashes (middle)",
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