File tree Expand file tree Collapse file tree 13 files changed +823
-41
lines changed Expand file tree Collapse file tree 13 files changed +823
-41
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ import BiViewListIcon from "assets/svg/bi_view_list_icon.svg";
99import { Card } from "component/common/card" ;
1010import { Pagination } from "component/common/pagination" ;
1111import { BiView } from "component/common/biView" ;
12- import { MOCK } from "../../../mock /constants" ;
12+ import { MOCK } from "../../../mocks/json /constants" ;
1313import * as S from "./book.styles" ;
1414import { ViewMode } from "./book.constants" ;
1515
Original file line number Diff line number Diff line change 1+ export async function register ( ) {
2+ if ( process . env . NEXT_RUNTIME === "nodejs" ) {
3+ console . log ( "server instrucmenttation" ) ;
4+ const { server } = await import ( "./mocks/server" ) ;
5+ server . listen ( ) ;
6+ }
7+ }
Original file line number Diff line number Diff line change 1+ import { setupWorker } from "msw/browser" ;
2+ import { handlers } from "./handlers" ;
3+
4+ export const worker = setupWorker ( ...handlers ) ;
Original file line number Diff line number Diff line change 1+ import sign from "./sign" ;
2+
3+ export const handlers = [ ...sign ] ;
Original file line number Diff line number Diff line change 1+ import { http , HttpResponse } from "msw" ;
2+
3+ const signIn = [
4+ http . post ( `${ process . env . NEXT_PUBLIC_API_KEY } /sign-in` , ( ) => {
5+ return HttpResponse . json ( {
6+ accessToken : "123" ,
7+ } ) ;
8+ } ) ,
9+ http . post ( `${ process . env . NEXT_PUBLIC_API_KEY } /sign-up` , ( ) => {
10+ return HttpResponse . json ( ) ;
11+ } ) ,
12+ ] ;
13+
14+ export default signIn ;
File renamed without changes.
Original file line number Diff line number Diff line change 1+ import { setupServer } from "msw/node" ;
2+ import { handlers } from "./handlers" ;
3+
4+ export const server = setupServer ( ...handlers ) ;
Original file line number Diff line number Diff line change @@ -5,8 +5,11 @@ module.exports = {
55 compiler : {
66 styledComponents : true ,
77 } ,
8+ experimental : {
9+ instrumentationHook : true ,
10+ } ,
811 // svgr : https://react-svgr.com/docs/next/
9- webpack ( config ) {
12+ webpack ( config , { isServer } ) {
1013 // Grab the existing rule that handles SVG imports
1114 const fileLoaderRule = config . module . rules . find ( ( rule ) =>
1215 rule . test ?. test ?. ( ".svg" ) ,
@@ -31,6 +34,20 @@ module.exports = {
3134 // Modify the file loader rule to ignore *.svg, since we have it handled now.
3235 fileLoaderRule . exclude = / \. s v g $ / i;
3336
37+ if ( isServer ) {
38+ if ( Array . isArray ( config . resolve . alias ) ) {
39+ config . resolve . alias . push ( { name : "msw/browser" , alias : false } ) ;
40+ } else {
41+ config . resolve . alias [ "msw/browser" ] = false ;
42+ }
43+ } else {
44+ if ( Array . isArray ( config . resolve . alias ) ) {
45+ config . resolve . alias . push ( { name : "msw/node" , alias : false } ) ;
46+ } else {
47+ config . resolve . alias [ "msw/node" ] = false ;
48+ }
49+ }
50+
3451 return config ;
3552 } ,
3653} ;
Original file line number Diff line number Diff line change 3131 "zustand" : " ^4.5.2"
3232 },
3333 "devDependencies" : {
34- "@sc-config/jest" : " workspace:*" ,
3534 "@next/eslint-plugin-next" : " ^13.4.19" ,
35+ "@sc-config/jest" : " workspace:*" ,
3636 "@svgr/webpack" : " ^8.1.0" ,
3737 "@tanstack/eslint-plugin-query" : " ^5.17.7" ,
3838 "@testing-library/jest-dom" : " ^6.1.4" ,
4343 "eslint-config-sc" : " workspace:*" ,
4444 "jest" : " ^29.7.0" ,
4545 "jest-environment-jsdom" : " ^29.6.4" ,
46+ "msw" : " ^2.2.12" ,
4647 "tsconfig-sc" : " workspace:*" ,
4748 "typescript" : " ^5.2.2"
49+ },
50+ "msw" : {
51+ "workerDirectory" : [
52+ " public"
53+ ]
4854 }
49- }
55+ }
Original file line number Diff line number Diff line change @@ -2,14 +2,17 @@ import type { ReactNode } from "react";
22import { ReactQueryProvider } from "./reactQuery" ;
33import StyledJsxProvider from "./emotion" ;
44import { ThemeProvider } from "./theme" ;
5+ import { MockProvider } from "./msw" ;
56
67const Providers = ( { children } : { children : ReactNode } ) => {
78 return (
8- < ReactQueryProvider >
9- < StyledJsxProvider >
10- < ThemeProvider > { children } </ ThemeProvider >
11- </ StyledJsxProvider >
12- </ ReactQueryProvider >
9+ < MockProvider >
10+ < ReactQueryProvider >
11+ < StyledJsxProvider >
12+ < ThemeProvider > { children } </ ThemeProvider >
13+ </ StyledJsxProvider >
14+ </ ReactQueryProvider >
15+ </ MockProvider >
1316 ) ;
1417} ;
1518
You can’t perform that action at this time.
0 commit comments