source: trip-planner-front/node_modules/karma/lib/stopper.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1const http = require('http')
2const cfg = require('./config')
3const logger = require('./logger')
4const helper = require('./helper')
5
6exports.stop = function (cliOptionsOrConfig, done) {
7 cliOptionsOrConfig = cliOptionsOrConfig || {}
8 const log = logger.create('stopper')
9 done = helper.isFunction(done) ? done : process.exit
10
11 let config
12 if (cliOptionsOrConfig instanceof cfg.Config) {
13 config = cliOptionsOrConfig
14 } else {
15 logger.setupFromConfig({
16 colors: cliOptionsOrConfig.colors,
17 logLevel: cliOptionsOrConfig.logLevel
18 })
19 const deprecatedCliOptionsMessage =
20 'Passing raw CLI options to `stopper(config, done)` is deprecated. Use ' +
21 '`parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` ' +
22 'to prepare a processed `Config` instance and pass that as the ' +
23 '`config` argument instead.'
24 log.warn(deprecatedCliOptionsMessage)
25 try {
26 config = cfg.parseConfig(
27 cliOptionsOrConfig.configFile,
28 cliOptionsOrConfig,
29 {
30 promiseConfig: false,
31 throwErrors: true
32 }
33 )
34 } catch (parseConfigError) {
35 // TODO: change how `done` falls back to exit in next major version
36 // SEE: https://github.com/karma-runner/karma/pull/3635#discussion_r565399378
37 done(1)
38 }
39 }
40
41 const request = http.request({
42 hostname: config.hostname,
43 path: config.urlRoot + 'stop',
44 port: config.port,
45 method: 'GET'
46 })
47
48 request.on('response', function (response) {
49 if (response.statusCode === 200) {
50 log.info('Server stopped.')
51 done(0)
52 } else {
53 log.error(`Server returned status code: ${response.statusCode}`)
54 done(1)
55 }
56 })
57
58 request.on('error', function (e) {
59 if (e.code === 'ECONNREFUSED') {
60 log.error(`There is no server listening on port ${config.port}`)
61 done(1, e.code)
62 } else {
63 throw e
64 }
65 })
66 request.end()
67}
Note: See TracBrowser for help on using the repository browser.