Skip to content

Commit

Permalink
Merge d840ced into 1248cb8
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Dec 26, 2018
2 parents 1248cb8 + d840ced commit 5591473
Show file tree
Hide file tree
Showing 26 changed files with 515 additions and 443 deletions.
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ env:
- TARGET=travis

node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "7"
- "8.4.0"
- "9"
- "10"

matrix:
include:
- name: Travis main 8.4.0
- name: Lint (8.4.0)
node_js: "8.4.0"
env: TARGET=travis-main
env: TARGET=lint
- name: Jest (8.4.0)
node_js: "8.4.0"
env: TARGET=test-jest
- name: Jasmine (8.4.0)
node_js: "8.4.0"
env: TARGET=test-jasmine
- name: Coverage (8.4.0)
node_js: "8.4.0"
env: TARGET=travis-coverage
- name: BrowserStack IE11
node_js: "8.4.0"
env: TARGET=test-browserstack-ie11
Expand Down
13 changes: 5 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ test-jest:
ifeq ($(MODERN_NODE), true)
./node_modules/.bin/jest
else
./node_modules/.bin/jest -c test/jest.es5.config.json
./node_modules/.bin/jest --rootDir . -c test/jest.es5.config.json
endif

test-jest-if-supported-node-version:
@node-version-gte-6 && make test-jest || echo Skipping, jest is unsupported with node $(shell node --version)

.PHONY: test
test: test-sources
@./node_modules/.bin/mocha --opts $(MOCHA_OPTS) $(TEST_SOURCES) $(TEST_SOURCE_MARKDOWN)
Expand Down Expand Up @@ -84,12 +81,12 @@ test-chrome-headless: ${TARGETS}
test-browserstack-%: ${TARGETS}
@./node_modules/.bin/karma start --browsers=$* --single-run

.PHONY: travis-main
travis-main: clean lint test test-jasmine test-jest coverage
.PHONY: travis-coverage
travis-coverage: clean coverage
-<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js

.PHONY: travis
travis: test test-jest-if-supported-node-version
travis: test

.PHONY: git-dirty-check
git-dirty-check:
Expand Down Expand Up @@ -117,7 +114,7 @@ changelog: git-dirty-check
fi

.PHONY: release-%
release-%: git-dirty-check lint ${TARGETS} test-chrome-headless test-jasmine test-jest-if-supported-node-version commit-unexpected deploy-site
release-%: git-dirty-check lint ${TARGETS} test-chrome-headless test-jasmine test-jest commit-unexpected deploy-site
IS_MAKE_RELEASE=yes npm version $*
make changelog
@echo $* release ready to be publised to NPM
Expand Down
54 changes: 27 additions & 27 deletions documentation/api/addType.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,32 +299,32 @@ block. The outputs below shows the contrast between setting the
inlineDiff = true;
expect(
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Janie Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Janie Doe', 24)
},
'to equal',
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Jane Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Jane Doe', 24)
}
);
```

```output
expected
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Janie Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Janie Doe', 24)
}
to equal
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Jane Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Jane Doe', 24)
}
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person(
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person(
'Janie Doe', // should be 'Jane Doe'
// -Janie Doe
// +Jane Doe
Expand All @@ -337,39 +337,39 @@ to equal
inlineDiff = false;
expect(
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Janie Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Janie Doe', 24)
},
'to equal',
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Jane Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Jane Doe', 24)
}
);
```

```output
expected
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Janie Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Janie Doe', 24)
}
to equal
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Jane Doe', 24)
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Jane Doe', 24)
}
{
'John Doe': new Person('John Doe', 42),
'Jane Doe': new Person('Janie Doe', 24) // should equal new Person('Jane Doe', 24)
//
// new Person(
// 'Janie Doe', // should be 'Jane Doe'
// // -Janie Doe
// // +Jane Doe
// 24
// )
JohnDoe: new Person('John Doe', 42),
JaneDoe: new Person('Janie Doe', 24) // should equal new Person('Jane Doe', 24)
//
// new Person(
// 'Janie Doe', // should be 'Jane Doe'
// // -Janie Doe
// // +Jane Doe
// 24
// )
}
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var expect = require('../lib');
var expect = require('../lib').clone();

expect.addAssertion('<any> to bar', function(expect, subject) {
expect(subject, 'to equal', 'bar');
Expand Down
2 changes: 1 addition & 1 deletion externaltests/failingAsync.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var expect = require('../lib');
var expect = require('../lib').clone();

expect.addAssertion('<any> when delayed a little bit <assertion?>', function(
expect,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var expect = require('../lib');
var expect = require('../lib').clone();

it('should fail', () => {
expect.addAssertion('<any> to foo', function(expect, subject) {
Expand Down
6 changes: 5 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ module.exports = function(config) {

browsers: ['ChromeHeadlessNoSandbox', 'ie11'],

browserDisconnectTimeout: '60000',
browserNoActivityTimeout: '60000',

client: {
mocha: {
reporter: 'html'
reporter: 'html',
timeout: '60000'
}
},

Expand Down
49 changes: 27 additions & 22 deletions lib/Unexpected.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const defaultDepth = require('./defaultDepth');
const createWrappedExpectProto = require('./createWrappedExpectProto');
const AssertionString = require('./AssertionString');
const throwIfNonUnexpectedError = require('./throwIfNonUnexpectedError');
const makeDiffResultBackwardsCompatible = require('./makeDiffResultBackwardsCompatible');

function isAssertionArg({ type }) {
return type.is('assertion');
Expand Down Expand Up @@ -235,6 +234,16 @@ function createExpectIt(unexpected, expectations) {
? context
: new Context(unexpected);

if (
orGroups.length === 1 &&
orGroups[0].length === 1 &&
orGroups[0][0].length === 1 &&
typeof orGroups[0][0][0] === 'function'
) {
// expect.it(subject => ...)
return oathbreaker(orGroups[0][0][0](subject));
}

const groupEvaluations = [];
const promises = [];
orGroups.forEach(orGroup => {
Expand Down Expand Up @@ -817,15 +826,13 @@ Unexpected.prototype.addType = function(type, childUnexpected) {
);
}

return makeDiffResultBackwardsCompatible(
baseType.diff(
actual,
expected,
output.clone(),
(actual, expected) => that.diff(actual, expected, output.clone()),
(value, depth) => output.clone().appendInspected(value, depth),
that.equal.bind(that)
)
return baseType.diff(
actual,
expected,
output.clone(),
(actual, expected) => that.diff(actual, expected, output.clone()),
(value, depth) => output.clone().appendInspected(value, depth),
that.equal.bind(that)
);
};

Expand Down Expand Up @@ -1329,7 +1336,7 @@ Unexpected.prototype._expect = function expect(context, args) {

if (args.length < 2) {
throw new Error('The expect function requires at least two parameters.');
} else if (testDescriptionString && testDescriptionString._expectIt) {
} else if (typeof testDescriptionString === 'function') {
return that.expect.withError(
() => testDescriptionString(subject),
err => {
Expand Down Expand Up @@ -1404,7 +1411,7 @@ Unexpected.prototype._expect = function expect(context, args) {
wrappedExpect,
subject
);
} else if (testDescriptionString && testDescriptionString._expectIt) {
} else if (typeof testDescriptionString === 'function') {
wrappedExpect.errorMode = 'nested';
return wrappedExpect.withError(
() => testDescriptionString(subject),
Expand Down Expand Up @@ -1586,16 +1593,14 @@ Unexpected.prototype.diff = function(
seen.push(a);
}

return makeDiffResultBackwardsCompatible(
this.findCommonType(a, b).diff(
a,
b,
output,
(actual, expected) =>
that.diff(actual, expected, output.clone(), recursions - 1, seen),
(v, depth) => output.clone().appendInspected(v, depth),
(actual, expected) => that.equal(actual, expected)
)
return this.findCommonType(a, b).diff(
a,
b,
output,
(actual, expected) =>
that.diff(actual, expected, output.clone(), recursions - 1, seen),
(v, depth) => output.clone().appendInspected(v, depth),
(actual, expected) => that.equal(actual, expected)
);
};

Expand Down
15 changes: 6 additions & 9 deletions lib/UnexpectedError.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const utils = require('./utils');
const defaultDepth = require('./defaultDepth');
const useFullStackTrace = require('./useFullStackTrace');
const makeDiffResultBackwardsCompatible = require('./makeDiffResultBackwardsCompatible');

const errorMethodBlacklist = [
'message',
Expand Down Expand Up @@ -71,14 +70,12 @@ UnexpectedError.prototype.buildDiff = function(options) {
const expect = this.expect;
return (
this.createDiff &&
makeDiffResultBackwardsCompatible(
this.createDiff(
output,
(actual, expected) => expect.diff(actual, expected, output.clone()),
(v, depth) =>
output.clone().appendInspected(v, (depth || defaultDepth) - 1),
(actual, expected) => expect.equal(actual, expected)
)
this.createDiff(
output,
(actual, expected) => expect.diff(actual, expected, output.clone()),
(v, depth) =>
output.clone().appendInspected(v, (depth || defaultDepth) - 1),
(actual, expected) => expect.equal(actual, expected)
)
);
};
Expand Down
Loading

0 comments on commit 5591473

Please sign in to comment.