Skip to content

Commit

Permalink
fix unit test issue cause by node's module rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Aug 11, 2023
1 parent 9087a20 commit 3c1af70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions test/utils/forceESM.cjs
Original file line number Diff line number Diff line change
@@ -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))


}

3 changes: 3 additions & 0 deletions test/utils/mockObjects.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ global.document.implementation = new DOMImplementation() // For jQUery
global.window = {
document: global.document,
setTimeout: function () {
},
location : {
href: ""
}
}

Expand Down

0 comments on commit 3c1af70

Please sign in to comment.