Files
2026-04-11 09:21:22 +02:00

58 lines
1.8 KiB
JavaScript

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
var mockPresentationPaths = {
"rethinking-econ-ep1": resolve(process.cwd(), "public/lectures/rethinking-econ-ep1.json")
};
function presentationApiPlugin() {
var handleRequest = function (req, res, next) {
if (req.method !== "GET" || !req.url) {
next();
return;
}
var match = req.url.match(/^\/api\/presentations\/([^/?#]+)/);
if (!match) {
next();
return;
}
var presentationId = decodeURIComponent(match[1]);
var mockPath = mockPresentationPaths[presentationId];
res.setHeader("Content-Type", "application/json");
res.setHeader("Cache-Control", "no-store");
if (!mockPath) {
res.statusCode = 404;
res.end(JSON.stringify({
error: "Presentation not found",
presentationId: presentationId
}));
return;
}
res.statusCode = 200;
res.end(readFileSync(mockPath, "utf8"));
};
return {
name: "mock-presentation-api",
configureServer: function (server) {
server.middlewares.use(handleRequest);
},
configurePreviewServer: function (server) {
server.middlewares.use(handleRequest);
}
};
}
export default defineConfig({
resolve: {
alias: {
"@gnommo/slide-contracts": resolve(process.cwd(), "packages/slide-contracts/src/index.ts")
}
},
plugins: [react(), presentationApiPlugin()],
test: {
environment: "jsdom",
setupFiles: "./src/test/setup.ts",
globals: true,
css: true
}
});