Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Add pm2 scenario.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Nov 28, 2017
1 parent 98a0b20 commit dd9c573
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.DS_Store
.node_repl_history
.nyc_output
.pm2
.vscode
package-lock.json
/build
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"plugins": [
"@babel/proposal-class-properties"
["@babel/proposal-class-properties", {
"loose": true
}]
],
"presets": [
["@babel/env", {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

require = require("../../../../")(module, true)
require("@babel/register")
module.exports = require("./main").default
console.log(require("./index.mjs").default)
33 changes: 30 additions & 3 deletions test/scenario-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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")
Expand Down
8 changes: 0 additions & 8 deletions test/scenario/babel-register.js

This file was deleted.

0 comments on commit dd9c573

Please sign in to comment.