Skip to content

Commit

Permalink
Adds soem debug logs to the vm2 runner
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Sep 1, 2018
1 parent ac4465b commit 065b2a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

## Master

# 3.8.9

- Adds debug logs to the vm2 runner used in Peril - [@orta][]

# 3.8.5 - 3.8.8

- Adds a function to handle creating or adding a label on a PR/Issue. Works with both Danger and Peril:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "danger",
"version": "3.8.7",
"version": "3.8.9",
"description": "Unit tests for Team Culture",
"main": "distribution/danger.js",
"typings": "distribution/danger.d.ts",
Expand Down
14 changes: 13 additions & 1 deletion source/runner/runners/vm2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NodeVM, NodeVMOptions } from "vm2"
import * as fs from "fs"

import { DangerContext } from "../../runner/Dangerfile"
import { debug } from "../../debug"

import compile from "./utils/transpiler"
import cleanDangerfile from "./utils/cleanDangerfile"
Expand All @@ -11,6 +12,8 @@ import { DangerResults } from "../../dsl/DangerResults"

declare const regeneratorRuntime: any

const d = debug("vm2")

// A WIP version of the runner which uses a vm2 based in-process runner, only used by self-hosted
// heroku instances of Peril.
//
Expand Down Expand Up @@ -39,7 +42,7 @@ export async function createDangerfileRuntimeEnvironment(dangerfileContext: Dang

export const runDangerfileEnvironment = async (
filenames: string[],
originalContents: (string | undefined)[],
originalContents: string[] | undefined[],
environment: any,
injectedObjectToExport?: any
): Promise<DangerResults> => {
Expand All @@ -50,6 +53,10 @@ export const runDangerfileEnvironment = async (
const index = filenames.indexOf(filename)
const originalContent = (originalContents && originalContents[index]) || fs.readFileSync(filename, "utf8")

d(`Preparing to evaluate: ${filename}\n\n\n `)
d(originalContent.split("\n").join("\n "))
d(`-`)

const vm = new NodeVM(environment)

// Require our dangerfile
Expand Down Expand Up @@ -88,6 +95,11 @@ export const runDangerfileEnvironment = async (
}

const results = environment.sandbox!.results!
d(
`Got md ${results.markdowns.length} w ${results.warnings.length} f ${results.fails.length} m ${
results.messages.length
}`
)
return {
fails: results.fails,
warnings: results.warnings,
Expand Down

0 comments on commit 065b2a5

Please sign in to comment.