MCPcopy
hub / github.com/vercel/next.js / runTests

Function runTests

test/integration/data-fetching-errors/test/index.test.ts:26–124  ·  view source on GitHub ↗
(isDev = false)

Source from the content-addressed store, hash-verified

24let origIndexPage = ''
25
26const runTests = (isDev = false) => {
27 const getStderr = async () => {
28 if (isDev) {
29 let stderr = ''
30 appPort = await findPort()
31 app = await launchApp(appDir, appPort, {
32 onStderr(msg) {
33 stderr += msg || ''
34 },
35 })
36 await renderViaHTTP(appPort, '/')
37 await killApp(app)
38 return stderr
39 } else {
40 const { stderr } = await nextBuild(appDir, undefined, { stderr: true })
41 return stderr
42 }
43 }
44
45 it('should show error for getStaticProps as component member', async () => {
46 await fs.writeFile(
47 indexPage,
48 `
49 const Page = () => 'hi'
50 Page.getStaticProps = () => ({ props: { hello: 'world' }})
51 export default Page
52 `
53 )
54 expect(await getStderr()).toContain(
55 `getStaticProps can not be attached to a page's component and must be exported from the page`
56 )
57 })
58
59 it('should show error for getServerSideProps as component member', async () => {
60 await fs.writeFile(
61 indexPage,
62 `
63 import React from 'react'
64 export default class MyPage extends React.Component {
65 static async getServerSideProps() {
66 return {
67 props: {
68 hello: 'world'
69 }
70 }
71 }
72 render() {
73 return 'hi'
74 }
75 }
76 `
77 )
78 expect(await getStderr()).toContain(
79 `getServerSideProps can not be attached to a page's component and must be exported from the page`
80 )
81 })
82
83 it('should show error for getStaticPaths as component member', async () => {

Callers 1

index.test.tsFile · 0.70

Calls 4

getStderrFunction · 0.85
writeFileMethod · 0.65
itFunction · 0.50
expectFunction · 0.50

Tested by

no test coverage detected