Skip to content

Commit

Permalink
Introduce msw to demonstrate bug
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenzhonauer committed Jan 26, 2022
1 parent 07203ed commit 1dc2a18
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions msw/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { setupWorker } from "msw"
import { handlers } from "./handlers"

export const worker = setupWorker(...handlers)
7 changes: 7 additions & 0 deletions msw/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { rest } from "msw"

export const handlers = [
rest.get("/sandbox", (req, res, ctx) => {
return res(ctx.status(200), ctx.json({ ok: true }))
}),
]
9 changes: 9 additions & 0 deletions msw/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default function setupMsw() {
if (typeof window === "undefined") {
const { server } = require("./server")
server.listen()
} else {
const { worker } = require("./browser")
worker.start()
}
}
6 changes: 6 additions & 0 deletions msw/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// src/mocks/server.js
import { setupServer } from "msw/node"
import { handlers } from "./handlers"

// This configures a request mocking server with the given request handlers.
export const server = setupServer(...handlers)
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"@types/node": "^15.12.4",
"@types/react": "^17.0.11",
"@types/react-dom": "^17.0.8",
"msw": "^0.36.7",
"typescript": "^4.3.4"
}
}
3 changes: 3 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { SessionProvider } from "next-auth/react"
import type { AppProps } from "next/app"
import setupMsw from "./../msw"
import "./styles.css"

setupMsw()

// Use the <SessionProvider> to improve performance and allow components that call
// `useSession()` anywhere in your application to access the `session` object.
export default function App({ Component, pageProps }: AppProps) {
Expand Down

0 comments on commit 1dc2a18

Please sign in to comment.