Skip to content

Commit b6daed2

Browse files
committed
chore!: remove usingPromise
Everyone should be using native promises by now, or should know how to stub natives
1 parent 95d4b8f commit b6daed2

File tree

14 files changed

+2
-430
lines changed

14 files changed

+2
-430
lines changed

docs/release-source/release/examples/stubs-10-use-promise-library.test.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/release-source/release/mocks.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ If any expectation is not satisfied, an exception is thrown.
7777

7878
Also restores the mocked methods.
7979

80-
#### `mock.usingPromise(promiseLibrary);`
81-
82-
Causes all expectations created from the mock to return promises using a specific
83-
Promise library instead of the global one when using `expectation.rejects` or
84-
`expectation.resolves`. Returns the mock object to allow chaining.
85-
86-
_Since `sinon@6.2.0`_
87-
8880
### Expectations
8981

9082
All the expectation methods return the expectation, meaning you can chain them.

docs/release-source/release/sandbox.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,6 @@ Fakes timers and binds the `clock` object to the sandbox such that it too is res
303303

304304
Access through `sandbox.clock`.
305305

306-
#### `sandbox.usingPromise(promiseLibrary);`
307-
308-
Causes all stubs and mocks created from the sandbox to return promises using a specific
309-
Promise library instead of the global one when using `stub.rejects` or
310-
`stub.resolves`. Returns the stub to allow chaining.
311-
312-
_Since `sinon@2.0.0`_
313-
314306
#### `sandbox.restore();`
315307

316308
Restores all fakes created through sandbox.

docs/release-source/release/stubs.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ examples:
1212
- stubs-7-call-fake
1313
- stubs-8-call-through
1414
- stubs-9-call-through-with-new
15-
- stubs-10-use-promise-library
1615
- stubs-12-yield-to
1716
- stubs-14-add-behavior
1817
- stubs-15-replace-getter
@@ -232,7 +231,6 @@ Causes the stub to return a Promise which resolves to the provided value.
232231

233232
When constructing the Promise, sinon uses the `Promise.resolve` method. You are
234233
responsible for providing a polyfill in environments which do not provide `Promise`.
235-
The Promise library can be overwritten using the `usingPromise` method.
236234

237235
_Since `sinon@2.0.0`_
238236

@@ -283,7 +281,6 @@ Causes the stub to return a Promise which rejects with an exception (`Error`).
283281

284282
When constructing the Promise, sinon uses the `Promise.reject` method. You are
285283
responsible for providing a polyfill in environments which do not provide `Promise`.
286-
The Promise library can be overwritten using the `usingPromise` method.
287284

288285
_Since `sinon@2.0.0`_
289286

@@ -332,16 +329,6 @@ Like `callsArg`, but with arguments to pass to the callback.
332329

333330
Like above but with an additional parameter to pass the `this` context.
334331

335-
#### `stub.usingPromise(promiseLibrary);`
336-
337-
Causes the stub to return promises using a specific Promise library instead of
338-
the global one when using `stub.rejects` or `stub.resolves`. Returns the stub
339-
to allow chaining.
340-
341-
<div data-example-id="stubs-10-use-promise-library"></div>
342-
343-
_Since `sinon@2.0.0`_
344-
345332
#### `stub.yields([arg1, arg2, ...])`
346333

347334
Similar to `callsArg`.

lib/sinon/default-behaviors.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ const slice = arrayProto.slice;
1010
const useLeftMostCallback = -1;
1111
const useRightMostCallback = -2;
1212

13-
const logger = require("@sinonjs/commons").deprecated;
14-
const wrap = logger.wrap;
15-
1613
function throwsException(fake, error, message) {
1714
if (typeof error === "function") {
1815
fake.exceptionCreator = error;
@@ -93,10 +90,6 @@ const defaultBehaviors = {
9390
fake.callsThrough = false;
9491
},
9592

96-
usingPromise: wrap(function usingPromise(fake, promiseLibrary) {
97-
fake.promiseLibrary = promiseLibrary;
98-
}, "usingPromise has been deprecated, and will be removed in the next major version"),
99-
10093
yields: function (fake) {
10194
fake.callArgAt = useLeftMostCallback;
10295
fake.callbackArguments = slice(arguments, 1);

lib/sinon/fake.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
const arrayProto = require("@sinonjs/commons").prototypes.array;
44
const createProxy = require("./proxy");
55
const nextTick = require("./util/core/next-tick");
6-
const logger = require("@sinonjs/commons").deprecated;
7-
const wrap = logger.wrap;
86

97
const slice = arrayProto.slice;
10-
let promiseLib = Promise;
118

129
module.exports = fake;
1310

@@ -121,7 +118,7 @@ fake.throws = function throws(value) {
121118
fake.resolves = function resolves(value) {
122119
// eslint-disable-next-line jsdoc/require-jsdoc
123120
function f() {
124-
return promiseLib.resolve(value);
121+
return Promise.resolve(value);
125122
}
126123

127124
return wrapFunc(f);
@@ -149,29 +146,12 @@ fake.resolves = function resolves(value) {
149146
fake.rejects = function rejects(value) {
150147
// eslint-disable-next-line jsdoc/require-jsdoc
151148
function f() {
152-
return promiseLib.reject(getError(value));
149+
return Promise.reject(getError(value));
153150
}
154151

155152
return wrapFunc(f);
156153
};
157154

158-
/**
159-
* Causes `fake` to use a custom Promise implementation, instead of the native
160-
* Promise implementation.
161-
*
162-
* @example
163-
* const bluebird = require("bluebird");
164-
* sinon.fake.usingPromise(bluebird);
165-
*
166-
* @memberof fake
167-
* @param {*} promiseLibrary
168-
* @returns {Function}
169-
*/
170-
fake.usingPromise = wrap(function usingPromise(promiseLibrary) {
171-
promiseLib = promiseLibrary;
172-
return fake;
173-
}, "usingPromise has been deprecated, and will be removed in the next major version");
174-
175155
/**
176156
* Returns a `fake` that calls the callback with the defined arguments.
177157
*

lib/sinon/mock.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const proxyCallToString = require("./proxy-call").toString;
66
const extend = require("./util/core/extend");
77
const deepEqual = require("@sinonjs/samsam").deepEqual;
88
const wrapMethod = require("./util/core/wrap-method");
9-
const usePromiseLibrary = require("./util/core/use-promise-library");
109

1110
const concat = arrayProto.concat;
1211
const filter = arrayProto.filter;
@@ -17,9 +16,6 @@ const push = arrayProto.push;
1716
const slice = arrayProto.slice;
1817
const unshift = arrayProto.unshift;
1918

20-
const logger = require("@sinonjs/commons").deprecated;
21-
const wrap = logger.wrap;
22-
2319
function mock(object) {
2420
if (!object || typeof object === "string") {
2521
return mockExpectation.create(object ? object : "Anonymous mock");
@@ -81,7 +77,6 @@ extend(mock, {
8177
const expectation = mockExpectation.create(method);
8278
expectation.wrappedMethod = this.object[method].wrappedMethod;
8379
push(this.expectations[method], expectation);
84-
usePromiseLibrary(this.promiseLibrary, expectation);
8580

8681
return expectation;
8782
},
@@ -122,12 +117,6 @@ extend(mock, {
122117
return true;
123118
},
124119

125-
usingPromise: wrap(function usingPromise(promiseLibrary) {
126-
this.promiseLibrary = promiseLibrary;
127-
128-
return this;
129-
}, "usingPromise has been deprecated, and will be removed in the next major version"),
130-
131120
invokeMethod: function invokeMethod(method, thisValue, args) {
132121
/* if we cannot find any matching files we will explicitly call mockExpection#fail with error messages */
133122
/* eslint consistent-return: "off" */

lib/sinon/sandbox.js

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

33
const arrayProto = require("@sinonjs/commons").prototypes.array;
44
const logger = require("@sinonjs/commons").deprecated;
5-
const wrap = logger.wrap;
65
const collectOwnMethods = require("./collect-own-methods");
76
const getPropertyDescriptor = require("./util/core/get-property-descriptor");
87
const isPropertyConfigurable = require("./util/core/is-property-configurable");
@@ -15,7 +14,6 @@ const sinonStub = require("./stub");
1514
const sinonCreateStubInstance = require("./create-stub-instance");
1615
const sinonFake = require("./fake");
1716
const valueToString = require("@sinonjs/commons").valueToString;
18-
const usePromiseLibrary = require("./util/core/use-promise-library");
1917

2018
const DEFAULT_LEAK_THRESHOLD = 10000;
2119

@@ -79,7 +77,6 @@ function Sandbox(opts = {}) {
7977
const sandbox = this;
8078
const assertOptions = opts.assertOptions || {};
8179
let fakeRestorers = [];
82-
let promiseLib;
8380

8481
let collection = [];
8582
let loggedLeakWarning = false;
@@ -114,8 +111,6 @@ function Sandbox(opts = {}) {
114111
addToCollection(method);
115112
});
116113

117-
usePromiseLibrary(promiseLib, ownMethods);
118-
119114
return stubbed;
120115
};
121116

@@ -169,7 +164,6 @@ function Sandbox(opts = {}) {
169164
const m = sinonMock.apply(null, arguments);
170165

171166
addToCollection(m);
172-
usePromiseLibrary(promiseLib, m);
173167

174168
return m;
175169
};
@@ -422,16 +416,12 @@ function Sandbox(opts = {}) {
422416
forEach(ownMethods, function (method) {
423417
addToCollection(method);
424418
});
425-
426-
usePromiseLibrary(promiseLib, ownMethods);
427419
} else if (Array.isArray(types)) {
428420
for (const accessorType of types) {
429421
addToCollection(spy[accessorType]);
430-
usePromiseLibrary(promiseLib, spy[accessorType]);
431422
}
432423
} else {
433424
addToCollection(spy);
434-
usePromiseLibrary(promiseLib, spy);
435425
}
436426

437427
return spy;
@@ -497,18 +487,6 @@ function Sandbox(opts = {}) {
497487
throw exception;
498488
}
499489
};
500-
501-
function usingPromise(promiseLibrary) {
502-
promiseLib = promiseLibrary;
503-
collection.promiseLibrary = promiseLibrary;
504-
505-
return sandbox;
506-
}
507-
508-
sandbox.usingPromise = wrap(
509-
usingPromise,
510-
"usingPromise has been deprecated, and will be removed in the next major version",
511-
);
512490
}
513491

514492
Sandbox.prototype.match = match;

lib/sinon/util/core/use-promise-library.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

test/fake-test.js

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -485,47 +485,4 @@ describe("fake", function () {
485485
assert.same(myFake.printf, proxy.printf);
486486
});
487487
});
488-
489-
describe(".usingPromise", function () {
490-
before(requirePromiseSupport);
491-
492-
it("should exist and be a function", function () {
493-
assert(fake.usingPromise);
494-
assert.isFunction(fake.usingPromise);
495-
});
496-
497-
it("should set the promise used by resolve", function () {
498-
const promise = {
499-
resolve: function (value) {
500-
return Promise.resolve(value);
501-
},
502-
};
503-
const object = {};
504-
505-
const myFake = fake.usingPromise(promise).resolves(object);
506-
507-
return myFake().then(function (actual) {
508-
assert.same(actual, object, "Same object resolved");
509-
});
510-
});
511-
512-
it("should set the promise used by reject", function () {
513-
const promise = {
514-
reject: function (err) {
515-
return Promise.reject(err);
516-
},
517-
};
518-
const reason = new Error();
519-
520-
const myFake = fake.usingPromise(promise).rejects(reason);
521-
522-
return myFake()
523-
.then(function () {
524-
referee.fail("this should not resolve");
525-
})
526-
.catch(function (actual) {
527-
assert.same(actual, reason, "Same object resolved");
528-
});
529-
});
530-
});
531488
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy