From dba5e598de59ed3d9b595c89fa45afc407cef635 Mon Sep 17 00:00:00 2001 From: tomas Date: Tue, 3 Mar 2026 13:45:39 +0000 Subject: [PATCH] fix: Fix custom ESM loader for tests within vscode extension --- build/mocha-esm-loader.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/mocha-esm-loader.js b/build/mocha-esm-loader.js index 153fdc306a..7a45afa78b 100644 --- a/build/mocha-esm-loader.js +++ b/build/mocha-esm-loader.js @@ -10,6 +10,7 @@ let unittestsModule; // Get absolute paths for imports in the loader const __dirname = path.dirname(fileURLToPath(import.meta.url)); const projectRoot = path.join(__dirname, '..'); +const projectOutUrl = pathToFileURL(path.join(projectRoot, 'out')).href + '/'; const vscodeMockPath = pathToFileURL(path.join(projectRoot, 'out/test/vscode-mock.js')).href; const telemetryMockPath = pathToFileURL(path.join(projectRoot, 'out/test/mocks/vsc/telemetryReporter.js')).href; @@ -421,9 +422,9 @@ export async function load(url, context, nextLoad) { // If URL parsing fails, fall through to other handlers } - // For .js files in the out/ directory, inject CJS globals shims + // For .js files in the project's out/ directory, inject CJS globals shims // This is needed because source files use native __dirname, __filename, require which don't exist in ESM - if (url.startsWith('file://') && url.includes('/out/') && url.endsWith('.js')) { + if (url.startsWith(projectOutUrl) && url.endsWith('.js')) { const filePath = fileURLToPath(url); const fs = await import('node:fs/promises'); const source = await fs.readFile(filePath, 'utf8');