2025-08-17 14:55:55 +08:00
|
|
|
// Test for issue #15947 - ESM library with dynamic imports
|
|
|
|
it("should use new URL() for dynamic imports in ESM library output", () => {
|
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
|
|
|
|
const outputPath = path.join(__dirname, "lib.js");
|
|
|
|
const content = fs.readFileSync(outputPath, "utf-8");
|
|
|
|
|
2025-08-17 16:21:07 +08:00
|
|
|
expect(content).toMatch(/new\s+URL/);
|
|
|
|
expect(content).toMatch(/import\.meta\.url/);
|
|
|
|
expect(content).not.toMatch(/import\s*\(\s*["']\.\/["']\s*\+/);
|
2025-08-17 14:55:55 +08:00
|
|
|
|
|
|
|
// Verify that the chunk file was created
|
|
|
|
const chunkFiles = fs
|
|
|
|
.readdirSync(__dirname)
|
|
|
|
.filter(f => f.startsWith("chunk.") && f.endsWith(".js"));
|
|
|
|
expect(chunkFiles.length).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
// Verify the ESM export is present
|
|
|
|
expect(content).toMatch(/export\s*\{/);
|
|
|
|
});
|