mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -07:00
Add msw file server
This commit is contained in:
parent
05a30017f6
commit
81340c5e97
3 changed files with 27 additions and 0 deletions
15
test/msw/handlers.js
Normal file
15
test/msw/handlers.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import path from 'node:path'
|
||||
import fs from 'node:fs/promises'
|
||||
|
||||
import { rest } from 'msw'
|
||||
|
||||
export const handlers = [
|
||||
rest.get('https://mock.msw/*', async (req, res, ctx) => {
|
||||
const { endpoint } = req.params;
|
||||
const urlPath = req.url.pathname
|
||||
|
||||
const fileContent = await fs.readFile( `./static/${urlPath}`, 'utf8')
|
||||
|
||||
return res(ctx.json(JSON.parse(fileContent)))
|
||||
}),
|
||||
];
|
||||
7
test/msw/native.js
Normal file
7
test/msw/native.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
// This module enables requests interception in React Native
|
||||
// using the same request handlers as in tests.
|
||||
import { setupServer } from 'msw/native'
|
||||
|
||||
import { handlers } from './handlers'
|
||||
|
||||
export const native = setupServer( ...handlers )
|
||||
5
test/msw/server.js
Normal file
5
test/msw/server.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { setupServer } from 'msw/node'
|
||||
|
||||
import { handlers } from './handlers'
|
||||
|
||||
export const mswServer = setupServer( ...handlers )
|
||||
Loading…
Add table
Add a link
Reference in a new issue