Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added htmlDiffer option #72

Merged
merged 1 commit into from
Feb 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/assets/tmpl-spec.jst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var assert = require('assert'),
<% } %>
dropRequireCache = require('enb/lib/fs/drop-require-cache'),
HtmlDiffer = require('${ paths['html-differ'] }').HtmlDiffer,
htmlDiffer = new HtmlDiffer('bem'),
htmlDiffer = new HtmlDiffer(${ JSON.stringify(diffOpts) }),
referencesFilename = require.resolve('${ paths.references }');

describe('${ describe }', function() {
Expand Down
1 change: 1 addition & 0 deletions lib/node-configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ exports.configure = function (config, options) {
[spec, {
engines: engines,
langs: langs,
diffOpts: options.diffOpts,
engineTargets: engineTargets,
saveHtml: options.saveHtml,
coverageEngines: coverageEngines,
Expand Down
11 changes: 8 additions & 3 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ module.exports = function (helper) {
_init: function (options) {
var root = helper.getRootPath(),
engines = options.engines,
coverage = options.coverage || {};
coverage = options.coverage || {},
diffOpts = options.htmlDiffer || {};

diffOpts.preset || (diffOpts.preset = 'bem');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут же мы вроде как уже обработали все.


if (coverage === true) {
coverage = {
Expand Down Expand Up @@ -85,7 +88,8 @@ module.exports = function (helper) {
process.env.BEM_TMPL_SPECS_SAVE_HTML) || false,
grep: (typeof process.env.BEM_TMPL_SPECS_GREP === 'undefined' ?
options.grep :
process.env.BEM_TMPL_SPECS_GREP) || false
process.env.BEM_TMPL_SPECS_GREP) || false,
diffOpts: diffOpts
};
},

Expand Down Expand Up @@ -157,7 +161,8 @@ module.exports = function (helper) {
engines: options.engines,
saveHtml: options.saveHtml,
coverage: options.coverage,
sublevels: options.sublevels
sublevels: options.sublevels,
diffOpts: options.diffOpts
});
});
},
Expand Down
11 changes: 9 additions & 2 deletions lib/reporters/spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
var util = require('util'),
HtmlDiffer = require('html-differ').HtmlDiffer,
htmlDiffer = new HtmlDiffer('bem'),
diffLogger = require('html-differ/lib/logger'),
ms = require('mocha/lib/ms'),
SpecReporter = require('mocha/lib/reporters/spec'),
color = require('mocha/lib/reporters/base').color;

exports = module.exports = Reporter;

function Reporter(runner) {
function Reporter(runner, diffOpts) {
diffOpts || (diffOpts = {});

diffOpts.preset || (diffOpts.preset = 'bem');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А зачем нам еще одна проверка, если мы уже получили опции и установили их.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, наверное, не стоит злоупотреблять ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Репортер можно захотеть использовать как-то отдельно/сбоку. Поэтому он не должен расчитывать на то, что опции уже инициализированны.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну тут разработчику виднее ;)


this._htmlDiffer = new HtmlDiffer(diffOpts);

SpecReporter.call(this, runner);
}

Expand Down Expand Up @@ -44,6 +49,8 @@ Reporter.prototype.epilogue = function () {
};

Reporter.prototype.list = function (failures) {
var htmlDiffer = this._htmlDiffer;

console.error();
failures.forEach(function (test, i) {
var fmt = color('error title', ' %s) %s:\n') + color('error message', ' %s\n'),
Expand Down
12 changes: 7 additions & 5 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.run = function (files, opts) {
var defer = vow.defer(),
mocha = new Mocha({
ui: 'bdd',
reporter: runReporters,
reporter: runReporters(opts.diffOpts),
grep: parseRe(opts.grep)
});

Expand All @@ -35,10 +35,12 @@ exports.run = function (files, opts) {
};

// Helper allow you to run the multiple reporters
function runReporters(runner) {
getReporters().forEach(function (Reporter) {
Reporter && new Reporter(runner);
});
function runReporters(diffOpts) {
return function (runner) {
getReporters().forEach(function (Reporter) {
Reporter && new Reporter(runner, diffOpts);
});
};
}

function getReporters() {
Expand Down
3 changes: 3 additions & 0 deletions lib/techs/tmpl-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = require('enb/lib/build-flow').create()
.defineRequiredOption('engines')
.defineOption('langs', [])
.defineOption('saveHtml', false)
.defineOption('diffOpts')
.defineOption('coverageEngines', [])
.defineOption('coverageBundle', false)
.useSourceFilename('references', '?.references.js')
Expand All @@ -37,6 +38,7 @@ module.exports = require('enb/lib/build-flow').create()
references = require(referencesFilename),
engines = this._engines,
langs = this._langs,
diffOpts = this._diffOpts,
oneLang = langs === true,
manyLangs = Array.isArray(langs) && langs.length > 0,
saveHtml = this._saveHtml,
Expand Down Expand Up @@ -75,6 +77,7 @@ module.exports = require('enb/lib/build-flow').create()
data = {
describe: path.basename(nodePath) + ' (' + path.dirname(nodePath) + ')',
its: its,
diffOpts: diffOpts,
engines: engines.map(function (engine) {
var target = contains(coverageEngines, engine.name) ?
instrumentedTarget(engine.target) : engine.target,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"enb-bem-pseudo-levels": "0.2.6",
"enb-bem-techs": "1.0.3",
"enb-source-map": "1.5.0",
"html-differ": "1.1.0",
"html-differ": "1.3.0",
"inherit": "2.2.2",
"istanbul": "0.3.6",
"jade": "1.9.2",
Expand Down