Skip to content

Commit

Permalink
isAsync and some refactoring
Browse files Browse the repository at this point in the history
- restored htmlBeautifier func-ty
- reworked langs it render
- added isAsync flag to force calling .apply on engine
  • Loading branch information
Alexej Yaroshevich committed Feb 11, 2015
1 parent d23bdb4 commit 3aa7b6d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
13 changes: 0 additions & 13 deletions lib/assets/it-i18n.jst

This file was deleted.

52 changes: 43 additions & 9 deletions lib/assets/it.jst
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
it('should be equal `${ it }` by ${ engine.name }', function (<% if (saveHtml) { %>done<% } %>) {
var bemjson = references['${ it }'].bemjson,
expected = references['${ it }'].html,
actual = engines['${ engine.name }'].apply(bemjson);
<%
// prepares
var titleSuffix = lang ? ' in `' + lang + '` lang' : '';
var subreference = lang ? '[' + lang + ']' : '';
var prettifyEngineName = function (ngn) {
return lang ? String(ngn).toLowerCase().replace(' ', '-') + '.' + lang : ngn;
};
if (saveHtml) { %>
function saveHtmlFile(filename, actual, done) {
fs.writeFile(path.join(__dirname, filename), beautifyHtml(actual), done);
}<%
}%>
it('should be equal `${ it }` by ${ engine.name }${ titleSuffix }', function (<% if (saveHtml || engine.isAsync) { %>done<% } %>) {
var bemjson = references['${ it }']${ subreference }.bemjson,
expected = references['${ it }']${ subreference }.html;<%
if (saveHtml) {%>
var filename = [it, prettifyEngineName(engine.name), 'html'].join('.');
}<%
if (!engine.isAsync) {%>
// sync mode
var actual = engines['${ engine.name }']${ subreference }.apply(bemjson);
assertHtml(actual, expected);<%
if (saveHtml) {
var filename = [it, engine.name, 'html'].join('.'),
sep = '\n ';
print(sep + 'fs.writeFile(path.join(__dirname, \'' + filename + '\'), beautifyHtml(actual), done);');
} %>
if (saveHtml) {%>
saveHtmlFile('${ filename }', actual, done);
<%}
} else {%>
// async mode
engines['${ engine.name }']${ subreference }.apply(bemjson, function (errs, actual) {
if (errs !== null) {
done(errs);
return;
}
assertHtml(actual, expected, function (err) {
err && done(err);%>
if (saveHtml) {%>
saveHtmlFile('${ filename }', actual, done);
%>}
});
});<%
}%>
});
7 changes: 5 additions & 2 deletions lib/assets/tmpl-spec.jst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ var assert = require('assert'),
path = require('path'),
<% if (saveHtml) { %>
fs = require('fs'),
beautifyHtml = require('${ paths['js-beautify'] }').html,
beautifyHtml = function (html) {
return require('${ paths['js-beautify'] }').html(html, beautifyHtmlConfig);
},
<% } %>
beautifyHtmlConfig = { unformatted: [
'a', 'span', 'img', 'address', 'script',
Expand Down Expand Up @@ -72,9 +74,10 @@ describe('${ it }', function() {
});<% }); %>
});

function assertHtml(actual, expected) {
function assertHtml(actual, expected, done) {
if (htmlDiffer.isEqual(actual, expected)) {
assert.ok(actual);
done && done(null);
} else {
assert.fail(actual, expected, null, '\n');
}
Expand Down
2 changes: 2 additions & 0 deletions lib/techs/tmpl-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ module.exports = require('enb/lib/build-flow').create()
var langTarget = target.replace('.js', '.' + lang + '.js');
return {
name: lang,
isAsync: engine.options.isAsync,
target: langTarget,
exportName: exportName
};
Expand All @@ -107,6 +108,7 @@ module.exports = require('enb/lib/build-flow').create()

return {
name: engine.name,
isAsync: engine.options.isAsync,
target: target,
exportName: exportName
};
Expand Down

0 comments on commit 3aa7b6d

Please sign in to comment.