Skip to content

Commit a654063

Browse files
committed
Remove vm2 from Danger
1 parent 2550ab6 commit a654063

File tree

7 files changed

+735
-1304
lines changed

7 files changed

+735
-1304
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<!-- Your comment below this -->
1717

18+
- Removed `vm2` from Danger, it's not being used in Peril now - [@orta][]
1819
- `danger pr` with `--json` or --js` now don't require a Dangerfile to be present - [@orta][]
1920

2021
# 7.0.5

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"scripts": {
5151
"release": "release-it",
5252
"test": "jest",
53+
"test:fixtures": "node ./scripts/run-fixtures.js",
5354
"test:watch": "jest --watch",
5455
"lint": "tslint \"source/**/*.ts\"",
5556
"lint:fix": "tslint \"source/**/*.ts\" --fix",
@@ -66,7 +67,7 @@
6667
"docs:cp_defs": "mkdir docs/docs_generate; cp source/danger.d.ts docs/docs_generate; cp node_modules/@octokit/rest/index.d.ts docs/docs_generate/github.d.ts",
6768
"docs": "yarn run docs:cp_defs; yarn typedoc --ignoreCompilerErrors --mode modules --json docs/js_ref_dsl_docs.json --includeDeclarations source",
6869
"dts-lint": "yarn run declarations && yarn dtslint types",
69-
"danger:prepush": "yarn build:fast; node distribution/commands/danger.js local --dangerfile dangerfile.lite.ts"
70+
"danger:prepush": "yarn build:fast; yarn test:fixtures; node distribution/commands/danger.js local --dangerfile dangerfile.lite.ts"
7071
},
7172
"repository": {
7273
"type": "git",
@@ -92,7 +93,7 @@
9293
"@types/debug": "0.0.30",
9394
"@types/get-stdin": "^5.0.1",
9495
"@types/http-proxy-agent": "^2.0.1",
95-
"@types/jest": "^23.3.2",
96+
"@types/jest": "^24.0.0",
9697
"@types/json5": "^0.0.30",
9798
"@types/jsonwebtoken": "^7.2.8",
9899
"@types/lodash.includes": "^4.3.4",
@@ -106,7 +107,7 @@
106107
"date-fns": "^1.29.0",
107108
"flow-bin": "^0.77.0",
108109
"husky": "^1.0.1",
109-
"jest": "^23.6.0",
110+
"jest": "^24.0.0",
110111
"jest-json-reporter": "^1.2.2",
111112
"lint-staged": "^7.3.0",
112113
"madge": "^3.2.0",
@@ -153,8 +154,7 @@
153154
"readline-sync": "^1.4.9",
154155
"require-from-string": "^2.0.2",
155156
"rfc6902": "^3.0.1",
156-
"supports-hyperlinks": "^1.0.1",
157-
"vm2": "^3.6.3"
157+
"supports-hyperlinks": "^1.0.1"
158158
},
159159
"optionalDependencies": {},
160160
"husky": {

scripts/run-fixtures.js

100644100755
+40-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
// Note: Keep this ES6 only, want to be able to run this directly via node
22
// to ensure that something like ts-node doesn't mess up paths etc
33

4-
// yarn build; cat source/_tests/fixtures/danger-js-pr-395.json | env DANGER_FAKE_CI="YEP" DANGER_TEST_REPO='danger/danger-js' DANGER_TEST_PR='395' node --inspect distribution/commands/danger-runner.js --text-only --dangerfile /Users/orta/dev/projects/danger/danger-js/source/runner/_tests/fixtures/__DangerfileAsync.js
4+
// yarn test:fixtures
5+
6+
// Toggle this on to update the JSON files for each run
7+
const writeResults = false
58

69
const fs = require("fs")
710
const child_process = require("child_process")
811
const { resolve } = require("path")
12+
const { basename } = require("path")
913
const chalk = require("chalk")
1014
const expect = require("expect")
1115

12-
// Toggle this on to update the JSON files for each run
13-
const writeResults = false
14-
console.log("If this script fails, you probably want to update the fixtures - just edit script/run-fixtures.js")
1516
const runnerFileJS = "distribution/commands/danger-runner.js"
1617

17-
// Get all the fixtures
18+
// Use a DSL fixture, and emulate being the `danger ci` host process
1819
const dangerDSLFixture = resolve(__dirname, "../source/_tests/fixtures/danger-js-pr-395.json")
1920
const dslJSON = fs.readFileSync(dangerDSLFixture, "utf8")
2021

@@ -28,14 +29,18 @@ const fixtures = fs
2829
.filter(f => !f.includes("Throws"))
2930
.filter(f => !f.includes("BadSyntax"))
3031

32+
let runCount = 0
33+
34+
console.log("Running Fixures for Danger JS. This uses the built version of danger.\n")
35+
3136
// Runs the danger runner over a fixture, then compares it to the
3237
// fixtured JSON data
3338
const runDangerfile = fixture => {
3439
let allLogs = ""
3540
const dangerfile = `${dangerFileFixtures}/${fixture}`
3641
const dangerfileResults = `${dangerFileResultsFixtures}/${fixture}.json`
3742

38-
console.log("Running fixture for " + chalk.bold(dangerfile))
43+
process.stdout.write(chalk.bold(basename(dangerfile)))
3944

4045
// Setup the command
4146
const commandArgs = ["node", runnerFileJS, "--text-only", "--dangerfile", dangerfile]
@@ -58,31 +63,48 @@ const runDangerfile = fixture => {
5863

5964
child.stdout.on("data", data => {
6065
data = data.toString()
66+
// console.log(`stdout: ${data}`)
67+
6168
const trimmed = data.trim()
62-
if (trimmed.startsWith("{") && trimmed.endsWith("}") && trimmed.includes("markdowns")) {
63-
const runtimeResults = JSON.parse(trimmed)
69+
const maybeJSON = getJSONURLFromSTDOUT(data)
70+
const url = maybeJSON.replace("danger-results:/", "")
71+
const runtimeResults = JSON.parse(fs.readFileSync(url, "utf8"))
72+
if (writeResults) {
73+
fs.writeFileSync(dangerfileResults, trimmed)
74+
}
6475

65-
if (writeResults) {
66-
fs.writeFileSync(dangerfileResults, trimmed)
67-
}
76+
const fixturedResults = JSON.parse(fs.readFileSync(dangerfileResults, "utf8"))
77+
// Fails include traces etc
78+
expect(runtimeResults).toEqual(fixturedResults)
6879

69-
const fixturedResults = JSON.parse(fs.readFileSync(dangerfileResults, "utf8"))
70-
// Fails include traces etc
71-
expect(runtimeResults).toEqual(fixturedResults)
80+
const tick = chalk.bold.greenBright("✓")
81+
process.stdout.write(" " + tick)
7282

73-
next()
74-
} else {
75-
allLogs += data
76-
}
83+
runCount++
84+
next()
7785
})
7886
}
7987

88+
/** Pulls out a URL that's from the STDOUT */
89+
const getJSONURLFromSTDOUT = stdout => {
90+
const match = stdout.match(/danger-results:\/\/*.+json/)
91+
if (!match) {
92+
return undefined
93+
}
94+
return match[0]
95+
}
96+
8097
// Keep an index and loop through the fixtures
8198
var index = 0
8299
const next = () => {
83100
const nextFixture = fixtures[index++]
84101
if (nextFixture) {
102+
if (index > 1) {
103+
process.stdout.write(", ")
104+
}
85105
runDangerfile(nextFixture)
106+
} else {
107+
expect(runCount).toEqual(fixtures.length)
86108
}
87109
}
88110

0 commit comments

Comments
 (0)