-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
테스트 환경에서 msw 모킹을 위한 세팅
- Loading branch information
Showing
18 changed files
with
164 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"preset": "ts-jest", | ||
"testEnvironment": "jest-environment-jsdom", | ||
|
||
|
||
|
||
"moduleNameMapper": { | ||
"^@_apis/(.*)$": "<rootDir>/src/apis/$1", | ||
"^@_constants/(.*)$": "<rootDir>/src/constants/$1", | ||
"^@_common/(.*)$": "<rootDir>/src/common/$1", | ||
"^@_components/(.*)$": "<rootDir>/src/components/$1", | ||
"^@_hooks/(.*)$": "<rootDir>/src/hooks/$1", | ||
"^@_layouts/(.*)$": "<rootDir>/src/layouts/$1", | ||
"^@_pages/(.*)$": "<rootDir>/src/pages/$1", | ||
"^@_types/(.*)$": "<rootDir>/src/types/$1", | ||
"^@_utils/(.*)$": "<rootDir>/src/utils/$1", | ||
"^@_routes/(.*)$": "<rootDir>/src/routes/$1", | ||
"^@_mocks/(.*)$": "<rootDir>/src/mocks/$1" | ||
}, | ||
"testEnvironmentOptions": { | ||
"customExportConditions": [""] | ||
}, | ||
"setupFiles": ["dotenv/config", "./jest.polyfills.js"], | ||
"setupFilesAfterEnv": ["<rootDir>/jest.setup.ts"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* @note The block below contains polyfills for Node.js globals | ||
* required for Jest to function when running JSDOM tests. | ||
* These HAVE to be require's and HAVE to be in this exact | ||
* order, since "undici" depends on the "TextEncoder" global API. | ||
* | ||
* Consider migrating to a more modern test runner if | ||
* you don't want to deal with this. | ||
*/ | ||
|
||
const { TextDecoder, TextEncoder } = require('node:util'); | ||
const { ReadableStream, TransformStream } = require('node:stream/web'); | ||
|
||
Object.defineProperties(globalThis, { | ||
TextDecoder: { value: TextDecoder }, | ||
TextEncoder: { value: TextEncoder }, | ||
ReadableStream: { value: ReadableStream }, | ||
TransformStream: { value: TransformStream }, | ||
}); | ||
|
||
const { Blob, File } = require('node:buffer'); | ||
const { fetch, Headers, FormData, Request, Response } = require('undici'); | ||
|
||
Object.defineProperties(globalThis, { | ||
fetch: { value: fetch, writable: true }, | ||
Blob: { value: Blob }, | ||
File: { value: File }, | ||
Headers: { value: Headers }, | ||
FormData: { value: FormData }, | ||
Request: { value: Request }, | ||
Response: { value: Response }, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { server } from './src/mocks/server'; | ||
import '@testing-library/jest-dom'; | ||
import dotenv from 'dotenv'; | ||
dotenv.config({ path: './.env' }); | ||
|
||
beforeAll(() => { | ||
console.log('befor all server listen'); | ||
server.listen({ | ||
onUnhandledRequest: 'error', // 이 옵션을 통해 핸들되지 않은 요청을 경고로 표시 | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
console.log('after each server reset handlers '); | ||
server.resetHandlers(); | ||
}); | ||
// Clean up after the tests are finished. | ||
afterAll(() => { | ||
console.log('after all server closed'); | ||
server.close(); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
import { setupWorker } from 'msw/browser'; | ||
import { moimHandler } from './handlers/moimHandler'; | ||
import { interestHandler } from './handlers/interestHandler'; | ||
import { pleaseHandler } from './handlers/pleaseHandler'; | ||
import { moimHandler } from './handler/moimHandler'; | ||
import { interestHandler } from './handler/interestHandler'; | ||
import { pleaseHandler } from './handler/pleaseHandler'; | ||
|
||
export const worker = setupWorker(...moimHandler, ...interestHandler, ...pleaseHandler); | ||
export const worker = setupWorker( | ||
...moimHandler, | ||
...interestHandler, | ||
...pleaseHandler, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { moimHandler } from './moimHandler'; | ||
|
||
export const handlers = [...moimHandler]; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { setupServer } from 'msw/node'; | ||
import { handlers } from './handler/index'; | ||
|
||
export const server = setupServer(...handlers); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { PropsWithChildren } from 'react'; | ||
|
||
const queryClient = new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
networkMode: 'always', | ||
retry: false, | ||
}, | ||
}, | ||
}); | ||
|
||
const wrapper = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
); | ||
}; | ||
|
||
export default wrapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters