Skip to content

Commit

Permalink
V15: Chore: Fix msw in client test runner (umbraco#17777)
Browse files Browse the repository at this point in the history
* remove unused

* Update index.ts

* add local files

* use fetch instead of import
  • Loading branch information
madsrasmussen authored Dec 11, 2024
1 parent 2f8866a commit 89061f1
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { handlers as backofficeHandlers } from './handlers/backoffice.handlers.js';
import { handlers as backofficeHandlers } from './handlers/backoffice/backoffice.handlers.js';
import { handlers as configHandlers } from './handlers/config.handlers.js';
import { handlers as cultureHandlers } from './handlers/culture.handlers.js';
import { handlers as dataTypeHandlers } from './handlers/data-type/index.js';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,50 +1,46 @@
const { rest } = window.MockServiceWorker;
import { umbracoPath } from '@umbraco-cms/backoffice/utils';

import logoUrl from '../../../../Umbraco.Cms.StaticAssets/wwwroot/umbraco/assets/logo.svg';
import loginLogoUrl from '../../../../Umbraco.Cms.StaticAssets/wwwroot/umbraco/assets/logo_light.svg';
import loginLogoAlternativeUrl from '../../../../Umbraco.Cms.StaticAssets/wwwroot/umbraco/assets/logo_dark.svg';
import loginBackgroundUrl from '../../../../Umbraco.Cms.StaticAssets/wwwroot/umbraco/assets/login.jpg';
const logoUrl = './src/mocks/handlers/backoffice/assets/logo.svg';
const loginLogoUrl = './src/mocks/handlers/backoffice/assets/logo_light.svg';
const loginLogoAlternativeUrl = './src/mocks/handlers/backoffice/assets/logo_dark.svg';
const loginBackgroundUrl = './src/mocks/handlers/backoffice/assets/login.jpg';

export const handlers = [
rest.get(umbracoPath('/security/back-office/graphics/logo'), async (req, res, ctx) => {
const imageBuffer = await fetch(logoUrl)
.then((res) => res.arrayBuffer());
const imageBuffer = await fetch(logoUrl).then((res) => res.arrayBuffer());

return res(
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
ctx.set('Content-Type', 'image/svg+xml'),
ctx.body(imageBuffer)
ctx.body(imageBuffer),
);
}),
rest.get(umbracoPath('/security/back-office/graphics/login-logo'), async (req, res, ctx) => {
const imageBuffer = await fetch(loginLogoUrl)
.then((res) => res.arrayBuffer());
const imageBuffer = await fetch(loginLogoUrl).then((res) => res.arrayBuffer());

return res(
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
ctx.set('Content-Type', 'image/svg+xml'),
ctx.body(imageBuffer)
ctx.body(imageBuffer),
);
}),
rest.get(umbracoPath('/security/back-office/graphics/login-logo-alternative'), async (req, res, ctx) => {
const imageBuffer = await fetch(loginLogoAlternativeUrl)
.then((res) => res.arrayBuffer());
const imageBuffer = await fetch(loginLogoAlternativeUrl).then((res) => res.arrayBuffer());

return res(
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
ctx.set('Content-Type', 'image/svg+xml'),
ctx.body(imageBuffer)
ctx.body(imageBuffer),
);
}),
rest.get(umbracoPath('/security/back-office/graphics/login-background'), async (req, res, ctx) => {
const imageBuffer = await fetch(loginBackgroundUrl)
.then((res) => res.arrayBuffer());
const imageBuffer = await fetch(loginBackgroundUrl).then((res) => res.arrayBuffer());

return res(
ctx.set('Content-Length', imageBuffer.byteLength.toString()),
ctx.set('Content-Type', 'image/jpeg'),
ctx.body(imageBuffer)
ctx.body(imageBuffer),
);
}),
];
4 changes: 2 additions & 2 deletions src/Umbraco.Web.UI.Client/utils/all-umb-consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const foundConsts = [{
},
{
path: '@umbraco-cms/backoffice/content',
consts: ["UMB_CONTENT_COLLECTION_WORKSPACE_CONTEXT","UMB_CONTENT_HAS_PROPERTIES_WORKSPACE_CONDITION","UMB_CONTENT_SECTION_ALIAS","UMB_CONTENT_PROPERTY_CONTEXT","UMB_CONTENT_WORKSPACE_CONTEXT"]
consts: ["UMB_CONTENT_COLLECTION_WORKSPACE_CONTEXT","UMB_CONTENT_HAS_PROPERTIES_WORKSPACE_CONDITION","UMB_CONTENT_SECTION_ALIAS","UMB_CONTENT_PROPERTY_CONTEXT","UMB_CONTENT_PROPERTY_DATASET_CONTEXT","UMB_CONTENT_WORKSPACE_CONTEXT"]
},
{
path: '@umbraco-cms/backoffice/culture',
Expand Down Expand Up @@ -216,7 +216,7 @@ export const foundConsts = [{
},
{
path: '@umbraco-cms/backoffice/member',
consts: ["UMB_MEMBER_COLLECTION_ALIAS","UMB_MEMBER_COLLECTION_CONTEXT","UMB_MEMBER_COLLECTION_REPOSITORY_ALIAS","UMB_MEMBER_TABLE_COLLECTION_VIEW_ALIAS","UMB_MEMBER_PICKER_MODAL","UMB_MEMBER_CREATE_OPTIONS_MODAL","UMB_MEMBER_ENTITY_TYPE","UMB_MEMBER_ROOT_ENTITY_TYPE","UMB_MEMBER_WORKSPACE_PATH","UMB_MEMBER_ROOT_WORKSPACE_PATH","UMB_CREATE_MEMBER_WORKSPACE_PATH_PATTERN","UMB_MEMBER_VARIANT_CONTEXT","UMB_MEMBER_DETAIL_REPOSITORY_ALIAS","UMB_MEMBER_DETAIL_STORE_ALIAS","UMB_MEMBER_DETAIL_STORE_CONTEXT","UMB_MEMBER_ITEM_REPOSITORY_ALIAS","UMB_MEMBER_STORE_ALIAS","UMB_MEMBER_ITEM_STORE_CONTEXT","UMB_MEMBER_SEARCH_PROVIDER_ALIAS","UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD","UMB_MEMBER_WORKSPACE_ALIAS","UMB_MEMBER_WORKSPACE_CONTEXT","UMB_MEMBER_ROOT_WORKSPACE_ALIAS"]
consts: ["UMB_MEMBER_COLLECTION_ALIAS","UMB_MEMBER_COLLECTION_CONTEXT","UMB_MEMBER_COLLECTION_REPOSITORY_ALIAS","UMB_MEMBER_TABLE_COLLECTION_VIEW_ALIAS","UMB_MEMBER_PICKER_MODAL","UMB_MEMBER_CREATE_OPTIONS_MODAL","UMB_MEMBER_ENTITY_TYPE","UMB_MEMBER_ROOT_ENTITY_TYPE","UMB_MEMBER_WORKSPACE_PATH","UMB_MEMBER_ROOT_WORKSPACE_PATH","UMB_CREATE_MEMBER_WORKSPACE_PATH_PATTERN","UMB_MEMBER_VARIANT_CONTEXT","UMB_MEMBER_DETAIL_REPOSITORY_ALIAS","UMB_MEMBER_DETAIL_STORE_ALIAS","UMB_MEMBER_DETAIL_STORE_CONTEXT","UMB_MEMBER_ITEM_REPOSITORY_ALIAS","UMB_MEMBER_STORE_ALIAS","UMB_MEMBER_ITEM_STORE_CONTEXT","UMB_MEMBER_VALIDATION_REPOSITORY_ALIAS","UMB_MEMBER_SEARCH_PROVIDER_ALIAS","UMB_MEMBER_DETAIL_MODEL_VARIANT_SCAFFOLD","UMB_MEMBER_WORKSPACE_ALIAS","UMB_MEMBER_WORKSPACE_CONTEXT","UMB_MEMBER_ROOT_WORKSPACE_ALIAS"]
},
{
path: '@umbraco-cms/backoffice/menu',
Expand Down
2 changes: 1 addition & 1 deletion src/Umbraco.Web.UI.Client/web-test-runner.index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { handlers } from './src/mocks/browser-handlers.js';
import { onUnhandledRequest } from './src/mocks/index.js';

const { setupWorker, rest } = window.MockServiceWorker;
const { setupWorker } = window.MockServiceWorker;

const worker = setupWorker(...handlers);

Expand Down

0 comments on commit 89061f1

Please sign in to comment.