diff --git a/.eslintrc.json b/.eslintrc.json index 0b07cf22e..28413ccee 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,7 +11,7 @@ "flowtype", "flow-vars" ], - "presets": ["es2015", "react"], + "presets": ["es2015"], "rules": { "quotes": [1, "double", "avoid-escape"], "flowtype/define-flow-type": 1, @@ -24,9 +24,7 @@ "flowtype/valid-syntax": 1 }, "ignore": [ - "**/*.test.js", - "distribution", - "**/_tests/" + "distribution" ], "settings": { "flowtype": { diff --git a/source/ci_source/_tests/_travis.test.js b/source/ci_source/_tests/_travis.test.js index a1cda5a10..a0924a0d6 100644 --- a/source/ci_source/_tests/_travis.test.js +++ b/source/ci_source/_tests/_travis.test.js @@ -6,9 +6,44 @@ let correctEnv = { "TRAVIS_REPO_SLUG": "artsy/eigen" } -describe(".validates_as_ci?", () => { +describe(".isCI", () => { test("validates when all Travis environment vars are set and Josh K says so", () => { let travis = new Travis(correctEnv) expect(travis.isCI).toBeTruthy() }) + test("does not validate without josh", () => { + let travis = new Travis({}) + expect(travis.isCI).toBeFalsy() + }) +}) + +describe(".isPR", () => { + test("validates when all Travis environment vars are set and Josh K says so", () => { + let travis = new Travis(correctEnv) + expect(travis.isPR).toBeTruthy() + }) + + test("does not validate without josh", () => { + let travis = new Travis({}) + expect(travis.isPR).toBeFalsy() + }) + + let envs = ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"] + envs.forEach((key: string) => { + var env = { + "HAS_JOSH_K_SEAL_OF_APPROVAL": "true", + "TRAVIS_PULL_REQUEST": "800", + "TRAVIS_REPO_SLUG": "artsy/eigen" + } + env[key] = null + + test(`does not validate when ${key} is missing`, () => { + let travis = new Travis({}) + expect(travis.isPR).toBeFalsy() + }) + }) + + xit("needs to have a PR number", () => { + + }) }) diff --git a/source/ci_source/travis.js b/source/ci_source/travis.js index 079051dbe..98148bcec 100644 --- a/source/ci_source/travis.js +++ b/source/ci_source/travis.js @@ -10,6 +10,13 @@ export default class Travis { } get isPR () : boolean { - return this.env.HAS_JOSH_K_SEAL_OF_APPROVAL != null + let mustHave = ["TRAVIS_PULL_REQUEST", "TRAVIS_REPO_SLUG"] + // TODO: has valid int for TRAVIS_PULL_REQUEST + let hasKey = mustHave.map((key: string) : boolean => { + return this.env.hasOwnProperty(key) && this.env[key].length > 0 + }) + + let gotRequiredKeys = !hasKey.includes(false) + return gotRequiredKeys } }