Skip to content

Commit 35a3122

Browse files
committed
edit tests
1 parent 1846c5c commit 35a3122

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

lib/API/Extra.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ module.exports = function(CLI) {
326326
Common.printError(err);
327327
return cb ? cb(Common.retErr(err)) : that.exitCli(cst.ERROR_EXIT);
328328
}
329+
330+
if (data.process_count == 0) {
331+
Common.printError('Not any process has received a command (offline or unexistent)');
332+
return cb ? cb(Common.retErr('Unknown process')) : that.exitCli(cst.ERROR_EXIT);
333+
}
334+
329335
process_wait_count = data.process_count;
330336
Common.printOut(chalk.bold('%s processes have received command %s'),
331337
data.process_count, action_name);

lib/API/Keymetrics/cli-api.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ module.exports = function(CLI) {
5454
CLI.prototype.monitorState = function(state, target, cb) {
5555
var that = this;
5656

57-
try {
58-
fs.statSync(this._conf.INTERACTION_CONF);
59-
} catch(e) {
60-
printMotd();
61-
return registerPrompt();
57+
if (process.env.NODE_ENV !== 'test') {
58+
try {
59+
fs.statSync(this._conf.INTERACTION_CONF);
60+
} catch(e) {
61+
printMotd();
62+
return registerPrompt();
63+
}
6264
}
6365

6466
if (!target) {

lib/God/ActionMethods.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,14 @@ module.exports = function(God) {
733733
var sent = 0;
734734

735735
(function ex(arr) {
736-
if (arr[0] == null) return cb(null, { process_count : sent, success : true });
736+
if (arr[0] == null || !arr) {
737+
return cb(null, {
738+
process_count : sent,
739+
success : true
740+
});
741+
}
737742

738-
var id = arr[0];
743+
var id = arr[0];
739744

740745
if (!God.clusters_db[id] || !God.clusters_db[id].pm2_env) {
741746
arr.shift();
@@ -744,19 +749,30 @@ module.exports = function(God) {
744749

745750
var proc_env = God.clusters_db[id].pm2_env;
746751

747-
if (p.basename(proc_env.pm_exec_path) == name || proc_env.name == name) {
748-
if (proc_env.status == cst.ONLINE_STATUS || proc.pm2_env.status == cst.LAUNCHING_STATUS) {
752+
if ((p.basename(proc_env.pm_exec_path) == name ||
753+
proc_env.name == name) &&
754+
(proc_env.status == cst.ONLINE_STATUS ||
755+
proc_env.status == cst.LAUNCHING_STATUS)) {
749756

750-
if (cmd.opts == null)
751-
God.clusters_db[id].send(cmd.msg);
752-
else
753-
God.clusters_db[id].send(cmd);
757+
proc_env.axm_actions.forEach(function(action) {
758+
if (action.action_name == cmd.msg) {
759+
action_exist = true;
760+
}
761+
});
754762

755-
sent++;
763+
if (action_exist == false || proc_env.axm_actions.length == 0) {
756764
arr.shift();
757765
return ex(arr);
758-
759766
}
767+
768+
if (cmd.opts == null)
769+
God.clusters_db[id].send(cmd.msg);
770+
else
771+
God.clusters_db[id].send(cmd);
772+
773+
sent++;
774+
arr.shift();
775+
return ex(arr);
760776
}
761777
else {
762778
arr.shift();

test/interface/monitor.mocha.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-env mocha */
22

3+
process.env.NODE_ENV='test';
4+
35
'use strict';
46

57
var pm2 = require('../../index.js');

test/programmatic/custom_action.mocha.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ describe('Custom actions via CLI/API', function() {
4141
});
4242
});
4343

44+
it('should handle unknown application', function(done) {
45+
pm2.trigger('indexxo', 'ping', function(err, ret) {
46+
should(err).not.be.null();
47+
done();
48+
});
49+
});
50+
4451
it('should cannot trigger message if unknow id', function(done) {
4552
pm2.trigger(10, 'ping', function(err, ret) {
4653
should(err).not.be.null();

test/programmatic/lazy_api.mocha.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ var PM2 = require('../..');
88
var should = require('should');
99

1010
describe('Lazy API usage', function() {
11-
before(function(done) {
12-
PM2.kill(function() { done() });
13-
});
14-
1511
it('should start a script without passing any args', function(done) {
1612
PM2.start('./../fixtures/child.js', done);
1713
});

0 commit comments

Comments
 (0)