Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): add StaticQuery to SSR test #28187

Merged
merged 4 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion integration-tests/ssr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"build": "gatsby build",
"clean": "gatsby clean",
"develop": "gatsby develop",
"develop": "cross-env GATSBY_EXPERIMENTAL_DEV_SSR=true gatsby develop",
"serve": "gatsby serve",
"start-dev-server": "start-server-and-test develop http://localhost:8000 test:jest",
"test": "cross-env GATSBY_EXPERIMENTAL_DEV_SSR=true npm-run-all -s build start-dev-server",
Expand Down
32 changes: 21 additions & 11 deletions integration-tests/ssr/src/pages/hi.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import React from "react"
import { useStaticQuery, graphql } from "gatsby"
import { StaticQuery, graphql } from "gatsby"

export default function Inline() {
const { site } = useStaticQuery(graphql`
{
site {
siteMetadata {
title
}
}
}
`)
return <div>hi1 {site.siteMetadata.title}</div>
return (
<div>
<StaticQuery
query={graphql`
query {
site {
siteMetadata {
title
}
}
}
`}
render={data => (
<header>
<h1>{data.site.siteMetadata.title}</h1>
</header>
)}
/>
</div>
)
}
12 changes: 9 additions & 3 deletions integration-tests/ssr/test-output.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@
)
)

const rawDevHtml = await fetch(`${devSiteBasePath}/${path}`).then(res =>
res.text()
)
let devStatus = 200
const rawDevHtml = await fetch(`${devSiteBasePath}/${path}`).then(res => {
devStatus = res.status
return res.text()
})

if (devStatus !== 200) {
return false
}

const devHtml = format(filterHtml(rawDevHtml))
const diffResult = diff(devHtml, builtHtml, {
Expand Down