Skip to content

Commit b5dbe5b

Browse files
committed
fix flaky test
1 parent 27f3c0e commit b5dbe5b

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// export function getServerSideProps() { { props: {} } }
22

33
export default function Page() {
4-
return null
4+
return 'client-gssp'
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// export function getStaticProps() { return { props: {} }}
22

33
export default function Page() {
4-
return null
4+
return 'client-gsp'
55
}

test/e2e/app-dir/index.test.ts

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { createNext, FileRef } from 'e2e-utils'
22
import { NextInstance } from 'test/lib/next-modes/base'
3-
import { fetchViaHTTP, renderViaHTTP, waitFor } from 'next-test-utils'
3+
import {
4+
check,
5+
fetchViaHTTP,
6+
getBrowserBodyText,
7+
hasRedbox,
8+
renderViaHTTP,
9+
waitFor,
10+
} from 'next-test-utils'
411
import path from 'path'
512
import cheerio from 'cheerio'
613
import webdriver from 'next-webdriver'
@@ -1024,48 +1031,60 @@ describe('app dir', () => {
10241031
})
10251032

10261033
if (isDev) {
1027-
it('should throw an error when getStaticProps is used', async () => {
1034+
it('should throw an error when getServerSideProps is used', async () => {
10281035
const pageFile =
1029-
'app/client-with-errors/get-static-props/page.client.js'
1036+
'app/client-with-errors/get-server-side-props/page.client.js'
10301037
const content = await next.readFile(pageFile)
1031-
await next.patchFile(
1032-
pageFile,
1033-
content.replace(
1034-
'// export function getStaticProps',
1035-
'export function getStaticProps'
1036-
)
1038+
const uncomment = content.replace(
1039+
'// export function getServerSideProps',
1040+
'export function getServerSideProps'
10371041
)
1042+
await next.patchFile(pageFile, uncomment)
10381043
const res = await fetchViaHTTP(
10391044
next.url,
1040-
'/client-with-errors/get-static-props'
1045+
'/client-with-errors/get-server-side-props'
10411046
)
10421047
await next.patchFile(pageFile, content)
1048+
1049+
await check(async () => {
1050+
const { status } = await fetchViaHTTP(
1051+
next.url,
1052+
'/client-with-errors/get-server-side-props'
1053+
)
1054+
return status
1055+
}, /200/)
1056+
10431057
expect(res.status).toBe(500)
10441058
expect(await res.text()).toContain(
1045-
'getStaticProps is not supported in client components'
1059+
'getServerSideProps is not supported in client components'
10461060
)
10471061
})
10481062

1049-
it('should throw an error when getServerSideProps is used', async () => {
1063+
it('should throw an error when getStaticProps is used', async () => {
10501064
const pageFile =
1051-
'app/client-with-errors/get-server-side-props/page.client.js'
1065+
'app/client-with-errors/get-static-props/page.client.js'
10521066
const content = await next.readFile(pageFile)
1053-
await next.patchFile(
1054-
pageFile,
1055-
content.replace(
1056-
'// export function getServerSideProps',
1057-
'export function getServerSideProps'
1058-
)
1067+
const uncomment = content.replace(
1068+
'// export function getStaticProps',
1069+
'export function getStaticProps'
10591070
)
1071+
await next.patchFile(pageFile, uncomment)
10601072
const res = await fetchViaHTTP(
10611073
next.url,
1062-
'/client-with-errors/get-server-side-props'
1074+
'/client-with-errors/get-static-props'
10631075
)
10641076
await next.patchFile(pageFile, content)
1077+
await check(async () => {
1078+
const { status } = await fetchViaHTTP(
1079+
next.url,
1080+
'/client-with-errors/get-static-props'
1081+
)
1082+
return status
1083+
}, /200/)
10651084

10661085
expect(res.status).toBe(500)
10671086
expect(await res.text()).toContain(
1068-
'getServerSideProps is not supported in client components'
1087+
'getStaticProps is not supported in client components'
10691088
)
10701089
})
10711090
}

0 commit comments

Comments
 (0)