From 48584b151af21b1c3bbf200b2cf03bf64cfa44f6 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Mon, 10 May 2021 18:25:09 -0400 Subject: [PATCH] add integration test --- test/integration/misc/app/queries/getBasic.ts | 3 ++ test/integration/misc/app/queries/getError.ts | 11 +++++++ test/integration/misc/babel.config.js | 4 +++ test/integration/misc/blitz.config.js | 1 + test/integration/misc/pages/_app.tsx | 11 +++++++ test/integration/misc/pages/_document.tsx | 23 +++++++++++++ test/integration/misc/pages/body-parser.tsx | 24 ++++++++++++++ test/integration/misc/test/index.test.ts | 32 +++++++++++++++++++ test/integration/misc/tsconfig.json | 25 +++++++++++++++ 9 files changed, 134 insertions(+) create mode 100644 test/integration/misc/app/queries/getBasic.ts create mode 100644 test/integration/misc/app/queries/getError.ts create mode 100644 test/integration/misc/babel.config.js create mode 100644 test/integration/misc/blitz.config.js create mode 100644 test/integration/misc/pages/_app.tsx create mode 100644 test/integration/misc/pages/_document.tsx create mode 100644 test/integration/misc/pages/body-parser.tsx create mode 100644 test/integration/misc/test/index.test.ts create mode 100644 test/integration/misc/tsconfig.json diff --git a/test/integration/misc/app/queries/getBasic.ts b/test/integration/misc/app/queries/getBasic.ts new file mode 100644 index 0000000000..ff5bfaa2a0 --- /dev/null +++ b/test/integration/misc/app/queries/getBasic.ts @@ -0,0 +1,3 @@ +export default async function getBasic() { + return "basic-result" +} diff --git a/test/integration/misc/app/queries/getError.ts b/test/integration/misc/app/queries/getError.ts new file mode 100644 index 0000000000..88519acfc1 --- /dev/null +++ b/test/integration/misc/app/queries/getError.ts @@ -0,0 +1,11 @@ +export default async function getError() { + return "should-not-succeed" +} + +export const config = { + api: { + bodyParser: { + sizeLimit: "0kb", + }, + }, +} diff --git a/test/integration/misc/babel.config.js b/test/integration/misc/babel.config.js new file mode 100644 index 0000000000..dfdf62cea1 --- /dev/null +++ b/test/integration/misc/babel.config.js @@ -0,0 +1,4 @@ +module.exports = { + presets: ["blitz/babel"], + plugins: [], +} diff --git a/test/integration/misc/blitz.config.js b/test/integration/misc/blitz.config.js new file mode 100644 index 0000000000..4ba52ba2c8 --- /dev/null +++ b/test/integration/misc/blitz.config.js @@ -0,0 +1 @@ +module.exports = {} diff --git a/test/integration/misc/pages/_app.tsx b/test/integration/misc/pages/_app.tsx new file mode 100644 index 0000000000..ecd77b80af --- /dev/null +++ b/test/integration/misc/pages/_app.tsx @@ -0,0 +1,11 @@ +import {AppProps} from "blitz" +import {ReactQueryDevtools} from "react-query/devtools" + +export default function App({Component, pageProps}: AppProps) { + return ( + <> + + + + ) +} diff --git a/test/integration/misc/pages/_document.tsx b/test/integration/misc/pages/_document.tsx new file mode 100644 index 0000000000..c7e0048bcd --- /dev/null +++ b/test/integration/misc/pages/_document.tsx @@ -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 ( + + + +
+ + + + ) + } +} + +export default MyDocument diff --git a/test/integration/misc/pages/body-parser.tsx b/test/integration/misc/pages/body-parser.tsx new file mode 100644 index 0000000000..06278e3e88 --- /dev/null +++ b/test/integration/misc/pages/body-parser.tsx @@ -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
{result}
+} + +function Page() { + return ( +
+
query failed
}> + + + +
+
+ ) +} + +export default Page diff --git a/test/integration/misc/test/index.test.ts b/test/integration/misc/test/index.test.ts new file mode 100644 index 0000000000..d2d75dc103 --- /dev/null +++ b/test/integration/misc/test/index.test.ts @@ -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() + }) + }) +}) diff --git a/test/integration/misc/tsconfig.json b/test/integration/misc/tsconfig.json new file mode 100644 index 0000000000..f84b4b0565 --- /dev/null +++ b/test/integration/misc/tsconfig.json @@ -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"] +}