-
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.
feat: Add possibility to stop a karma server
Add detached mode using the `karma start --detached` command. Add middleware for stopping a server (detached or not). Described the detached option.
- Loading branch information
Showing
9 changed files
with
193 additions
and
19 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
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,18 @@ | ||
/** | ||
* Stopper middleware is responsible for communicating with `karma stop`. | ||
*/ | ||
|
||
var log = require('../logger').create('middleware:stopper') | ||
|
||
var createStopperMiddleware = function (urlRoot) { | ||
return function (request, response, next) { | ||
if (request.url !== urlRoot + 'stop') return next() | ||
response.writeHead(200) | ||
log.info('Stopping server') | ||
response.end('OK') | ||
process.exit(0) | ||
} | ||
} | ||
|
||
createStopperMiddleware.$inject = ['config.urlRoot'] | ||
exports.create = createStopperMiddleware |
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,33 @@ | ||
var http = require('http') | ||
|
||
var cfg = require('./config') | ||
var logger = require('./logger') | ||
|
||
exports.stop = function (config) { | ||
logger.setupFromConfig(config) | ||
var log = logger.create('stopper') | ||
config = cfg.parseConfig(config.configFile, config) | ||
var options = { | ||
hostname: config.hostname, | ||
path: config.urlRoot + 'stop', | ||
port: config.port, | ||
method: 'GET' | ||
} | ||
|
||
var request = http.request(options) | ||
|
||
request.on('response', function (response) { | ||
log.info('Server stopped.') | ||
process.exit(response.statusCode === 200 ? 0 : 1) | ||
}) | ||
|
||
request.on('error', function (e) { | ||
if (e.code === 'ECONNREFUSED') { | ||
log.error('There is no server listening on port %d', options.port) | ||
process.exit(1, e.code) | ||
} else { | ||
throw e | ||
} | ||
}) | ||
request.end() | ||
} |
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,42 @@ | ||
Feature: Stop karma | ||
TODO write this | ||
|
||
Scenario: A server can't be stopped if it isn't running | ||
When I stop Karma | ||
Then it fails with like: | ||
""" | ||
ERROR \[stopper\]: There is no server listening on port [0-9]+ | ||
""" | ||
|
||
Scenario: A server can be stopped | ||
Given a configuration with: | ||
""" | ||
files = ['basic/plus.js', 'basic/test.js']; | ||
browsers = ['PhantomJS']; | ||
plugins = [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher' | ||
]; | ||
singleRun = false; | ||
""" | ||
When I start a server in background | ||
And I stop Karma | ||
Then The server is dead with exit code 0 | ||
|
||
Scenario: A server can be stopped and give informative output | ||
Given a configuration with: | ||
""" | ||
files = ['basic/plus.js', 'basic/test.js']; | ||
browsers = ['PhantomJS']; | ||
plugins = [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher' | ||
]; | ||
singleRun = false; | ||
""" | ||
When I start a server in background | ||
And I stop Karma with log-level info | ||
Then it passes with like: | ||
""" | ||
Server stopped. | ||
""" |