Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

strongloop / node-foreman / 275

9 May 2016 - 4:39 First build on master at 90.726%
275

Pull #117

travis-ci

8bd1dd86bbf8705a5a702b86a2f3a390?size=18&default=identiconrmg
fixup! ci: generate test report on appveyor
Pull Request #117: WIP: Upgrade all outdated dependencies

63 of 66 new or added lines in 6 files covered. (95.45%)

587 of 647 relevant lines covered (90.73%)

73.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/lib/proc.js
1
// Copyright IBM Corp. 2012,2016. All Rights Reserved.
2
// Node module: foreman
3
// This file is licensed under the MIT License.
4
// License text available at https://opensource.org/licenses/MIT
5

6
var prog       = require('child_process');
60×
7

8
var cons       = require('./console').Console;
60×
9

10
var _colors    = require('./colors');
60×
11
var colors_max = _colors.colors_max;
60×
12
var colors     = _colors.colors;
60×
13

14
var os         = require('os');
60×
15
var platform   = os.platform();
60×
16

17
// Run a Specific Process
18
// - Key is a Process Name and Number
19
// - Proc is an object with the launch properties
20
//
21
// i.e. web=2 becomes the web.2 key
22
function run(key, proc, emitter) {
60×
23
  var file, args;
32×
24
  if (platform === 'win32') {
32×
25
    file = process.env.comspec || 'cmd.exe';
!
26
    args = ['/s', '/c', proc.command];
!
27
  } else {
28
    file = '/bin/sh';
32×
29
    args = ['-c', proc.command];
32×
30
  }
31
  var child = prog.spawn(file, args, { env: proc.env });
32×
32

33
  child.stdout.on('data', function(data) {
32×
34
    cons.log(key, proc, data.toString());
24×
35
  });
36

37
  child.stderr.on('data', function(data) {
32×
38
    cons.log(key, proc, data.toString());
38×
39
  });
40

41
  child.on('close', function(code) {
32×
42
    if(code === 0) {
32×
43
      cons.info(key, proc, "Exited Successfully");
10×
44
    } else {
45
      cons.error(key, proc, "Exited with exit code " + code);
22×
46
    }
47
  });
48

49
  child.on('exit', function(code, signal) {
32×
50
    emitter.emit('killall', signal);
32×
51
  });
52

53
  emitter.on('killall', function(signal) {
32×
54
    try {
80×
55
      child.kill(signal);
80×
56
    } catch(_e) {
NEW
57
      cons.Warn('Proxy server already dead');
!
58
    }
59
  });
60

61
}
62

63
// Run a Specific Process Once using the ENV variables
64
// from the .env file
65
function once(input, envs, callback) {
60×
66
  var file, args;
8×
67
  var proc = {
8×
68
    command : input,
69
    env     : merge(merge({}, process.env), envs)
70
  };
71

72
  if (platform === 'win32') {
8×
73
    file = process.env.comspec || 'cmd.exe';
!
74
    args = ['/s', '/c', proc.command];
!
75
  } else {
76
    file = '/bin/sh';
8×
77
    args = ['-c', proc.command];
8×
78
  }
79

80
  var child = prog.spawn(file, args, { env: proc.env, stdio: 'inherit' });
8×
81

82
  child.on('close', function(code) {
8×
83
    callback(code);
8×
84
  });
85
}
86

87
// Figure Out What to Start Based on Procfile Processes
88
// And Requirements Passed as Command Line Arguments
89
//
90
// e.g. web=2,api=3 are requirements
91
function start(procs, requirements, envs, portarg, emitter){
60×
92

93
  var j = 0;
16×
94
  var k = 0;
16×
95
  var port = parseInt(portarg);
16×
96

97
  if(port < 1024) {
16×
98
    return cons.Error('Only Proxies Can Bind to Privileged Ports - '+
!
99
                      'Try \'sudo nf start -x %s\'', port);
100
  }
101

102

103
  for(var key in requirements) {
16×
104
    var n = parseInt(requirements[key]);
32×
105

106
    for(var i = 0; i < n; i++) {
32×
107

108
      var color_val = (j + k) % colors_max;
32×
109

110
      if (!procs[key]) {
32×
111
        cons.Warn("Required Key '%s' Does Not Exist in Procfile Definition", key);
!
112
        continue;
!
113
      }
114

115
      var p = {
32×
116
        command : procs[key],
117
        color   : colors[color_val],
118
        env     : merge(merge({}, process.env), envs)
119
      };
120

121
      p.env.PORT = port + j + k * 100;
32×
122
      p.env.FOREMAN_WORKER_NAME = p.env.FOREMAN_WORKER_NAME || key + "." + (i + 1);
32×
123

124
      run(key + "." + (i + 1), p, emitter);
32×
125

126
      j++;
32×
127

128
    }
129
    j = 0;
32×
130
    k++;
32×
131
  }
132
}
133

134
// Merge object b into object a
135
function merge(a, b) {
60×
136
  if (a && b) {
80×
137
    for (var key in b) {
76×
138
      a[key] = b[key];
8,552×
139
    }
140
  }
141
  return a;
80×
142
}
143

144
module.exports.start = start;
60×
145
module.exports.run   = run;
60×
146
module.exports.once  = once;
60×
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc