diff --git a/.gitignore b/.gitignore index 9dc4f518c..c823b50c3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ .DS_Store .node_repl_history .nyc_output +.pm2 .vscode package-lock.json /build diff --git a/package.json b/package.json index 7c0bebd4e..9eb2b87ab 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "optimize-js-plugin": "0.0.4", "optional-dev-dependency": "^2.0.1", "pify": "^3.0.0", + "pm2": "^2.8.0", "semver": "^5.4.1", "trash": "^4.1.0", "typescript": "^2.6.1", diff --git a/test/fixture/scenario/babel-register/.babelrc b/test/fixture/scenario/babel-register-pm2/.babelrc similarity index 57% rename from test/fixture/scenario/babel-register/.babelrc rename to test/fixture/scenario/babel-register-pm2/.babelrc index 0584ef934..48b3a5c79 100644 --- a/test/fixture/scenario/babel-register/.babelrc +++ b/test/fixture/scenario/babel-register-pm2/.babelrc @@ -1,6 +1,8 @@ { "plugins": [ - "@babel/proposal-class-properties" + ["@babel/proposal-class-properties", { + "loose": true + }] ], "presets": [ ["@babel/env", { diff --git a/test/fixture/scenario/babel-register/.esmrc b/test/fixture/scenario/babel-register-pm2/.esmrc similarity index 100% rename from test/fixture/scenario/babel-register/.esmrc rename to test/fixture/scenario/babel-register-pm2/.esmrc diff --git a/test/fixture/scenario/babel-register/index.js b/test/fixture/scenario/babel-register-pm2/index.js similarity index 66% rename from test/fixture/scenario/babel-register/index.js rename to test/fixture/scenario/babel-register-pm2/index.js index 5153a18ae..3204c7938 100644 --- a/test/fixture/scenario/babel-register/index.js +++ b/test/fixture/scenario/babel-register-pm2/index.js @@ -2,4 +2,4 @@ require = require("../../../../")(module, true) require("@babel/register") -module.exports = require("./main").default +console.log(require("./index.mjs").default) diff --git a/test/fixture/scenario/babel-register/main.mjs b/test/fixture/scenario/babel-register-pm2/index.mjs similarity index 100% rename from test/fixture/scenario/babel-register/main.mjs rename to test/fixture/scenario/babel-register-pm2/index.mjs diff --git a/test/scenario-tests.mjs b/test/scenario-tests.mjs index 22242b1ad..40dfc8931 100644 --- a/test/scenario-tests.mjs +++ b/test/scenario-tests.mjs @@ -2,6 +2,7 @@ import assert from "assert" import execa from "execa" import path from "path" import require from "./require.js" +import trash from "trash" const pkgPath = require.resolve("../") const testPath = path.dirname(require.resolve("./tests.mjs")) @@ -15,9 +16,35 @@ function exec(filePath, args) { describe("scenarios", function () { this.timeout(0) - it("should work with @babel/register", () => - exec(process.execPath, ["./scenario/babel-register.js"]) - ) + it("should work with @babel/register and pm2", () => { + const dirPath = path.resolve(testPath, "fixture/scenario/babel-register-pm2") + const indexPath = path.resolve(dirPath, "index.js") + const logPath = path.resolve(testPath, "env/home/.pm2/logs") + const errorPath = path.resolve(logPath, "babel-register-pm2-error-0.log") + const outPath = path.resolve(logPath, "babel-register-pm2-out-0.log") + + const nodeArgs = ["-r", pkgPath, "-r", "@babel/register"] + const pm2Args = [ + "start", + "--no-autorestart", + "--name", "babel-register-pm2", + "--node-args", nodeArgs.join(" "), + indexPath + ] + + return Promise.resolve() + .then(() => trash([logPath])) + .then(() => exec("pm2", ["kill"])) + .then(() => exec("pm2", pm2Args)) + .then(() => new Promise((resolve) => setTimeout(resolve, 1000))) + .then(() => { + const errorLog = fs.readFileSync(errorPath, "utf8") + const outLog = fs.readFileSync(outPath, "utf8") + + assert.strictEqual(errorLog.trim(), "") + assert.strictEqual(outLog.trim(), "{ [Function: Class] a: 'a' }") + }) + }) it("should work with ava, nyc, and tsc", () => { const dirPath = path.resolve(testPath, "fixture/scenario/ava-nyc-tsc") diff --git a/test/scenario/babel-register.js b/test/scenario/babel-register.js deleted file mode 100644 index 6f970ea20..000000000 --- a/test/scenario/babel-register.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict" - -const assert = require("assert") -const def = require("../fixture/scenario/babel-register") - -module.exports = () => { - assert.strictEqual(def.a, "a") -}