Skip to content

Commit

Permalink
server: read record key from environment variable, close #820
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 26, 2017
1 parent 70fcee8 commit a38c732
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cli/lib/exec/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/cypress.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
16 changes: 15 additions & 1 deletion packages/server/test/integration/cypress_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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 = =>
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down

0 comments on commit a38c732

Please sign in to comment.