Unverified Commit 1b87ebd4 authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[test] Move all files to .ts (3/6) (#85638)

parent f811a6d5
......@@ -27,7 +27,7 @@ const runTests = () => {
it('should have correct fallback query (hydration)', async () => {
const browser = await webdriver(appPort, '/second')
const initialSlug = await browser.eval(() => window.initialSlug)
const initialSlug = await browser.eval(() => (window as any).initialSlug)
expect(initialSlug).toBeFalsy()
await browser.waitForElementByCss('#query')
......
......@@ -17,7 +17,7 @@ let app
let apiServerPort
let apiServer
const startApiServer = async (optEnv = {}, opts) => {
const startApiServer = async (optEnv = {}, opts?: any) => {
const scriptPath = join(appDir, 'api-server.js')
apiServerPort = await findPort()
const env = Object.assign(
......
......@@ -19,7 +19,7 @@ let app
let apiServerPort
let apiServer
const startApiServer = async (optEnv = {}, opts) => {
const startApiServer = async (optEnv = {}, opts?: any) => {
const scriptPath = join(appDir, 'api-server.js')
apiServerPort = await findPort()
const env = Object.assign(
......
......@@ -4482,7 +4482,7 @@ describe('File Serving', () => {
await killApp(app)
})
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -9,7 +9,7 @@ const appDir = join(__dirname, '../')
let appPort
let server
const context = {}
const context: Record<string, any> = {}
const startServer = async (optEnv = {}) => {
const scriptPath = join(appDir, 'server.js')
......@@ -23,7 +23,7 @@ describe('FileSystemPublicRoutes', () => {
beforeAll(() => startServer())
afterAll(() => killApp(server))
const fetch = (p, q) => fetchViaHTTP(context.appPort, p, q)
const fetch = (p, q?: any) => fetchViaHTTP(context.appPort, p, q)
it('should not route to the index page', async () => {
const res = await fetch('/')
......
......@@ -74,7 +74,7 @@ function runTests(startServer = nextStart) {
expect(res.status).toBe(200)
const originalCookies = res.headers.get('set-cookie').split(',')
const cookies = originalCookies.map(cookie.parse)
const cookies = originalCookies.map((rawCookie) => cookie.parse(rawCookie))
expect(originalCookies.every((c) => c.includes('; Secure;'))).toBe(true)
......@@ -143,7 +143,7 @@ function runTests(startServer = nextStart) {
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map(cookie.parse)
.map((rawCookie) => cookie.parse(rawCookie))
expect(cookies.length).toBe(2)
expect(cookies[0]).toMatchObject({
......@@ -193,7 +193,7 @@ describe('ServerSide Props Preview Mode', () => {
const cookies = res.headers
.get('set-cookie')
.split(',')
.map(cookie.parse)
.map((rawCookie) => cookie.parse(rawCookie))
expect(cookies.length).toBe(2)
previewCookieString =
......@@ -231,7 +231,7 @@ describe('ServerSide Props Preview Mode', () => {
.get('set-cookie')
.replace(/(=(?!Lax)\w{3}),/g, '$1')
.split(',')
.map(cookie.parse)
.map((rawCookie) => cookie.parse(rawCookie))
expect(cookies.length).toBe(2)
})
......
......@@ -20,7 +20,7 @@ let app
let appPort
let indexPageContent
const runTests = (isDev) => {
const runTests = (isDev: boolean) => {
const getData = async () => {
if (isDev) {
appPort = await findPort()
......@@ -96,7 +96,7 @@ describe('gip identifiers', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
runTests()
runTests(false)
}
)
})
......@@ -20,7 +20,7 @@ let appPort
const basePath = '/docs'
const runTests = (isDev) => {
const runTests = (isDev: boolean) => {
it('should apply temporary redirect when visited directly for GSSP page', async () => {
const res = await fetchViaHTTP(
appPort,
......@@ -142,7 +142,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe(`${basePath}/gsp-blog/redirect-dest-_gsp-blog_first`)
})
......@@ -165,7 +165,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
// since it was cached the initial value is now the redirect
// result
......@@ -184,7 +184,7 @@ const runTests = (isDev) => {
await browser.waitForElementByCss('#index')
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe(`${basePath}/gsp-blog/redirect-dest-_`)
})
......@@ -201,7 +201,7 @@ const runTests = (isDev) => {
await browser.waitForElementByCss('#index')
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe(`${basePath}`)
})
......@@ -221,7 +221,7 @@ const runTests = (isDev) => {
/oops not found/
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
const curUrl = await browser.url()
......@@ -243,7 +243,7 @@ const runTests = (isDev) => {
'example.vercel.sh'
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
})
......@@ -261,7 +261,7 @@ const runTests = (isDev) => {
'example.vercel.sh'
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
const res = await fetchViaHTTP(
......@@ -503,7 +503,7 @@ describe('GS(S)P Redirect Support', () => {
})
afterAll(() => killApp(app))
runTests()
runTests(false)
it('should error for redirect during prerendering', async () => {
await fs.mkdirp(join(appDir, 'pages/invalid'))
......
......@@ -12,7 +12,7 @@ import webdriver from 'next-webdriver'
// test suites
const context = {}
const context: Record<string, any> = {}
describe('getServerSideProps redirects', () => {
beforeAll(async () => {
......
......@@ -18,7 +18,7 @@ const appDir = join(__dirname, '..')
let app
let appPort
const runTests = (isDev) => {
const runTests = (isDev: boolean) => {
it('should apply temporary redirect when visited directly for GSSP page', async () => {
const res = await fetchViaHTTP(
appPort,
......@@ -103,7 +103,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/redirect-dest-_gsp-blog_first')
})
......@@ -125,7 +125,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/first')
})
......@@ -147,7 +147,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/first')
})
......@@ -169,7 +169,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/first')
})
......@@ -191,7 +191,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/first')
})
......@@ -214,7 +214,7 @@ const runTests = (isDev) => {
post: 'first',
},
})
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
// since it was cached the initial value is now the redirect
// result
......@@ -229,7 +229,7 @@ const runTests = (isDev) => {
await browser.waitForElementByCss('#index')
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/gsp-blog/redirect-dest-_')
})
......@@ -242,7 +242,7 @@ const runTests = (isDev) => {
await browser.waitForElementByCss('#index')
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
const { pathname } = url.parse(initialHref)
expect(pathname).toBe('/')
})
......@@ -262,7 +262,7 @@ const runTests = (isDev) => {
/oops not found/
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
const curUrl = await browser.url()
......@@ -284,7 +284,7 @@ const runTests = (isDev) => {
'example.vercel.sh'
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
})
......@@ -302,7 +302,7 @@ const runTests = (isDev) => {
'example.vercel.sh'
)
const initialHref = await browser.eval(() => window.initialHref)
const initialHref = await browser.eval(() => (window as any).initialHref)
expect(initialHref).toBeFalsy()
const res = await fetchViaHTTP(
......@@ -537,7 +537,7 @@ describe('GS(S)P Redirect Support', () => {
})
afterAll(() => killApp(app))
runTests()
runTests(false)
it('should not have errors in output', async () => {
expect(output).not.toContain('Failed to update prerender files')
......
......@@ -46,7 +46,7 @@ describe('Hashbang', () => {
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -15,7 +15,7 @@ import {
const appDir = join(__dirname, '../')
const nextConfig = new File(join(appDir, 'next.config.js'))
const ctx = {
const ctx: Record<string, any> = {
basePath: '/docs',
appDir,
}
......@@ -27,14 +27,14 @@ describe('i18n Support basePath', () => {
res.statusCode = 200
res.end(JSON.stringify({ url: req.url, external: true }))
})
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
ctx.externalApp.listen(ctx.externalPort, (err) =>
err ? reject(err) : resolve()
)
})
})
afterAll(async () => {
await new Promise((resolve, reject) =>
await new Promise<void>((resolve, reject) =>
ctx.externalApp.close((err) => {
err ? reject(err) : resolve()
})
......@@ -43,7 +43,7 @@ describe('i18n Support basePath', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
const curCtx: Record<string, any> = {
...ctx,
isDev: true,
}
......
......@@ -21,17 +21,13 @@ let buildPagesDir
const locales = ['en-US', 'nl-NL', 'nl-BE', 'nl', 'fr-BE', 'fr', 'en']
function runTests(isDev) {
function runTests(isDev: boolean) {
if (!isDev) {
it('should output prerendered index routes correctly', async () => {
expect(await fs.exists(join(buildPagesDir, 'pages/en-US.html'))).toBe(
true
)
expect(await fs.exists(join(buildPagesDir, 'pages/en-US.json'))).toBe(
true
)
expect(await fs.exists(join(buildPagesDir, 'pages/fr.html'))).toBe(true)
expect(await fs.exists(join(buildPagesDir, 'pages/fr.json'))).toBe(true)
expect(fs.existsSync(join(buildPagesDir, 'pages/en-US.html'))).toBe(true)
expect(fs.existsSync(join(buildPagesDir, 'pages/en-US.json'))).toBe(true)
expect(fs.existsSync(join(buildPagesDir, 'pages/fr.html'))).toBe(true)
expect(fs.existsSync(join(buildPagesDir, 'pages/fr.json'))).toBe(true)
})
}
......@@ -246,7 +242,7 @@ describe('i18n Support Root Catch-all', () => {
})
afterAll(() => killApp(app))
runTests()
runTests(false)
}
)
})
......@@ -116,7 +116,7 @@ describe('Custom routes i18n custom error', () => {
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -27,7 +27,7 @@ function runTests() {
['/', { hello: 'world' }],
['/en', { hello: 'world' }],
['/fr', { hello: 'world' }],
]) {
] as const) {
const asPath = url.format({ pathname, query })
const browser = await webdriver(appPort, asPath)
......@@ -56,7 +56,7 @@ function runTests() {
['/dynamic/first', { hello: 'world' }],
['/en/dynamic/first', { hello: 'world' }],
['/fr/dynamic/first', { hello: 'world' }],
]) {
] as const) {
const asPath = url.format({ pathname, query })
const browser = await webdriver(appPort, asPath)
......
......@@ -27,7 +27,7 @@ function runTests() {
['/', { hello: 'world' }],
['/en', { hello: 'world' }],
['/fr', { hello: 'world' }],
]) {
] as const) {
const asPath = url.format({ pathname, query })
const browser = await webdriver(appPort, asPath)
......@@ -56,7 +56,7 @@ function runTests() {
['/dynamic/first', { hello: 'world' }],
['/en/dynamic/first', { hello: 'world' }],
['/fr/dynamic/first', { hello: 'world' }],
]) {
] as const) {
const asPath = url.format({ pathname, query })
const browser = await webdriver(appPort, asPath)
......
......@@ -84,7 +84,7 @@ describe('Custom routes i18n support index rewrite', () => {
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -79,7 +79,7 @@ describe('Hash changes i18n', () => {
app = await launchApp(appDir, appPort)
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -19,7 +19,7 @@ import assert from 'assert'
const appDir = join(__dirname, '../')
const nextConfig = new File(join(appDir, 'next.config.js'))
const ctx = {
const ctx: Record<string, any> = {
basePath: '',
appDir,
}
......@@ -31,7 +31,7 @@ describe('i18n Support', () => {
res.statusCode = 200
res.end(JSON.stringify({ url: req.url, external: true }))
})
await new Promise((resolve, reject) => {
await new Promise<void>((resolve, reject) => {
ctx.externalApp.listen(ctx.externalPort, (err) =>
err ? reject(err) : resolve()
)
......@@ -41,7 +41,7 @@ describe('i18n Support', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
const curCtx: Record<string, any> = {
...ctx,
isDev: true,
}
......@@ -426,7 +426,7 @@ describe('i18n Support', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
const curCtx: Record<string, any> = {
...ctx,
isDev: true,
}
......@@ -496,7 +496,7 @@ describe('i18n Support', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
const curCtx = {
const curCtx: Record<string, any> = {
...ctx,
isDev: true,
}
......
......@@ -40,7 +40,7 @@ describe('Custom routes invalid multi-match', () => {
})
})
afterAll(() => killApp(app))
runTests(true)
runTests()
}
)
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
......
......@@ -6,7 +6,10 @@ const warningMessage =
describe('Invalid server options', () => {
test('next() called with no parameters should throw error', () => {
expect(() => next()).toThrow(
expect(() =>
// @ts-expect-error
next()
).toThrow(
'The server has not been instantiated properly. https://nextjs.org/docs/messages/invalid-server-options'
)
})
......@@ -25,7 +28,7 @@ describe('Invalid server options', () => {
test('next() called with dev as string should send warning', () => {
const consoleSpy = jest.spyOn(console, 'warn')
const dev = 'string'
const dev: any = 'string'
next({ dev, dir })
expect(consoleSpy).toHaveBeenCalledWith(warningMessage)
......@@ -33,7 +36,7 @@ describe('Invalid server options', () => {
test('next() called with dev as number should send warning', () => {
const consoleSpy = jest.spyOn(console, 'warn')
const dev = 123
const dev: any = 123
next({ dev, dir })
expect(consoleSpy).toHaveBeenCalledWith(warningMessage)
......@@ -41,7 +44,7 @@ describe('Invalid server options', () => {
test('next() called with dev as array should send warning', () => {
const consoleSpy = jest.spyOn(console, 'warn')
const dev = ['array']
const dev: any = ['array']
next({ dev, dir })
expect(consoleSpy).toHaveBeenCalledWith(warningMessage)
......@@ -49,7 +52,7 @@ describe('Invalid server options', () => {
test('next() called with dev as object should send warning', () => {
const consoleSpy = jest.spyOn(console, 'warn')
const dev = { test: 'goes here' }
const dev: any = { test: 'goes here' }
next({ dev, dir })
expect(consoleSpy).toHaveBeenCalledWith(warningMessage)
......@@ -57,7 +60,7 @@ describe('Invalid server options', () => {
test('next() called with dev as function should send warning', () => {
const consoleSpy = jest.spyOn(console, 'warn')
const dev = () => console.log('test')
const dev: any = () => console.log('test')
next({ dev, dir })
expect(consoleSpy).toHaveBeenCalledWith(warningMessage)
......
{
"compilerOptions": {
"baseUrl": "."
}
},
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
......@@ -17,7 +17,7 @@ const appDir = join(__dirname, '..')
let appPort
let app
async function get$(path, query) {
async function get$(path, query?: any) {
const html = await renderViaHTTP(appPort, path, query)
return cheerio.load(html)
}
......
......@@ -4,5 +4,6 @@
"paths": {
"*": ["node_modules/*"]
}
}
},
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
......@@ -16,7 +16,7 @@ const appDir = join(__dirname, '..')
let appPort
let app
async function get$(path, query) {
async function get$(path, query?: any) {
const html = await renderViaHTTP(appPort, path, query)
return cheerio.load(html)
}
......
......@@ -6,5 +6,6 @@
"@lib/*": ["lib/a/*", "lib/b/*"],
"@mycomponent": ["components/hello.js"]
}
}
},
"exclude": ["node_modules", "**/*.test.ts", "**/*.test.tsx"]
}
......@@ -20,7 +20,7 @@ const appDir = join(__dirname, '..')
let appPort
let app
async function get$(path, query) {
async function get$(path, query?: any) {
const html = await renderViaHTTP(appPort, path, query)
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