Add msw file server

This commit is contained in:
ThatGuySam 2023-08-12 16:01:50 -05:00
parent 05a30017f6
commit 81340c5e97
3 changed files with 27 additions and 0 deletions

15
test/msw/handlers.js Normal file
View 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
View 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
View file

@ -0,0 +1,5 @@
import { setupServer } from 'msw/node'
import { handlers } from './handlers'
export const mswServer = setupServer( ...handlers )