Skip to content

Commit bebaec7

Browse files
committed
feat: native promises instead bluebird
1 parent 8fb6e76 commit bebaec7

14 files changed

+750
-6649
lines changed

dist/hamjest.js

Lines changed: 654 additions & 6549 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hamjest.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
process.env.BLUEBIRD_DEBUG = 1;
4-
53
const gulp = require('gulp');
64
const gulpEslint = require('gulp-eslint');
75
const gulpMocha = require('gulp-mocha');

lib/Description.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const _isRegExp = require('lodash/isRegExp');
99
const _isString = require('lodash/isString');
1010
const _isUndefined = require('lodash/isUndefined');
1111
const _padEnd = require('lodash/padEnd');
12-
const Bluebird = require('bluebird');
1312

1413
function asSelfDescribing(value) {
1514
if (!value || !_isFunction(value.describeTo)) {
@@ -47,7 +46,7 @@ function Description() {
4746
this.indentation += 1;
4847
const result = describingfn();
4948
if (result && _isFunction(result.then)) {
50-
return Bluebird.resolve(result)
49+
return Promise.resolve(result)
5150
.finally(() => {
5251
this.indentation -= 1;
5352
});

lib/matchers/promiseAgnostic.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,35 @@ const _isArray = require('lodash/isArray');
66
const _isFunction = require('lodash/isFunction');
77
const _reduce = require('lodash/reduce');
88
const _some = require('lodash/some');
9-
const Bluebird = require('bluebird');
109

1110
function resolve(promises) {
1211
if (_isArray(promises)) {
13-
return Bluebird.all(promises);
12+
return Promise.all(promises);
1413
} else {
15-
return Bluebird.props(promises);
14+
return Promise.resolve(promises)
15+
.then((object) =>
16+
Promise.all(
17+
Object.entries(object).map(([key, value]) =>
18+
Promise.resolve(value).then((value) => [key, value])
19+
)
20+
)
21+
)
22+
.then((items) => {
23+
const results = {};
24+
25+
for (const [key, value] of items) {
26+
results[key] = value;
27+
}
28+
29+
return results;
30+
});
1631
}
1732
}
1833

1934
const promiseAgnostic = {
2035
matches: function (result, handler) {
2136
if (isPromise(result)) {
22-
return Bluebird.resolve(result).then(handler);
37+
return Promise.resolve(result).then(handler);
2338
} else {
2439
return handler(result);
2540
}
@@ -36,7 +51,7 @@ const promiseAgnostic = {
3651
return resolve(results).then((results) => {
3752
return _reduce(results, (chain, result, key) => {
3853
return chain.then(() => handler(result, key));
39-
}, Bluebird.resolve());
54+
}, Promise.resolve());
4055
})
4156
.then(suffixFn || _identity);
4257
} else {
@@ -50,7 +65,7 @@ const promiseAgnostic = {
5065
},
5166
describeMismatch: function (result, handler, suffixFn) {
5267
if (isPromise(result)) {
53-
return Bluebird.resolve(result)
68+
return Promise.resolve(result)
5469
.then(handler)
5570
.then(suffixFn || _identity);
5671
} else {

lib/promiseThat.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const _isFunction = require('lodash/isFunction');
44
const AssertionError = require('assertion-error');
5-
const Bluebird = require('bluebird');
6-
75
const Description = require('./Description');
86

97
function promiseThat(reason, actual, matcher) {
@@ -13,24 +11,24 @@ function promiseThat(reason, actual, matcher) {
1311
reason = '';
1412
}
1513

16-
return Bluebird.try(() => matcher.matches(actual)).then((result) => {
14+
return Promise.resolve().then(() => matcher.matches(actual)).then((result) => {
1715
if (!result) {
1816
const description = new Description();
1917
description.append(reason)
2018
.append('\nExpected: ')
2119
.appendDescriptionOf(matcher)
2220
.append('\n but: ');
23-
return Bluebird.try(() => matcher.describeMismatch(actual, description))
21+
return Promise.resolve().then(() => matcher.describeMismatch(actual, description))
2422
.then(() => {
2523
if (!_isFunction(matcher.getExpectedForDiff) ||
2624
!_isFunction(matcher.formatActualForDiff)) {
2725
return {};
2826
}
2927

30-
return Bluebird.all([
28+
return Promise.all([
3129
matcher.getExpectedForDiff(),
3230
matcher.formatActualForDiff(actual)
33-
]).spread((expected, actual) => {
31+
]).then(([expected, actual]) => {
3432
return {
3533
showDiff: true,
3634
expected: expected,

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
],
4444
"dependencies": {
4545
"assertion-error": "^1.1.0",
46-
"bluebird": "^3.3.4",
4746
"lodash": "^4.17.15"
4847
},
4948
"devDependencies": {

test/node/assertThatSpec.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
'use strict';
22

33
const assert = require('assert');
4-
54
const AssertionError = require('assertion-error');
6-
const Bluebird = require('bluebird');
75

86
const __ = require('../..');
97
const TestMatcher = require('./TestMatcher');
@@ -93,7 +91,7 @@ describe('assertThat', () => {
9391
let thrown;
9492

9593
try {
96-
__.assertThat('a value', new TestMatcher(() => Bluebird.resolve(true)));
94+
__.assertThat('a value', new TestMatcher(() => Promise.resolve(true)));
9795
} catch (e) {
9896
thrown = e;
9997
}

test/node/deferMatcher.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
'use strict';
22

3-
const Bluebird = require('bluebird');
4-
53
function deferMatcher(matcher) {
64
return {
75
matches: function (actual) {
8-
return Bluebird.try(() => matcher.matches(actual));
6+
return Promise.resolve().then(() => matcher.matches(actual));
97
},
108
describeTo: function (description) {
119
description.append('deferred: ');
1210
matcher.describeTo(description);
1311
},
1412
describeMismatch: function (actual, description) {
1513
description.append('deferred: ');
16-
return Bluebird.try(() => matcher.describeMismatch(actual, description));
14+
return Promise.resolve().then(() => matcher.describeMismatch(actual, description));
1715
}
1816
};
1917
}

0 commit comments

Comments
 (0)