Skip to content

Commit

Permalink
Add tests for getStaticProps and getServerSideProps (#37014)
Browse files Browse the repository at this point in the history
* Add tests for getStaticProps and getServerSideProps

* Add test for revalidate

* Add additional test

* Add gitkeep
  • Loading branch information
timneutkens authored May 23, 2022
1 parent f9ed795 commit 6f2a8d3
Show file tree
Hide file tree
Showing 17 changed files with 400 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/e2e/views-dir/app-rendering/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
experimental: {
viewsDir: true,
runtime: 'nodejs',
reactRoot: true,
serverComponents: true,
},
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function getServerSideProps() {
return {
props: {
message: 'hello from layout',
},
}
}

export default function gsspLayout(props) {
return (
<>
<h1 id="layout-message">{props.message}</h1>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export async function getServerSideProps() {
return {
props: {
message: 'hello from page',
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="page-message">{props.message}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function getServerSideProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow page',
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="slow-page-message">{props.message}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function getServerSideProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow layout',
},
}
}

export default function gsspLayout(props) {
return (
<>
<h1 id="slow-layout-message">{props.message}</h1>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function getStaticProps() {
return {
props: {
message: 'hello from page',
nowDuringBuild: Date.now(),
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="page-message">{props.message}</p>
<p id="page-now">{props.nowDuringBuild}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export async function getServerSideProps() {
return {
props: {
message: 'hello from layout',
nowDuringExecution: Date.now(),
},
}
}

export default function gspLayout(props) {
return (
<>
<h1 id="layout-message">{props.message}</h1>
<p id="layout-now">{props.nowDuringExecution}</p>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export async function getStaticProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow page',
nowDuringBuild: Date.now(),
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="slow-page-message">{props.message}</p>
<p id="slow-page-now">{props.nowDuringBuild}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export async function getServerSideProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow layout',
nowDuringExecution: Date.now(),
},
}
}

export default function gspLayout(props) {
return (
<>
<h1 id="slow-layout-message">{props.message}</h1>
<p id="slow-layout-now">{props.nowDuringExecution}</p>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export async function getStaticProps() {
return {
props: {
message: 'hello from layout',
now: Date.now(),
},
revalidate: 1,
}
}

export default function gspLayout(props) {
return (
<>
<h1 id="layout-message">{props.message}</h1>
<p id="layout-now">{props.now}</p>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function getStaticProps() {
return {
props: {
message: 'hello from page',
now: Date.now(),
},
revalidate: 1,
}
}
export default function nestedPage(props) {
return (
<>
<p id="page-message">{props.message}</p>
<p id="page-now">{props.now}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function getStaticProps() {
return {
props: {
message: 'hello from layout',
},
}
}

export default function gspLayout(props) {
return (
<>
<h1 id="layout-message">{props.message}</h1>
{props.children}
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export async function getStaticProps() {
return {
props: {
message: 'hello from page',
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="page-message">{props.message}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export async function getStaticProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow page',
},
}
}

export default function nestedPage(props) {
return (
<>
<p id="slow-page-message">{props.message}</p>
</>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export async function getStaticProps() {
await new Promise((resolve) => setTimeout(resolve, 5000))
return {
props: {
message: 'hello from slow layout',
},
}
}

export default function gspLayout(props) {
return (
<>
<h1 id="slow-layout-message">{props.message}</h1>
{props.children}
</>
)
}
Loading

0 comments on commit 6f2a8d3

Please sign in to comment.