-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2183 from jamestalmage/allow-frameworks-to-inject…
…-middleware Allow frameworks to inject middleware
- Loading branch information
Showing
9 changed files
with
131 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Feature: Middleware | ||
In order to use Karma | ||
As a person who wants to write great tests | ||
I want to use custom middleware with Karma. | ||
|
||
Scenario: Simple middleware | ||
Given a configuration with: | ||
""" | ||
files = ['middleware/test.js']; | ||
browsers = ['PhantomJS']; | ||
plugins = [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
_resolve('middleware/middleware') | ||
]; | ||
middleware = [ | ||
'foo' | ||
] | ||
""" | ||
When I start Karma | ||
Then it passes with: | ||
""" | ||
. | ||
PhantomJS | ||
""" | ||
|
||
Scenario: Frameworks can add middleware | ||
Given a configuration with: | ||
""" | ||
files = ['middleware/test.js']; | ||
browsers = ['PhantomJS']; | ||
plugins = [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
_resolve('middleware/middleware') | ||
]; | ||
frameworks = ['jasmine', 'foo'] | ||
""" | ||
When I start Karma | ||
Then it passes with: | ||
""" | ||
. | ||
PhantomJS | ||
""" |
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 |
---|---|---|
|
@@ -19,5 +19,4 @@ Feature: Passing Options | |
Then it passes with no debug: | ||
""" | ||
. | ||
PhantomJS | ||
""" |
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,21 @@ | ||
function middleware (request, response, next) { | ||
if (/\/foo\.js/.test(request.normalizedUrl)) { | ||
response.setHeader('Content-Type', 'text/plain') | ||
response.writeHead(200) | ||
response.end('this is the middleware response') | ||
return | ||
} | ||
next() | ||
} | ||
|
||
function framework (config) { | ||
config.middleware = config.middleware || [] | ||
config.middleware.push('foo') | ||
} | ||
|
||
framework.$inject = ['config'] | ||
|
||
module.exports = { | ||
'framework:foo': ['factory', framework], | ||
'middleware:foo': ['value', middleware] | ||
} |
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 @@ | ||
function httpGet (url) { | ||
var xmlHttp = new XMLHttpRequest() | ||
|
||
xmlHttp.open('GET', url, false) | ||
xmlHttp.send(null) | ||
|
||
return xmlHttp.responseText | ||
} | ||
|
||
describe('foo', function () { | ||
it('should should serve /foo.js', function () { | ||
expect(httpGet('/foo.js')).toBe('this is the middleware response') | ||
}) | ||
}) |
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,11 @@ | ||
function framework (config) { | ||
config.proxies = { | ||
'/foo.js': '/base/proxy/foo.js' | ||
} | ||
} | ||
|
||
framework.$inject = ['config'] | ||
|
||
module.exports = { | ||
'framework:foo': ['factory', framework] | ||
} |
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