1 import fs from "node:fs/promises";
2 import jsdom, { JSDOM } from "jsdom";
3 import path from "node:path";
4 import { fileURLToPath } from "node:url";
5 import { runRollupEsmAndCommonJs, runRollupPureEsm } from "./lib/run-rollup.js";
6 import { runWebpack } from "./lib/run-webpack.js";
7 import { cleanTmpBundlersDir } from "./lib/utils.js";
9 const dirname = path.dirname( fileURLToPath( import.meta.url ) );
11 async function runJSDOMTest( { title, folder } ) {
12 console.log( "Running bundlers tests:", title );
14 const template = await fs.readFile( `${ dirname }/test.html`, "utf-8" );
15 const scriptSource = await fs.readFile(
16 `${ dirname }/tmp/${ folder }/main.js`, "utf-8" );
19 .replace( /@TITLE\b/, () => title )
20 .replace( /@SCRIPT\b/, () => scriptSource );
22 const virtualConsole = new jsdom.VirtualConsole();
23 virtualConsole.sendTo( console );
24 virtualConsole.on( "assert", ( success, message ) => {
32 runScripts: "dangerously",
36 if ( process.exitCode === 0 || process.exitCode == null ) {
37 console.log( "Bundlers tests passed for:", title );
39 console.error( "Bundlers tests failed for:", title );
43 async function buildAndTest() {
44 await cleanTmpBundlersDir();
48 runRollupEsmAndCommonJs(),
54 title: "Rollup with pure ESM setup",
55 folder: "rollup-pure-esm"
59 title: "Rollup with ESM + CommonJS",
60 folder: "rollup-commonjs"
69 // The directory won't be cleaned in case of failures; this may aid debugging.
70 await cleanTmpBundlersDir();