Skip to content

Instantly share code, notes, and snippets.

@Jpunt
Created March 1, 2016 20:27
Show Gist options
  • Save Jpunt/09dfa4d37f8d201d12d9 to your computer and use it in GitHub Desktop.
Save Jpunt/09dfa4d37f8d201d12d9 to your computer and use it in GitHub Desktop.
const jsdom = require("jsdom");
jsdom.env({
html: `
<!DOCTYPE html>
<body>
<script>
var script = document.createElement("script");
script.setAttribute('type', 'application/javascript');
script.textContent = "ran = true;";
document.body.appendChild(script);
console.log('ran:', ran);
</script>
</body>
`,
features: {
FetchExternalResources: ["script"],
ProcessExternalResources: ["script"]
},
virtualConsole: jsdom.createVirtualConsole().sendTo(console),
done: (err, window) => {
if (err) {
throw err;
}
console.log(window.ran);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment