diff --git a/test/bash/mjs.sh b/test/bash/mjs.sh new file mode 100644 index 00000000..817ea2dd --- /dev/null +++ b/test/bash/mjs.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +SRC=$(cd $(dirname "$0"); pwd) +source "${SRC}/include.sh" + +cd $file_path/mjs + +# Activate test only for Node > 9.0.0 +node -e "require('semver').gte(process.versions.node, '9.0.0') ? process.exit(0) : process.exit(1)" +[ $? -eq 0 ] || exit 0 + +$pm2 start --node-args="--experimental-modules" index.mjs -o outech.log -e errech.log +>outech.log +>errech.log +sleep 1 +should 'should app be online in fork mode with MJS support' 'online' 1 + +$pm2 delete all + +$pm2 start --node-args="--experimental-modules" -i 2 index.mjs +sleep 1 +should 'should app be online in cluster mode with MJS support' 'online' 2 diff --git a/test/fixtures/mjs/ecosystem.config.js b/test/fixtures/mjs/ecosystem.config.js new file mode 100644 index 00000000..03d8ed50 --- /dev/null +++ b/test/fixtures/mjs/ecosystem.config.js @@ -0,0 +1,14 @@ +module.exports = { + + apps : [ + + + { + name : 'Test es6 modules', + script : 'index.mjs', + node_args : '--experimental-modules' + } + ], + + +}; diff --git a/test/fixtures/mjs/index.mjs b/test/fixtures/mjs/index.mjs new file mode 100644 index 00000000..5b229f01 --- /dev/null +++ b/test/fixtures/mjs/index.mjs @@ -0,0 +1,3 @@ +import {test} from './test' + +test(); diff --git a/test/fixtures/mjs/package.json b/test/fixtures/mjs/package.json new file mode 100644 index 00000000..c8052ea3 --- /dev/null +++ b/test/fixtures/mjs/package.json @@ -0,0 +1,18 @@ +{ + "name": "test-es6-pm2", + "version": "1.0.0", + "description": "A simple project to test pm2 es6-modules pm2 support", + "main": "index.mjs", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node --experimental-modules index.mjs" + }, + "keywords": [ + "es6-modules", + "import", + "export", + "pm2" + ], + "author": "vpotseluyko", + "license": "ISC" +} diff --git a/test/fixtures/mjs/test.mjs b/test/fixtures/mjs/test.mjs new file mode 100644 index 00000000..12fa85ea --- /dev/null +++ b/test/fixtures/mjs/test.mjs @@ -0,0 +1,3 @@ +export function test() { + setInterval(() => console.log(`Hello es6 from pm2`), 1000); +} diff --git a/test/pm2_behavior_tests.sh b/test/pm2_behavior_tests.sh index bf27f224..09650000 100644 --- a/test/pm2_behavior_tests.sh +++ b/test/pm2_behavior_tests.sh @@ -33,6 +33,8 @@ spec "resurrect test" # spec "Docker tests" bash ./test/bash/nvm-node-version.sh spec "NVM node version setting" +bash ./test/bash/mjs.sh +spec "Test import syntax" bash ./test/bash/cron-system.sh spec "Cron system tests"