Skip to content

Commit

Permalink
test: skip tests and require when node4
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Mar 7, 2019
1 parent 59c4b20 commit ca13ded
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
21 changes: 14 additions & 7 deletions lib/API/Serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ var http = require('http');
var url = require('url');
var path = require('path');
var debug = require('debug')('pm2:serve');
var probe = require('@pm2/io');
var semver = require('semver')

var isNode4 = require('semver').lt(process.version, '6.0.0')

if (!isNode4) {
var probe = require('@pm2/io');
var errorMeter = probe.meter({
name : '404/sec',
samples : 1,
timeframe : 60
})
}

/**
* list of supported content types.
Expand Down Expand Up @@ -186,11 +197,6 @@ var contentTypes = {
'ttf': 'application/font-sfnt'
};

var errorMeter = probe.meter({
name : '404/sec',
samples : 1,
timeframe : 60
});

var options = {
port: process.env.PM2_SERVE_PORT || process.argv[3] || 8080,
Expand Down Expand Up @@ -219,7 +225,8 @@ http.createServer(function (request, response) {
if (error) {
console.error('[%s] Error while serving %s with content-type %s : %s',
Date.now(), filePath, contentType, error.message || error);
errorMeter.mark();
if (!isNode4)
errorMeter.mark();
if (error.code === 'ENOENT') {
fs.readFile(options.path + '/404.html', function (err, content) {
content = err ? '404 Not Found' : content;
Expand Down
7 changes: 7 additions & 0 deletions test/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ runTest ./test/e2e/cli/smart-start.sh
runTest ./test/e2e/cli/args.sh
runTest ./test/e2e/cli/attach.sh
runTest ./test/e2e/cli/serve.sh

SUPV=`node -e "require('semver').lt(process.versions.node, '6.0.0') ? console.log('<6') : console.log('>6')"`

if [ $SUPV = '<6' ]; then
exit
fi

runTest ./test/e2e/cli/monit.sh
runTest ./test/e2e/cli/cli-actions-1.sh
runTest ./test/e2e/cli/cli-actions-2.sh
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cli/app-configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
SRC=$(cd $(dirname "$0"); pwd)
source "${SRC}/../include.sh"

node -e "require('semver').lt(process.versions.node, '6.0.0') ? process.exit(0) : process.exit(1)"
[ $? -eq 1 ] || exit 0

cd $file_path

$pm2 unset echo
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/cli/serve.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l`
[ $OUT -eq 1 ] || fail "should be listening on port $PORT_2"
success "should be listening on port $PORT_2"

node -e "require('semver').lt(process.versions.node, '6.0.0') ? process.exit(0) : process.exit(1)"
[ $? -eq 1 ] || exit 0

$pm2 delete all

$pm2 serve . $PORT_2 --name frontend
Expand Down
4 changes: 4 additions & 0 deletions test/interface/bus.fork.spec.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var should = require('should');
var PM2 = require('../..');
var Plan = require('../helpers/plan.js');

if (require('semver').lt(process.version, '6.0.0')) {
return process.exit(0)
}

var PROCESS_ARCH = Object.keys({
pm_id : 0,
name : 'app'
Expand Down
10 changes: 7 additions & 3 deletions test/interface/bus.spec.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var should = require('should');
var PM2 = require('../..');
var Plan = require('../helpers/plan.js');

if (require('semver').lt(process.version, '6.0.0')) {
return process.exit(0)
}

const PATH_FIXTURES = process.cwd() + '/test/interface/fixtures/';

var PROCESS_ARCH = Object.keys({
Expand Down Expand Up @@ -127,7 +131,7 @@ describe('PM2 BUS / RPC', function() {

it('should (process:exception)', function(done) {
var plan = new Plan(1, done);
let called = false
var called = false

pm2_bus.on('*', function(event, data) {
if (event == 'process:exception') {
Expand All @@ -145,7 +149,7 @@ describe('PM2 BUS / RPC', function() {
});

it('should (process:exception) with promise', function(done) {
let called = false
var called = false
pm2_bus.on('*', function(event, data) {
if (event == 'process:exception') {
if (called) return
Expand All @@ -162,7 +166,7 @@ describe('PM2 BUS / RPC', function() {
});

it('should (human:event)', function(done) {
let called = false
var called = false
pm2_bus.on('*', function(event, data) {
if (event == 'human:event') {
if (called) return
Expand Down
5 changes: 5 additions & 0 deletions test/programmatic/custom_action.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ process.chdir(__dirname);

var pm2 = require('../..');
var should = require('should');
var semver = require('semver')

if (semver.lt(process.version, '6.0.0')) {
return process.exit(0)
}

describe('Custom actions via CLI/API', function() {
before(function(done) {
Expand Down

0 comments on commit ca13ded

Please sign in to comment.