enable meta by default on server

This commit is contained in:
Michael Rawlings 2017-02-09 14:34:55 -08:00
parent bfe419617a
commit 5a977077cb
76 changed files with 563 additions and 116 deletions

View File

@ -102,7 +102,7 @@ class CompileContext extends EventEmitter {
this.taglibLookup = taglibLookup.buildLookup(this.dirname);
this.data = {};
this._dataStacks = {};
this.meta = null;
this.meta = {};
this.options = options || {};
@ -125,7 +125,7 @@ class CompileContext extends EventEmitter {
this._preserveWhitespace = null;
this._preserveComments = null;
this.inline = this.options.inline === true;
this.useMeta = this.options.meta;
this.useMeta = this.options.meta !== false;
this._moduleRuntimeTarget = this.outputType === 'vdom' ? 'marko/vdom' : 'marko/html';
this.unrecognizedTags = [];
this._parsingFinished = false;
@ -594,10 +594,6 @@ class CompileContext extends EventEmitter {
pushMeta(key, value, unique) {
var property;
if(!this.meta) {
this.meta = {};
}
property = this.meta[key];
if(!property) {

View File

@ -108,7 +108,7 @@ function compileForBrowser(src, filename, options, callback) {
options = null;
}
options = extend({output: 'vdom', browser: true, sourceOnly: false}, options);
options = extend({output: 'vdom', meta: false, browser: true, sourceOnly: false}, options);
return compile(src, filename, options, callback);
}
@ -142,7 +142,7 @@ function compileFileForBrowser(filename, options, callback) {
options = null;
}
options = extend({output: 'vdom', browser: true, sourceOnly: false}, options);
options = extend({output: 'vdom', meta: false, browser: true, sourceOnly: false}, options);
return compileFile(filename, options, callback);
}

View File

@ -2,6 +2,7 @@
var fs = require('fs');
var enabledTest = process.env.TEST;
var updateExpectations = process.env.hasOwnProperty('UPDATE_EXPECTATIONS');
var path = require('path');
var assert = require('assert');
@ -36,7 +37,16 @@ function compareHelper(dir, actual, prefix, suffix) {
actual = isObject ? JSON.parse(actualString) : actualString.replace(/\r?\n$/, '');
var expected = isObject ? JSON.parse(expectedString) : expectedString.replace(/\r?\n$/, '');
assert.deepEqual(actual, expected);
try {
assert.deepEqual(actual, expected);
} catch(e) {
if (updateExpectations) {
fs.writeFileSync(expectedPath, actualString, { encoding: 'utf8' });
} else {
throw e;
}
}
}
function autoTest(name, dir, run, options, done) {

View File

@ -6,3 +6,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -6,3 +6,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -6,3 +6,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -10,3 +10,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -10,3 +10,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -8,3 +8,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -21,3 +21,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -17,3 +17,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-addNestedVariable/renderer"
]
};

View File

@ -23,3 +23,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -13,3 +13,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -10,3 +10,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -20,3 +20,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-hello/renderer"
]
};

View File

@ -15,3 +15,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-body-function/renderer"
]
};

View File

@ -26,3 +26,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./custom-tag-data-tag"
]
};

View File

@ -17,3 +17,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-import-var/renderer"
]
};

View File

@ -14,3 +14,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./hello.marko"
]
};

View File

@ -12,3 +12,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-hello/renderer"
]
};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -22,3 +22,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -16,3 +16,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -9,3 +9,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -9,3 +9,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -8,3 +8,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -14,3 +14,10 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./target.marko",
"marko/taglibs/core/include-tag"
]
};

View File

@ -9,3 +9,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -30,3 +30,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -14,3 +14,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -18,3 +18,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./components/test-message/template.marko"
]
};

View File

@ -24,3 +24,9 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {
tags: [
"./tags/test-nested-tags-overlay/renderer"
]
};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -22,3 +22,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -40,3 +40,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -12,3 +12,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -7,3 +7,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -14,3 +14,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -11,3 +11,5 @@ function render(input, out) {
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -17,3 +19,16 @@ function render(input, out, widget, state) {
marko_template._ = marko_widgets.r(render, {
type: marko_widgetType
});
marko_template.meta = {
deps: [
{
type: "require",
path: "./"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -17,3 +19,16 @@ function render(input, out, widget, state) {
marko_template._ = marko_widgets.r(render, {
type: marko_widgetType
});
marko_template.meta = {
deps: [
{
type: "require",
path: "./widget"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -11,6 +11,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"><h1>Header</h1><div" +
@ -30,3 +32,19 @@ marko_template._ = marko_widgets.r(render, {
type: marko_widgetType,
body: 0
});
marko_template.meta = {
deps: [
{
type: "require",
path: "./"
},
{
type: "require",
path: "marko/widgets"
}
],
tags: [
"marko/widgets/taglib/include-tag"
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -20,3 +22,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -20,3 +22,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.elId("_r0")) +
">A</div><span" +
@ -26,3 +28,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -11,6 +11,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var foo = marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -21,3 +23,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -19,3 +21,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -1,6 +1,8 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<div></div>");
}

View File

@ -1,7 +1,11 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<style>.foo{}</style><div></div>");
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -14,6 +14,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
widget.t(marko_widgetTypes[data.isMobile ? "default" : "mobile"]);
out.w("<div" +
@ -22,3 +24,5 @@ function render(input, out, widget, state) {
}
marko_template._ = marko_widgets.r(render, {});
marko_template.meta = {};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -19,3 +21,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -8,6 +8,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -16,3 +18,16 @@ function render(input, out, widget, state) {
marko_template._ = marko_widgets.r(render, {
type: marko_widgetType
});
marko_template.meta = {
deps: [
{
type: "require",
path: "./widget"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -11,6 +11,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"><h1>Header</h1>");
@ -35,3 +37,19 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
],
tags: [
"marko/widgets/taglib/include-tag"
]
};

View File

@ -12,6 +12,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -22,3 +24,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -20,3 +22,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -20,3 +22,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -10,6 +10,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.elId("_r0")) +
">A</div><span" +
@ -26,3 +28,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -11,6 +11,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var foo = marko_component = {};
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -21,3 +23,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -17,3 +19,16 @@ function render(input, out, widget, state) {
marko_template._ = marko_widgets.r(render, {
type: marko_widgetType
}, marko_component);
marko_template.meta = {
deps: [
{
type: "require",
path: "./widget"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -9,6 +9,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");
@ -19,3 +21,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -12,6 +12,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
var __widgetId0 = widget.id;
out.w("<div" +
@ -32,3 +34,19 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
],
tags: [
"marko/widgets/taglib/include-tag"
]
};

View File

@ -1,7 +1,11 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<div></div>");
}
marko_template._ = render;
marko_template.meta = {};

View File

@ -8,6 +8,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
marko_attr = marko_helpers.a;
function render(input, out, widget, state) {
var data = input;
out.w("<div" +
marko_attr("id", widget.id) +
"></div>");

View File

@ -12,6 +12,8 @@ var marko_template = module.exports = require("marko/html").t(__filename),
var marko_component = {};
function render(input, out, widget, state) {
var data = input;
function macro_renderButton(color, out, renderBody) {
out.w("<button" +
marko_attr("data-_onclick", widget.d("handleColorClick", [
@ -42,3 +44,16 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
]
};

View File

@ -17,6 +17,8 @@ var marko_component = {
};
function render(input, out, widget, state) {
var data = input;
out.w("<div class=\"root\"" +
marko_attr("id", widget.id) +
">");
@ -38,3 +40,19 @@ marko_template._ = marko_widgets.r(render, {
}, marko_component);
marko_template.Widget = marko_widgets.w(marko_component, marko_template._);
marko_template.meta = {
deps: [
{
type: "require",
path: "./index.marko"
},
{
type: "require",
path: "marko/widgets"
}
],
tags: [
"./components/app-foo"
]
};

View File

@ -1,6 +1,8 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<div></div>");
}

View File

@ -1,6 +1,8 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<div></div>");
}

View File

@ -1,6 +1,8 @@
var marko_template = module.exports = require("marko/html").t(__filename);
function render(input, out) {
var data = input;
out.w("<div></div>");
}

View File

@ -1,12 +0,0 @@
var varDataStr = "\n var data = input;\n";
function stripVarData(src) {
var index = src.indexOf(varDataStr);
if (index !== -1) {
src = src.substring(0, index) + src.substring(index + varDataStr.length);
}
return src;
}
module.exports = stripVarData;

View File

@ -2,66 +2,57 @@ require('./util/patch-module');
var fs = require('fs');
var path = require('path');
var testFilter = require('./util/autotest/test-filter');
var autotest = require('./autotest');
var compiler = require('marko/compiler');
var expect = require('chai').expect;
require('marko/node-require').install();
var stripVarData = require('./util/stripVarData');
describe('marko-widgets (compilation, deprecated)', function() {
var testsPath = path.join(__dirname, './autotests/widgets-compilation-deprecated');
var tests = fs.readdirSync(testsPath);
var autoTestDir = path.join(__dirname, 'autotests/widgets-compilation-deprecated');
tests.forEach(function(testName) {
var itFunc = testFilter.isOnlyTest(testName) ? it.only : it;
autotest.scanDir(autoTestDir, function run(dir, helpers, done) {
var templatePath = path.join(dir, 'index.marko');
var mainPath = path.join(dir, 'test.js');
var main;
itFunc('[' + testName + '] ', function(done) {
var testPath = path.join(testsPath, testName);
var templatePath = path.join(testPath, 'index.marko');
if (!fs.existsSync(templatePath)) {
templatePath = path.join(dir, 'template.marko');
if (!fs.existsSync(templatePath)) {
templatePath = path.join(testPath, 'template.marko');
if (!fs.existsSync(templatePath)) {
return done(new Error('Template not found for test'));
}
return done(new Error('Template not found for test'));
}
var mainPath = path.join(testPath, 'test.js');
var main;
}
if (fs.existsSync(mainPath)) {
main = require(mainPath);
if (fs.existsSync(mainPath)) {
main = require(mainPath);
}
var compilerOptions = { writeVersionComment: false };
if (main && main.checkError) {
var e;
try {
compiler.compileFile(templatePath, compilerOptions);
} catch(_e) {
e = _e;
}
var compilerOptions = { writeVersionComment: false };
if (main && main.checkError) {
var e;
try {
compiler.compileFile(templatePath, compilerOptions);
} catch(_e) {
e = _e;
}
if (!e) {
throw new Error('Error expected');
}
main.checkError(e);
done();
} else {
var actualSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
actualSrc = stripVarData(actualSrc);
var actualPath = path.join(testPath, './actual.js');
var expectedPath = path.join(testPath, './expected.js');
fs.writeFileSync(actualPath, actualSrc);
var expectedSrc = fs.readFileSync(expectedPath, 'utf-8');
expect(actualSrc).to.equal(expectedSrc);
done();
if (!e) {
throw new Error('Error expected');
}
});
main.checkError(e);
done();
} else if(main && main.checkTemplate) {
var template = require('marko').load(templatePath, Object.assign(compilerOptions, main.compilerOptions));
main.checkTemplate(template);
done();
} else {
var compiledSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
helpers.compare(compiledSrc, '.js');
done();
}
});
});

View File

@ -2,67 +2,57 @@ require('./util/patch-module');
var fs = require('fs');
var path = require('path');
var testFilter = require('./util/autotest/test-filter');
var autotest = require('./autotest');
var compiler = require('marko/compiler');
var expect = require('chai').expect;
require('marko/node-require').install();
var stripVarData = require('./util/stripVarData');
describe('marko-widgets (compilation)', function() {
var testsPath = path.join(__dirname, './autotests/widgets-compilation');
var tests = fs.readdirSync(testsPath);
var autoTestDir = path.join(__dirname, 'autotests/widgets-compilation');
tests.forEach(function(testName) {
var itFunc = testFilter.isOnlyTest(testName) ? it.only : it;
autotest.scanDir(autoTestDir, function run(dir, helpers, done) {
var templatePath = path.join(dir, 'index.marko');
var mainPath = path.join(dir, 'test.js');
var main;
itFunc('[' + testName + '] ', function(done) {
var testPath = path.join(testsPath, testName);
var templatePath = path.join(testPath, 'index.marko');
if (!fs.existsSync(templatePath)) {
templatePath = path.join(dir, 'template.marko');
if (!fs.existsSync(templatePath)) {
templatePath = path.join(testPath, 'template.marko');
if (!fs.existsSync(templatePath)) {
return done(new Error('Template not found for test'));
}
return done(new Error('Template not found for test'));
}
var mainPath = path.join(testPath, 'test.js');
var main;
}
if (fs.existsSync(mainPath)) {
main = require(mainPath);
if (fs.existsSync(mainPath)) {
main = require(mainPath);
}
var compilerOptions = { writeVersionComment: false };
if (main && main.checkError) {
var e;
try {
compiler.compileFile(templatePath, compilerOptions);
} catch(_e) {
e = _e;
}
var compilerOptions = { writeVersionComment: false };
if (main && main.checkError) {
var e;
try {
compiler.compileFile(templatePath, compilerOptions);
} catch(_e) {
e = _e;
}
if (!e) {
throw new Error('Error expected');
}
main.checkError(e);
done();
} else {
var actualSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
actualSrc = stripVarData(actualSrc);
var actualPath = path.join(testPath, './actual.js');
var expectedPath = path.join(testPath, './expected.js');
fs.writeFileSync(actualPath, actualSrc);
var expectedSrc = fs.readFileSync(expectedPath, 'utf-8');
expect(actualSrc).to.equal(expectedSrc);
done();
if (!e) {
throw new Error('Error expected');
}
});
main.checkError(e);
done();
} else if(main && main.checkTemplate) {
var template = require('marko').load(templatePath, Object.assign(compilerOptions, main.compilerOptions));
main.checkTemplate(template);
done();
} else {
var compiledSrc = compiler.compileFile(templatePath, Object.assign(compilerOptions, main && main.compilerOptions));
helpers.compare(compiledSrc, '.js');
done();
}
});
});