add separation of msw handlers into browser and e2e contexts, and replace the import.meta statements into the browser file since only the browser can handle esmodules
This commit is contained in:
28
src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts
Normal file
28
src/Umbraco.Web.UI.Client/src/mocks/browser-handlers.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { handlers as contentHandlers } from './domains/content.handlers';
|
||||
import { handlers as installHandlers } from './domains/install.handlers';
|
||||
import { handlers as manifestsHandlers } from './domains/manifests.handlers';
|
||||
import * as serverHandlers from './domains/server.handlers';
|
||||
import { handlers as upgradeHandlers } from './domains/upgrade.handlers';
|
||||
import { handlers as userHandlers } from './domains/user.handlers';
|
||||
|
||||
const handlers = [
|
||||
serverHandlers.serverVersionHandler,
|
||||
...contentHandlers,
|
||||
...installHandlers,
|
||||
...upgradeHandlers,
|
||||
...manifestsHandlers,
|
||||
...userHandlers,
|
||||
];
|
||||
|
||||
switch (import.meta.env.VITE_UMBRACO_INSTALL_STATUS) {
|
||||
case 'must-install':
|
||||
handlers.push(serverHandlers.serverMustInstallHandler);
|
||||
break;
|
||||
case 'must-upgrade':
|
||||
handlers.push(serverHandlers.serverMustUpgradeHandler);
|
||||
break;
|
||||
default:
|
||||
handlers.push(serverHandlers.serverRunningHandler);
|
||||
}
|
||||
|
||||
export { handlers };
|
||||
@@ -1,6 +1,6 @@
|
||||
import { MockedRequest, setupWorker } from 'msw';
|
||||
|
||||
import { handlers } from './handlers';
|
||||
import { handlers } from './browser-handlers';
|
||||
|
||||
const worker = setupWorker(...handlers);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ export const handlers = [
|
||||
displayName: 'SQLite',
|
||||
defaultDatabaseName: 'Umbraco',
|
||||
providerName: 'Microsoft.Data.SQLite',
|
||||
isConfigured: import.meta.env.VITE_UMBRACO_INSTALL_PRECONFIGURED === 'true',
|
||||
isConfigured: false,
|
||||
requiresServer: false,
|
||||
serverPlaceholder: null,
|
||||
requiresCredentials: false,
|
||||
|
||||
@@ -3,23 +3,42 @@ import { rest } from 'msw';
|
||||
import umbracoPath from '../../core/helpers/umbraco-path';
|
||||
import { StatusResponse, VersionResponse } from '../../core/models';
|
||||
|
||||
export const handlers = [
|
||||
rest.get(umbracoPath('/server/status'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<StatusResponse>({
|
||||
serverStatus: import.meta.env.VITE_UMBRACO_INSTALL_STATUS,
|
||||
})
|
||||
);
|
||||
}),
|
||||
rest.get(umbracoPath('/server/version'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<VersionResponse>({
|
||||
version: '13.0.0',
|
||||
})
|
||||
);
|
||||
}),
|
||||
];
|
||||
export const serverRunningHandler = rest.get(umbracoPath('/server/status'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<StatusResponse>({
|
||||
serverStatus: 'running',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
export const serverMustInstallHandler = rest.get(umbracoPath('/server/status'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<StatusResponse>({
|
||||
serverStatus: 'must-install',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
export const serverMustUpgradeHandler = rest.get(umbracoPath('/server/status'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<StatusResponse>({
|
||||
serverStatus: 'must-upgrade',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
export const serverVersionHandler = rest.get(umbracoPath('/server/version'), (_req, res, ctx) => {
|
||||
return res(
|
||||
// Respond with a 200 status code
|
||||
ctx.status(200),
|
||||
ctx.json<VersionResponse>({
|
||||
version: '13.0.0',
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { handlers as contentHandlers } from './domains/content.handlers';
|
||||
import { handlers as installHandlers } from './domains/install.handlers';
|
||||
import { handlers as manifestsHandlers } from './domains/manifests.handlers';
|
||||
import { handlers as serverHandlers } from './domains/server.handlers';
|
||||
import * as serverHandlers from './domains/server.handlers';
|
||||
import { handlers as upgradeHandlers } from './domains/upgrade.handlers';
|
||||
import { handlers as userHandlers } from './domains/user.handlers';
|
||||
|
||||
export const handlers = [
|
||||
...serverHandlers,
|
||||
serverHandlers.serverRunningHandler,
|
||||
serverHandlers.serverVersionHandler,
|
||||
...contentHandlers,
|
||||
...installHandlers,
|
||||
...upgradeHandlers,
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect, test as base } from '@playwright/test';
|
||||
import { createWorkerFixture } from 'playwright-msw';
|
||||
|
||||
import { handlers } from './src/mocks/handlers';
|
||||
import { handlers } from './src/mocks/e2e-handlers';
|
||||
|
||||
import type { MockServiceWorker } from 'playwright-msw';
|
||||
const test = base.extend<{
|
||||
|
||||
Reference in New Issue
Block a user