Compare commits
7 Commits
blitz@2.0.
...
@blitzjs/r
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c096891bf0 | ||
|
|
81b4b41a99 | ||
|
|
e8271d579c | ||
|
|
9e798b152b | ||
|
|
3c6f43a11d | ||
|
|
8107138e2f | ||
|
|
8cb1134d94 |
5
.changeset/nice-starfishes-live.md
Normal file
5
.changeset/nice-starfishes-live.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
add mounted check to app generator template
|
||||
@@ -37,6 +37,7 @@
|
||||
"twenty-beans-pump",
|
||||
"two-kiwis-help",
|
||||
"unlucky-papayas-sleep",
|
||||
"wicked-ghosts-cough"
|
||||
"wicked-ghosts-cough",
|
||||
"wise-frogs-give"
|
||||
]
|
||||
}
|
||||
|
||||
5
.changeset/wise-frogs-give.md
Normal file
5
.changeset/wise-frogs-give.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@blitzjs/generator": patch
|
||||
---
|
||||
|
||||
use latest tag for generator template on rpc & auth packages
|
||||
37
.github/workflows/release.yml
vendored
Normal file
37
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
concurrency: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Node.js 16.x
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 16.x
|
||||
|
||||
- name: Pre-publish
|
||||
uses: pnpm/action-setup@646cdf48217256a3d0b80361c5a50727664284f2
|
||||
with:
|
||||
version: 6.32.6
|
||||
- run: pnpm install --frozen-lockfile
|
||||
- run: pnpm changeset version
|
||||
- run: pnpm build
|
||||
|
||||
- name: Create Release Pull Request
|
||||
uses: changesets/action@v1
|
||||
with:
|
||||
publish: pnpm changeset publish
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -1,5 +1,15 @@
|
||||
# toolkit-app
|
||||
|
||||
## 1.0.1-alpha.16
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.21
|
||||
- @blitzjs/auth@2.0.0-alpha.21
|
||||
- @blitzjs/next@2.0.0-alpha.21
|
||||
- @blitzjs/rpc@2.0.0-alpha.21
|
||||
- @blitzjs/config@2.0.0-alpha.21
|
||||
|
||||
## 1.0.1-alpha.15
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "toolkit-app",
|
||||
"version": "1.0.1-alpha.15",
|
||||
"version": "1.0.1-alpha.16",
|
||||
"scripts": {
|
||||
"start:dev": "pnpm run prisma:start && next dev",
|
||||
"buildapp": "pnpm i && pnpm prisma generate && next build",
|
||||
@@ -29,7 +29,7 @@
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@hookform/resolvers": "2.8.8",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:2.0.0-alpha.20",
|
||||
"blitz": "workspace:2.0.0-alpha.21",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
|
||||
@@ -12,7 +12,7 @@ export const getServerSideProps = gSSP<Props>(async ({ctx}) => {
|
||||
props: {
|
||||
userId: session.userId,
|
||||
publicData: session.$publicData,
|
||||
publishedAt: new Date(0)
|
||||
publishedAt: new Date(0),
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
1
integration-tests/qm/.eslintrc.js
Normal file
1
integration-tests/qm/.eslintrc.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = require("@blitzjs/config/eslint")
|
||||
3
integration-tests/qm/.gitignore
vendored
Normal file
3
integration-tests/qm/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
*.sqlite
|
||||
5
integration-tests/qm/next-env.d.ts
vendored
Normal file
5
integration-tests/qm/next-env.d.ts
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
/// <reference types="next" />
|
||||
/// <reference types="next/image-types/global" />
|
||||
|
||||
// NOTE: This file should not be edited
|
||||
// see https://nextjs.org/docs/basic-features/typescript for more information.
|
||||
4
integration-tests/qm/next.config.js
Normal file
4
integration-tests/qm/next.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({
|
||||
// update me
|
||||
})
|
||||
34
integration-tests/qm/package.json
Normal file
34
integration-tests/qm/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "test-qm",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"test-watch": "vitest",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "workspace:*",
|
||||
"@blitzjs/config": "workspace:*",
|
||||
"@blitzjs/next": "workspace:*",
|
||||
"@blitzjs/rpc": "workspace:*",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "workspace:*",
|
||||
"next": "12.1.6-canary.17",
|
||||
"prisma": "3.9.0",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-query": "3.21.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@types/react": "17.0.43",
|
||||
"@vitejs/plugin-react": "1.3.0",
|
||||
"delay": "5.0.0",
|
||||
"eslint": "7.32.0",
|
||||
"eslint-config-next": "latest",
|
||||
"eslint-plugin-testing-library": "5.0.1",
|
||||
"jsdom": "^19.0.0",
|
||||
"typescript": "^4.5.3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with query function 1`] = `"\\"useMutation\\" was expected to be called with a mutation but was called with a \\"query\\""`;
|
||||
|
||||
exports[`useMutation > useMutation calls the resolver with the argument > shouldn't work with regular functions 1`] = `"Either the file path to your resolver is incorrect (must be in a \\"queries\\" or \\"mutations\\" folder that isn't nested inside \\"pages\\" or \\"api\\") or you are trying to use Blitz's useQuery to fetch from third-party APIs (to do that, import useQuery directly from \\"react-query\\")"`;
|
||||
@@ -0,0 +1,5 @@
|
||||
// Vitest Snapshot v1
|
||||
|
||||
exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with mutation function 1`] = `"Cannot read properties of null (reading 'isReady')"`;
|
||||
|
||||
exports[`useQuery > a "query" that converts the string parameter to uppercase > shouldn't work with regular functions 1`] = `"Cannot read properties of null (reading 'isReady')"`;
|
||||
55
integration-tests/qm/test/use-mutation.test.tsx
Normal file
55
integration-tests/qm/test/use-mutation.test.tsx
Normal file
@@ -0,0 +1,55 @@
|
||||
import {describe, it, expect, beforeAll, vi} from "vitest"
|
||||
import {act, screen} from "@testing-library/react"
|
||||
import {useMutation} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
import {buildMutationRpc, buildQueryRpc, render} from "../../utils/blitz-test-utils"
|
||||
|
||||
beforeAll(() => {
|
||||
globalThis.__BLITZ_SESSION_COOKIE_PREFIX = "qm-test-cookie-prefix"
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
})
|
||||
|
||||
describe("useMutation", () => {
|
||||
const setupHook = (resolver: (...args: any) => Promise<any>): [{mutate?: Function}, Function] => {
|
||||
let res = {}
|
||||
|
||||
function TestHarness() {
|
||||
const [mutate, {isSuccess}] = useMutation(resolver)
|
||||
|
||||
Object.assign(res, {mutate})
|
||||
return <div id="harness">{isSuccess ? "Sent" : "Waiting"}</div>
|
||||
}
|
||||
|
||||
const ui = () => <TestHarness />
|
||||
|
||||
const {rerender} = render(ui())
|
||||
return [res, () => rerender(ui())]
|
||||
}
|
||||
|
||||
describe("useMutation calls the resolver with the argument", () => {
|
||||
// eslint-disable-next-line require-await
|
||||
const mutateFn = vi.fn()
|
||||
it("should work with Blitz mutations", async () => {
|
||||
const [res] = setupHook(buildMutationRpc(mutateFn))
|
||||
await act(async () => {
|
||||
await res.mutate!("data")
|
||||
})
|
||||
|
||||
await screen.findByText("Sent")
|
||||
expect(mutateFn).toHaveBeenCalledTimes(1)
|
||||
expect(mutateFn).toHaveBeenCalledWith("data", {fromQueryHook: true})
|
||||
})
|
||||
|
||||
it("shouldn't work with regular functions", () => {
|
||||
console.error = vi.fn()
|
||||
expect(() => setupHook(mutateFn)).toThrowErrorMatchingSnapshot()
|
||||
})
|
||||
|
||||
it("shouldn't work with query function", () => {
|
||||
console.error = vi.fn()
|
||||
const mutationFn = vi.fn()
|
||||
|
||||
expect(() => setupHook(buildQueryRpc(mutationFn))).toThrowErrorMatchingSnapshot()
|
||||
})
|
||||
})
|
||||
})
|
||||
166
integration-tests/qm/test/use-query.test.tsx
Normal file
166
integration-tests/qm/test/use-query.test.tsx
Normal file
@@ -0,0 +1,166 @@
|
||||
import {describe, it, expect, beforeAll, vi} from "vitest"
|
||||
import {act, screen, waitForElementToBeRemoved, waitFor} from "@testing-library/react"
|
||||
import {useQuery, useInfiniteQuery} from "@blitzjs/rpc"
|
||||
import React from "react"
|
||||
import delay from "delay"
|
||||
import {buildMutationRpc, buildQueryRpc, render} from "../../utils/blitz-test-utils"
|
||||
|
||||
describe("useQuery", () => {
|
||||
it("Placeholder", async () => {
|
||||
console.log("placeholder")
|
||||
})
|
||||
})
|
||||
// beforeAll(() => {
|
||||
// globalThis.__BLITZ_SESSION_COOKIE_PREFIX = "qm-test-cookie-prefix"
|
||||
// globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
// })
|
||||
|
||||
// describe("useQuery", () => {
|
||||
// const setupHook = (
|
||||
// params: any,
|
||||
// queryFn: (...args: any) => any,
|
||||
// options: Parameters<typeof useQuery>[2] = {} as any,
|
||||
// ): [{data?: any; setQueryData?: any}, Function] => {
|
||||
// let res = {}
|
||||
// function TestHarness() {
|
||||
// const [data, {setQueryData}] = useQuery(queryFn, params, {
|
||||
// suspense: true,
|
||||
// ...options,
|
||||
// } as any)
|
||||
// Object.assign(res, {data, setQueryData})
|
||||
// return (
|
||||
// <div id="harness">
|
||||
// <span>{data ? "Ready" : "No data"}</span>
|
||||
// <span>{data}</span>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
// const ui = () => (
|
||||
// <React.Suspense fallback="Loading...">
|
||||
// <TestHarness />
|
||||
// </React.Suspense>
|
||||
// )
|
||||
|
||||
// const {rerender} = render(ui())
|
||||
// return [res, () => rerender(ui())]
|
||||
// }
|
||||
|
||||
// describe('a "query" that converts the string parameter to uppercase', () => {
|
||||
// const upcase = async (args: string) => {
|
||||
// await delay(1000)
|
||||
// return args.toUpperCase()
|
||||
// }
|
||||
// it("should work with Blitz queries", async () => {
|
||||
// const [res] = setupHook("test", buildQueryRpc(upcase))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("Ready")
|
||||
// expect(res.data).toBe("TEST")
|
||||
// })
|
||||
// })
|
||||
|
||||
// it("should be able to change the data with setQueryData", async () => {
|
||||
// const [res] = setupHook("test", buildQueryRpc(upcase))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("Ready")
|
||||
// expect(res.data).toBe("TEST")
|
||||
// res.setQueryData((p: string) => p.substr(1, 2), {refetch: false})
|
||||
// await waitFor(() => screen.getByText("ES"))
|
||||
// })
|
||||
// })
|
||||
|
||||
// it("shouldn't work with regular functions", () => {
|
||||
// console.error = vi.fn()
|
||||
// expect(() => setupHook("test", upcase)).toThrowErrorMatchingSnapshot()
|
||||
// })
|
||||
|
||||
// it("shouldn't work with mutation function", () => {
|
||||
// console.error = vi.fn()
|
||||
// expect(() => setupHook("test", buildMutationRpc(upcase))).toThrowErrorMatchingSnapshot()
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is false", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {enabled: false})
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is undefined", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {enabled: undefined})
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
|
||||
// it("suspense disabled if enabled is false and suspense set", async () => {
|
||||
// setupHook("test", buildQueryRpc(upcase), {
|
||||
// enabled: false,
|
||||
// suspense: true,
|
||||
// })
|
||||
// await screen.findByText("No data")
|
||||
// })
|
||||
// })
|
||||
|
||||
// // it("works with options other than enabled & suspense without type error", () => {
|
||||
// // const queryFn = ((() => true) as unknown) as () => Promise<boolean>
|
||||
// // useQuery(queryFn, undefined, {refetchInterval: 10000})
|
||||
// // })
|
||||
// })
|
||||
|
||||
// describe("useInfiniteQuery", () => {
|
||||
// const setupHook = (
|
||||
// params: (arg?: any) => any,
|
||||
// queryFn: (...args: any) => any,
|
||||
// ): [{data?: any; setQueryData?: any}, Function] => {
|
||||
// let res = {}
|
||||
// function TestHarness() {
|
||||
// // TODO - fix typing
|
||||
// //@ts-ignore
|
||||
// const [groupedData] = useInfiniteQuery(queryFn, params, {
|
||||
// suspense: true,
|
||||
// getNextPageParam: () => {},
|
||||
// })
|
||||
// Object.assign(res, {groupedData})
|
||||
// return (
|
||||
// <div id="harness">
|
||||
// <span>{groupedData ? "Ready" : "No data"}</span>
|
||||
// <div>
|
||||
// {groupedData.map((data: any, i) => (
|
||||
// <div key={i}>{data}</div>
|
||||
// ))}
|
||||
// </div>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
// const ui = () => (
|
||||
// <React.Suspense fallback="Loading...">
|
||||
// <TestHarness />
|
||||
// </React.Suspense>
|
||||
// )
|
||||
|
||||
// const {rerender} = render(ui())
|
||||
// return [res, () => rerender(ui())]
|
||||
// }
|
||||
|
||||
// const getItems = ({id}: {id: number}) => {
|
||||
// if (id === 1) {
|
||||
// return "item1"
|
||||
// } else if (id === 2) {
|
||||
// return "item2"
|
||||
// } else {
|
||||
// throw new Error("No item for this id")
|
||||
// }
|
||||
// }
|
||||
// it("should work", async () => {
|
||||
// setupHook(() => ({id: 1}), buildQueryRpc(getItems))
|
||||
// await waitForElementToBeRemoved(() => screen.getByText("Loading..."))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("item1")
|
||||
// })
|
||||
|
||||
// setupHook(() => ({id: 2}), buildQueryRpc(getItems))
|
||||
// await act(async () => {
|
||||
// await screen.findByText("item2")
|
||||
// })
|
||||
// })
|
||||
// })
|
||||
13
integration-tests/qm/tsconfig.json
Normal file
13
integration-tests/qm/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "@blitzjs/config/tsconfig.nextjs.json",
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../utils/blitz-test-utils.tsx"],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"paths": {
|
||||
"react": ["./node_modules/@types/react"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"baseUrl": "."
|
||||
}
|
||||
12
integration-tests/qm/vitest.config.ts
Normal file
12
integration-tests/qm/vitest.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference types="vitest" />
|
||||
|
||||
import { defineConfig } from 'vitest/config'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
},
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
const {withBlitz} = require("@blitzjs/next")
|
||||
module.exports = withBlitz({
|
||||
// update me
|
||||
target: 'experimental-serverless-trace',
|
||||
})
|
||||
|
||||
123
integration-tests/utils/blitz-test-utils.tsx
Normal file
123
integration-tests/utils/blitz-test-utils.tsx
Normal file
@@ -0,0 +1,123 @@
|
||||
import {render as defaultRender} from "@testing-library/react"
|
||||
import {NextRouter} from "next/router"
|
||||
import {vi} from "vitest"
|
||||
import {QueryClient, QueryClientProvider} from "react-query"
|
||||
import React from "react"
|
||||
import {BlitzRpcPlugin} from "@blitzjs/rpc"
|
||||
|
||||
const mockRouter: NextRouter = {
|
||||
basePath: "",
|
||||
pathname: "/",
|
||||
route: "/",
|
||||
asPath: "/",
|
||||
query: {},
|
||||
isReady: true,
|
||||
isLocaleDomain: false,
|
||||
isPreview: false,
|
||||
push: vi.fn(),
|
||||
replace: vi.fn(),
|
||||
reload: vi.fn(),
|
||||
back: vi.fn(),
|
||||
prefetch: vi.fn(),
|
||||
beforePopState: vi.fn(),
|
||||
events: {
|
||||
on: vi.fn(),
|
||||
off: vi.fn(),
|
||||
emit: vi.fn(),
|
||||
},
|
||||
isFallback: false,
|
||||
}
|
||||
|
||||
type DefaultParams = Parameters<typeof defaultRender>
|
||||
type RenderUI = DefaultParams[0]
|
||||
type RenderOptions = DefaultParams[1] & {
|
||||
router?: Partial<NextRouter>
|
||||
}
|
||||
export type BlitzProviderProps = {
|
||||
client?: QueryClient
|
||||
contextSharing?: boolean
|
||||
}
|
||||
|
||||
const BlitzProvider = ({
|
||||
client,
|
||||
contextSharing = false,
|
||||
children,
|
||||
}: BlitzProviderProps & {children: JSX.Element}) => {
|
||||
if (globalThis.queryClient) {
|
||||
return (
|
||||
<QueryClientProvider
|
||||
client={client || globalThis.queryClient}
|
||||
contextSharing={contextSharing}
|
||||
>
|
||||
{children}
|
||||
</QueryClientProvider>
|
||||
)
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
export const RouterContext = React.createContext(null as any)
|
||||
RouterContext.displayName = "RouterContext"
|
||||
const compose =
|
||||
(...rest) =>
|
||||
(x: React.ComponentType<any>) =>
|
||||
rest.reduceRight((y, f) => f(y), x)
|
||||
|
||||
const BlitzWrapper = ({plugins, children}) => {
|
||||
const providers = plugins.reduce((acc, plugin) => {
|
||||
return plugin.withProvider ? acc.concat(plugin.withProvider) : acc
|
||||
}, [])
|
||||
const withPlugins = compose(...providers)
|
||||
const component = React.useMemo(() => withPlugins(children), [children])
|
||||
|
||||
return (
|
||||
<BlitzProvider>
|
||||
<RouterContext.Provider value={{...mockRouter}}>{component}</RouterContext.Provider>
|
||||
</BlitzProvider>
|
||||
)
|
||||
}
|
||||
|
||||
export function render(ui: RenderUI, {wrapper, router, ...options}: RenderOptions = {}) {
|
||||
if (!wrapper) {
|
||||
wrapper = ({children}) => {
|
||||
return (
|
||||
<BlitzWrapper
|
||||
plugins={[
|
||||
BlitzRpcPlugin({
|
||||
reactQueryOptions: {
|
||||
queries: {
|
||||
staleTime: 7000,
|
||||
},
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</BlitzWrapper>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return defaultRender(ui, {wrapper, ...options})
|
||||
}
|
||||
|
||||
// This enhance fn does what buildRpcFunction does during build time
|
||||
export function buildQueryRpc(fn: any) {
|
||||
const newFn = (...args: any) => {
|
||||
const [data, ...rest] = args
|
||||
return fn(data, ...rest)
|
||||
}
|
||||
newFn._isRpcClient = true
|
||||
newFn._resolverType = "query"
|
||||
newFn._routePath = "/api/test/url/" + Math.random()
|
||||
return newFn
|
||||
}
|
||||
|
||||
// This enhance fn does what buildRpcFunction does during build time
|
||||
export function buildMutationRpc(fn: any) {
|
||||
const newFn = (...args: any) => fn(...args)
|
||||
newFn._isRpcClient = true
|
||||
newFn._resolverType = "mutation"
|
||||
newFn._routePath = "/api/test/url"
|
||||
return newFn
|
||||
}
|
||||
@@ -12,6 +12,8 @@ export function waitFor(millis) {
|
||||
return new Promise((resolve) => setTimeout(resolve, millis))
|
||||
}
|
||||
|
||||
export {By}
|
||||
|
||||
const {
|
||||
BROWSER_NAME: browserName = "chrome",
|
||||
BROWSERSTACK,
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace: *",
|
||||
"@blitzjs/rpc": "workspace: *",
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@types/express": "4.17.13",
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/node-fetch": "2.6.1",
|
||||
@@ -16,6 +19,9 @@
|
||||
"fs-extra": "10.0.1",
|
||||
"get-port": "6.1.2",
|
||||
"node-fetch": "3.2.3",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-query": "3.21.1",
|
||||
"rimraf": "3.0.2",
|
||||
"selenium-webdriver": "4.1.1",
|
||||
"tree-kill": "1.2.2",
|
||||
|
||||
13
integration-tests/utils/tsconfig.json
Normal file
13
integration-tests/utils/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"extends": "@blitzjs/config/tsconfig.nextjs.json",
|
||||
"include": ["*.ts", "*.tsx"],
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"paths": {
|
||||
"react": ["./node_modules/@types/react"]
|
||||
}
|
||||
},
|
||||
"exclude": ["node_modules"],
|
||||
"baseUrl": "."
|
||||
}
|
||||
@@ -88,6 +88,10 @@ export default class Chain {
|
||||
return this.updateChain(() => this.browser.findElements(By.css(sel)))
|
||||
}
|
||||
|
||||
elementsById(sel) {
|
||||
return this.updateChain(() => this.browser.findElements(By.id(sel)))
|
||||
}
|
||||
|
||||
waitForElementByCss(sel, timeout) {
|
||||
return this.updateChain(() => this.browser.wait(until.elementLocated(By.css(sel), timeout)))
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"@changesets/cli": "2.22.0",
|
||||
"eslint": "7.32.0",
|
||||
"husky": "7.0.4",
|
||||
"jsdom": "19.0.0",
|
||||
"jsdom": "^19.0.0",
|
||||
"lint-staged": "12.1.7",
|
||||
"next": "12.1.6-canary.17",
|
||||
"only-allow": "1.1.0",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @blitzjs/auth
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/auth",
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"predev": "wait-on -d 250 ../blitz/dist/index-server.d.ts",
|
||||
@@ -24,7 +24,7 @@
|
||||
"@types/secure-password": "3.1.1",
|
||||
"b64-lite": "1.4.0",
|
||||
"bad-behavior": "1.0.1",
|
||||
"blitz": "2.0.0-alpha.20",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"cookie": "0.4.1",
|
||||
"debug": "4.3.3",
|
||||
"http": "0.0.1-security",
|
||||
@@ -35,7 +35,7 @@
|
||||
"url": "0.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.20",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@testing-library/react": "13.0.0",
|
||||
"@testing-library/react-hooks": "7.0.2",
|
||||
"@types/cookie": "0.4.1",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @blitzjs/next
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- @blitzjs/rpc@2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/next",
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "pnpm predev && pnpm watch unbuild src --wait=0.2",
|
||||
@@ -23,7 +23,7 @@
|
||||
"eslint.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@blitzjs/rpc": "2.0.0-alpha.20",
|
||||
"@blitzjs/rpc": "2.0.0-alpha.21",
|
||||
"@types/hoist-non-react-statics": "3.3.1",
|
||||
"debug": "4.3.3",
|
||||
"fs-extra": "10.0.1",
|
||||
@@ -32,7 +32,7 @@
|
||||
"superjson": "1.8.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.20",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@testing-library/dom": "8.13.0",
|
||||
"@testing-library/jest-dom": "5.16.3",
|
||||
"@testing-library/react": "13.0.0",
|
||||
@@ -43,7 +43,7 @@
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"@types/testing-library__react-hooks": "4.0.0",
|
||||
"blitz": "2.0.0-alpha.20",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"cross-spawn": "7.0.3",
|
||||
"find-up": "4.1.0",
|
||||
"lodash.frompairs": "4.0.1",
|
||||
|
||||
@@ -10,7 +10,7 @@ import Head from "next/head"
|
||||
import React from "react"
|
||||
import {QueryClient, QueryClientProvider} from "react-query"
|
||||
import {Hydrate, HydrateOptions} from "react-query/hydration"
|
||||
import {withSuperJSONPage} from './superjson'
|
||||
import {withSuperJSONPage} from "./superjson"
|
||||
|
||||
export * from "./error-boundary"
|
||||
export * from "./error-component"
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# @blitzjs/rpc
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- blitz@2.0.0-alpha.21
|
||||
- @blitzjs/auth@2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/rpc",
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"predev": "wait-on -d 250 ../blitz/dist/index-server.d.ts && wait-on -d 250 ../blitz-auth/dist/index-browser.d.ts",
|
||||
@@ -20,7 +20,7 @@
|
||||
"dist/**"
|
||||
],
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "2.0.0-alpha.20",
|
||||
"@blitzjs/auth": "2.0.0-alpha.21",
|
||||
"b64-lite": "1.4.0",
|
||||
"bad-behavior": "1.0.1",
|
||||
"chalk": "^4.1.0",
|
||||
@@ -30,11 +30,11 @@
|
||||
"zod": "3.10.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.20",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@types/debug": "4.1.7",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"blitz": "2.0.0-alpha.20",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"next": "12.1.6-canary.17",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
@@ -43,7 +43,7 @@
|
||||
"watch": "1.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"blitz": "2.0.0-alpha.20",
|
||||
"blitz": "2.0.0-alpha.21",
|
||||
"next": "*"
|
||||
},
|
||||
"publishConfig": {
|
||||
|
||||
20
packages/blitz-rpc/test/blitz-test-utils.ts
Normal file
20
packages/blitz-rpc/test/blitz-test-utils.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
// This enhance fn does what buildRpcFunction does during build time
|
||||
export function buildQueryRpc(fn: any) {
|
||||
const newFn = (...args: any) => {
|
||||
const [data, ...rest] = args
|
||||
return fn(data, ...rest)
|
||||
}
|
||||
newFn._isRpcClient = true
|
||||
newFn._resolverType = "query"
|
||||
newFn._routePath = "/api/test/url/" + Math.random()
|
||||
return newFn
|
||||
}
|
||||
|
||||
// This enhance fn does what buildRpcFunction does during build time
|
||||
export function buildMutationRpc(fn: any) {
|
||||
const newFn = (...args: any) => fn(...args)
|
||||
newFn._isRpcClient = true
|
||||
newFn._resolverType = "mutation"
|
||||
newFn._routePath = "/api/test/url"
|
||||
return newFn
|
||||
}
|
||||
98
packages/blitz-rpc/test/unit/react-query-utils.unit.test.ts
Normal file
98
packages/blitz-rpc/test/unit/react-query-utils.unit.test.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
/**
|
||||
* @vitest-environment jsdom
|
||||
*/
|
||||
import {assert, expect, test, beforeEach, describe, spyOn, it} from "vitest"
|
||||
|
||||
import {queryClient, invalidateQuery, setQueryData} from "../../src/data-client"
|
||||
|
||||
import {getQueryCacheFunctions} from "../../src/data-client/react-query-utils"
|
||||
import {buildQueryRpc} from "../blitz-test-utils"
|
||||
|
||||
// eslint-disable-next-line require-await
|
||||
const isEmpty = async (arg: string): Promise<boolean> => {
|
||||
return Boolean(arg)
|
||||
}
|
||||
|
||||
describe("getQueryCacheFunctions", () => {
|
||||
const spyRefetchQueries = spyOn(queryClient, "invalidateQueries")
|
||||
|
||||
beforeEach(() => {
|
||||
spyRefetchQueries.mockReset()
|
||||
})
|
||||
|
||||
it("returns a setQueryData function with working options", async () => {
|
||||
window.requestIdleCallback = undefined as any
|
||||
|
||||
const {setQueryData} = getQueryCacheFunctions(buildQueryRpc(isEmpty), "a")
|
||||
expect(setQueryData).toBeTruthy()
|
||||
await setQueryData(true)
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
await setQueryData(true, {refetch: false})
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
await setQueryData(true, {refetch: true})
|
||||
expect(spyRefetchQueries).toBeCalledTimes(2)
|
||||
})
|
||||
|
||||
it("works even when requestIdleCallback is undefined", async () => {
|
||||
window.requestIdleCallback = undefined as any
|
||||
const {setQueryData} = getQueryCacheFunctions(buildQueryRpc(isEmpty), "a")
|
||||
expect(setQueryData).toBeTruthy()
|
||||
await setQueryData(true)
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
await setQueryData(true, {refetch: false})
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
await setQueryData(true, {refetch: true})
|
||||
expect(spyRefetchQueries).toBeCalledTimes(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe("invalidateQuery", () => {
|
||||
const spyRefetchQueries = spyOn(queryClient, "invalidateQueries")
|
||||
|
||||
beforeEach(() => {
|
||||
spyRefetchQueries.mockReset()
|
||||
})
|
||||
|
||||
it("invalidates a query given resolver and params", async () => {
|
||||
await invalidateQuery(buildQueryRpc(isEmpty), "a")
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
const calledWith = spyRefetchQueries.mock.calls[0][0] as any
|
||||
// json of the queryKey is "a"
|
||||
expect(calledWith[1].json).toEqual("a")
|
||||
})
|
||||
})
|
||||
|
||||
describe("setQueryData", () => {
|
||||
const spyRefetchQueries = spyOn(queryClient, "invalidateQueries")
|
||||
const spySetQueryData = spyOn(queryClient, "setQueryData")
|
||||
|
||||
beforeEach(() => {
|
||||
spyRefetchQueries.mockReset()
|
||||
spySetQueryData.mockReset()
|
||||
})
|
||||
|
||||
it("without refetch will not invalidate queries", async () => {
|
||||
await setQueryData(buildQueryRpc(isEmpty), "params", "newValue", {
|
||||
refetch: false,
|
||||
})
|
||||
expect(spyRefetchQueries).toBeCalledTimes(0)
|
||||
expect(spySetQueryData).toBeCalledTimes(1)
|
||||
|
||||
const calledWith = spySetQueryData.mock.calls[0] as Array<any>
|
||||
expect(calledWith[0][1].json).toEqual("params")
|
||||
expect(calledWith[1]).toEqual("newValue")
|
||||
})
|
||||
|
||||
it("will invalidate queries by default", async () => {
|
||||
await setQueryData(buildQueryRpc(isEmpty), "params", "newValue")
|
||||
expect(spyRefetchQueries).toBeCalledTimes(1)
|
||||
expect(spySetQueryData).toBeCalledTimes(1)
|
||||
|
||||
const invalidateCalledWith = spyRefetchQueries.mock.calls[0][0] as any
|
||||
expect(invalidateCalledWith[1].json).toEqual("params")
|
||||
|
||||
const calledWith = spySetQueryData.mock.calls[0] as Array<any>
|
||||
expect(calledWith[0][1].json).toEqual("params")
|
||||
expect(calledWith[1]).toEqual("newValue")
|
||||
})
|
||||
})
|
||||
@@ -1,5 +1,12 @@
|
||||
# blitz
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- Updated dependencies
|
||||
- @blitzjs/generator@2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
### Patch Changes
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "blitz",
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"scripts": {
|
||||
"build": "unbuild",
|
||||
"dev": "watch unbuild src --wait=0.2",
|
||||
@@ -23,7 +23,7 @@
|
||||
"blitz": "bin/blitz"
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/generator": "2.0.0-alpha.20",
|
||||
"@blitzjs/generator": "2.0.0-alpha.21",
|
||||
"arg": "5.0.1",
|
||||
"chalk": "^4.1.0",
|
||||
"console-table-printer": "2.10.0",
|
||||
@@ -47,7 +47,7 @@
|
||||
"tslog": "3.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.20",
|
||||
"@blitzjs/config": "workspace:2.0.0-alpha.21",
|
||||
"@types/cookie": "0.4.1",
|
||||
"@types/cross-spawn": "6.0.2",
|
||||
"@types/debug": "4.1.7",
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# @blitzjs/config
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
## 2.0.0-alpha.19
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@blitzjs/config",
|
||||
"private": true,
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@typescript-eslint/eslint-plugin": "5.9.1",
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# @blitzjs/generator
|
||||
|
||||
## 2.0.0-alpha.21
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- use latest tag for generator template on rpc & auth packages
|
||||
|
||||
## 2.0.0-alpha.20
|
||||
|
||||
## 2.0.0-alpha.19
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@blitzjs/generator",
|
||||
"version": "2.0.0-alpha.20",
|
||||
"version": "2.0.0-alpha.21",
|
||||
"scripts": {
|
||||
"dev": "watch unbuild src --wait=0.2",
|
||||
"build": "unbuild && pnpm build:templates",
|
||||
@@ -45,7 +45,7 @@
|
||||
"vinyl": "2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-alpha.20",
|
||||
"@blitzjs/config": "2.0.0-alpha.21",
|
||||
"@juanm04/cpx": "2.0.1",
|
||||
"@types/babel__core": "7.1.19",
|
||||
"@types/diff": "5.0.2",
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
"*.{js}": ["eslint --fix"]
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "alpha",
|
||||
"@blitzjs/auth": "latest",
|
||||
"@blitzjs/next": "alpha",
|
||||
"@blitzjs/rpc": "alpha",
|
||||
"@blitzjs/rpc": "latest",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "alpha",
|
||||
"next": "12.1.1",
|
||||
|
||||
@@ -22,9 +22,9 @@
|
||||
"*.{js,ts,tsx}": ["eslint --fix"]
|
||||
},
|
||||
"dependencies": {
|
||||
"@blitzjs/auth": "alpha",
|
||||
"@blitzjs/auth": "latest",
|
||||
"@blitzjs/next": "alpha",
|
||||
"@blitzjs/rpc": "alpha",
|
||||
"@blitzjs/rpc": "latest",
|
||||
"@prisma/client": "3.9.0",
|
||||
"blitz": "alpha",
|
||||
"next": "12.1.1",
|
||||
|
||||
@@ -25,11 +25,15 @@ function RootErrorFallback({error}: ErrorFallbackProps) {
|
||||
}
|
||||
|
||||
function MyApp({Component, pageProps}: AppProps) {
|
||||
const [mounted, setMounted] = React.useState(false)
|
||||
React.useEffect(() => {
|
||||
setMounted(true)
|
||||
}, [])
|
||||
return (
|
||||
<ErrorBoundary FallbackComponent={RootErrorFallback}>
|
||||
<Suspense fallback="Loading...">
|
||||
{mounted && <Suspense fallback="Loading...">
|
||||
<Component {...pageProps} />
|
||||
</Suspense>
|
||||
</Suspense> }
|
||||
</ErrorBoundary>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"@typescript-eslint/parser": "5.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@blitzjs/config": "2.0.0-alpha.20",
|
||||
"@blitzjs/config": "2.0.0-alpha.21",
|
||||
"@types/react": "17.0.43",
|
||||
"@types/react-dom": "17.0.14",
|
||||
"react": "18.0.0",
|
||||
|
||||
616
pnpm-lock.yaml
generated
616
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user