-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for mocking services #90
Open
adamrbennett
wants to merge
15
commits into
BlueOakJS:master
Choose a base branch
from
adamrbennett:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b419565
Add mocks command line argument
bba06c9
Load mock services when appropriate
e254f78
Add test for mocks
2a35017
Use lodash to support older JS runtimes
ec59917
Prepare to support mocking things other than services
be88f40
Improve mock tests
6f25a0a
Use commander instead of minimist for cli option parsing
b7b815d
Use test directory instead of tests
4e42609
Add documentation for mocking services
cf7cd71
Improve and add mock tests
73d4235
Refactor to add support for mocking service modules
822be83
Fix lint errors
7b00fe0
Restore tests
d7379f5
Add support for mocking middleware
2660153
Update docs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
10 changes: 10 additions & 0 deletions
10
test/integration/fixtures/server12/middleware/pet-middleware1.js
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,10 @@ | ||
exports.init = function (app, config, logger, callback) { | ||
app.use(middleware); | ||
logger.info('Pet Middleware1 initialized'); | ||
callback(); | ||
}; | ||
|
||
function middleware(req, res, next) { | ||
res.header('x-pet-middleware1', 'pet-middleware1'); | ||
next(); | ||
} |
10 changes: 10 additions & 0 deletions
10
test/integration/fixtures/server12/middleware/pet-middleware2.js
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,10 @@ | ||
exports.init = function (app, config, logger, callback) { | ||
app.use(middleware); | ||
logger.info('Pet Middleware2 initialized'); | ||
callback(); | ||
}; | ||
|
||
function middleware(req, res, next) { | ||
res.header('x-pet-middleware2', 'pet-middleware2'); | ||
next(); | ||
} |
10 changes: 10 additions & 0 deletions
10
test/integration/fixtures/server12/test/bos-mocks/middleware/pet-middleware1.js
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,10 @@ | ||
exports.init = function (app, config, logger, callback) { | ||
app.use(middleware); | ||
logger.info('Pet Middleware1 Mock initialized'); | ||
callback(); | ||
}; | ||
|
||
function middleware(req, res, next) { | ||
res.header('x-pet-middleware1', 'pet-middleware1-mock'); | ||
next(); | ||
} |
10 changes: 10 additions & 0 deletions
10
test/integration/fixtures/server12/test/bos-mocks/middleware/pet-middleware2.js
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,10 @@ | ||
exports.init = function (app, config, logger, callback) { | ||
app.use(middleware); | ||
logger.info('Pet Middleware2 Mock initialized'); | ||
callback(); | ||
}; | ||
|
||
function middleware(req, res, next) { | ||
res.header('x-pet-middleware2', 'pet-middleware2-mock'); | ||
next(); | ||
} |
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,10 @@ | ||
{ | ||
"express": { | ||
"port": "5000", | ||
"middleware": ["pet-middleware"] | ||
}, | ||
|
||
"cluster": { | ||
"maxWorkers": 1 | ||
} | ||
} |
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,24 @@ | ||
/* | ||
* Copyright (c) 2015-2016 PointSource, LLC. | ||
* MIT Licensed | ||
*/ | ||
var service1; | ||
var service2; | ||
var serviceModule; | ||
exports.init = function (logger, petService1, petService2, petServiceModule) { | ||
service1 = petService1; | ||
service2 = petService2; | ||
serviceModule = petServiceModule; | ||
}; | ||
|
||
exports.getPets1 = function (req, res, next) { | ||
res.send(service1.getPets()); | ||
}; | ||
|
||
exports.getPets2 = function (req, res, next) { | ||
res.send(service2.getPets()); | ||
}; | ||
|
||
exports.getPets3 = function (req, res, next) { | ||
res.send(serviceModule.getPets()); | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/integration/fixtures/server13/middleware/pet-middleware.js
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,3 @@ | ||
exports.init = function () { | ||
|
||
}; |
14 changes: 14 additions & 0 deletions
14
test/integration/fixtures/server13/node_modules/pet-service-module/index.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
test/integration/fixtures/server13/services/pet-service1.js
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,14 @@ | ||
/* | ||
* Copyright (c) 2015-2016 PointSource, LLC. | ||
* MIT Licensed | ||
*/ | ||
exports.init = function(logger) { | ||
logger.info('Pet Service1 initialized'); | ||
}; | ||
|
||
exports.getPets = function() { | ||
return { | ||
id: 1, | ||
name: 'service1 pet' | ||
}; | ||
}; |
14 changes: 14 additions & 0 deletions
14
test/integration/fixtures/server13/services/pet-service2.js
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,14 @@ | ||
/* | ||
* Copyright (c) 2015-2016 PointSource, LLC. | ||
* MIT Licensed | ||
*/ | ||
exports.init = function(logger) { | ||
logger.info('Pet Service2 initialized'); | ||
}; | ||
|
||
exports.getPets = function() { | ||
return { | ||
id: 2, | ||
name: 'service2 pet' | ||
}; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Middleware mocks were not loading because middleware was not loaded with
subRequire
. I did this to make it work, but admittedly do not understand all of the potential ramifications of this change.