test: restore moved Vitest config paths

This commit is contained in:
Peter Steinberger
2026-04-10 15:31:48 +01:00
parent a48eb84181
commit 3c0e5f0ea5
11 changed files with 71 additions and 23 deletions

View File

@@ -1,3 +1,4 @@
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { loadBundledPluginPublicSurfaceModuleSync } from "../plugin-sdk/facade-loader.js";
@@ -74,16 +75,34 @@ export function resolveBundledPluginPublicModulePath(params: {
);
}
function resolveVitestSourceModulePath(targetPath: string): string {
if (!targetPath.endsWith(".js")) {
return targetPath;
}
const sourcePath = `${targetPath.slice(0, -".js".length)}.ts`;
return pathExists(sourcePath) ? sourcePath : targetPath;
}
function pathExists(filePath: string): boolean {
try {
return Boolean(filePath) && path.isAbsolute(filePath) && fs.statSync(filePath).isFile();
} catch {
return false;
}
}
export function resolveRelativeBundledPluginPublicModuleId(params: {
fromModuleUrl: string;
pluginId: string;
artifactBasename: string;
}): string {
const fromFilePath = fileURLToPath(params.fromModuleUrl);
const targetPath = resolveBundledPluginPublicModulePath({
pluginId: params.pluginId,
artifactBasename: params.artifactBasename,
});
const targetPath = resolveVitestSourceModulePath(
resolveBundledPluginPublicModulePath({
pluginId: params.pluginId,
artifactBasename: params.artifactBasename,
}),
);
const relativePath = path
.relative(path.dirname(fromFilePath), targetPath)
.replaceAll(path.sep, "/");