Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
orta committed Oct 15, 2017
2 parents 3f3bf26 + a3bcb33 commit 59e100e
Show file tree
Hide file tree
Showing 10 changed files with 2,419 additions and 108 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ docs/js_ref_dsl_docs.json

types/index.d.ts
.jest/
test-results.json
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ matrix:

# Does the real danger run
- node_js: node
before_script:
- greenkeeper-lockfile-update
after_script:
- yarn run link
script:
- echo "This is only for running the real danger on this repo"
- danger run --verbose
after_script:
- greenkeeper-lockfile-upload

# Create some fake projects at runtime
- node_js: '7'
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

### Master

- Moves away from vm2 to a require-based Dangerfile runner. This removes the sandboxing aspect of
the Dangerfile completely, but the sandboxing was mainly for Peril and I have a plan for that.

https://github.com/danger/peril/issues/159

I would like to move the main parts of Danger JS to also work like `danger process`, so I'll
be continuing to work as a alpha for a bit more. One interesting side-effect of this could be that
I can remove `schedule` from the DSL. I've not tested it yet though. Turns out this change is _real_
hard to write tests for. I've made #394 for that.

### 2.0.0-alpha.18 - 19

Expand Down
3 changes: 3 additions & 0 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ schedule(async () => {
import yarn from "danger-plugin-yarn"
schedule(yarn())

import jest from "danger-plugin-jest"
jest()

// Some good old-fashioned maintainance upkeep

// Ensure the danger.d.ts is always up to date inside this repo.
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"transform": {
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testResultsProcessor": "jest-json-reporter",
"testRegex": "(.test)\\.(ts|tsx)$",
"verbose": true,
"testPathIgnorePatterns": ["/node_modules/", "/distribution/", "/types/"],
Expand Down Expand Up @@ -72,10 +73,12 @@
"babel-preset-es2015": "7.0.0-alpha.19",
"babel-preset-stage-3": "7.0.0-alpha.19",
"babel-traverse": "7.0.0-alpha.19",
"danger-plugin-jest": "^1.0.1",
"danger-plugin-yarn": "^1.0.0",
"date-fns": "^1.28.3",
"husky": "^0.14.0",
"jest": "21",
"jest-json-reporter": "^1.2.2",
"lint-staged": "^4.0.0",
"madge": "^2.0.0",
"prettier": "^1.7.4",
Expand Down
4 changes: 1 addition & 3 deletions source/commands/utils/_tests/file-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
let mockDangerfilePath = ""
jest.mock("fs", () => {
return { existsSync: p => p === mockDangerfilePath }
})
jest.mock("fs", () => ({ existsSync: p => p === mockDangerfilePath }))

import { dangerfilePath } from "../file-utils"

Expand Down
23 changes: 0 additions & 23 deletions source/runner/runners/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ export async function createDangerfileRuntimeEnvironment(dangerfileContext: Dang
return dangerfileContext
}

// /**
// * A quick implmentation of what actually happens when require is called, but
// * without the file acccess. This comes from
// * https://stackoverflow.com/questions/17581830/load-node-js-module-from-string-in-memory#17585470
// *
// * If this implmentation isn't enough, we can use the module require-from-string
// *
// * @param src the source code
// * @param filename the path the file represents on disk
// */
// function requireFromString(src: string, filename: string) {
// var parent = module.parent
// var m = new Module(filename, parent)
// m.paths = Module._nodeModulePaths(path.dirname(filename))
// m._compile(src, filename)
// return m.exports
// }

/**
* Executes a Dangerfile at a specific path, with a context.
* The values inside a Danger context are applied as globals to the Dangerfiles runtime.
Expand Down Expand Up @@ -82,12 +64,7 @@ export async function runDangerfileEnvironment(
// this[key] = element
}
}
// const myCWD = path.dirname(process.cwd())
// process.chdir(path.dirname(filename))
// eval(compiled)
// process.chdir(myCWD)

// _eval(compiled, filename, environment, true)
_require(compiled, filename, {})

const results = environment.results
Expand Down
1,675 changes: 1,675 additions & 0 deletions tests.json

Large diffs are not rendered by default.

49 changes: 25 additions & 24 deletions wallaby.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
module.exports = (wallaby) => ({
files: [
{pattern: "source/**/fixtures/**/*.*", instrument: false},
"source/**/!(*.test).ts",
{pattern: "package.json", instrument: false}
],
module.exports = wallaby => {
const babel = JSON.parse(require("fs").readFileSync(require("path").join(__dirname, ".babelrc")))
babel.presets.push("babel-preset-jest")

tests: [
"source/**/*.test.ts"
],
return {
files: [
"tsconfig.json",
{ pattern: "source/**/fixtures/**/*.*", instrument: false },
"source/**/!(*.test).ts",
{ pattern: "package.json", instrument: false },
],

env: {
type: "node"
},
tests: ["source/**/*.test.ts"],

compilers: {
"**/*.ts?(x)": wallaby.compilers.typeScript()
},
env: {
type: "node",
},

// fixtures are not instrumented, but still need to be compiled
preprocessors: {
"source/**/fixtures/**/*.js?(x)": file => require('babel-core')
.transform(
file.content,
JSON.parse(require('fs').readFileSync(require('path').join(__dirname, '.babelrc'))))
},
compilers: {
"**/*.ts?(x)": wallaby.compilers.typeScript(),
},

testFramework: "jest"
})
// fixtures are not instrumented, but still need to be compiled
preprocessors: {
"source/**/fixtures/**/*.js?(x)": file => require("babel-core").transform(file.content, babel),
},

testFramework: "jest",
}
}
Loading

0 comments on commit 59e100e

Please sign in to comment.