From a38c732d97f37a6c8d0a14132aa57f0d204226fd Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Thu, 26 Oct 2017 10:44:34 -0400 Subject: [PATCH] server: read record key from environment variable, close #820 --- cli/lib/exec/run.js | 2 ++ packages/server/lib/cypress.coffee | 4 ++++ .../server/test/integration/cypress_spec.coffee | 16 +++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cli/lib/exec/run.js b/cli/lib/exec/run.js index d81c9b602c9f..0260e1ed2d3d 100644 --- a/cli/lib/exec/run.js +++ b/cli/lib/exec/run.js @@ -4,10 +4,12 @@ const spawn = require('./spawn') const verify = require('../tasks/verify') const processRunOptions = (options = {}) => { + debug('processing run options') const args = ['--run-project', options.project] //// if key is set use that - else attempt to find it by env var if (options.key == null) { + debug('--key is not set, looking up environment variable CYPRESS_RECORD_KEY') options.key = process.env.CYPRESS_RECORD_KEY || process.env.CYPRESS_CI_KEY } diff --git a/packages/server/lib/cypress.coffee b/packages/server/lib/cypress.coffee index 4618956cbe69..4f89a93861a7 100644 --- a/packages/server/lib/cypress.coffee +++ b/packages/server/lib/cypress.coffee @@ -108,6 +108,7 @@ module.exports = { start: (argv = []) -> require("./logger").info("starting desktop app", args: argv) + log("starting cypress server") ## make sure we have the appData folder require("./util/app_data").ensure() @@ -148,6 +149,9 @@ module.exports = { ## enable old CLI tools to record when options.record or options.ci options.mode = "record" + if not options.key + log("trying to read option key from environment") + options.key = process.env.CYPRESS_RECORD_KEY || process.env.CYPRESS_CI_KEY when options.runProject ## go into headless mode when told to run diff --git a/packages/server/test/integration/cypress_spec.coffee b/packages/server/test/integration/cypress_spec.coffee index 69be22e6611a..532f19e0dcec 100644 --- a/packages/server/test/integration/cypress_spec.coffee +++ b/packages/server/test/integration/cypress_spec.coffee @@ -703,6 +703,7 @@ describe "lib/cypress", -> context "--record or --ci", -> afterEach -> delete process.env.CYPRESS_PROJECT_ID + delete process.env.CYPRESS_RECORD_KEY beforeEach -> @setup = => @@ -821,7 +822,7 @@ describe "lib/cypress", -> @setup() ## set the projectId to be todos even though - ## we are running the prisine project + ## we are running the pristine project process.env.CYPRESS_PROJECT_ID = @projectId @createRun.resolves() @@ -832,6 +833,19 @@ describe "lib/cypress", -> expect(errors.warning).not.to.be.called @expectExitWith(3) + it "uses process.env.CYPRESS_RECORD_KEY", -> + @setup() + + process.env.CYPRESS_RECORD_KEY = "token-123" + + @createRun.resolves() + @sandbox.stub(api, "createInstance").resolves() + + cypress.start(["--run-project=#{@todosPath}", "--record"]) + .then => + expect(errors.warning).not.to.be.called + @expectExitWith(3) + it "still records even with old --ci option", -> @setup()