Skip to content

Commit

Permalink
Merge 4b6d5b0 into c39040b
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Nov 8, 2018
2 parents c39040b + 4b6d5b0 commit 2426c4a
Show file tree
Hide file tree
Showing 25 changed files with 501 additions and 441 deletions.
16 changes: 6 additions & 10 deletions .travis.yml
@@ -1,12 +1,8 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- "4"
- "5"
- "6"
- "7"
- "8.4.0"
- "9"
- "10"
script: "make travis"
- '6'
- '7'
- '8.4.0'
- '9'
- '10'
script: 'make travis'
9 changes: 3 additions & 6 deletions Makefile
Expand Up @@ -65,12 +65,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 All @@ -93,7 +90,7 @@ test-browser: create-html-runners ${TARGETS}
@./node_modules/.bin/serve .

.PHONY: travis-secondary
travis-secondary: clean test test-jest-if-supported-node-version coverage
travis-secondary: clean test test-jest coverage

.PHONY: travis-main
travis-main: clean lint test test-jasmine test-jest coverage
Expand Down Expand Up @@ -134,7 +131,7 @@ changelog: git-dirty-check
fi

.PHONY: release-%
release-%: git-dirty-check lint ${TARGETS} test-phantomjs test-jasmine test-jest-if-supported-node-version commit-unexpected deploy-site
release-%: git-dirty-check lint ${TARGETS} test-phantomjs 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
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
@@ -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
@@ -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
@@ -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
49 changes: 27 additions & 22 deletions lib/Unexpected.js
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
@@ -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

0 comments on commit 2426c4a

Please sign in to comment.