Socket
Socket
Sign inDemoInstall

karma-jasmine-diff-reporter

Package Overview
Dependencies
142
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.3 to 1.0.0

.eslintignore

8

demo/custom-matcher.spec.js

@@ -11,3 +11,3 @@ describe('Option', function () {

compare: function (actual, expected) {
if (expected === undefined) {
if (typeof expected === 'undefined') {
expected = '';

@@ -40,4 +40,4 @@ }

it('should diff objects', function () {
var a = { foo: 'bar' },
b = { baz: 'qux' };
var a = { foo: 'bar' };
var b = { baz: 'qux' };
expect(a).toEqual(b);

@@ -48,2 +48,2 @@ });

});
});

@@ -43,3 +43,3 @@ describe('Matcher', function () {

it('should diff undefined with string with newlines', function () {
expect(undefined).toBe('yo ban\nana apple');
expect(void 0).toBe('yo ban\nana apple');
});

@@ -56,3 +56,3 @@

it('should NOT diff', function () {
expect(undefined).toBeDefined();
expect(void 0).toBeDefined();
});

@@ -81,3 +81,3 @@

it('should NOT diff', function () {
expect(3).toBeCloseTo(5);
expect('defined').toBeCloseTo(5);
});

@@ -87,2 +87,2 @@

});
});

@@ -6,4 +6,4 @@ describe('Matcher', function () {

it('should diff objects', function () {
var a = { foo: 'bar' },
b = { baz: 'qux' };
var a = { foo: 'bar' };
var b = { baz: 'qux' };
expect(a).toEqual(b);

@@ -28,3 +28,3 @@ });

a: 0,
b: 1,
b: 1
}

@@ -40,3 +40,3 @@ };

c: 2,
a: 0,
a: 0
}

@@ -47,4 +47,23 @@ };

it('should NOT diff with jasmine.objectContaining', function () {
var a = {
foo: 42,
'ma-bar': 'baz'
};
expect(a).toEqual(jasmine.objectContaining({ foo: 43 }));
});
it('should NOT diff with jasmine.objectContaining', function () {
var a = {
foo: function () {},
bar: function () {}
};
var b = {
foo: function () {},
bar: jasmine.any(Function)
};
expect(a).toEqual(b);
});
});
});
});

@@ -7,4 +7,4 @@ describe('Matcher', function () {

var spy = jasmine.createSpy('spy');
var a = { foo: 'bar' },
b = { baz: 'qux' };
var a = { foo: 'bar' };
var b = { baz: 'qux' };

@@ -24,4 +24,20 @@ spy(a);

it('multiple calls', function () {
var foo = {
bar: function () {}
};
spyOn(foo, 'bar');
foo.bar(5);
foo.bar(6);
foo.bar(10);
expect(foo.bar).toHaveBeenCalledWith(8);
});
});
});
});

@@ -7,2 +7,3 @@ describe('Matcher', function () {

var foo = function () {
// eslint-disable-next-line no-undef
return a + 1;

@@ -26,2 +27,2 @@ };

});
});

@@ -46,2 +46,2 @@ describe('Option', function () {

});
});

@@ -1,2 +0,6 @@

module.exports = function(config) {
'use strict';
var reporter = require('../../');
module.exports = function (config) {
config.set({

@@ -24,3 +28,3 @@

'karma-chrome-launcher',
require('../..')
reporter
],

@@ -57,4 +61,3 @@

pretty: true,
multiline: true,
json: false
multiline: true
}

@@ -61,0 +64,0 @@

@@ -7,8 +7,45 @@ 'use strict';

var jasmineDiff = require('./src/jasmine-diff');
var createColorFormatter = require('./src/color-formatter');
var createColorHighlighter = require('./src/color-highlighter');
var format = require('./src/format');
var defaults = require('./src/utils/object').defaults;
var karmaMajorVersion = Number(karma.VERSION.split('.')[0]);
function JasmineDiffReporter(baseReporterDecorator, config, logger) {
function jasmineDiffFramework(config, logger) {
var log = logger.create('jasmine-diff');
// karma-jasmine uses adapter to work with Jasmine
// Use it to include custom patch for Jasmine right before adapter starts
var jasminePath = path.dirname(require.resolve('jasmine-core'));
var coreFile = '/jasmine-core/jasmine.js';
var jasmineCorePath = jasminePath + coreFile;
var index = -1;
for (var i = 0, l = config.files.length; i < l; i++) {
if (config.files[i].pattern === jasmineCorePath) {
index = i;
break;
}
}
if (index === -1) {
log.warn('File "%s" not found in module "jasmine-core".', coreFile);
log.warn('You may be using a not supported Jasmine version.');
log.warn('Pretty print option will not be available');
return;
}
var patchPath = path.join(__dirname, 'src', 'karma-jasmine', 'pp-patch.js');
config.files.splice(index + 2, 0, {
pattern: patchPath,
included: true,
served: true,
watched: false
});
}
function jasmineDiffReporter(baseReporterDecorator, config, logger) {
var self = this;

@@ -19,17 +56,15 @@

var reporterOptions = config.jasmineDiffReporter || {};
var reporterConfig = defaults(config.jasmineDiffReporter || {}, {
matchers: {},
color: {},
pretty: false,
multiline: false,
verbose: true
});
var options = {
matchers: reporterOptions.matchers || {},
color: reporterOptions.color || {},
pretty: reporterOptions.pretty || false,
multiline: reporterOptions.multiline || false,
json: reporterOptions.json || false
};
reporterConfig.color.enabled = !!config.colors;
options.color.enabled = !!config.colors;
// Create formatter responsible for highlighting message fragments
// and pass it to diff function as a dep to be able to replace it in tests
var colorFormatter = createColorFormatter(options.color);
var colorFormatter = createColorHighlighter(reporterConfig.color);

@@ -46,5 +81,4 @@ // Check if reporter is last in the list of config reporters

self.specFailure = function (browser, result) {
result.log = result.log.map(function (message) {
return jasmineDiff.createDiffMessage(message, colorFormatter, options);
return format(message, colorFormatter, reporterConfig);
});

@@ -81,58 +115,12 @@

} else {
JasmineDiffFramework(config, logger);
jasmineDiffFramework(config, logger);
}
}
function JasmineDiffFramework(config, logger) {
var reporterOptions = config.jasmineDiffReporter || {};
var options = {
json: reporterOptions.json || false
};
var log = logger.create('jasmine-diff');
jasmineDiffReporter.$inject = ['baseReporterDecorator', 'config', 'logger'];
jasmineDiffFramework.$inject = ['config', 'logger'];
// karma-jasmine uses adapter to work with Jasmine
// Use it to include custom patch for Jasmine right before adapter starts
var jasminePath = path.dirname(require.resolve('jasmine-core'));
var coreFile = '/jasmine-core/jasmine.js';
var jasmineCorePath = jasminePath + coreFile;
var index = -1;
for (var i = 0, l = config.files.length; i < l; i++) {
if (config.files[i].pattern === jasmineCorePath) {
index = i;
break;
}
}
if (index === -1) {
log.warn('File "%s" not found in module "jasmine-core".', coreFile);
log.warn('You may be using a not supported Jasmine version.');
log.warn('Pretty print option will not be available');
return false;
}
var patchFileName = 'pp-patch.js';
if (options.json) {
patchFileName = 'pp-json-patch.js';
}
var patchPath = path.join(__dirname, 'src', 'karma-jasmine', patchFileName);
config.files.splice(index + 2, 0, {
pattern: patchPath,
included: true,
served: true,
watched: false
});
}
JasmineDiffReporter.$inject = ['baseReporterDecorator', 'config', 'logger'];
JasmineDiffFramework.$inject = ['config', 'logger'];
var modules = {
'reporter:jasmine-diff': ['type', JasmineDiffReporter]
'reporter:jasmine-diff': ['type', jasmineDiffReporter]
};

@@ -144,5 +132,5 @@

if (karmaMajorVersion < 1) {
modules['framework:jasmine-diff'] = ['factory', JasmineDiffFramework];
modules['framework:jasmine-diff'] = ['factory', jasmineDiffFramework];
}
module.exports = modules;
{
"name": "karma-jasmine-diff-reporter",
"version": "0.6.3",
"description": "Karma reporter to highlight diffs of failed equality expectations for Jasmine",
"version": "1.0.0",
"description": "Diff and pretty print for failed tests",
"main": "index.js",

@@ -10,3 +10,4 @@ "keywords": [

"jasmine",
"diff"
"diff",
"pretty"
],

@@ -22,8 +23,8 @@ "author": "Michael Radionov",

"chalk": "^1.1.0",
"extend": "^3.0.0"
},
"peerDependencies": {
"karma": ">=0.9"
},
"devDependencies": {
"eslint": "^3.14.1",
"eslint-config-airbnb-es5": "^1.1.0",
"eslint-config-es5": "^0.5.0",
"jasmine-core": "*",

@@ -33,2 +34,3 @@ "karma": "*",

"karma-jasmine": "*",
"tap-min": "^1.1.0",
"tape": "^4.5.1"

@@ -38,4 +40,5 @@ },

"start": "karma start demo/setup/karma.conf.js",
"test": "tape 'test/**/*.test.js'"
"test": "tape 'test/**/*.test.js' | tap-min",
"lint": "eslint index.js demo src test"
}
}
karma-jasmine-diff-reporter [![Build status](https://travis-ci.org/mradionov/karma-jasmine-diff-reporter.svg?branch=master)](https://travis-ci.org/mradionov/karma-jasmine-diff-reporter)
===
> [Karma](http://karma-runner.github.io/) reporter to highlight diffs of failed equality expectations for [Jasmine](http://jasmine.github.io/).
> Diff and pretty print for failed tests.
Jasmine matchers that will be processed:
![Example](http://i.imgur.com/5fkAvw2.jpg "Example")
- toBe
- toBeUndefined
- toBeNaN
- toBeNull
- toEqual
- toHaveBeenCalledWith
- toThrow
- toThrowError
## Install
Example: ![Example base](http://i.imgur.com/5fkAvw2.jpg "Example base")
Expectations have red background, actual results - green.
*Note: there are matchers like `toBeTruthy` or `toBeDefined` in Jasmine, but they won't be highlighted because the messages outputed are `Expected 0 to be truthy` or `Expected undefined to be defined` respectively, and words `truthy` and `defined` are not the part of JavaScript.*
*Note: if you use custom matchers, they also might be accidently highlighted, if their messages match the patterns I use to extract the data for comparison. There is no a solution to disable it yet. You can find more about custom matchers below.*
### Support
Only Jasmine 2.x is supported, this extension **will not work** with Jasmine 1.3.
### Installation
```bash

@@ -35,8 +14,4 @@ npm install karma-jasmine-diff-reporter --save-dev

*Note: you also need to have karma and karma-jasmine installed*
Add reporter to karma config file:
### Configuration
The idea behind *karma-jasmine-diff-reporter* is that it does not output info by itself, but just modifies the message, so as a result **you can use it in conjunction with your favorite reporter**. To do so, you have to put it before reporter you normally use in the Karma config file:
```js

@@ -46,13 +21,3 @@ // karma.conf.js

config.set({
frameworks: ['jasmine'],
// use Progress reporter and still highlight diffs
reporters: ['jasmine-diff', 'progress']
// reporters: ['jasmine-diff, 'mocha'] // karma-mocha-reporter
// reporters: ['jasmine-diff', 'nested'] // karma-nested-reporter
// reporters: ['jasmine-diff'] // use Karma default Base reporter
reporters: ['jasmine-diff']
});

@@ -62,22 +27,18 @@ };

Otherwise, if you do not use any extra reporters, Karma Base reporter will be used by default.
You can use it together with another reporters, which tweak the output - just place them after:
Because of this specific order-dependent behavior some of the reporters that are listed after `jasmine-diff` might break (for example `karma-junit-reporter` which converts result into XML, which does not support characters used to set colors in terminal).
```js
reporters: ['jasmine-diff', 'junit']
reporters: ['jasmine-diff', 'progress']
```
The workaround is actually to put `jasmine-diff` after broken reporter:
Some specific reporters might break because of how the output is changed, make sure to place them before:
```js
reporters: ['junit', 'jasmine-diff']
reporters: ['junit', 'jasmine-diff']
```
### Options
## Options
##### Colors
Default options:
Karma config has an option `colors` which accepts a boolean value telling whether or not colors should be used in output. If this option is set to `false`, then *karma-jasmine-diff-reporter* will print diffs using inverse colors.
```js

@@ -87,65 +48,23 @@ // karma.conf.js

config.set({
frameworks: ['jasmine'],
reporters: ['jasmine-diff'],
colors: false
});
};
```
Example: ![Example inverse](http://i.imgur.com/l0xqQv5.jpg "Example inverse")
Also you can explicitly specify what colors you want to see for diffs:
```js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
reporters: ['jasmine-diff'],
jasmineDiffReporter: {
// Bg - background
// Fg - foreground (text)
color: {
expectedBg: 'bgYellow', // default 'bgRed'
expectedFg: 'black', // default 'white'
actualBg: 'bgCyan', // default 'bgGreen'
actualFg: 'red', // default 'white',
defaultBg: 'white', // default - none
defaultFg: 'grey' // default - none,
expectedWhitespaceBg: 'bgYellow', // default 'bgRed'
actualWhitespaceBg: 'bgCyan' // default 'bgGreen'
}
}
expectedBg: 'bgRed',
expectedWhitespaceBg: 'bgRed',
expectedFg: 'white',
});
};
```
actualBg: 'bgGreen',
actualWhitespaceBg: 'bgGreen',
actualFg: 'white',
Example: ![Example custom colors](http://i.imgur.com/eOTgERa.jpg "Example custom colors")
warningBg: 'bgYellow',
warningWhitespaceBg: 'bgYellow',
warningFg: 'white',
You can use any [colors](https://github.com/chalk/chalk#styles) that a supported by [`chalk`](https://github.com/chalk/chalk).
* Defaults for "expected" message is red background with white text and for "actual" - green background with white text.
* `defaultBg` and `defaultFg` - for parts of the diff that were not changed, it allows to highlight the rest of the object and distinguish it from matcher text
* `expectedWhitespaceBg` and `actualWhitespaceBg` - for the cases when you have a diff background of the same color as a terminal and only foreground color is used to identify diffs. In this case whitespace diffs won't be visible, when diff background has the same color as a terminal. To workaround it, it is possible to set a separate background for whitespace only using these options.
To use default terminal color use empty value:
```js
// karma.conf.js
module.exports = function(config) {
config.set({
jasmineDiffReporter: {
color: {
expectedBg: '', // default 'bgRed'
expectedFg: 'green', // default 'white'
actualBg: '', // default 'bgGreen'
actualFg: 'red', // default 'white',
}
defaultBg: '',
defaultFg: ''
},
pretty: false,
multiline: false,
verbose: true,
matchers: {}
}

@@ -156,174 +75,90 @@ });

If you have `colors:false` in Karma config, none of the custom or default colors will be used, diffs will be inversed instead.
#### color
##### Custom matchers
- `expected*` - colors for test expectations
- `actual*` - colors for actual results
- `warning*` - values which reporter could not fully diff and they are worth attention
- `default*` - text of the value which was not highlighted with any of the above colors
If you have custom Jasmine matchers, which compare your data for equality, but the message of your matchers does not fit to *karma-jasmine-diff-reporter*, you can specify the rules to extract the objects for comparison of the custom matcher in the configuration:
You can use any [colors](https://github.com/chalk/chalk#styles) that a supported by [chalk](https://github.com/chalk/chalk).
```js
// karma.conf.js
module.exports = function(config) {
config.set({
If karma config option `colors: false` is set, then reporter will ignore any custom colors and display diffs in inverse color of the terminal. ([see output example](http://i.imgur.com/l0xqQv5.jpg)).
frameworks: ['jasmine'],
To use default terminal color for any of the option just provide an empty string (`''`) as a value.
reporters: ['jasmine-diff']
#### pretty
jasmineDiffReporter: {
Values in objects and arrays will be indented depending on the nesting level.
([see output example](http://i.imgur.com/6TTlSmB.jpg))
matchers: {
Disabled by default. To enable:
toLookTheSameAs: {
pattern: /Expected ([\S\s]*?) to look the same as ([\S\s]*?)\./,
reverse: true
}
- `pretty: true` - 2 spaces for indent level
- `pretty: 4` - number of spaces per level
- `pretty: '\t'` - string per level
}
}
#### multiline
});
};
```
Adds extra newlines to separate Jasmine matcher text from actual values. ([see output example](http://storage6.static.itmages.com/i/16/0531/h_1464718207_5857499_e7d1091267.jpeg))
Matcher must have a property called `pattern`, which is a pattern to parse a failure message. It should have **two** capturing groups, which will capture your data to compare. If you have less or more - it will be ignored. Suggested regular expression for capturing group is `[\S\s]*`, which will capture all characters including whitespaces in non-greedy way. Also there is an optional property `reverse`, if it is set to `true`, then the colors, which are used to highlight *actual* and *expected* data objects, should be switched. By default, first capturing group stands for *expected* data and second - for *actual* data. You can take a look at the definitions of default matchers [here in the source code](src/jasmine-diff.js#8). You can even override default matchers by using their property name in config file (do it at your own risk).
Disabled by default. To enable:
*Note: this feature is experimental and may cover just a few cases and may not cover a lot more, because custom matchers can be way to custom. But if there are some stable libraries, which provide popular custom matchers (like [Jasmine-Matchers](https://github.com/JamieMason/Jasmine-Matchers)) and you think you want it to be supported, let me know the use-cases in the issues.*
- `multiline: true` - 2 newlines before and after the value + 2 spaces of indentation.
- Each option can configured using numbers (number of newlines/spaces) and strings.
##### Pretty print
```js
multiline: {
before: 3, // 3 newlines
after: '\n', // 1 newline
indent: ' ' // 2 spaces
}
```
Pretty print option enables output of each key/value pair for an object and/or array on a new line, each line indentation depends on nesting level. Option is disabled by default. Set `pretty` option to `true` to enable default indentation - 2 spaces. You can also pass a string or a number instead of `true`. String will represent one level on indentation, number - number of spaces for one level of indentation. It is also possible to override `pretty` option for particular matchers, it will be used in favor of global option, so you could customize or even disable pretty output for any matchers (built-in or custom).
#### verbose
```js
// karma.conf.js
module.exports = function(config) {
config.set({
If turned off, reduces the output by cutting of some Jasmine-specific syntax.
frameworks: ['jasmine'],
Enabled by default, which means nothing is cut off. To disable:
reporters: ['jasmine-diff']
- `verbose: false` - remove all extra Jasmine syntax
- Detailed configuration:
jasmineDiffReporter: {
pretty: true, // 2 spaces by default for one indent level
// pretty: ' ' // string - string to be used for one indent level
// pretty: 4 // number - number of spaces for one indent level
```js
verbose: {
object: false
}
```
matchers: {
toEqual: {
pretty: false // disable pretty print for toEqual
},
- `object` - Jasmine wraps objects - `Object({ foo: 42 })`, if set to `false` objects will be displayed without this wrapper - `{ foo: 42 }`.
toHaveBeenCalledWith: {
pretty: '___' // use 3 underscores for one indent level
}
}
}
#### matchers
});
};
```
By default only Jasmine core matchers are supported. Use this option to add any custom matchers so they could be correctly parsed and highlighted as well.
Example: ![Example pretty print](http://i.imgur.com/6TTlSmB.jpg "Example pretty print")
##### Multiline
Multiline option provides extra formatting by adding newlines before and after diffed objects so they can spotted even easier. Setting `multiline` to `true` will add 2 newlines before and 2 after for both actual and expected object, and will also indent them by 2 spaces. It can also be configured individually - for each sub-option `before`, `after` and `indent` you can pass a string or a number. String will be used once per options as is, number - number of newlines (for `before` and `after`) or number of spaces (for `indent`). It is also possible to override `multiline` option for particular matchers, it will be used in favor of global option, so you could customize or even disable multiline output for any matchers (built-in or custom). It works really good along with `pretty` option turned on (see pretty).
```js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
reporters: ['jasmine-diff']
jasmineDiffReporter: {
multiline: true, // before: 2 newlines, after: 2 newlines, indent: 2 spaces
matchers: {
toEqual: {
multiline: false // disable multiline for toEqual
}
}
}
});
};
matchers: {
toLookTheSameAs: {
pattern: /Expected ([\S\s]*) to look the same as ([\S\s]*)\./,
reverse: true
}
}
```
Example: ![Example multiline](http://storage6.static.itmages.com/i/16/0531/h_1464718207_5857499_e7d1091267.jpeg "Example multiline")
- `pattern` (required) - pattern to parse a failure message. It must have **two** capturing groups, which will capture actual and expected values. Suggested regular expression for capturing group is `[\S\s]*`, which will capture all characters including whitespaces.
- `reverse` (optional) - if set to `true`, then the colors, which are used to highlight actual and expected values will be swapped. By default, first capturing group stands for expected value and second - for actual value.
Configure individually:
Take a look at the [definitions of in-built matchers](src/matchers.js) to have a better understaning.
```js
// karma.conf.js
module.exports = function(config) {
config.set({
## Support
frameworks: ['jasmine'],
- jasmine 2.x
- karma 0.9+
- karma-jasmine 0.3+
reporters: ['jasmine-diff']
## Pitfalls
jasmineDiffReporter: {
Diffs won't be displayed for a deep nested objects or large arrays, a threshold for these situations is configured in Jasmine. By default it has object nest level `MAX_PRETTY_PRINT_DEPTH = 40` and array length `MAX_PRETTY_PRINT_ARRAY_LENGTH = 100`. It means that if the diff is out of these bounds, then Jasmine will return the same strings for both compared objects and the reporter won't be able to highlight those diffs.
multiline: {
before: 1, // 1 newline
after: 3, // 3 newlines
## License
indent: 4 // 4 spaces
// indent: '\t' // 1 tab
// indent: ' ' // 4 spaces
}
matchers: {
toHaveBeenCalledWith: {
multiline: {
before: 1 // use 1 newline before objects
}
}
}
}
});
};
```
#### JSON
JSON option allows to have output to be formatted as JSON instead of using Jasmine default pretty-printer, which adds extras like `Object({})`, so it could be possible to copy JSON right from terminal and use it. Setting `json` option to `true` will turn the feature on for all supported matchers, instead of `toThrow` and `toThrowError`, because there is no way to correctly represent errors in JSON format. The option **can't** be configured individually for each matcher, it will affect all of them. Internally objects are passed to `JSON.stringify`.
```js
// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],
reporters: ['jasmine-diff']
jasmineDiffReporter: {
json: true // format results as JSON
}
});
};
```
### Dependencies
- [diff](https://www.npmjs.com/package/diff) - Text differencing
- [chalk](https://www.npmjs.com/package/chalk) - Terminal string styling
- [extend](https://www.npmjs.com/package/extend) - Deep extend JS objects
### Pitfalls
Diffs won't be displayed for a deep nested objects or large arrays, a threshold for these situations is configured in Jasmine. By default it has object nest level `MAX_PRETTY_PRINT_DEPTH = 40` and array length `MAX_PRETTY_PRINT_ARRAY_LENGTH = 100`. It means that if the diff is out of these bounds, then Jasmine will return the same strings for both compared objects and *karma-jasmine-diff-reporter* won't be able to highlight those diffs.
### License
[MIT](LICENSE)
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var createTest = require('./helpers/test');
test('custom-matcher: default order', function (assert) {
var options = {
matchers: {
toLookTheSameAS: {
pattern: /Expected ([\S\s]*?) to look the same as ([\S\s]*?)\./
}
}
};
var input =
"Expected true to look the same as false." + stack;
var expected =
"Expected <e>true</e> to look the same as <a>false</a>." + stack;
var test = createTest('format: custom:');
var out = diff(input, formatter, options);
test('default order',
assert.equal(out, expected);
assert.end();
});
'Expected true to look the same as false.',
test('custom-matcher: reverse order', function (assert) {
var options = {
matchers: {
toLookTheSameAS: {
pattern: /Expected ([\S\s]*?) to look the same as ([\S\s]*?)\./,
reverse: true
}
'Expected <e>true</e> to look the same as <a>false</a>.',
{ format: { matchers: {
toLookTheSameAS: {
pattern: /Expected ([\S\s]*?) to look the same as ([\S\s]*?)\./
}
};
var input =
"Expected true to look the same as false." + stack;
var expected =
"Expected <a>true</a> to look the same as <e>false</e>." + stack;
}}}
);
var out = diff(input, formatter, options);
test('reverse order',
assert.equal(out, expected);
assert.end();
});
'Expected true to look the same as false.',
'Expected <a>true</a> to look the same as <e>false</e>.',
{ format: { matchers: {
toLookTheSameAS: {
pattern: /Expected ([\S\s]*?) to look the same as ([\S\s]*?)\./,
reverse: true
}
}}}
);
'use strict';
// Wrap string in markers used in pp-patch.js
var marker = require('../../src/marker');
var MARKER = '\u200C';
exports.mark = function(string) {
return MARKER + "'" + MARKER + string + MARKER + "'" + MARKER;
}
exports.markJSON = function(string) {
return MARKER + string + MARKER;
}
exports.MARKER = MARKER;
module.exports = function mark(string) {
return marker.wrapString(string);
};
'use strict';
module.exports = "\nat Object.<anonymous> (/path/to/file.js:42:0)";
module.exports = '\nat Object.<anonymous> (/path/to/file.js:42:0)';
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var mark = require('./helpers/mark').mark;
var createTest = require('./helpers/test');
var m = require('./helpers/mark');
test('marker: clear when processed', function (assert) {
var input =
"Expected " + mark('foo') + " to be " + mark('bar') + "." +
stack;
var expected =
"Expected <d>'</d><a>foo</a><d>'</d> to be <d>'</d><e>bar</e><d>'</d>." +
stack;
var test = createTest('marker:');
var out = diff(input, formatter);
test('clear when processed',
assert.equal(out, expected);
assert.end();
});
'Expected ' + m('foo') + ' to be ' + m('bar') + '.',
test('marker: clear when unknown matcher', function (assert) {
var input =
"Unknown message format " + mark('foo') + " with marked string." +
stack;
var expected =
"Unknown message format 'foo' with marked string." +
stack;
"Expected '<a>foo</a>' to be '<e>bar</e>'."
);
var out = diff(input, formatter);
test('clear when unknown matcher',
assert.equal(out, expected);
assert.end();
});
'Unknown message format ' + m('foo') + ' with marked string.',
test('marker: clear when unwanted matcher', function (assert) {
var input =
"Expected " + mark('foo') + " to be falsy." +
stack;
var expected =
"Expected 'foo' to be falsy." +
stack;
var out = diff(input, formatter);
assert.equal(out, expected);
assert.end();
});
"Unknown message format 'foo' with marked string."
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var createTest = require('./helpers/test');
var m = require('./helpers/mark');
test('toBe: booleans', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected <a>true</a> to be <e>false</e>." + stack;
var test = createTest('format: toBe:');
var out = diff(input, formatter);
test('booleans',
assert.equal(out, expected);
assert.end();
});
'Expected true to be false.',
test('toBe: strings', function (assert) {
var input =
"Expected 'life' to be 'great'." +
stack;
var expected =
"Expected <d>'</d><a>life</a><d>'</d>" +
" to be <d>'</d><e>great</e><d>'</d>." +
stack;
'Expected <a>true</a> to be <e>false</e>.'
);
var out = diff(input, formatter);
test('strings',
assert.equal(out, expected);
assert.end();
});
'Expected ' + m('foo') + ' to be ' + m('bar') + '.',
test('toBe: strings content', function (assert) {
var input =
"Expected 'I hate cats' to be 'I love cats'." +
stack;
var expected =
"Expected <d>'I </d><a>hate</a><d> cats'</d>" +
" to be <d>'I </d><e>love</e><d> cats'</d>." +
stack;
"Expected '<a>foo</a>' to be '<e>bar</e>'."
);
var out = diff(input, formatter);
test('strings content',
assert.equal(out, expected);
assert.end();
});
'Expected ' + m('I hate cats') + ' to be ' + m('I love cats') + '.',
test('toBe: strings with dots', function (assert) {
var input =
"Expected 'Kill. All. Humans.' to be 'Live. All. Robots.'." +
stack;
var expected =
"Expected <d>'</d><a>Kill</a><d>. All. </d><a>Humans</a><d>.'</d>" +
" to be <d>'</d><e>Live</e><d>. All. </d><e>Robots</e><d>.'</d>." +
stack;
"Expected 'I <a>hate</a> cats' " +
"to be 'I <e>love</e> cats'."
);
var out = diff(input, formatter);
test('strings with dots',
assert.equal(out, expected);
assert.end();
});
'Expected ' + m('foo. bar. baz.') + ' to be ' + m('qux. bar. daz.') + '.',
test('toBe: string with whitespace', function (assert) {
var input =
"Expected 'space space' to be 'space\nspace'." +
stack;
var expected =
"Expected <d>'space</d><aw> </aw><d>space'</d>" +
" to be <d>'space</d><ew>\n</ew><d>space'</d>." +
stack;
"Expected '<a>foo</a>. bar. <a>baz</a>.' " +
"to be '<e>qux</e>. bar. <e>daz</e>.'."
);
var out = diff(input, formatter);
test('undefined facing a string',
assert.equal(out, expected);
assert.end();
});
'Expected ' + m('defined') + ' to be undefined.',
// It should be tested because of inner logic of splitting stack from message
test('toBe: string with whitespace right after dot', function (assert) {
var input =
"Expected 'space. dot' to be 'space.\ndot'." +
stack;
var expected =
"Expected <d>'space.</d><aw> </aw><d>dot'</d>" +
" to be <d>'space.</d><ew>\n</ew><d>dot'</d>." +
stack;
"Expected <a>'defined'</a> to be <e>undefined</e>."
);
var out = diff(input, formatter);
test('defined',
assert.equal(out, expected);
assert.end();
});
'Expected undefined to be defined.',
test('toBe: arrays', function (assert) {
var input =
"Expected [2, 2, 8] to be [2, 3, 8]." +
stack;
var expected =
"Expected <d>[2, </d><a>2</a><d>, 8]</d>" +
" to be <d>[2, </d><e>3</e><d>, 8]</d>." +
stack;
'Expected <a>undefined</a> to be <e>defined</e>.'
);
var out = diff(input, formatter);
test('truthy',
assert.equal(out, expected);
assert.end();
});
'Expected false to be truthy.',
// Issue #6 not capturing newlines inside strings
test('toBe: undefined vs string with newlines', function (assert) {
var input =
"Expected undefined to be 'space\nspace'." +
stack;
var expected =
"Expected <a>undefined</a> to be <e>'space</e><ew>\n</ew><e>space'</e>." +
stack;
'Expected <a>false</a> to be <e>truthy</e>.'
);
var out = diff(input, formatter);
test('falsy',
assert.equal(out, expected);
assert.end();
});
'Expected true to be falsy.',
// Note: this behavior is a bit weird comparing to toBeUndefined and others -
// that equal parts are highlighted with default colors. Not critical
test('toBe: no diff for equal booleans', function (assert) {
var input =
"Expected true not to be true." +
stack;
var expected =
"Expected <d>true</d> not to be <d>true</d>." +
stack;
'Expected <a>true</a> to be <e>falsy</e>.'
);
var out = diff(input, formatter);
test('close to',
assert.equal(out, expected);
assert.end();
});
'Expected 3 to be close to 5.',
'Expected <a>3</a> to be ' +
'<e>close to 5</e>.'
);
test('greater than',
'Expected 3 to be greater than 5.',
'Expected <a>3</a> to be ' +
'<e>greater than 5</e>.'
);
test('less than',
'Expected 5 to be less than 3.',
'Expected <a>5</a> to be ' +
'<e>less than 3</e>.'
);
test('objects by ref',
'Expected Object({ foo: 42 }) to be Object({ foo: 42 }).',
'Expected <w>Object({ foo: 42 })</w> ' +
'to be <w>Object({ foo: 42 })</w>.'
);
test('arrays by ref',
'Expected [ 1, 2, 3 ] to be [ 1, 2, 3 ].',
'Expected <w>[ 1, 2, 3 ]</w> to be <w>[ 1, 2, 3 ]</w>.'
);
test('functions by ref',
'Expected Function to be Function.',
'Expected <w>Function</w> to be <w>Function</w>.'
);
test('no diff for equal booleans',
'Expected true not to be true.',
'Expected true not to be true.'
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var createTest = require('./helpers/test');
var m = require('./helpers/mark');
test('toHaveBeenCalledWith: bools', function (assert) {
var input =
"Expected spy foo to have been called with [ false ]" +
" but actual calls were [ true ]." +
stack;
var expected =
"Expected spy foo to have been called with <d>[ </d><e>false</e><d> ]</d>" +
" but actual calls were <d>[ </d><a>true</a><d> ]</d>." +
stack;
var test = createTest('format: toHaveBeenCalledWith:');
var out = diff(input, formatter);
test('bools',
assert.equal(out, expected);
assert.end();
});
'Expected spy foo to have been called with [ false ]' +
' but actual calls were [ true ].',
test('toHaveBeenCalledWith: objects', function (assert) {
var input =
"Expected spy foo to have been called with" +
" [ Object({ foo: 'bar' }) ]" +
" but actual calls were" +
" [ Object({ baz: 'qux' }) ]." +
stack;
var expected =
"Expected spy foo to have been called with" +
" <d>[ Object({ </d><e>foo</e><d>: '</d><e>bar</e><d>' }) ]</d>" +
" but actual calls were" +
" <d>[ Object({ </d><a>baz</a><d>: '</d><a>qux</a><d>' }) ]</d>." +
stack;
'Expected spy foo to have been called with [ <e>false</e> ]' +
' but actual calls were [ <a>true</a> ].'
);
var out = diff(input, formatter);
test('objects with different props',
assert.equal(out, expected);
assert.end();
});
'Expected spy foo to have been called with ' +
'[ Object({ foo: ' + m('bar') + ' }) ] ' +
'but actual calls were ' +
'[ Object({ baz: ' + m('qux') + ' }) ].',
'Expected spy foo to have been called with ' +
"[ Object({ <e>foo: 'bar'</e> }) ] " +
'but actual calls were ' +
"[ Object({ <a>baz: 'qux'</a> }) ]."
);
// Jasmine outputs all args for multiple calls in multiple arrays
// https://github.com/jasmine/jasmine/issues/228
test('multiple calls',
'Expected spy foo to have been called with [ 1, 2 ] ' +
'but actual calls were [ 4, 2 ], [ 1, 3 ].',
'Expected spy foo to have been called with [ 1, 2 ] ' +
'but actual calls were [ <a>4</a>, 2 ], [ 1, <a>3</a> ].'
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var createTest = require('./helpers/test');
test('toThrow: without message', function (assert) {
var input =
"Expected function to throw" +
" TypeError: foo," +
" but it threw" +
" ReferenceError: a is not defined." +
stack;
var expected =
"Expected function to throw" +
" <e>TypeError</e><d>: </d><e>foo</e>," +
" but it threw" +
" <a>ReferenceError</a><d>: </d><a>a</a><aw> </aw><a>is</a><aw> </aw><a>not</a><aw> </aw><a>defined</a>." +
stack;
var test = createTest('format: toThrow:');
var out = diff(input, formatter);
test('without message',
assert.equal(out, expected);
assert.end();
});
'Expected function to throw' +
' TypeError: foo,' +
' but it threw' +
' ReferenceError: a is not defined.',
test('toThrow: with message', function (assert) {
var input =
"Expected function to throw" +
" TypeError with message 'foo'," +
" but it threw" +
" ReferenceError with message 'bar'." +
stack;
var expected =
"Expected function to throw" +
" <e>TypeError</e><d> with message '</d><e>foo</e><d>'</d>," +
" but it threw" +
" <a>ReferenceError</a><d> with message '</d><a>bar</a><d>'</d>." +
stack;
'Expected function to throw' +
' <e>TypeError</e>: <e>foo</e>,' +
' but it threw' +
' <a>ReferenceError</a>: <a>a is not defined</a>.'
);
var out = diff(input, formatter);
test('with message',
assert.equal(out, expected);
assert.end();
});
'Expected function to throw' +
" TypeError with message 'foo'," +
' but it threw' +
" ReferenceError with message 'bar'.",
'Expected function to throw' +
" <e>TypeError</e> with message '<e>foo</e>'," +
' but it threw' +
" <a>ReferenceError</a> with message '<a>bar</a>'."
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var createTest = require('./helpers/test');
test('multiline: to be', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected\n" +
"\n" +
" <a>true</a>\n" +
"\n" +
"to be\n" +
"\n" +
" <e>false</e>\n" +
"\n" +
"." +
stack;
var test = createTest('multiline:');
var out = diff(input, formatter, { multiline: true });
test('primitives, matcher toBe',
assert.equal(out, expected);
assert.end();
});
'Expected true to be false.',
test('multiline: to have been called with', function (assert) {
var input =
"Expected spy foo to have been called with [ false ]" +
" but actual calls were [ true ]." +
stack;
var expected =
"Expected spy foo to have been called with\n" +
"\n" +
" <d>[ </d><e>false</e><d> ]</d>\n" +
"\n" +
"but actual calls were\n" +
"\n" +
" <d>[ </d><a>true</a><d> ]</d>\n" +
"\n" +
"." +
stack;
'Expected\n' +
'\n' +
' <a>true</a>\n' +
'\n' +
'to be\n' +
'\n' +
' <e>false</e>\n' +
'\n' +
'.',
var out = diff(input, formatter, { multiline: true });
{ format: { multiline: true } }
);
assert.equal(out, expected);
assert.end();
});
test('different types, matcher toBe',
test('multiline: to throw', function (assert) {
var input =
"Expected function to throw" +
" TypeError: foo," +
" but it threw" +
" ReferenceError: a is not defined." +
stack;
var expected =
"Expected function to throw\n" +
"\n" +
" <e>TypeError</e><d>: </d><e>foo</e>\n" +
"\n" +
"but it threw\n" +
"\n" +
" <a>ReferenceError</a><d>: </d><a>a</a><aw> </aw><a>is</a><aw> </aw><a>not</a><aw> </aw><a>defined</a>\n" +
"\n" +
"." +
stack;
'Expected true to be 42.',
var out = diff(input, formatter, { multiline: true });
'Expected\n' +
'\n' +
' <a>true</a>\n' +
'\n' +
'to be\n' +
'\n' +
' <e>42</e>\n' +
'\n' +
'.',
assert.equal(out, expected);
assert.end();
});
{ format: { multiline: true } }
);
test('multiline: before, after, indent int', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected\n" +
" <a>true</a>\n" +
"\n" +
"\n" +
"to be\n" +
" <e>false</e>\n" +
"\n" +
"\n" +
"." +
stack;
test('arrays, matcher toBe',
var out = diff(input, formatter, {
multiline: {
before: 1,
after: 3,
indent: 4
}
});
'Expected [ 1, 2, 3 ] to be [ 1, 4, 3 ].',
assert.equal(out, expected);
assert.end();
});
'Expected\n' +
'\n' +
' <w>[ 1, 2, 3 ]</w>\n' +
'\n' +
'to be\n' +
'\n' +
' <w>[ 1, 4, 3 ]</w>\n' +
'\n' +
'.',
test('multiline: indent string', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected\n" +
"\n" +
"\t<a>true</a>\n" +
"\n" +
"to be\n" +
"\n" +
"\t<e>false</e>\n" +
"\n" +
"." +
stack;
{ format: { multiline: true } }
);
var out = diff(input, formatter, {
multiline: {
indent: '\t'
}
});
test('matcher toThrow',
assert.equal(out, expected);
assert.end();
});
'Expected function to throw' +
' TypeError: foo,' +
' but it threw' +
' ReferenceError: a is not defined.',
test('multiline: before after string', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected--^^<a>true</a>__to be--^^<e>false</e>__." +
stack;
'Expected function to throw\n' +
'\n' +
' <e>TypeError</e>: <e>foo</e>\n' +
'\n' +
'but it threw\n' +
'\n' +
' <a>ReferenceError</a>: <a>a is not defined</a>\n' +
'\n' +
'.',
var out = diff(input, formatter, {
multiline: {
before: '--',
after: '__',
indent: '^^'
}
});
{ format: { multiline: true } }
);
assert.equal(out, expected);
assert.end();
});
test('matcher toHaveBeenCalledWith',
test('multiline: pretty', function (assert) {
var input =
"Expected [ 5, 'foo', Object({ baz: true }) ]" +
" to equal [ 10, 'bar', Object({ baz: false }) ]." +
stack;
var expected =
"Expected\n" +
"\n" +
" <d>[\n" +
" </d><a>5</a><d>,\n" +
" '</d><a>foo</a><d>',\n" +
" Object({\n" +
" baz: </d><a>true</a><d>\n" +
" })\n" +
" ]</d>\n" +
"\n" +
"to equal\n" +
"\n" +
" <d>[\n" +
" </d><e>10</e><d>,\n" +
" '</d><e>bar</e><d>',\n" +
" Object({\n" +
" baz: </d><e>false</e><d>\n" +
" })\n" +
" ]</d>\n" +
"\n" +
"." +
stack;
'Expected spy foo to have been called with [ false ]' +
' but actual calls were [ true ].',
var out = diff(input, formatter, {
pretty: true,
multiline: true
});
'Expected spy foo to have been called with\n' +
'\n' +
' [ <e>false</e> ]\n' +
'\n' +
'but actual calls were\n' +
'\n' +
' [ <a>true</a> ]\n' +
'\n' +
'.',
assert.equal(out, expected);
assert.end();
});
{ format: { multiline: true } }
);
test('multiline: matcher overrides global', function (assert) {
var input =
"Expected true to be false." + stack;
var expected =
"Expected\n" +
"\n" +
"\n" +
"--<a>true</a>\n" +
"\n" +
"to be\n" +
"\n" +
"\n" +
"--<e>false</e>\n" +
"\n" +
"." +
stack;
test('before, after, indent int',
var out = diff(input, formatter, {
multiline: {
before: 1,
after: 1,
indent: '\t'
},
matchers: {
toBe: {
multiline: {
before: 3,
after: 2,
indent: '--'
}
}
}
});
'Expected true to be false.',
assert.equal(out, expected);
assert.end();
});
'Expected\n' +
' <a>true</a>\n' +
'\n' +
'\n' +
'to be\n' +
' <e>false</e>\n' +
'\n' +
'\n' +
'.',
{ format: { multiline: {
before: 1,
after: 3,
indent: 4
}}}
);
test('indent string',
'Expected true to be false.',
'Expected\n' +
'\n' +
'\t<a>true</a>\n' +
'\n' +
'to be\n' +
'\n' +
'\t<e>false</e>\n' +
'\n' +
'.',
{ format: { multiline: {
indent: '\t'
}}}
);
test('before after string',
'Expected true to be false.',
'Expected--^^<a>true</a>__to be--^^<e>false</e>__.',
{ format: { multiline: {
before: '--',
after: '__',
indent: '^^'
}}}
);
test('pretty',
"Expected [ 5, 'foo', Object({ baz: true }) ] " +
"to equal [ 10, 'bar', Object({ baz: false }) ].",
'Expected\n' +
'\n' +
' [\n' +
' <a>5</a>,\n' +
" <a>'foo'</a>,\n" +
' Object({\n' +
' baz: <a>true</a>\n' +
' })\n' +
' ]\n' +
'\n' +
'to equal\n' +
'\n' +
' [\n' +
' <e>10</e>,\n' +
" <e>'bar'</e>,\n" +
' Object({\n' +
' baz: <e>false</e>\n' +
' })\n' +
' ]\n' +
'\n' +
'.',
{ format: { multiline: true, pretty: true } }
);
test('pretty multiple calls, matcher toHaveBeenCalledWith',
'Expected spy foo to have been called with [ 1, 2 ] ' +
'but actual calls were [ 4, 2 ], [ 1, 3 ].',
'Expected spy foo to have been called with\n\n' +
' [\n' +
' 1,\n' +
' 2\n' +
' ]\n\n' +
'but actual calls were\n\n' +
' [\n' +
' <a>4</a>,\n' +
' 2\n' +
' ],\n' +
' [\n' +
' 1,\n' +
' <a>3</a>\n' +
' ]\n\n' +
'.',
{ format: { multiline: true, pretty: true } }
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formatter = require('./helpers/test-formatter')();
var stack = require('./helpers/stack');
var mark = require('./helpers/mark').mark;
var createTest = require('./helpers/test');
var m = require('./helpers/mark');
test('pretty: arrays two spaces default', function (assert) {
var input =
"Expected [ 5, 'foo', Object({ baz: true }) ]" +
" to equal [ 10, 'bar', Object({ baz: false }) ]." +
stack;
var expected =
"Expected <d>[\n" +
" </d><a>5</a><d>,\n" +
" '</d><a>foo</a><d>',\n" +
" Object({\n" +
" baz: </d><a>true</a><d>\n" +
" })\n" +
"]</d> to equal <d>[\n" +
" </d><e>10</e><d>,\n" +
" '</d><e>bar</e><d>',\n" +
" Object({\n" +
" baz: </d><e>false</e><d>\n" +
" })\n" +
"]</d>." +
stack;
var test = createTest('pretty:');
var out = diff(input, formatter, { pretty: true });
test('primitives are the same',
assert.equal(out, expected);
assert.end();
});
'Expected 2 to be 5.',
test('pretty: arrays tab', function (assert) {
var input =
"Expected [ 5, 'foo', Object({ baz: true }) ]" +
" to equal [ 10, 'bar', Object({ baz: false }) ]." +
stack;
var expected =
"Expected <d>[\n" +
"\t</d><a>5</a><d>,\n" +
"\t'</d><a>foo</a><d>',\n" +
"\tObject({\n" +
"\t\tbaz: </d><a>true</a><d>\n" +
"\t})\n" +
"]</d> to equal <d>[\n" +
"\t</d><e>10</e><d>,\n" +
"\t'</d><e>bar</e><d>',\n" +
"\tObject({\n" +
"\t\tbaz: </d><e>false</e><d>\n" +
"\t})\n" +
"]</d>." +
stack;
'Expected <a>2</a> to be <e>5</e>.'
);
var out = diff(input, formatter, { pretty: '\t' });
test('one-level objects, matcher toBe',
assert.equal(out, expected);
assert.end();
});
'Expected Object({ foo: 42 }) to be Object({ foo: 43 }).',
test('pretty: arrays string', function (assert) {
var input =
"Expected [ 5, 'foo', Object({ baz: true }) ]" +
" to equal [ 10, 'bar', Object({ baz: false }) ]." +
stack;
var expected =
"Expected <d>[\n" +
"---</d><a>5</a><d>,\n" +
"---'</d><a>foo</a><d>',\n" +
"---Object({\n" +
"------baz: </d><a>true</a><d>\n" +
"---})\n" +
"]</d> to equal <d>[\n" +
"---</d><e>10</e><d>,\n" +
"---'</d><e>bar</e><d>',\n" +
"---Object({\n" +
"------baz: </d><e>false</e><d>\n" +
"---})\n" +
"]</d>." +
stack;
'Expected <w>Object({ foo: 42 })</w> to be <w>Object({ foo: 43 })</w>.',
var out = diff(input, formatter, { pretty: '---' });
{ format: { pretty: true } }
);
assert.equal(out, expected);
assert.end();
});
test('one-level objects, matcher toEqual',
test('pretty: deep object', function (assert) {
var input =
"Expected Object({ foo: 'bar', baz: 5," +
" tux: Object({ a: Object({ b: 4, c: [ 'foo', true ] }) }), qux: true })" +
" to equal Object({ foo: 'baz', bar: 10," +
" tux: Object({ a: Object({ b: 4, c: [ 'foo', false ] }) }), qqx: true })." +
stack;
var expected =
"Expected <d>Object({\n" +
" foo: '</d><a>bar</a><d>',\n" +
" </d><a>baz</a><d>: </d><a>5</a><d>,\n" +
" tux: Object({\n" +
" a: Object({\n" +
" b: 4,\n" +
" c: [\n" +
" 'foo',\n" +
" </d><a>true</a><d>\n" +
" ]\n" +
" })\n" +
" }),\n" +
" </d><a>qux</a><d>: true\n" +
"})</d> to equal <d>Object({\n" +
" foo: '</d><e>baz</e><d>',\n" +
" </d><e>bar</e><d>: </d><e>10</e><d>,\n" +
" tux: Object({\n" +
" a: Object({\n" +
" b: 4,\n" +
" c: [\n" +
" 'foo',\n" +
" </d><e>false</e><d>\n" +
" ]\n" +
" })\n" +
" }),\n" +
" </d><e>qqx</e><d>: true\n" +
"})</d>." +
stack;
'Expected Object({ foo: 42 }) to equal Object({ foo: 43 }).',
var out = diff(input, formatter, { pretty: true });
'Expected Object({\n' +
' foo: <a>42</a>\n' +
'}) to equal Object({\n' +
' foo: <e>43</e>\n' +
'}).',
assert.equal(out, expected);
assert.end();
});
{ format: { pretty: true } }
);
test('pretty: dirty object', function (assert) {
var input =
"Expected Object({" +
" foo: " + mark("ba', r Object({ ,, []\\") + "," +
" baz: 5, qux: true })" +
" to equal Object({" +
" foo: " + mark("ba', r \'Object({ ,, []\\") + "," +
" batz: 5, qux: false })." +
stack;
var expected =
"Expected <d>Object({\n" +
" foo: 'ba', r </d><d>Object({ ,, []\\',\n" +
" </d><a>baz</a><d>: 5,\n" +
" qux: </d><a>true</a><d>\n" +
"})</d> to equal <d>Object({\n" +
" foo: 'ba', r </d><e>'</e><d>Object({ ,, []\\',\n" +
" </d><e>batz</e><d>: 5,\n" +
" qux: </d><e>false</e><d>\n" +
"})</d>." +
stack;
test('one-level objects, matcher toHaveBeenCalledWith',
var out = diff(input, formatter, { pretty: true });
'Expected spy foo to have been called with [ ' +
'Object({ foo: 42 })' +
'] but actual calls were [ ' +
'Object({ foo: 43 })' +
'].',
assert.equal(out, expected);
assert.end();
});
'Expected spy foo to have been called with [\n' +
' Object({\n' +
' foo: <e>42</e>\n' +
' })\n' +
'] but actual calls were [\n' +
' Object({\n' +
' foo: <a>43</a>\n' +
' })\n' +
'].',
{ format: { pretty: true } }
);
test('two-level objects',
'Expected Object({ foo: Object({ bar: 42, baz: 43 }), qux: 44 }) ' +
'to equal Object({ foo: Object({ bar: 45, baz: 43 }), qux: 44 }).',
'Expected Object({\n' +
' foo: Object({\n' +
' bar: <a>42</a>,\n' +
' baz: 43\n' +
' }),\n' +
' qux: 44\n' +
'}) to equal Object({\n' +
' foo: Object({\n' +
' bar: <e>45</e>,\n' +
' baz: 43\n' +
' }),\n' +
' qux: 44\n' +
'}).',
{ format: { pretty: true } }
);
test('one-level arrays, matcher toBe',
'Expected [ 1, 2, 3 ] to be [ 1, 2, 4 ].',
'Expected <w>[ 1, 2, 3 ]</w> to be <w>[ 1, 2, 4 ]</w>.',
{ format: { pretty: true } }
);
test('one-level arrays, matcher toEqual',
'Expected [ 1, 2, 3 ] to equal [ 1, 2, 4 ].',
'Expected [\n' +
' 1,\n' +
' 2,\n' +
' <a>3</a>\n' +
'] to equal [\n' +
' 1,\n' +
' 2,\n' +
' <e>4</e>\n' +
'].',
{ format: { pretty: true } }
);
test('two-level arrays',
'Expected [ 1, [ 2, 3 ], 5 ] to equal [ 1, [ 4, 3 ], 5 ].',
'Expected [\n' +
' 1,\n' +
' [\n' +
' <a>2</a>,\n' +
' 3\n' +
' ],\n' +
' 5\n' +
'] to equal [\n' +
' 1,\n' +
' [\n' +
' <e>4</e>,\n' +
' 3\n' +
' ],\n' +
' 5\n' +
'].',
{ format: { pretty: true } }
);
test('array with number, string and obj',
'Expected [ 5, ' + m('foo') + ', Object({ baz: true }) ] ' +
'to equal [ 10, ' + m('bar') + ', Object({ baz: false }) ].',
'Expected [\n' +
' <a>5</a>,\n' +
" <a>'foo'</a>,\n" +
' Object({\n' +
' baz: <a>true</a>\n' +
' })\n' +
'] to equal [\n' +
' <e>10</e>,\n' +
" <e>'bar'</e>,\n" +
' Object({\n' +
' baz: <e>false</e>\n' +
' })\n' +
'].',
{ format: { pretty: true } }
);
test('tabs as indent',
'Expected [ 5, ' + m('foo') + ', Object({ baz: true }) ] ' +
'to equal [ 10, ' + m('bar') + ', Object({ baz: false }) ].',
'Expected [\n' +
'\t<a>5</a>,\n' +
"\t<a>'foo'</a>,\n" +
'\tObject({\n' +
'\t\tbaz: <a>true</a>\n' +
'\t})\n' +
'] to equal [\n' +
'\t<e>10</e>,\n' +
"\t<e>'bar'</e>,\n" +
'\tObject({\n' +
'\t\tbaz: <e>false</e>\n' +
'\t})\n' +
'].',
{ format: { pretty: '\t' } }
);
test('string as indent',
'Expected [ 5, ' + m('foo') + ', Object({ baz: true }) ]' +
' to equal [ 10, ' + m('bar') + ', Object({ baz: false }) ].',
'Expected [\n' +
'---<a>5</a>,\n' +
"---<a>'foo'</a>,\n" +
'---Object({\n' +
'------baz: <a>true</a>\n' +
'---})\n' +
'] to equal [\n' +
'---<e>10</e>,\n' +
"---<e>'bar'</e>,\n" +
'---Object({\n' +
'------baz: <e>false</e>\n' +
'---})\n' +
'].',
{ format: { pretty: '---' } }
);
test('pretty: deep object',
'Expected Object({ foo: ' + m('bar') + ', baz: 5,' +
" tux: Object({ a: Object({ b: 4, c: [ 'foo', true ] }) }), qux: true })" +
' to equal Object({ foo: ' + m('baz') + ', bar: 10,' +
" tux: Object({ a: Object({ b: 4, c: [ 'foo', false ] }) }), qqx: true }).",
'Expected Object({\n' +
" foo: <a>'bar'</a>,\n" +
' <a>baz: 5</a>,\n' +
' tux: Object({\n' +
' a: Object({\n' +
' b: 4,\n' +
' c: [\n' +
" 'foo',\n" +
' <a>true</a>\n' +
' ]\n' +
' })\n' +
' }),\n' +
' <a>qux: true</a>\n' +
'}) to equal Object({\n' +
" foo: <e>'baz'</e>,\n" +
' <e>bar: 10</e>,\n' +
' tux: Object({\n' +
' a: Object({\n' +
' b: 4,\n' +
' c: [\n' +
" 'foo',\n" +
' <e>false</e>\n' +
' ]\n' +
' })\n' +
' }),\n' +
' <e>qqx: true</e>\n' +
'}).',
{ format: { pretty: true } }
);
test('dirty object',
'Expected Object({' +
' foo: ' + m("ba', r Object({ ,, []\\") + ',' +
' baz: 5, qux: true })' +
' to equal Object({' +
' foo: ' + m("ba', r \'Object({ ,, []\\") + ',' +
' batz: 5, qux: false }).',
'Expected Object({\n' +
" foo: <a>'ba', r Object({ ,, []\\'</a>,\n" +
' <a>baz: 5</a>,\n' +
' qux: <a>true</a>\n' +
'}) to equal Object({\n' +
" foo: <e>'ba', r 'Object({ ,, []\\'</e>,\n" +
' <e>batz: 5</e>,\n' +
' qux: <e>false</e>\n' +
'}).',
{ format: { pretty: true } }
);
test('objects different props',
'Expected Object({ foo: 42 }) to equal Object({ bar: 43 }).',
'Expected Object({\n' +
' <a>foo: 42</a>\n' +
'}) to equal Object({\n' +
' <e>bar: 43</e>\n' +
'}).',
{ format: { pretty: true } }
);
test('object containing missing prop',
'Expected Object({ foo: 42 }) ' +
'to equal <jasmine.objectContaining(Object({ bar: 43 }))>.',
'Expected Object({\n' +
' foo: 42\n' +
'}) to equal <jasmine.objectContaining(Object({\n' +
' <e>bar: 43</e>\n' +
'}))>.',
{ format: { pretty: true } }
);
test('array with missing prop',
'Expected [ 1, 2, 3 ] to equal [ 1, 2 ].',
'Expected [\n' +
' 1,\n' +
' 2,\n' +
' <a>3</a>\n' +
'] to equal [\n' +
' 1,\n' +
' 2\n' +
'].',
{ format: { pretty: true } }
);
test('array containing wrong value',
'Expected [ 1, 2, 3 ] to equal <jasmine.arrayContaining([ 4, 2, 5 ])>.',
'Expected [\n' +
' 1,\n' +
' 2,\n' +
' 3\n' +
'] to equal <jasmine.arrayContaining([\n' +
' <e>4</e>,\n' +
' 2,\n' +
' <e>5</e>\n' +
'])>.',
{ format: { pretty: true } }
);
test('multiple calls, matcher toHaveBeenCalledWith',
'Expected spy foo to have been called with [ 1, 2 ] ' +
'but actual calls were [ 4, 2 ], [ 1, 3 ].',
'Expected spy foo to have been called with [\n' +
' 1,\n' +
' 2\n' +
'] but actual calls were [\n' +
' <a>4</a>,\n' +
' 2\n' +
'],\n' +
'[\n' +
' 1,\n' +
' <a>3</a>\n' +
'].',
{ format: { pretty: true } }
);
'use strict';
var test = require('tape');
var diff = require('../src/jasmine-diff').createDiffMessage;
var formater = require('./helpers/test-formatter')();
var createTest = require('./helpers/test');
var test = createTest('stacktrace:');
// Issue #10 with Phantom JS
test('stacktrace: dont capture stacktrace without "at"', function (assert) {
var input =
"Expected true to be false." +
"\ncheck@/path/to/file.js:42:0";
var expected =
"Expected <a>true</a> to be <e>false</e>." +
"\ncheck@/path/to/file.js:42:0";
test('don\'t capture stacktrace without "at"',
var out = diff(input, formater);
'Expected true to be false.',
assert.equal(out, expected);
assert.end();
});
'Expected <a>true</a> to be <e>false</e>.',
{ stack: '\ncheck@/path/to/file.js:42:0' }
);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc