mradionov / karma-jasmine-diff-reporter Goto Github PK
View Code? Open in Web Editor NEWDiff and pretty print for failed tests
Home Page: https://www.npmjs.com/package/karma-jasmine-diff-reporter
License: MIT License
Diff and pretty print for failed tests
Home Page: https://www.npmjs.com/package/karma-jasmine-diff-reporter
License: MIT License
Based on PR #11
Add new option to enhance the output of error messages by adding extra indents and new lines between matcher text and diffed objects.
Matcher initial text ...
object1
Matcher middle text ...
object2
Matcher end text ...
Examples:
Expected
foo
to equal
bar
Expected
Object({
foo: 'bar'
})
to equal
Object({
baz: 'qux'
})
Expected function to throw
TypeError: boo
but it threw
ReferenceError: a is not defined
Objects should be equally indented comparing to matcher's initial, middle and end text. Because of it pretty print feature should also be tweaked a bit. It might also require some work with matcher default text, because for example toHaveBeenCalledWith wraps objects in array and it looks different from other matchers.
I'm getting additional characters (a "ÔÇî" sequence) appearing in the output when displaying string data, both in our test suite and the demo one provided.
Environment:
Windows 7 (64 bit)
Node.js 4.2.3 LTS
Karma 0.13.19
Karma-Jasmine: 0.3.7
The attached output is from powershell hosted in the "cmder" utility, although similar results occur in cmd.exe (with "?" appearing instead).
When running in a normal Powershell window or Git Bash the additional characters do not display or appear in the output.
I'll do some more digging to see if I can isolate the issue.
Hi,
I'm trying to display results like in the documentation:
(http://i.imgur.com/6TTlSmB.jpg)
Changing colors and verbose works well, but pretty has no effect. All the following settings display objects on only one line:
pretty: true
pretty: '\t'
pretty: 2
multiline: {
before: 3,
after: '\n',
indent: ' '
}
pretty: true,
multiline: true
Thanks for help.
I would like to be able to use this and suppress output from all console.log statements. I use a few other reporters in conjunction with this one and I am seeing all my log outputs twice in the console
When have have two Function
into an object that we compare, the Function
's are not highlighted.
We were talking a bit about it in #17.
I suggest adding a new color (by default it would be orange?) that when we compare Function
to Function
both would be in that color to lift up a flag that it could be different.
Also, regarding this, I would consider jasmine.any(Function)
and Function
the same and therefore not show any colors at all.
At the moment defaults set bgColor. I'd prefer to ser text color instead. Something like:
Unfortunately chald does not have "bgDefault" or something, so if I set bgBlack it actually becomes black, which is not working very well on default grey bg:
I suggest to allow to pass undefined
color that will allow to "not set" bg colors.
So instead of
var styles = [
color.actualBg || 'bgGreen',
color.actualFg || 'white'
];
I see it like:
var styles = [
color.hasOwnProperty('actualBg') ? color.actualBg : 'bgGreen',
color.hasOwnProperty('actualFg') ? color.actualBg : 'white'
];
I have this warning message tell me i can't use the pretty print option which i will like to use
here is all the karma plugin i have:
"jasmine-core": "2.5.2",
"karma": "1.1.2",
"karma-angular-filesort": "0.1.0",
"karma-chrome-launcher": "1.0.1",
"karma-coverage": "1.1.1",
"karma-jasmine": "1.0.2",
"karma-jasmine-diff-reporter": "0.6.2",
"karma-junit-reporter": "1.1.0",
"karma-phantomjs-launcher": "1.0.1",
"karma-threshold-reporter": "0.1.15",
Do you think it would be possible to add an option that remove the "Object()" strings in the diff view. The goal is to display real JSON in the diff so it can be easily copy-pasted.
Hi there,
Would it be possible that you add an option that we could set to true
to allow undefined
values in the JSON output.
By default, JSON.stringify
removes all undefined
value, so we would have to replace it with a undefined
string.
So let's say we have the following :
var obj1 = {Foo: 'Foo', Bar: undefined};
var obj2 = {Foo: 'Foo'};
console.log(JSON.stringify(obj1));
// '{"Foo": "Foo"}'
console.log(JSON.stringify(obj2));
// '{"Foo": "Foo"}'
So it would do this while testing, but we cannot see why it is not passing :
Expected '{"Foo": "Foo"}' to equal '{"Foo": "Foo"}'
Perhaps it's only due to my terminal settings, but I couldn't use the reporter with its out-of-the-box color configuration.
I changed my color configuration to the following:
color: {
actualFg: 'red',
expectedFg: 'green',
actualBg: 'inverse',
expectedBg: 'inverse',
actualWhitespaceBg: '',
expectedWhitespaceBg: '',
}
I believe the inverse
setting is a better choice by virtue of it using the terminal's default background color as its foreground color. The background color generally would have high contrast next to colors such as green and red, as text rendered in green and red would have to be visible against the background in the first place.
Following the example in the README.md
:
$ npm install karma-jasmine-diff-reporter --save-dev
[email protected] ~/github/my-project
└── [email protected]
and
reporters: ['jasmine-diff', 'progress', 'coverage'],
results in:
Running "karma:unit" (karma) task
14 09 2017 14:07:29.870:ERROR [reporter]: Can not load reporter "jasmine-diff", it is not registered!
Perhaps you are missing some plugin?
14 09 2017 14:07:30.133:ERROR [karma]: Found 1 load error
For instance, if you do:
expect('test test').toEqual('test test')
In this example, it's quite obvious but in a big diff it can get tricky...
I understand that this is not a bug but just that the extra space is actually colored but not visible.
A solution might be to replace spaces that are different by the ␣ character or by another one.
The following deprecation notice is shown when I use this reporter:
DEPRECATION: jasmine.matchersUtil is deprecated and will be removed in a future release. Use the instance passed to the matcher factory or the asymmetric equality tester's `asymmetricMatch` method instead. See <https://jasmine.github.io/tutorials/upgrading_to_Jasmine_4.0#static-utils> for details.
at <Jasmine>
at matchersUtilPatched (http://localhost:9876/base/node_modules/karma-jasmine-diff-reporter/src/karma-jasmine/util-patch.js?24ebf18c87e51712a9f46a9365bf0873ee5ebc85:11:17)
at http://localhost:9876/base/node_modules/karma-jasmine-diff-reporter/src/karma-jasmine/util-patch.js?24ebf18c87e51712a9f46a9365bf0873ee5ebc85:8:31
at http://localhost:9876/base/node_modules/karma-jasmine-diff-reporter/src/karma-jasmine/util-patch.js?24ebf18c87e51712a9f46a9365bf0873ee5ebc85:28:2
Note: This message will be shown only once. Set the verboseDeprecations config property to true to see every occurrence.'
Implement pretty print option, as it was suggested here: http://stackoverflow.com/a/32280598/1573638
jasmineDiff: {
pretty: true
pretty: false (default)
pretty: function (objString) {
return JSON.stringify(objString, null, 4);
}
}
toThrow
and toThrowError
pretty print is useless.Jasmine finally got it's own version of "pretty print" for objects, which is available from version 2.6.0, and you are probably using that same version. That would be the reason why you might not have an output, which was expected from my reporter. Now it will look like this:
Expected object to have properties
b: 43
Expected object not to have properties
a: 42
at Object.<anonymous> (spec/test.test.js:3:27)
Here is original issue in Jasmine rep: jasmine/jasmine#675 and respective PR jasmine/jasmine#1163.
I have to think about what to do next, because I did not expect it to happen this soon and I've just recently completed a major rewrite of the reporter. Probably I'll just keep it as is, so it will work only with Jasmine versions prior 2.6, because I have no idea how they are gonna continue improving their diff output and it might be difficult to adapt to from my side.
Thank you for your report, if you really want to use this reporter at full capacity, the only thing for now is to downgrade Jasmine to 2.5, but I am not insisting on it in any ways, because Jasmine might have things fixed and improved in latest versions.
Another option might be to introduce an option in my reporter to ignore new Jasmine 2.6 diff output and bring back old 2.5 output by monkey-patching Jasmine, what I already do anyways, but it will also allow reporter to continue working as before.
I guess every user who wants to use a reporter has to always enable legacy mode, otherwise reporter is useless for Jasmine 2.6 + users (see readme). I can just simply enable it by default, there is no reason to keep at as an option. It will require a major version bump.
I'm using the packages below and while pretty
works, the colors do not. I have tried pruning down my karma file to only include the bare essentials and to no avail the colors wouldn't show up.
"grunt-karma": "^2.0.0",
"jasmine-core": "^2.2.0",
"karma-jasmine-diff-reporter": "^0.6.2"
var web_dependencies = require('./web_dependencies');
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
browsers: ['Chrome'],
files: web_dependencies.concat([
...
]),
ngHtml2JsPreprocessor: {
stripPrefix: 'public',
moduleName: 'templates'
},
reporters: ['jasmine-diff'],
jasmineDiffReporter: {
pretty: true
},
colors: true
});
};
It's worth noting that my terminal window does show other colors:
When trying to run our tests with Jasmine 4.2, I get the following error:
TypeError: Cannot read properties of undefined (reading 'equals')
The error is coming from util-patch.js
:
function matchersUtilPatched(j$) {
var util = j$.matchersUtil;
var oldEquals = util.equals.bind(util); // <--- crashes here because util is undefined
...
According to Jasmine 4 upgrade notes jasmine.matchersUtil
is deprecated and apparently has been removed now.
Moved from comment: #27 (comment)
I'm getting duplicate output with these settings, is that expected? Is that what you mean by "bring back old output and reporter highlights as well"? If so, any chance this can be changed to show only the diff reported output?
Hello,
i am getting this very strange error:
TypeError: value.and.identity is not a function in node_modules/karma-jasmine-diff-reporter/src/karma-jasmine/pp-patch.js (line 82)
I am using these karma dependencies:
"karma": "2.0.0",
"karma-angular-filesort": "1.0.2",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.1",
"karma-firefox-launcher": "1.1.0",
"karma-jasmine": "1.1.1",
"karma-jasmine-diff-reporter": "1.1.1",
"karma-jasmine-matchers": "3.7.0",
"karma-junit-reporter": "1.2.0",
"karma-ng-html2js-preprocessor": "1.0.0",
"karma-ng-pug2js-preprocessor": "1.0.0-beta.0",
"karma-safari-launcher": "1.0.0",
"karma-spec-reporter": "0.0.31",
Could you please advice what is wrong?
Thank you!
Andrej
There is jasmine's toContain()
method which check whether string (or an array) is containing sub-string. Any chance to show diff highlighting for this?
I understand, that this will also show me highlighted extra characters of parent string, but this is very ok for me. Even in this case, it vill be much easier for me to recognize the issue.
Spaces in key names are not displayed in the diff report. This can result in a failing test with no diff highlighted by the reporter. Not sure if this is a bug or a configuration issue?
Recreate:
it('should have a space in the key', () => {
expect({ hithere: true }).toEqual({ 'hi there': true });
});
The test will correctly fail but the reporter will print the following result:
Expected
Object({ hithere: true })
to equal
Object({ hithere: true })
The reporter settings:
jasmineDiffReporter: {
pretty: true,
multiline: true,
matchers: {
toContain: {
pattern: /Expected ([\S\s]*) to contain ([\S\s]*)\./,
reverse: false
}
}
}
Running with dots reporter:
reporters: ['jasmine-diff', 'dots']
npm audit is reporting security vulnerabilities in some of karma-jasmine-diff-reporter direct or indirect dependencies, so you might consider addressing this.
Affected dependencies:
hoek
timespan
tunnel-agent
Show diffs like mocha does: https://mochajs.org/#diffs
jasmineDiff: {
merge: true
merge: false
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.