Skip to content

Commit 2c56a69

Browse files
authored
[test] Move all files to .ts (4/6) (#85639)
1 parent 8bfa443 commit 2c56a69

File tree

57 files changed

+165
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+165
-174
lines changed

test/integration/link-with-encoding/test/index.test.js renamed to test/integration/link-with-encoding/test/index.test.ts

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ describe('Link Component with Encoding', () => {
4040
{ pathname: encodeURI('/single/hello world ') }
4141
)`
4242
)
43-
await check(() => browser.hasElementByCssSelector('#query-content'), {
44-
test(val) {
45-
return Boolean(val)
46-
},
47-
})
43+
await check(
44+
() => browser.hasElementByCssSelector('#query-content'),
45+
true
46+
)
4847
const text = await browser.elementByCss('#query-content').text()
4948
expect(text).toMatchInlineSnapshot(`"{"slug":"hello world "}"`)
5049
} finally {
@@ -57,11 +56,10 @@ describe('Link Component with Encoding', () => {
5756
try {
5857
await waitFor(2000)
5958
await browser.elementByCss('#single-spaces').click()
60-
await check(() => browser.hasElementByCssSelector('#query-content'), {
61-
test(val) {
62-
return Boolean(val)
63-
},
64-
})
59+
await check(
60+
() => browser.hasElementByCssSelector('#query-content'),
61+
true
62+
)
6563
const text = await browser.elementByCss('#query-content').text()
6664
expect(text).toMatchInlineSnapshot(`"{"slug":"hello world "}"`)
6765
} finally {
@@ -91,11 +89,10 @@ describe('Link Component with Encoding', () => {
9189
{ pathname: encodeURI('/single/hello%world') }
9290
)`
9391
)
94-
await check(() => browser.hasElementByCssSelector('#query-content'), {
95-
test(val) {
96-
return Boolean(val)
97-
},
98-
})
92+
await check(
93+
() => browser.hasElementByCssSelector('#query-content'),
94+
true
95+
)
9996
const text = await browser.elementByCss('#query-content').text()
10097
expect(text).toMatchInlineSnapshot(`"{"slug":"hello%world"}"`)
10198
} finally {
@@ -108,11 +105,10 @@ describe('Link Component with Encoding', () => {
108105
try {
109106
await waitFor(2000)
110107
await browser.elementByCss('#single-percent').click()
111-
await check(() => browser.hasElementByCssSelector('#query-content'), {
112-
test(val) {
113-
return Boolean(val)
114-
},
115-
})
108+
await check(
109+
() => browser.hasElementByCssSelector('#query-content'),
110+
true
111+
)
116112
const text = await browser.elementByCss('#query-content').text()
117113
expect(text).toMatchInlineSnapshot(`"{"slug":"hello%world"}"`)
118114
} finally {
@@ -145,11 +141,10 @@ describe('Link Component with Encoding', () => {
145141
{ pathname: '/single/hello${encodeURIComponent('/')}world' }
146142
)`
147143
)
148-
await check(() => browser.hasElementByCssSelector('#query-content'), {
149-
test(val) {
150-
return Boolean(val)
151-
},
152-
})
144+
await check(
145+
() => browser.hasElementByCssSelector('#query-content'),
146+
true
147+
)
153148
const text = await browser.elementByCss('#query-content').text()
154149
expect(text).toMatchInlineSnapshot(`"{"slug":"hello/world"}"`)
155150
} finally {
@@ -162,11 +157,10 @@ describe('Link Component with Encoding', () => {
162157
try {
163158
await waitFor(2000)
164159
await browser.elementByCss('#single-slash').click()
165-
await check(() => browser.hasElementByCssSelector('#query-content'), {
166-
test(val) {
167-
return Boolean(val)
168-
},
169-
})
160+
await check(
161+
() => browser.hasElementByCssSelector('#query-content'),
162+
true
163+
)
170164
const text = await browser.elementByCss('#query-content').text()
171165
expect(text).toMatchInlineSnapshot(`"{"slug":"hello/world"}"`)
172166
} finally {
@@ -203,11 +197,10 @@ describe('Link Component with Encoding', () => {
203197
{ pathname: '/single/hello${encodeURIComponent('"')}world' }
204198
)`
205199
)
206-
await check(() => browser.hasElementByCssSelector('#query-content'), {
207-
test(val) {
208-
return Boolean(val)
209-
},
210-
})
200+
await check(
201+
() => browser.hasElementByCssSelector('#query-content'),
202+
true
203+
)
211204
const text = await browser.elementByCss('#query-content').text()
212205
expect(JSON.parse(text)).toMatchInlineSnapshot(`
213206
{
@@ -224,11 +217,10 @@ describe('Link Component with Encoding', () => {
224217
try {
225218
await waitFor(2000)
226219
await browser.elementByCss('#single-double-quote').click()
227-
await check(() => browser.hasElementByCssSelector('#query-content'), {
228-
test(val) {
229-
return Boolean(val)
230-
},
231-
})
220+
await check(
221+
() => browser.hasElementByCssSelector('#query-content'),
222+
true
223+
)
232224
const text = await browser.elementByCss('#query-content').text()
233225
expect(JSON.parse(text)).toMatchInlineSnapshot(`
234226
{
@@ -265,11 +257,10 @@ describe('Link Component with Encoding', () => {
265257
{ pathname: '/single/hello${encodeURIComponent(':')}world' }
266258
)`
267259
)
268-
await check(() => browser.hasElementByCssSelector('#query-content'), {
269-
test(val) {
270-
return Boolean(val)
271-
},
272-
})
260+
await check(
261+
() => browser.hasElementByCssSelector('#query-content'),
262+
true
263+
)
273264
const text = await browser.elementByCss('#query-content').text()
274265
expect(text).toMatchInlineSnapshot(`"{"slug":"hello:world"}"`)
275266
} finally {
@@ -282,11 +273,10 @@ describe('Link Component with Encoding', () => {
282273
try {
283274
await waitFor(2000)
284275
await browser.elementByCss('#single-colon').click()
285-
await check(() => browser.hasElementByCssSelector('#query-content'), {
286-
test(val) {
287-
return Boolean(val)
288-
},
289-
})
276+
await check(
277+
() => browser.hasElementByCssSelector('#query-content'),
278+
true
279+
)
290280
const text = await browser.elementByCss('#query-content').text()
291281
expect(text).toMatchInlineSnapshot(`"{"slug":"hello:world"}"`)
292282
} finally {

test/integration/middleware-dev-update/test/index.test.js renamed to test/integration/middleware-dev-update/test/index.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
import { join } from 'path'
1111
import webdriver from 'next-webdriver'
1212

13+
let app
14+
let appPort
1315
const context = {
1416
appDir: join(__dirname, '../'),
1517
logs: { output: '', stdout: '', stderr: '' },
@@ -19,8 +21,8 @@ const context = {
1921
describe('Middleware development errors', () => {
2022
beforeEach(async () => {
2123
context.logs = { output: '', stdout: '', stderr: '' }
22-
context.appPort = await findPort()
23-
context.app = await launchApp(context.appDir, context.appPort, {
24+
appPort = await findPort()
25+
app = await launchApp(context.appDir, appPort, {
2426
onStdout(msg) {
2527
context.logs.output += msg
2628
context.logs.stdout += msg
@@ -34,14 +36,14 @@ describe('Middleware development errors', () => {
3436

3537
afterEach(async () => {
3638
context.middleware.restore()
37-
if (context.app) {
38-
await killApp(context.app)
39+
if (app) {
40+
await killApp(app)
3941
}
4042
})
4143

4244
async function assertMiddlewareFetch(hasMiddleware, path = '/') {
4345
await check(async () => {
44-
const res = await fetchViaHTTP(context.appPort, path)
46+
const res = await fetchViaHTTP(appPort, path)
4547
expect(res.status).toBe(200)
4648
expect(res.headers.get('x-from-middleware')).toBe(
4749
hasMiddleware ? 'true' : null
@@ -51,7 +53,7 @@ describe('Middleware development errors', () => {
5153
}
5254

5355
async function assertMiddlewareRender(hasMiddleware, path = '/') {
54-
const browser = await webdriver(context.appPort, path)
56+
const browser = await webdriver(appPort, path)
5557
const fromMiddleware = await browser.elementById('from-middleware').text()
5658
expect(fromMiddleware).toBe(hasMiddleware ? 'true' : 'null')
5759
}

test/integration/middleware-prefetch/tests/index.test.js renamed to test/integration/middleware-prefetch/tests/index.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414

1515
jest.setTimeout(1000 * 60 * 2)
1616

17+
let appPort
18+
let app
1719
const context = {
1820
appDir: join(__dirname, '../'),
1921
buildLogs: { output: '', stdout: '', stderr: '' },
@@ -24,27 +26,23 @@ describe('Middleware Production Prefetch', () => {
2426
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
2527
'production mode',
2628
() => {
27-
afterAll(() => killApp(context.app))
29+
afterAll(() => killApp(app))
2830
beforeAll(async () => {
2931
const build = await nextBuild(context.appDir, undefined, {
3032
stderr: true,
3133
stdout: true,
3234
})
3335

34-
context.buildId = await fs.readFile(
35-
join(context.appDir, '.next/BUILD_ID'),
36-
'utf8'
37-
)
36+
await fs.readFile(join(context.appDir, '.next/BUILD_ID'), 'utf8')
3837

3938
context.buildLogs = {
4039
output: build.stdout + build.stderr,
4140
stderr: build.stderr,
4241
stdout: build.stdout,
4342
}
44-
context.dev = false
4543

46-
context.appPort = await findPort()
47-
context.app = await nextStart(context.appDir, context.appPort, {
44+
appPort = await findPort()
45+
app = await nextStart(context.appDir, appPort, {
4846
env: {
4947
MIDDLEWARE_TEST: 'asdf',
5048
},
@@ -60,7 +58,7 @@ describe('Middleware Production Prefetch', () => {
6058
})
6159

6260
it(`prefetch correctly for unexistent routes`, async () => {
63-
const browser = await webdriver(context.appPort, `/`)
61+
const browser = await webdriver(appPort, `/`)
6462
await browser.elementByCss('#made-up-link').moveTo()
6563
await check(async () => {
6664
const scripts = await browser.elementsByCss('script')
@@ -76,7 +74,7 @@ describe('Middleware Production Prefetch', () => {
7674
})
7775

7876
it(`does not prefetch provided path if it will be rewritten`, async () => {
79-
const browser = await webdriver(context.appPort, `/`)
77+
const browser = await webdriver(appPort, `/`)
8078
await browser.elementByCss('#ssg-page-2').moveTo()
8179
await check(async () => {
8280
const scripts = await browser.elementsByCss('script')

test/integration/middleware-src-node/test/index.test.js renamed to test/integration/middleware-src-node/test/index.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-env jest */
2-
31
import fs from 'fs-extra'
42
import { join } from 'path'
53
import {
@@ -40,6 +38,7 @@ function runDoubleMiddlewareTests() {
4038

4139
async function writeRootMiddleware() {
4240
await fs.copy(join(appDir, 'src/pages'), join(appDir, 'pages'), {
41+
// @ts-expect-error
4342
force: true,
4443
recursive: true,
4544
})
@@ -68,9 +67,19 @@ return response
6867
}
6968

7069
async function removeRootMiddleware() {
71-
await fs.remove(rootMiddlewareJSFile, { force: true })
72-
await fs.remove(rootMiddlewareTSFile, { force: true })
73-
await fs.remove(join(appDir, 'pages'), { force: true, recursive: true })
70+
await fs.remove(rootMiddlewareJSFile, {
71+
// @ts-expect-error
72+
force: true,
73+
})
74+
await fs.remove(rootMiddlewareTSFile, {
75+
// @ts-expect-error
76+
force: true,
77+
})
78+
await fs.remove(join(appDir, 'pages'), {
79+
// @ts-expect-error
80+
force: true,
81+
recursive: true,
82+
})
7483
}
7584

7685
describe.each([

test/integration/middleware-src/test/index.test.js renamed to test/integration/middleware-src/test/index.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-env jest */
2-
31
import fs from 'fs-extra'
42
import { join } from 'path'
53
import {
@@ -40,6 +38,7 @@ function runDoubleMiddlewareTests() {
4038

4139
async function writeRootMiddleware() {
4240
await fs.copy(join(appDir, 'src/pages'), join(appDir, 'pages'), {
41+
// @ts-expect-error
4342
force: true,
4443
recursive: true,
4544
})
@@ -68,9 +67,19 @@ return response
6867
}
6968

7069
async function removeRootMiddleware() {
71-
await fs.remove(rootMiddlewareJSFile, { force: true })
72-
await fs.remove(rootMiddlewareTSFile, { force: true })
73-
await fs.remove(join(appDir, 'pages'), { force: true, recursive: true })
70+
await fs.remove(rootMiddlewareJSFile, {
71+
// @ts-expect-error
72+
force: true,
73+
})
74+
await fs.remove(rootMiddlewareTSFile, {
75+
// @ts-expect-error
76+
force: true,
77+
})
78+
await fs.remove(join(appDir, 'pages'), {
79+
// @ts-expect-error
80+
force: true,
81+
recursive: true,
82+
})
7483
}
7584

7685
describe.each([

0 commit comments

Comments
 (0)