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

Fix tests for turbopack support #4317

Closed
wants to merge 11 commits into from
22 changes: 22 additions & 0 deletions .changeset/silly-jobs-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"blitz": minor
"@blitzjs/next": minor
"@blitzjs/rpc": minor
---

Turbopack support for Blitz

This PR includes the changes required to make the Blitz loaders work with Turbopack.

Usage:

```ts
//next.config.js
const nextConfig = {
blitz: {
turbo: true,
},
}

module.exports = withBlitz(nextConfig)
```
14 changes: 13 additions & 1 deletion apps/next13/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const {withBlitz} = require("@blitzjs/next")

const loaderClient = require.resolve("@blitzjs/rpc/dist/loader-client.cjs")
const loaderServer = require.resolve("@blitzjs/rpc/dist/loader-server.cjs")
const loaderServerResolvers = require.resolve("@blitzjs/rpc/dist/loader-server-resolvers.cjs")

console.log("loaderClient", loaderClient)
console.log("loaderServer", loaderServer)
console.log("loaderServerResolvers", loaderServerResolvers)

/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {
blitz: {
turbo: true,
},
}

module.exports = withBlitz(nextConfig)
2 changes: 1 addition & 1 deletion apps/next13/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@tanstack/react-query": "4.0.10",
"blitz": "2.0.6",
"flatted": "3.2.7",
"next": "14.0.4",
"next": "canary",
"prisma": "^4.5.0",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/toolkit-app-passportjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@hookform/resolvers": "2.9.10",
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"openid-client": "5.2.1",
"prisma": "4.6.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/toolkit-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@hookform/resolvers": "2.9.10",
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"next-auth": "4.18.7",
"prisma": "4.6.1",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"blitz": "2.0.6",
"jest": "29.3.0",
"jest-environment-jsdom": "29.3.0",
"next": "14.0.4",
"next": "canary",
"passport-mock-strategy": "2.0.0",
"passport-twitter": "1.0.4",
"prisma": "4.6.1",
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/auth-with-rpc/next.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const {withBlitz} = require("@blitzjs/next")
module.exports = withBlitz({})
module.exports = withBlitz({
blitz: {
turbo: true,
},
})
2 changes: 1 addition & 1 deletion integration-tests/auth-with-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"delay": "5.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
17 changes: 16 additions & 1 deletion integration-tests/auth-with-rpc/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ const runTests = () => {
}

describe("Auth Tests", () => {
describe("dev mode", () => {
describe("dev mode - webpack", () => {
beforeAll(async () => {
mode = "dev"
try {
Expand All @@ -290,6 +290,21 @@ describe("Auth Tests", () => {
runTests()
})

describe("dev mode - turbo", () => {
beforeAll(async () => {
mode = "dev"
try {
await runBlitzCommand(["prisma", "migrate", "reset", "--force"])
appPort = await findPort()
app = await blitzLaunchApp(appPort, {cwd: process.cwd()}, true)
} catch (error) {
console.log(error)
}
}, 5000 * 60 * 2)
afterAll(async () => await killApp(app))
runTests()
})

describe("server mode", () => {
beforeAll(async () => {
mode = "server"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/get-initial-props/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/middleware/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@blitzjs/next": "2.0.6",
"@blitzjs/rpc": "2.0.6",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
34 changes: 0 additions & 34 deletions integration-tests/next-13-app-dir/app/react-query.tsx

This file was deleted.

6 changes: 5 additions & 1 deletion integration-tests/next-13-app-dir/next.config.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const {withBlitz} = require("@blitzjs/next")
module.exports = withBlitz({})
module.exports = withBlitz({
blitz: {
turbo: true,
},
})
2 changes: 1 addition & 1 deletion integration-tests/next-13-app-dir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
32 changes: 16 additions & 16 deletions integration-tests/next-13-app-dir/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const runTests = (mode?: string) => {
}

describe("Auth Tests", () => {
describe("dev mode", async () => {
describe("dev mode - webpack", async () => {
beforeAll(async () => {
try {
await runBlitzCommand(["prisma", "migrate", "reset", "--force"])
Expand All @@ -169,19 +169,19 @@ describe("Auth Tests", () => {
runTests()
})

// describe("server mode", () => {
// beforeAll(async () => {
// try {
// await runBlitzCommand(["prisma", "generate"])
// await runBlitzCommand(["prisma", "migrate", "deploy"])
// await blitzBuild()
// // appPort = await findPort()
// app = await blitzStart(appPort, {cwd: process.cwd()})
// } catch (err) {
// console.log(err)
// }
// }, 5000 * 60 * 2)
// afterAll(async () => await killApp(app))
// runTests()
// })
describe("dev mode - turbo", async () => {
beforeAll(async () => {
try {
await runBlitzCommand(["prisma", "migrate", "reset", "--force"])
appPort = await findPort()
app = await blitzLaunchApp(appPort, {cwd: process.cwd()}, true)
} catch (error) {
console.log(error)
}
}, 5000 * 60 * 2)
afterAll(async () => {
await killApp(app)
})
runTests()
})
})
2 changes: 1 addition & 1 deletion integration-tests/no-suspense/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/qm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@prisma/client": "4.6.1",
"@tanstack/react-query": "4.0.10",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/react-query-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Content() {
)
}

function PageWithGetQueryData() {
function PageWithMonorepoGetQueryData() {
return (
<div id="page">
<Suspense fallback={"Loading..."}>
Expand All @@ -32,4 +32,4 @@ function PageWithGetQueryData() {
)
}

export default PageWithGetQueryData
export default PageWithMonorepoGetQueryData
2 changes: 1 addition & 1 deletion integration-tests/rpc-path-root/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@blitzjs/next": "2.0.6",
"@blitzjs/rpc": "2.0.6",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@blitzjs/next": "2.0.6",
"@blitzjs/rpc": "2.0.6",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"react": "18.2.0",
"react-dom": "18.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/trailing-slash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@prisma/client": "4.6.1",
"blitz": "2.0.6",
"lowdb": "3.0.0",
"next": "14.0.4",
"next": "canary",
"prisma": "4.6.1",
"react": "18.2.0",
"react-dom": "18.2.0"
Expand Down
11 changes: 7 additions & 4 deletions integration-tests/utils/next-test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,11 @@ export function runBlitzCommandDev(argv, stdOut, opts: RunNextCommandDevOptions
__NEXT_TEST_MODE: "true",
...opts.env,
}
const turbo = opts.turbo ? ["--turbo"] : []

return new Promise<void>((resolve, reject) => {
const instance = spawn("node", [blitzBin, ...argv], {
console.log(`Running command "blitz ${argv.join(" ")}"`)
const instance = spawn("node", [blitzBin, ...argv, ...turbo], {
cwd,
env,
} as {})
Expand Down Expand Up @@ -294,8 +296,8 @@ export function runBlitzCommandDev(argv, stdOut, opts: RunNextCommandDevOptions
}

// Blitz Utils
export function blitzLaunchApp(port, opts: RunNextCommandDevOptions) {
return runBlitzCommandDev(["dev", "-p", port], undefined, opts)
export function blitzLaunchApp(port, opts: RunNextCommandDevOptions, turbo = false) {
return runBlitzCommandDev(["dev", "-p", port, turbo ? "--turbo" : ""], undefined, opts)
}

export function blitzBuild(args = [], opts = {}): any {
Expand Down Expand Up @@ -437,7 +439,7 @@ export function runNextCommandDev(argv, stdOut, opts: RunNextCommandDevOptions =
}

if (opts.stdout !== false) {
process.stdout.write(message)
process.stdout.write(message)
}
}

Expand Down Expand Up @@ -923,4 +925,5 @@ interface RunNextCommandDevOptions {
nodeArgs?: []
bootupMarker?: any
nextStart?: boolean
turbo?: boolean
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"husky": "8.0.2",
"jsdom": "^19.0.0",
"lint-staged": "13.0.3",
"next": "14.0.4",
"next": "canary",
"only-allow": "1.1.0",
"prettier": "^2.7.1",
"prettier-plugin-prisma": "4.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@types/react": "18.0.25",
"@types/react-dom": "17.0.14",
"blitz": "2.0.6",
"next": "14.0.4",
"next": "canary",
"next-auth": "4.18.7",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/blitz-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"blitz": "2.0.6",
"cross-spawn": "7.0.3",
"find-up": "4.1.0",
"next": "14.0.4",
"next": "canary",
"next-router-mock": "0.9.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
Loading
Loading