Skip to content

Commit

Permalink
reflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexej Yaroshevich committed Feb 13, 2015
1 parent 8ae4f68 commit 0916336
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 45 deletions.
4 changes: 0 additions & 4 deletions lib/assets/it.jst
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ it('should be equal `${ it }` by ${ engine.name }${ titleSuffix }', function (<%
var bemjson = references['${ it }']${ subreference }.bemjson,
expected = references['${ it }']${ subreference }.html;<%
if (lang) { %>
lazies['${ engine.name }${ lang }']();
<% }
if (!engine.async) { %>
// sync mode
var actual = engines['${ engine.name }']${ subreference }.apply(bemjson);
Expand Down
107 changes: 66 additions & 41 deletions lib/assets/tmpl-spec.jst
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
<%
function reRequire(where, what, lazy) {
var name = what.name,
target = what.target,
exportName = what.exportName;
lazy && print('lazies[\'' + lazy + '\'] = function () {\n');
print('dropRequireCache(require, require.resolve(\'' + target + '\'));\n');
print((lazy ? 'return ' : '') + where + '[\'' + name + '\'] = require(\'' + target + '\')' + exportName + ';\n');
lazy && print('};\n');
}
%>
var assert = require('assert'),
path = require('path'),
<% if (saveHtml) { %>
Expand All @@ -32,56 +21,92 @@ var assert = require('assert'),
dropRequireCache = require('enb/lib/fs/drop-require-cache'),
HtmlDiffer = require('${ paths['html-differ'] }').HtmlDiffer,
htmlDiffer = new HtmlDiffer('bem'),
referencesFilename = require.resolve('${ paths.references }'),
engines,
lazies = {},
references;
referencesFilename = require.resolve('${ paths.references }');

describe('${ describe }', function() {
var engines = {},
references;

beforeEach(function () {
// reload references
dropRequireCache(require, referencesFilename);
references = require(referencesFilename);
});

<% if (!(langs && langs.length)) { %>
//
// no langs mode
//
beforeEach(function () {
// reload engines artifacts
engines = {};
<% _.forEach(engines, function(engine) {
if (langs && langs.length) {
var engineObject = 'engines[\'' + engine.name + '\']';
print(engineObject + ' = {};\n');
_.forEach(engine.langs, function(lang) {
reRequire(engineObject, lang, engine.name + lang.name);
});
} else {
reRequire('engines', engine);
}
reRequire('engines', engine);
}); %>
});
<% _.forEach(its, function(it) { %>
describe('${ it }', function() {
<% _.forEach(its, function(it) { %>
describe('${ it }', function() {
<% _.forEach(engines, function(engine) {
if (langs && langs.length) {
_.forEach(langs, function(lang) {
<% _.forEach(engines, function(engine) {
print(template('it', {
it: it,
engine: engine,
lang: lang,
lang: null,
saveHtml: saveHtml
}));
}); %>
}); // describe ${ it }
<% }); // _.forEach its %>
<% } else { // langs.length > 0 %>
//
// langs mode
//
<% _.forEach(langs, function (lang) { %>
describe('with lang `${ lang }`', function() {
beforeEach(function () {
<% _.forEach(engines, function(engine) {
var engineObject = 'engines[\'' + engine.name + '\']';
print(engineObject + ' = {};\n');
reRequire(engineObject, engine.langs.filter(function (_lang) { return lang === _lang.name; })[0]);
}); %>
});
} else {
print(template('it', {
it: it,
engine: engine,
lang: null,
saveHtml: saveHtml
}));
}
}); %>
});<% }); %>
});
<% _.forEach(its, function(it) { %>
describe('${ it }', function() {
<% _.forEach(engines, function(engine) {
print(template('it', {
it: it,
engine: engine,
lang: lang,
saveHtml: saveHtml
}));
}); %>
});
<% }); %>
});
<% }); %>
<% }; // /if langs %>
}); // /describe ${ describe }
<%
function reRequire(where, what) {
var name = what.name,
target = what.target,
exportName = what.exportName;
print('dropRequireCache(require, require.resolve(\'' + target + '\'));\n');
print(where + '[\'' + name + '\'] = require(\'' + target + '\')' + exportName + ';\n');
}
%>
function assertHtml(actual, expected, done) {
if (htmlDiffer.isEqual(actual, expected)) {
assert.ok(actual);
Expand Down

0 comments on commit 0916336

Please sign in to comment.