mocha: πŸ› Bug: Comparing buffers hangs when computing the diff report

I am having the very same issue as #1433 mocha 2.2.1 and chai 2.1.1. When 2 buffers are not equal, the diff computation hangs and CPU gets crazy.

Any chance of a regression bug here?

Sample code to reproduce this:

var chai = require('chai');
var expect = chai.expect;

// chai.config.showDiff = false; // Without this line, the diff generation hangs

describe('Testing buffer equality', function () {
  it('should not take foreveeeeeer', function () {
    var file1 = Fs.readFileSync('/tmp/file1');
    var file2 = Fs.readFileSync('/tmp/file2');
    expect(file1).to.deep.equal(file2);
  });
});

At this point of writing, I am unclear if this issue comes from mocha or from chai, though…

About this issue

  • Original URL
  • State: open
  • Created 9 years ago
  • Reactions: 1
  • Comments: 16 (12 by maintainers)

Most upvoted comments

Is there a way the code above can be used without displaying the diff (nor hiding it by default for all tests)?

Yes, this is just a patch, but it should work.

try {
  expect(x).to.equal(y)
} catch(e) {
  e.showDiff = false
  throw e
}