mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
"use strict";
|
|
|
|
const jQuery = require("jquery");
|
|
const createBrowser = require("jsdom-context-require");
|
|
const compiler = require("../../compiler");
|
|
const noop = function() {};
|
|
const globals = [
|
|
"console",
|
|
"__coverage__",
|
|
"Error",
|
|
"describe",
|
|
"before",
|
|
"after",
|
|
"beforeEach",
|
|
"afterEach",
|
|
"it"
|
|
];
|
|
|
|
const browserExtensions = {
|
|
".marko": function(module, filename) {
|
|
return module._compile(
|
|
compiler.compileFile(filename, {
|
|
writeToDisk: false,
|
|
output: "vdom",
|
|
browser: true,
|
|
meta: true
|
|
}),
|
|
filename
|
|
);
|
|
}
|
|
};
|
|
|
|
module.exports = function(dir, html, options) {
|
|
options = options || {};
|
|
return createBrowser({
|
|
dir: dir,
|
|
html: html,
|
|
extensions: browserExtensions,
|
|
// runScripts: 'dangerously', // JSDOM 10+
|
|
beforeParse(window, browser) {
|
|
jQuery(window);
|
|
browser.require("complain").log = noop;
|
|
globals.forEach(function(k) {
|
|
window[k] = global[k];
|
|
});
|
|
if (options.beforeParse) {
|
|
options.beforeParse(window, browser);
|
|
}
|
|
}
|
|
});
|
|
};
|