Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 6e44257

Browse files
committed
deprecate 'cypress ci', expand 'cypress run'
- allow ‘cypress run’ to verify + install if not installed - no longer pass —ci args - enable passing —no-record - deprecate cypress ci message - check for CYPRESS_RECORD_KEY env var - refactor some of these horrendous class interfaces (why god why)
1 parent 3f861e1 commit 6e44257

File tree

8 files changed

+206
-182
lines changed

8 files changed

+206
-182
lines changed

lib/cli.coffee

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pkg = require("../package.json")
88
updater({pkg: pkg, updateCheckInterval: human("one hour")}).notify()
99

1010
parseOpts = (opts) ->
11-
_.pick(opts, "spec", "reporter", "reporterOptions", "path", "destination", "port", "env", "cypressVersion", "config")
11+
_.pick(opts, "spec", "reporter", "reporterOptions", "path", "destination", "port", "env", "cypressVersion", "config", "noRecord")
1212

1313
descriptions = {
1414
destination: "destination path to extract and install Cypress to"
@@ -19,6 +19,7 @@ descriptions = {
1919
env: "sets environment variables. separate multiple values with a comma. overrides any value in cypress.json or cypress.env.json"
2020
config: "sets configuration values. separate multiple values with a comma. overrides any value in cypress.json."
2121
version: "installs a specific version of Cypress"
22+
noRecord: "silences the console warning when you do not provide a record key"
2223
}
2324

2425
text = (d) ->
@@ -45,32 +46,33 @@ module.exports = ->
4546
.option("-d, --destination <path>", text("destination"))
4647
.option("--cypress-version <version>", text("version"))
4748
.action (opts) ->
48-
require("./commands/install")(parseOpts(opts))
49+
require("./commands/install").start(parseOpts(opts))
4950

5051
program
5152
.command("update")
5253
.description("Updates Cypress to the latest version")
5354
.option("-d, --destination <path>", text("destination"))
5455
.action (opts) ->
55-
require("./commands/install")(parseOpts(opts))
56+
require("./commands/install").start(parseOpts(opts))
5657

5758
program
5859
.command("run [project]")
5960
.usage("[project] [options]")
60-
.description("Runs Cypress Tests Headlessly")
61+
.description("Runs Cypress Headlessly")
6162
.option("-s, --spec <spec>", text("spec"))
6263
.option("-r, --reporter <reporter>", text("reporter"))
6364
.option("-o, --reporter-options <reporter-options>", text("reporterOptions"))
6465
.option("-p, --port <port>", text("port"))
6566
.option("-e, --env <env>", text("env"))
6667
.option("-c, --config <config>", text("config"))
68+
.option("--no-record", text("noRecord"))
6769
.action (project, opts) ->
68-
require("./commands/run")(project, parseOpts(opts))
70+
require("./commands/run").start(project, parseOpts(opts))
6971

7072
program
7173
.command("ci [key]")
7274
.usage("[key] [options]")
73-
.description("Runs Cypress in CI Mode")
75+
.description("[DEPRECATED] Use 'cypress run --key <record_key>'")
7476
.option("-s, --spec <spec>", text("spec"))
7577
.option("-r, --reporter <reporter>", text("reporter"))
7678
.option("-o, --reporter-options <reporter-options>", text("reporterOptions"))

lib/commands/ci.coffee

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
_ = require("lodash")
2-
path = require("path")
3-
os = require("os")
42
chalk = require("chalk")
3+
run = require("./run")
54
utils = require("../utils")
6-
Run = require("./run")
7-
Install = require("./install")
85

96
class Ci
107
constructor: (key, options = {}) ->
@@ -13,7 +10,7 @@ class Ci
1310

1411
## if we dont have a key assume
1512
## its in an env variable
16-
key ?= process.env.CYPRESS_CI_KEY
13+
key ?= process.env.CYPRESS_RECORD_KEY or process.env.CYPRESS_CI_KEY
1714

1815
return @_noKeyErr(options) if not key
1916

@@ -28,28 +25,17 @@ class Ci
2825
_noKeyErr: (options) ->
2926
console.log("")
3027
console.log(chalk.bgRed.white(" -Error- "))
31-
console.log(chalk.red.underline("Running Cypress in CI requires a secret project key."))
28+
console.log(chalk.red.underline("Running Cypress in CI requires a Record Key."))
3229
console.log("")
3330
console.log("You did not pass a specific key to:", chalk.blue("cypress ci"))
3431
console.log("")
35-
console.log("Since no key was passed, we checked for an environment\nvariable but none was found with the name:", chalk.blue("CYPRESS_CI_KEY"))
32+
console.log("Since no key was passed, we checked for an environment\nvariable but none was found with the name:", chalk.blue("CYPRESS_RECORD_KEY"))
3633
console.log("")
37-
console.log("You can receive your project's secret key by running\nthe terminal command:", chalk.blue("cypress get:key"))
38-
console.log("")
39-
console.log("Please provide us your project's secret key and then rerun.")
34+
console.log("https://on.cypress.io/what-is-a-record-key")
35+
4036
process.exit(1)
4137

4238
initialize: (options) ->
43-
run = ->
44-
Run(null, options)
45-
46-
utils.verifyCypressExists()
47-
.then(run)
48-
.catch ->
49-
console.log("")
50-
console.log("Cypress was not found:", chalk.green("Installing a fresh copy."))
51-
console.log("")
52-
53-
Install({after: run, displayOpen: false})
39+
run.start(null, options)
5440

55-
module.exports = Ci
41+
module.exports = Ci

lib/commands/install.coffee

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ fs = Promise.promisifyAll(fs)
1919

2020
baseUrl = "https://download.cypress.io/"
2121

22-
class Install
23-
constructor: (options = {}) ->
24-
if not (@ instanceof Install)
25-
return new Install(options)
26-
22+
module.exports = {
23+
start: (options = {}) ->
2724
_.defaults options,
28-
initialize: true
2925
displayOpen: true
3026
version: null
3127
cypressVersion: null
@@ -39,18 +35,16 @@ class Install
3935
executable: utils.getPathToUserExecutable()
4036
after: ->
4137

42-
return if not options.initialize
43-
4438
@initialize(options)
4539

4640
initialize: (options) ->
4741
@download(options)
48-
.bind(@)
49-
.catch(@downloadErr)
50-
.then(@unzip)
51-
.catch(@unzipErr)
52-
.then ->
53-
@finish(options)
42+
.bind(@)
43+
.catch(@downloadErr)
44+
.then(@unzip)
45+
.catch(@unzipErr)
46+
.then ->
47+
@finish(options)
5448

5549
downloadErr: (err) ->
5650
console.log("")
@@ -273,4 +267,4 @@ class Install
273267

274268
options.after(options)
275269

276-
module.exports = Install
270+
}

lib/commands/run.coffee

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
_ = require("lodash")
22
path = require("path")
3+
chalk = require("chalk")
4+
install = require("./install")
35
utils = require("../utils")
46

5-
class Run
6-
constructor: (project = ".", options = {}) ->
7-
if not (@ instanceof Run)
8-
return new Run(project, options)
7+
run = (options) ->
8+
opts = {}
9+
args = ["--project", options.project]
910

11+
## if key is set use that - else attempt to find it by env var
12+
options.key ?= process.env.CYPRESS_RECORD_KEY or process.env.CYPRESS_CI_KEY
13+
14+
if options.env
15+
args.push("--env", options.env)
16+
17+
if options.config
18+
args.push("--config", options.config)
19+
20+
if options.port
21+
args.push("--port", options.port)
22+
23+
## if we have a specific spec push that into the args
24+
if options.spec
25+
args.push("--spec", options.spec)
26+
27+
## if we have a specific reporter push that into the args
28+
if options.reporter
29+
args.push("--reporter", options.reporter)
30+
31+
## if we have a specific reporter push that into the args
32+
if options.reporterOptions
33+
args.push("--reporter-options", options.reporterOptions)
34+
35+
if options.noRecord
36+
args.push("--no-record")
37+
38+
## if we have a key assume we're in record mode
39+
if options.key
40+
args.push("--key", options.key)
41+
opts.xvfb = true
42+
43+
utils.spawn(args, opts)
44+
45+
module.exports = {
46+
start: (project = ".", options = {}) ->
1047
_.defaults options,
1148
key: null
1249
spec: null
@@ -17,35 +54,19 @@ class Run
1754
@run(options)
1855

1956
run: (options) ->
20-
opts = {}
21-
args = ["--run-project", options.project]
22-
23-
if options.env
24-
args.push("--env", options.env)
25-
26-
if options.config
27-
args.push("--config", options.config)
28-
29-
if options.port
30-
args.push("--port", options.port)
31-
32-
## if we have a specific spec push that into the args
33-
if options.spec
34-
args.push("--spec", options.spec)
35-
36-
## if we have a specific reporter push that into the args
37-
if options.reporter
38-
args.push("--reporter", options.reporter)
57+
after = ->
58+
run(options)
3959

40-
## if we have a specific reporter push that into the args
41-
if options.reporterOptions
42-
args.push("--reporter-options", options.reporterOptions)
60+
utils.verifyCypressExists()
61+
.then(after)
62+
.catch ->
63+
console.log("")
64+
console.log("Cypress was not found:", chalk.green("Installing a fresh copy."))
65+
console.log("")
4366

44-
## if we have a key assume we're in CI mode
45-
if options.key
46-
args.push("--ci", "--key", options.key)
47-
opts.xvfb = true
67+
## TODO: no reason after should be a callback function here
68+
## just use a promise
69+
install.start({after: after, displayOpen: false})
4870

49-
utils.spawn(args, opts)
5071

51-
module.exports = Run
72+
}

test/commands/ci_spec.coffee

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ describe "Ci", ->
6161
Ci(key, options).initialize(options)
6262

6363
afterEach ->
64-
delete process.env.CYPRESS_CI_KEY
64+
delete process.env.CYPRESS_RECORD_KEY
6565

66-
it "spawns --run-project with --ci and --key and xvfb", ->
66+
it "spawns --project with --ci and --key and xvfb", ->
6767
@setup("abc12345").then =>
6868
pathToProject = path.resolve(process.cwd(), ".")
69-
expect(@spawn).to.be.calledWith(["--run-project", pathToProject, "--ci", "--key", "abc12345"], {xvfb: true})
69+
expect(@spawn).to.be.calledWith(["--project", pathToProject, "--key", "abc12345"])
7070

7171
it "can pass a specific reporter", ->
7272
@setup("foo", {reporter: "some/custom/reporter.js"}).then =>
@@ -80,8 +80,8 @@ describe "Ci", ->
8080
args = @spawn.getCall(0).args[0]
8181
expect(args).to.include("--port", "2500")
8282

83-
it "uses process.env.CYPRESS_CI_KEY when no key was passed", ->
84-
process.env.CYPRESS_CI_KEY = "987-654-321"
83+
it "uses process.env.CYPRESS_RECORD_KEY when no key was passed", ->
84+
process.env.CYPRESS_RECORD_KEY = "987-654-321"
8585
@setup().then =>
8686
args = @spawn.getCall(0).args[0]
8787
expect(args).to.include("--key", "987-654-321")
@@ -94,45 +94,9 @@ describe "Ci", ->
9494
it "spawns with config", ->
9595
@setup("abc123", {config: "watchForFileChanges=false,baseUrl=localhost"}).then =>
9696
pathToProject = path.resolve(process.cwd(), ".")
97-
expect(@spawn).to.be.calledWith(["--run-project", pathToProject, "--config", "watchForFileChanges=false,baseUrl=localhost", "--ci", "--key", "abc123"])
97+
expect(@spawn).to.be.calledWith(["--project", pathToProject, "--config", "watchForFileChanges=false,baseUrl=localhost", "--key", "abc123"])
9898

99-
context "#initialize", ->
100-
beforeEach ->
101-
@Ci = proxyquire("../lib/commands/ci", {
102-
"./run": @Run = @sandbox.stub()
103-
"./install": @Install = @sandbox.spy (opts) ->
104-
opts.after(opts)
105-
})
106-
107-
@verify = @sandbox.stub(utils, "verifyCypressExists").resolves()
108-
@log = @sandbox.spy(console, "log")
109-
110-
@setup = (key, options = {}) =>
111-
options.initialize = false
112-
@Ci(key, options)
113-
114-
it "verifies cypress first", ->
115-
ci = @setup("abc123")
116-
ci.initialize().then =>
117-
expect(@verify).to.be.calledOnce
118-
119-
it "installs cypress if verification failed", ->
120-
@verify.rejects()
121-
122-
ci = @setup("abc123")
123-
ci.initialize({key: "abc123"}).then =>
124-
expect(@Install.getCall(0).args[0].displayOpen).to.be.false
125-
expect(@Install.getCall(0).args[0].after).to.be.a("function")
126-
expect(@Run).to.be.calledWithMatch(null, {key: "abc123"})
127-
128-
it "logs out install message", ->
129-
@verify.rejects()
130-
131-
ci = @setup("abc123")
132-
ci.initialize().then =>
133-
expect(@log).to.be.calledWithMatch("Cypress was not found:", "Installing a fresh copy.")
134-
135-
context "#_noKeyErr", ->
99+
context "#_noKeyErr", ->
136100
beforeEach ->
137101
@exit = @sandbox.stub(process, "exit")
138102
@log = @sandbox.stub(console, "log")
@@ -144,8 +108,5 @@ describe "Ci", ->
144108

145109
it "logs error message", ->
146110
expect(@log).to.be.calledWithMatch("You did not pass a specific key to:", "cypress ci")
147-
expect(@log).to.be.calledWithMatch("You can receive your project's secret key by running", "cypress get:key")
148-
expect(@log).to.be.calledWith("Please provide us your project's secret key and then rerun.")
149-
150-
it "logs the env key we checked for", ->
151-
expect(@log).to.be.calledWithMatch(/\w+/, "CYPRESS_CI_KEY")
111+
expect(@log).to.be.calledWithMatch("Since no key was passed, we checked for an environment\nvariable but none was found with the name:", "CYPRESS_RECORD_KEY")
112+
expect(@log).to.be.calledWith("https://on.cypress.io/what-is-a-record-key")

0 commit comments

Comments
 (0)