-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor bootstrap to take the 'config' and 'providers' as …
…arguments Pass the 'config' object and 'providers' array as arguments to the application bootstrap (src/bootstrap/index.js file) and have the boostrap inject the config into each provider's constructor
- Loading branch information
1 parent
7166b3e
commit 64a2db9
Showing
3 changed files
with
88 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-env node, mocha */ | ||
|
||
const { chai } = require("../lib/test-helper"); | ||
const bootstrap = require("."); | ||
|
||
let expect; | ||
|
||
|
||
module.exports = { | ||
bootstrap() { | ||
describe("bootstrap(config, providers)", function() { | ||
before(async function() { | ||
expect = (await chai()).expect; | ||
}); | ||
|
||
it("should throw if a provider is neither a constructor nor a class", function() { | ||
const providers = [ { register() {} } ]; | ||
|
||
expect(() => bootstrap({}, providers)).to.throw(/A Service Provider must be a class or constructor function/); | ||
}); | ||
|
||
it("should throw if a provider has no register method defined", function() { | ||
const providers = [ function TestServiceProvider() {} ]; | ||
|
||
expect(() => bootstrap({}, providers)).to.throw( | ||
"Service providers must define a 'register()' method. " + | ||
"Service Provider 'TestServiceProvider' has no 'register()' method defined." | ||
); | ||
}); | ||
|
||
it("should invoke the 'register()' method of every passed provider", function() { | ||
let className; | ||
let funcName; | ||
let protoFuncName; | ||
|
||
class ClassServiceProvider { | ||
register() { className = "ClassServiceProvider"; } | ||
} | ||
|
||
function FunctionServiceProvider() { | ||
this.register = function register() { | ||
funcName = "FunctionServiceProvider"; | ||
}; | ||
} | ||
|
||
function ProtoFunctionServiceProvider() {} | ||
|
||
ProtoFunctionServiceProvider.prototype.register = function register() { | ||
protoFuncName = "PrototypeInheritedRegisterMethod"; | ||
}; | ||
|
||
expect(className).to.be.undefined; | ||
expect(funcName).to.be.undefined; | ||
expect(protoFuncName).to.be.undefined; | ||
|
||
bootstrap({}, [ | ||
ClassServiceProvider, | ||
FunctionServiceProvider, | ||
ProtoFunctionServiceProvider | ||
]); | ||
|
||
expect(className).to.equal("ClassServiceProvider"); | ||
expect(funcName).to.equal("FunctionServiceProvider"); | ||
expect(protoFuncName).to.equal("PrototypeInheritedRegisterMethod"); | ||
}); | ||
}); | ||
} | ||
}; |