-
-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: move logic into separate file and rename
This is basically a small cleanup of the work done to get rid of Proxyquire before the release of version 17. - Pull out Sinon extraction to own file to avoid needless export on the root Sinon object - Rename file to match Colorizer class
- Loading branch information
Showing
8 changed files
with
74 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
|
||
const behavior = require("./sinon/behavior"); | ||
const createSandbox = require("./sinon/create-sandbox"); | ||
const extend = require("./sinon/util/core/extend"); | ||
const fakeTimers = require("./sinon/util/fake-timers"); | ||
const Sandbox = require("./sinon/sandbox"); | ||
const stub = require("./sinon/stub"); | ||
const promise = require("./sinon/promise"); | ||
const assert = require("node:assert"); | ||
|
||
/** | ||
* @param {object} opts injection point to override the default XHR lib in testing | ||
* @param {object} opts.sinonXhrLib | ||
* @returns {object} a configured sandbox | ||
*/ | ||
module.exports = function createApi({ sinonXhrLib }) { | ||
assert(sinonXhrLib, "No XHR lib passed in"); | ||
|
||
const apiMethods = { | ||
createSandbox: createSandbox, | ||
assert: require("./sinon/assert"), | ||
match: require("@sinonjs/samsam").createMatcher, | ||
restoreObject: require("./sinon/restore-object"), | ||
|
||
expectation: require("./sinon/mock-expectation"), | ||
defaultConfig: require("./sinon/util/core/default-config"), | ||
|
||
// fake timers | ||
timers: fakeTimers.timers, | ||
|
||
// fake XHR | ||
xhr: sinonXhrLib.fakeXhr.xhr, | ||
FakeXMLHttpRequest: sinonXhrLib.fakeXhr.FakeXMLHttpRequest, | ||
|
||
// fake server | ||
fakeServer: sinonXhrLib.fakeServer, | ||
fakeServerWithClock: sinonXhrLib.fakeServerWithClock, | ||
createFakeServer: sinonXhrLib.fakeServer.create.bind( | ||
sinonXhrLib.fakeServer, | ||
), | ||
createFakeServerWithClock: sinonXhrLib.fakeServerWithClock.create.bind( | ||
sinonXhrLib.fakeServerWithClock, | ||
), | ||
|
||
addBehavior: function (name, fn) { | ||
behavior.addBehavior(stub, name, fn); | ||
}, | ||
|
||
// fake promise | ||
promise: promise, | ||
}; | ||
|
||
const sandbox = new Sandbox(); | ||
return extend(sandbox, apiMethods); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,6 @@ | ||
"use strict"; | ||
|
||
const behavior = require("./sinon/behavior"); | ||
const createSandbox = require("./sinon/create-sandbox"); | ||
const extend = require("./sinon/util/core/extend"); | ||
const fakeTimers = require("./sinon/util/fake-timers"); | ||
const nise = require("nise"); | ||
const Sandbox = require("./sinon/sandbox"); | ||
const stub = require("./sinon/stub"); | ||
const promise = require("./sinon/promise"); | ||
const createApi = require("./create-sinon-api"); | ||
|
||
/** | ||
* @param {object} opts injection point to override the default XHR lib in testing | ||
* @param {object} opts.sinonXhrLib | ||
* @returns {object} a configured sandbox | ||
*/ | ||
function createApi({ sinonXhrLib }) { | ||
const apiMethods = { | ||
createSandbox: createSandbox, | ||
assert: require("./sinon/assert"), | ||
match: require("@sinonjs/samsam").createMatcher, | ||
restoreObject: require("./sinon/restore-object"), | ||
|
||
expectation: require("./sinon/mock-expectation"), | ||
defaultConfig: require("./sinon/util/core/default-config"), | ||
|
||
// fake timers | ||
timers: fakeTimers.timers, | ||
|
||
// fake XHR | ||
xhr: sinonXhrLib.fakeXhr.xhr, | ||
FakeXMLHttpRequest: sinonXhrLib.fakeXhr.FakeXMLHttpRequest, | ||
|
||
// fake server | ||
fakeServer: sinonXhrLib.fakeServer, | ||
fakeServerWithClock: sinonXhrLib.fakeServerWithClock, | ||
createFakeServer: sinonXhrLib.fakeServer.create.bind( | ||
sinonXhrLib.fakeServer, | ||
), | ||
createFakeServerWithClock: sinonXhrLib.fakeServerWithClock.create.bind( | ||
sinonXhrLib.fakeServerWithClock, | ||
), | ||
|
||
addBehavior: function (name, fn) { | ||
behavior.addBehavior(stub, name, fn); | ||
}, | ||
|
||
// fake promise | ||
promise: promise, | ||
}; | ||
|
||
const sandbox = new Sandbox(); | ||
return extend(sandbox, apiMethods); | ||
} | ||
|
||
const api = createApi({ sinonXhrLib: nise }); | ||
|
||
module.exports = api; | ||
|
||
// solely exposed for easier testing | ||
module.exports.createApi = createApi; | ||
module.exports = createApi({ sinonXhrLib: nise }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters