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

Fix bugs with error diff calculation #276

Merged
merged 1 commit into from Mar 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/reporter/base.js
Expand Up @@ -126,8 +126,15 @@ const GlaceReporter = function (runner) {
runner.on("fail", (mochaTest, err) => {

if (err.actual && err.expected) {
err.diff = colors.strip(
MochaReporter.generateDiff(err.actual, err.expected));
try {
err.diff = colors.strip(
MochaReporter.generateDiff(err.actual, err.expected));
if (err.diff.trim() === "+ expected - actual") {
delete err.diff;
}
} catch (e) {
/* do nothing */
}
}
utils.accountError(mochaTest.title, err);

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/testGlobals.js
Expand Up @@ -8,6 +8,25 @@ suite("globals", () => {
sandbox.restore();
});

test("chai", () => {
let chai = require("chai"),
threshold = chai.config.truncateThreshold;

beforeChunk(() => {
CONF.report.deepErrors = true;
});

afterChunk(() => {
CONF.report.deepErrors = false;
chai.config.truncateThreshold = threshold;
});

chunk("shows full objects in errors", () => {
rewire("../../lib/globals");
expect(chai.config.truncateThreshold).to.be.equal(0);
});
});

test("chai as promised", () => {

chunk("checks fulfilled promise", async () => {
Expand Down
16 changes: 14 additions & 2 deletions tests/unit/testReporterBase.js
Expand Up @@ -9,11 +9,11 @@ const runner = {
};

suite("reporter/base", () => {
let glaceReporter;
let glaceReporter, MochaReporter;
const sandbox = sinon.createSandbox();

beforeChunk(() => {
const MochaReporter = function () {};
MochaReporter = function () {};
MochaReporter.generateDiff = () => "";
GlaceReporter.__set__("MochaReporter", MochaReporter);
glaceReporter = new GlaceReporter(runner);
Expand Down Expand Up @@ -393,6 +393,18 @@ suite("reporter/base", () => {
reporters.push({});
onFail({ title: "my chunk" }, "error");
});

chunk("does not add diff if it is empty", () => {
MochaReporter.generateDiff = () => "+ expected - actual";
reporters.push({ fail: sinon.spy() });
onFail({ title: "my chunk" },
{ actual: "{\n\"a\": 1}", expected: "{\n\"b\": 1}" });

expect(accountError).to.be.calledOnce;
expect(accountError.args[0][0]).to.be.equal("my chunk");
expect(accountError.args[0][1]).to.be
.eql({ actual: "{\n\"a\": 1}", expected: "{\n\"b\": 1}" });
});
});

test("on pending", () => {
Expand Down