From a651c0b722ba8a7ff1aebbcdf0118818de9d28d4 Mon Sep 17 00:00:00 2001 From: Roesh Date: Sun, 28 Feb 2021 20:52:05 -0500 Subject: [PATCH 01/13] don't throw an error if checkYarn is null or checkYarn.stdout is null or undefined --- packages/cli/src/commands/new.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/new.ts b/packages/cli/src/commands/new.ts index 57234b8f8a..04f1ca0526 100644 --- a/packages/cli/src/commands/new.ts +++ b/packages/cli/src/commands/new.ts @@ -67,7 +67,7 @@ export class New extends Command { if (!flags["skip-upgrade"]) { const latestVersion = (await getLatestVersion("blitz")).value || this.config.version - if (lt(this.config.version, latestVersion)) { + if (true) { const upgradeChoices: Array<{name: string; message?: string}> = [ {name: "yes", message: `Yes - Upgrade to ${latestVersion}`}, { @@ -84,10 +84,13 @@ export class New extends Command { }) if (promptUpgrade.upgrade === "yes") { + var useYarn: boolean = false + const checkYarn = spawn.sync("yarn", ["global", "list"], {stdio: "pipe"}) - const useYarn = checkYarn.stdout.toString().includes("blitz@") + if (checkYarn && checkYarn.stdout) { + useYarn = checkYarn.stdout.toString().includes("blitz@") + } const upgradeOpts = useYarn ? ["global", "add", "blitz"] : ["i", "-g", "blitz@latest"] - spawn.sync(useYarn ? "yarn" : "npm", upgradeOpts, {stdio: "inherit"}) const versionResult = spawn.sync("blitz", ["--version"], {stdio: "pipe"}) From 55c6afafb01791d0de0185f2fd97b366a6403903 Mon Sep 17 00:00:00 2001 From: Roesh Date: Sun, 28 Feb 2021 20:55:53 -0500 Subject: [PATCH 02/13] make sure to check if this version is less than the latest version --- packages/cli/src/commands/new.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/new.ts b/packages/cli/src/commands/new.ts index 04f1ca0526..0dff98dda7 100644 --- a/packages/cli/src/commands/new.ts +++ b/packages/cli/src/commands/new.ts @@ -67,7 +67,7 @@ export class New extends Command { if (!flags["skip-upgrade"]) { const latestVersion = (await getLatestVersion("blitz")).value || this.config.version - if (true) { + if (lt(this.config.version, latestVersion)) { const upgradeChoices: Array<{name: string; message?: string}> = [ {name: "yes", message: `Yes - Upgrade to ${latestVersion}`}, { From 71285b5671fb849862f5ac8ab4e69c916c188f92 Mon Sep 17 00:00:00 2001 From: Roshan Manuel Date: Fri, 12 Mar 2021 20:32:39 -0500 Subject: [PATCH 03/13] fix forgotpassword test template, sync auth example tests --- .../app/auth/mutations/forgotPassword.test.ts | 14 ++++----- examples/auth/app/pages/index.test.tsx | 30 +++++++++---------- .../app/auth/mutations/forgotPassword.test.ts | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/examples/auth/app/auth/mutations/forgotPassword.test.ts b/examples/auth/app/auth/mutations/forgotPassword.test.ts index d218a16038..40d015b5d2 100644 --- a/examples/auth/app/auth/mutations/forgotPassword.test.ts +++ b/examples/auth/app/auth/mutations/forgotPassword.test.ts @@ -1,4 +1,4 @@ -import {hash256, Ctx} from "blitz" +import { hash256, Ctx } from "blitz" import forgotPassword from "./forgotPassword" import db from "db" import previewEmail from "preview-email" @@ -8,15 +8,15 @@ beforeEach(async () => { }) const generatedToken = "plain-token" -jest.mock("@blitzjs/core/server", () => ({ - ...jest.requireActual("@blitzjs/core/server")!, +jest.mock("blitz", () => ({ + ...jest.requireActual("blitz")!, generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) describe("forgotPassword mutation", () => { it("does not throw error if user doesn't exist", async () => { - await expect(forgotPassword({email: "no-user@email.com"}, {} as Ctx)).resolves.not.toThrow() + await expect(forgotPassword({ email: "no-user@email.com" }, {} as Ctx)).resolves.not.toThrow() }) it("works correctly", async () => { @@ -34,13 +34,13 @@ describe("forgotPassword mutation", () => { }, }, }, - include: {tokens: true}, + include: { tokens: true }, }) // Invoke the mutation - await forgotPassword({email: user.email}, {} as Ctx) + await forgotPassword({ email: user.email }, {} as Ctx) - const tokens = await db.token.findMany({where: {userId: user.id}}) + const tokens = await db.token.findMany({ where: { userId: user.id } }) const token = tokens[0] // delete's existing tokens diff --git a/examples/auth/app/pages/index.test.tsx b/examples/auth/app/pages/index.test.tsx index 6dc20c9087..2a37cbb643 100644 --- a/examples/auth/app/pages/index.test.tsx +++ b/examples/auth/app/pages/index.test.tsx @@ -1,17 +1,10 @@ -import {render} from "test/utils" +import { render } from "test/utils" + import Home from "./index" +import { useCurrentUser } from "app/core/hooks/useCurrentUser" -jest.mock("@blitzjs/core", () => ({ - ...jest.requireActual("@blitzjs/core")!, - useQuery: () => [ - { - id: 1, - name: "User", - email: "user@email.com", - role: "user", - }, - ], -})) +jest.mock("app/core/hooks/useCurrentUser") +const mockUseCurrentUser = useCurrentUser as jest.MockedFunction test("renders blitz documentation link", () => { // This is an example of how to ensure a specific item is in the document @@ -19,9 +12,14 @@ test("renders blitz documentation link", () => { // when you remove the the default content from the page // This is an example on how to mock api hooks when testing + mockUseCurrentUser.mockReturnValue({ + id: 1, + name: "User", + email: "user@email.com", + role: "user", + }) - const {getByText} = render() - const element = getByText(/powered by blitz/i) - // @ts-ignore - expect(element).toBeInTheDocument() + const { getByText } = render() + const linkElement = getByText(/Documentation/i) + expect(linkElement).toBeInTheDocument() }) diff --git a/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts b/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts index d5d0098f9d..40d015b5d2 100644 --- a/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts +++ b/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts @@ -9,7 +9,7 @@ beforeEach(async () => { const generatedToken = "plain-token" jest.mock("blitz", () => ({ - ...jest.requireActual("blitz")!, + ...jest.requireActual("blitz")!, generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) From 8ea14c91be5e4f894e65204c4349ec734ec2e48d Mon Sep 17 00:00:00 2001 From: Roshan Manuel <31125563+Roesh@users.noreply.github.com> Date: Mon, 15 Mar 2021 19:22:44 -0400 Subject: [PATCH 04/13] revert to ensure monorepo tests work --- examples/auth/app/auth/mutations/forgotPassword.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/auth/app/auth/mutations/forgotPassword.test.ts b/examples/auth/app/auth/mutations/forgotPassword.test.ts index 40d015b5d2..7bcd4ecb6a 100644 --- a/examples/auth/app/auth/mutations/forgotPassword.test.ts +++ b/examples/auth/app/auth/mutations/forgotPassword.test.ts @@ -8,8 +8,8 @@ beforeEach(async () => { }) const generatedToken = "plain-token" -jest.mock("blitz", () => ({ - ...jest.requireActual("blitz")!, +jest.mock("@blitzjs/core/server", () => ({ + ...jest.requireActual("@blitzjs/core/server")!, generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) From 88de5c5e28f37b88401afee74341edbf35c222ba Mon Sep 17 00:00:00 2001 From: Roshan Manuel Date: Tue, 16 Mar 2021 22:45:41 -0400 Subject: [PATCH 05/13] revert to original password and index tests --- .../app/auth/mutations/forgotPassword.test.ts | 16 +++++----- examples/auth/app/pages/index.test.tsx | 32 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/examples/auth/app/auth/mutations/forgotPassword.test.ts b/examples/auth/app/auth/mutations/forgotPassword.test.ts index 40d015b5d2..45621a95c3 100644 --- a/examples/auth/app/auth/mutations/forgotPassword.test.ts +++ b/examples/auth/app/auth/mutations/forgotPassword.test.ts @@ -1,4 +1,4 @@ -import { hash256, Ctx } from "blitz" +import {hash256, Ctx} from "blitz" import forgotPassword from "./forgotPassword" import db from "db" import previewEmail from "preview-email" @@ -8,15 +8,15 @@ beforeEach(async () => { }) const generatedToken = "plain-token" -jest.mock("blitz", () => ({ - ...jest.requireActual("blitz")!, +jest.mock("@blitzjs/core/server", () => ({ + ...jest.requireActual("@blitzjs/core/server")!, generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) describe("forgotPassword mutation", () => { it("does not throw error if user doesn't exist", async () => { - await expect(forgotPassword({ email: "no-user@email.com" }, {} as Ctx)).resolves.not.toThrow() + await expect(forgotPassword({email: "no-user@email.com"}, {} as Ctx)).resolves.not.toThrow() }) it("works correctly", async () => { @@ -34,13 +34,13 @@ describe("forgotPassword mutation", () => { }, }, }, - include: { tokens: true }, + include: {tokens: true}, }) // Invoke the mutation - await forgotPassword({ email: user.email }, {} as Ctx) + await forgotPassword({email: user.email}, {} as Ctx) - const tokens = await db.token.findMany({ where: { userId: user.id } }) + const tokens = await db.token.findMany({where: {userId: user.id}}) const token = tokens[0] // delete's existing tokens @@ -53,4 +53,4 @@ describe("forgotPassword mutation", () => { expect(token.expiresAt > new Date()).toBe(true) expect(previewEmail).toBeCalled() }) -}) +}) \ No newline at end of file diff --git a/examples/auth/app/pages/index.test.tsx b/examples/auth/app/pages/index.test.tsx index 2a37cbb643..dd9fc429be 100644 --- a/examples/auth/app/pages/index.test.tsx +++ b/examples/auth/app/pages/index.test.tsx @@ -1,10 +1,17 @@ -import { render } from "test/utils" - +import {render} from "test/utils" import Home from "./index" -import { useCurrentUser } from "app/core/hooks/useCurrentUser" -jest.mock("app/core/hooks/useCurrentUser") -const mockUseCurrentUser = useCurrentUser as jest.MockedFunction +jest.mock("@blitzjs/core", () => ({ + ...jest.requireActual("@blitzjs/core")!, + useQuery: () => [ + { + id: 1, + name: "User", + email: "user@email.com", + role: "user", + }, + ], +})) test("renders blitz documentation link", () => { // This is an example of how to ensure a specific item is in the document @@ -12,14 +19,9 @@ test("renders blitz documentation link", () => { // when you remove the the default content from the page // This is an example on how to mock api hooks when testing - mockUseCurrentUser.mockReturnValue({ - id: 1, - name: "User", - email: "user@email.com", - role: "user", - }) - const { getByText } = render() - const linkElement = getByText(/Documentation/i) - expect(linkElement).toBeInTheDocument() -}) + const {getByText} = render() + const element = getByText(/powered by blitz/i) + // @ts-ignore + expect(element).toBeInTheDocument() +}) \ No newline at end of file From 2e17e47ff5d903d7182bfb4303b910d1449872f3 Mon Sep 17 00:00:00 2001 From: Roshan Manuel <31125563+Roesh@users.noreply.github.com> Date: Tue, 16 Mar 2021 23:00:44 -0400 Subject: [PATCH 06/13] remove merge reference --- examples/auth/app/auth/mutations/forgotPassword.test.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/auth/app/auth/mutations/forgotPassword.test.ts b/examples/auth/app/auth/mutations/forgotPassword.test.ts index 1f7f35c78b..eaec59648b 100644 --- a/examples/auth/app/auth/mutations/forgotPassword.test.ts +++ b/examples/auth/app/auth/mutations/forgotPassword.test.ts @@ -9,11 +9,7 @@ beforeEach(async () => { const generatedToken = "plain-token" jest.mock("@blitzjs/core/server", () => ({ -<<<<<<< HEAD ...jest.requireActual("@blitzjs/core/server")!, -======= - ...jest.requireActual("@blitzjs/core/server")!, ->>>>>>> 8ea14c91be5e4f894e65204c4349ec734ec2e48d generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) @@ -57,4 +53,4 @@ describe("forgotPassword mutation", () => { expect(token.expiresAt > new Date()).toBe(true) expect(previewEmail).toBeCalled() }) -}) \ No newline at end of file +}) From 650d285d44839922fe88094b19b3ac279c7d7eff Mon Sep 17 00:00:00 2001 From: Roshan Manuel Date: Tue, 16 Mar 2021 23:01:13 -0400 Subject: [PATCH 07/13] fix merge issue --- examples/auth/app/auth/mutations/forgotPassword.test.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/auth/app/auth/mutations/forgotPassword.test.ts b/examples/auth/app/auth/mutations/forgotPassword.test.ts index 1f7f35c78b..45621a95c3 100644 --- a/examples/auth/app/auth/mutations/forgotPassword.test.ts +++ b/examples/auth/app/auth/mutations/forgotPassword.test.ts @@ -9,11 +9,7 @@ beforeEach(async () => { const generatedToken = "plain-token" jest.mock("@blitzjs/core/server", () => ({ -<<<<<<< HEAD ...jest.requireActual("@blitzjs/core/server")!, -======= - ...jest.requireActual("@blitzjs/core/server")!, ->>>>>>> 8ea14c91be5e4f894e65204c4349ec734ec2e48d generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) From e4ab17756309f8b75b66f73085a2823cd08f96e5 Mon Sep 17 00:00:00 2001 From: Roshan Manuel Date: Tue, 30 Mar 2021 10:40:25 -0400 Subject: [PATCH 08/13] Quirrel recipe: start > dev, double quote command --- recipes/quirrel/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/quirrel/index.ts b/recipes/quirrel/index.ts index bc3c8a8a73..92fcf88c88 100644 --- a/recipes/quirrel/index.ts +++ b/recipes/quirrel/index.ts @@ -29,11 +29,11 @@ export default RecipeBuilder() explanation: "Make sure that your local Quirrel server runs when you need it.", singleFileSearch: paths.packageJson(), transformPlain(program) { - return program.replace(/("start":\s*")(.*)(")/, (_fullMatch, start, command: string, end) => { + return program.replace(/("dev":\s*")(.*)(")/, (_fullMatch, start, command: string, end) => { if (command.includes("concurrently")) { command += ` 'quirrel'` } else { - command = `concurrently --raw '${command}' 'quirrel'` + command = `concurrently --raw \\\"${command}\\\" 'quirrel'` } return [start, command, end].join("") From 3a0910098c5af9bdd7b12dc4432c52910f41047e Mon Sep 17 00:00:00 2001 From: Roshan Manuel Date: Mon, 26 Apr 2021 17:20:05 -0400 Subject: [PATCH 09/13] add Suspense boundary --- .../templates/app/app/pages/_app.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/generator/templates/app/app/pages/_app.tsx b/packages/generator/templates/app/app/pages/_app.tsx index 10c35dac60..86e2431e89 100644 --- a/packages/generator/templates/app/app/pages/_app.tsx +++ b/packages/generator/templates/app/app/pages/_app.tsx @@ -9,19 +9,24 @@ import { } from "blitz" import { ErrorBoundary } from "react-error-boundary" import LoginForm from "app/auth/components/LoginForm" +import { Suspense } from "react" export default function App({ Component, pageProps }: AppProps) { const getLayout = Component.getLayout || ((page) => page) const router = useRouter() return ( - - {getLayout()} - + // NOTE: This suspense tag provides a convenient global fallback + // Make sure to add suspense lower in the tree to optimize loading experience where possible + + + {getLayout()} + + ) } From 79a7885e0f9e79aa549efc10cd349c0bccf50fc6 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Tue, 27 Apr 2021 17:22:15 -0400 Subject: [PATCH 10/13] Update packages/generator/templates/app/app/pages/_app.tsx --- packages/generator/templates/app/app/pages/_app.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/generator/templates/app/app/pages/_app.tsx b/packages/generator/templates/app/app/pages/_app.tsx index 86e2431e89..429ba0196a 100644 --- a/packages/generator/templates/app/app/pages/_app.tsx +++ b/packages/generator/templates/app/app/pages/_app.tsx @@ -16,8 +16,6 @@ export default function App({ Component, pageProps }: AppProps) { const router = useRouter() return ( - // NOTE: This suspense tag provides a convenient global fallback - // Make sure to add suspense lower in the tree to optimize loading experience where possible Date: Wed, 21 Jul 2021 11:44:57 -0400 Subject: [PATCH 11/13] send "blitz.js" in x-powered-by header --- nextjs/packages/next/next-server/server/send-payload.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nextjs/packages/next/next-server/server/send-payload.ts b/nextjs/packages/next/next-server/server/send-payload.ts index 400e4c210f..c7bb99faa0 100644 --- a/nextjs/packages/next/next-server/server/send-payload.ts +++ b/nextjs/packages/next/next-server/server/send-payload.ts @@ -51,7 +51,7 @@ export function sendPayload( } if (poweredByHeader && type === 'html') { - res.setHeader('X-Powered-By', 'Next.js') + res.setHeader('X-Powered-By', 'Blitz.js') } const etag = generateEtags ? generateETag(payload) : undefined From 115a60e9209631fa7b38f3d5c18b93808759d179 Mon Sep 17 00:00:00 2001 From: Roshan Manuel <31125563+Roesh@users.noreply.github.com> Date: Wed, 21 Jul 2021 11:50:40 -0400 Subject: [PATCH 12/13] Update test for powered-by-header Considered making the test check to see if anything at all was present, but not needed for our use case right now --- nextjs/test/integration/config/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nextjs/test/integration/config/test/index.test.js b/nextjs/test/integration/config/test/index.test.js index 4aa8ee9e9d..ea8c48683a 100644 --- a/nextjs/test/integration/config/test/index.test.js +++ b/nextjs/test/integration/config/test/index.test.js @@ -61,7 +61,7 @@ describe('Configuration', () => { it('should disable X-Powered-By header support', async () => { const url = `http://localhost:${context.appPort}/` const header = (await fetch(url)).headers.get('X-Powered-By') - expect(header).not.toBe('Next.js') + expect(header).not.toBe('Blitz.js') }) test('renders css imports', async () => { From ba3e0594d639fed62fc6c45486ea5f759f4898db Mon Sep 17 00:00:00 2001 From: Roshan Manuel <31125563+Roesh@users.noreply.github.com> Date: Wed, 21 Jul 2021 11:52:44 -0400 Subject: [PATCH 13/13] Update test to check for x-powered-by --- nextjs/test/integration/production/test/index.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nextjs/test/integration/production/test/index.test.js b/nextjs/test/integration/production/test/index.test.js index 20bd919c4c..6d900f819b 100644 --- a/nextjs/test/integration/production/test/index.test.js +++ b/nextjs/test/integration/production/test/index.test.js @@ -179,7 +179,7 @@ describe('Production Usage', () => { const url = `http://localhost:${appPort}/` const header = (await fetch(url)).headers.get('X-Powered-By') - expect(header).toBe('Next.js') + expect(header).toBe('Blitz.js') }) it('should render 404 for routes that do not exist', async () => {