Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
flybayer committed May 10, 2021
1 parent a1e27bb commit 48584b1
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/integration/misc/app/queries/getBasic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default async function getBasic() {
return "basic-result"
}
11 changes: 11 additions & 0 deletions test/integration/misc/app/queries/getError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default async function getError() {
return "should-not-succeed"
}

export const config = {
api: {
bodyParser: {
sizeLimit: "0kb",
},
},
}
4 changes: 4 additions & 0 deletions test/integration/misc/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
presets: ["blitz/babel"],
plugins: [],
}
1 change: 1 addition & 0 deletions test/integration/misc/blitz.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
11 changes: 11 additions & 0 deletions test/integration/misc/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {AppProps} from "blitz"
import {ReactQueryDevtools} from "react-query/devtools"

export default function App({Component, pageProps}: AppProps) {
return (
<>
<Component {...pageProps} />
<ReactQueryDevtools />
</>
)
}
23 changes: 23 additions & 0 deletions test/integration/misc/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {BlitzScript, Document, DocumentHead, Html, Main} from "blitz"

class MyDocument extends Document {
// Only uncomment if you need to customize this behaviour
// static async getInitialProps(ctx: DocumentContext) {
// const initialProps = await Document.getInitialProps(ctx)
// return {...initialProps}
// }

render() {
return (
<Html lang="en">
<DocumentHead />
<body>
<Main />
<BlitzScript />
</body>
</Html>
)
}
}

export default MyDocument
24 changes: 24 additions & 0 deletions test/integration/misc/pages/body-parser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import getError from "app/queries/getError"
import {useQuery} from "blitz"
import {Suspense} from "react"
import {ErrorBoundary} from "react-error-boundary"

function Content() {
const [result] = useQuery(getError, undefined)

return <div id="content">{result}</div>
}

function Page() {
return (
<div id="page">
<ErrorBoundary FallbackComponent={() => <div id="error">query failed</div>}>
<Suspense fallback="Loading...">
<Content />
</Suspense>
</ErrorBoundary>
</div>
)
}

export default Page
32 changes: 32 additions & 0 deletions test/integration/misc/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env jest */
import {findPort, killApp, launchApp, renderViaHTTP, waitFor} from "lib/blitz-test-utils"
import webdriver from "lib/next-webdriver"
import {join} from "path"

const context: any = {}
jest.setTimeout(1000 * 60 * 5)

describe("Misc", () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(join(__dirname, "../"), context.appPort, {
env: {__NEXT_TEST_WITH_DEVTOOL: 1},
})

const prerender = ["/body-parser"]
await Promise.all(prerender.map((route) => renderViaHTTP(context.appPort, route)))
})
afterAll(() => killApp(context.server))

describe("body parser config", () => {
it("should render query result", async () => {
const browser = await webdriver(context.appPort, "/body-parser")
let text = await browser.elementByCss("#page").text()
expect(text).toMatch(/Loading/)
await browser.waitForElementByCss("#error")
text = await browser.elementByCss("#error").text()
expect(text).toMatch(/query failed/)
if (browser) await browser.close()
})
})
})
25 changes: 25 additions & 0 deletions test/integration/misc/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"baseUrl": "./",
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"tsBuildInfoFile": ".tsbuildinfo",
"paths": {
"lib/*": ["../../lib/*"]
}
},
"exclude": ["node_modules"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

0 comments on commit 48584b1

Please sign in to comment.