marko/packages/marko/test/__util__/create-marko-jsdom-module.js
Michael Rawlings ea6736d085
feat: update apis/tests for new compiler
BREAKING CHANGE: api for compile-time tags has changed.
This affects tranformer/node-factory/code-generator tags.

Co-authored-by: Michael Rawlings <mirawlings@ebay.com>
Co-authored-by: Dylan Piercey <dpiercey@ebay.com>
Co-authored-by: Andrew Gliga <agliga@ebay.com>
2020-02-24 19:20:23 -08:00

55 lines
1.1 KiB
JavaScript

"use strict";
const createBrowser = require("jsdom-context-require");
const compiler = require("../../compiler");
const globals = [
"console",
"__coverage__",
"Error",
"describe",
"before",
"after",
"beforeEach",
"afterEach",
"it"
];
const browserExtensions = {
".marko": compileMarkoModule,
".html": compileMarkoModule
};
module.exports = function(dir, html, options) {
options = options || {};
return createBrowser({
dir: dir,
html: html,
extensions: browserExtensions,
// runScripts: 'dangerously', // JSDOM 10+
beforeParse(window, browser) {
window.global = window;
window.alert = () => {};
browser.require("complain").log = (...args) =>
require("complain").log(...args);
globals.forEach(function(k) {
window[k] = global[k];
});
if (options.beforeParse) {
options.beforeParse(window, browser);
}
}
});
};
function compileMarkoModule(module, filename) {
return module._compile(
compiler.compileFile(filename, {
writeToDisk: false,
output: "vdom",
browser: true,
meta: true
}),
filename
);
}