test(frontend): migrate MSW in Storybook to v2 (#13195)
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
import { type SharedOptions, rest } from 'msw';
|
||||
import { type SharedOptions, http, HttpResponse } from 'msw';
|
||||
|
||||
export const onUnhandledRequest = ((req, print) => {
|
||||
if (req.url.hostname !== 'localhost' || /^\/(?:client-assets\/|fluent-emojis?\/|iframe.html$|node_modules\/|src\/|sb-|static-assets\/|vite\/)/.test(req.url.pathname)) {
|
||||
@@ -13,19 +13,31 @@ export const onUnhandledRequest = ((req, print) => {
|
||||
}) satisfies SharedOptions['onUnhandledRequest'];
|
||||
|
||||
export const commonHandlers = [
|
||||
rest.get('/fluent-emoji/:codepoints.png', async (req, res, ctx) => {
|
||||
const { codepoints } = req.params;
|
||||
http.get('/fluent-emoji/:codepoints.png', async ({ params }) => {
|
||||
const { codepoints } = params;
|
||||
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
|
||||
return res(ctx.set('Content-Type', 'image/png'), ctx.body(value));
|
||||
return new HttpResponse(value, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
});
|
||||
}),
|
||||
rest.get('/fluent-emojis/:codepoints.png', async (req, res, ctx) => {
|
||||
const { codepoints } = req.params;
|
||||
http.get('/fluent-emojis/:codepoints.png', async ({ params }) => {
|
||||
const { codepoints } = params;
|
||||
const value = await fetch(`https://raw.githubusercontent.com/misskey-dev/emojis/main/dist/${codepoints}.png`).then((response) => response.blob());
|
||||
return res(ctx.set('Content-Type', 'image/png'), ctx.body(value));
|
||||
return new HttpResponse(value, {
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
},
|
||||
});
|
||||
}),
|
||||
rest.get('/twemoji/:codepoints.svg', async (req, res, ctx) => {
|
||||
const { codepoints } = req.params;
|
||||
http.get('/twemoji/:codepoints.svg', async ({ params }) => {
|
||||
const { codepoints } = params;
|
||||
const value = await fetch(`https://unpkg.com/@discordapp/twemoji@15.0.2/dist/svg/${codepoints}.svg`).then((response) => response.blob());
|
||||
return res(ctx.set('Content-Type', 'image/svg+xml'), ctx.body(value));
|
||||
return new HttpResponse(value, {
|
||||
headers: {
|
||||
'Content-Type': 'image/svg+xml',
|
||||
},
|
||||
});
|
||||
}),
|
||||
];
|
||||
|
Reference in New Issue
Block a user