diff --git a/package.json b/package.json index 50e84d7b2..bbbead67c 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build": "node scripts/updateVersion.cjs && node scripts/generateEmbedCss.cjs && npx rollup --config", "build_iife": "node scripts/updateVersion.cjs && node scripts/generateEmbedCss.cjs && npx rollup --config rollup.config.iife.js", "updateCSS": "node scripts/generateEmbedCss.cjs", - "test": "mocha -ui tdd" + "test": "node test/utils/forceESM.cjs && mocha -ui tdd" }, "author": { "name": "Jim Robinson" diff --git a/test/utils/forceESM.cjs b/test/utils/forceESM.cjs new file mode 100644 index 000000000..5fff3d99c --- /dev/null +++ b/test/utils/forceESM.cjs @@ -0,0 +1,23 @@ +/* +* Workaround for nodes archaic insistence that es modules have ".mjs" extensions or have "type=module" in package.json. +* This script will insert "type": "module" into the package.json of listed modules* +*/ + +const fs = require('fs') + +const packages = ['html2canvas'] + +for (let p of packages) { + forceESM(p) +} +function forceESM(packageName) { + + const packageJSON = require(`../../node_modules/${packageName}/package.json`) + packageJSON['type'] = 'module' + + const outputFile = require.resolve(`../../node_modules/${packageName}/package.json`) + fs.writeFileSync(outputFile, JSON.stringify(packageJSON, null, 2)) + + +} + diff --git a/test/utils/mockObjects.js b/test/utils/mockObjects.js index bb2fdd8da..35e18f66d 100644 --- a/test/utils/mockObjects.js +++ b/test/utils/mockObjects.js @@ -17,6 +17,9 @@ global.document.implementation = new DOMImplementation() // For jQUery global.window = { document: global.document, setTimeout: function () { + }, + location : { + href: "" } }