|
1 | 1 | import { createNext, FileRef } from 'e2e-utils' |
2 | 2 | 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' |
4 | 11 | import path from 'path' |
5 | 12 | import cheerio from 'cheerio' |
6 | 13 | import webdriver from 'next-webdriver' |
@@ -1024,48 +1031,60 @@ describe('app dir', () => { |
1024 | 1031 | }) |
1025 | 1032 |
|
1026 | 1033 | if (isDev) { |
1027 | | - it('should throw an error when getStaticProps is used', async () => { |
| 1034 | + it('should throw an error when getServerSideProps is used', async () => { |
1028 | 1035 | 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' |
1030 | 1037 | 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' |
1037 | 1041 | ) |
| 1042 | + await next.patchFile(pageFile, uncomment) |
1038 | 1043 | const res = await fetchViaHTTP( |
1039 | 1044 | next.url, |
1040 | | - '/client-with-errors/get-static-props' |
| 1045 | + '/client-with-errors/get-server-side-props' |
1041 | 1046 | ) |
1042 | 1047 | 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 | + |
1043 | 1057 | expect(res.status).toBe(500) |
1044 | 1058 | expect(await res.text()).toContain( |
1045 | | - 'getStaticProps is not supported in client components' |
| 1059 | + 'getServerSideProps is not supported in client components' |
1046 | 1060 | ) |
1047 | 1061 | }) |
1048 | 1062 |
|
1049 | | - it('should throw an error when getServerSideProps is used', async () => { |
| 1063 | + it('should throw an error when getStaticProps is used', async () => { |
1050 | 1064 | 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' |
1052 | 1066 | 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' |
1059 | 1070 | ) |
| 1071 | + await next.patchFile(pageFile, uncomment) |
1060 | 1072 | const res = await fetchViaHTTP( |
1061 | 1073 | next.url, |
1062 | | - '/client-with-errors/get-server-side-props' |
| 1074 | + '/client-with-errors/get-static-props' |
1063 | 1075 | ) |
1064 | 1076 | 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/) |
1065 | 1084 |
|
1066 | 1085 | expect(res.status).toBe(500) |
1067 | 1086 | expect(await res.text()).toContain( |
1068 | | - 'getServerSideProps is not supported in client components' |
| 1087 | + 'getStaticProps is not supported in client components' |
1069 | 1088 | ) |
1070 | 1089 | }) |
1071 | 1090 | } |
|
0 commit comments