server: send warning when headed and can’t connect to baseUrl

This commit is contained in:
Chris Breiding
2017-06-19 14:17:17 -04:00
parent 51107f33d5
commit 76fbed9e90
7 changed files with 59 additions and 11 deletions

View File

@@ -281,6 +281,12 @@ API = {
Please start this server and then run Cypress again.
"""
when "CANNOT_CONNECT_BASE_URL_WARNING"
"""
Cypress could not verify this server is running: #{arg1}
We run this check because this server has been set as your 'baseUrl'. You likely forgot to boot this web server prior to running Cypress.
"""
get: (type, arg1, arg2) ->
msg = @getMsgByType(type, arg1, arg2)

View File

@@ -200,10 +200,14 @@ handleEvent = (options, bus, event, id, type, arg) ->
bus.emit("focus:tests")
onWarning = (warning) ->
sendErr(warning)
openProject.create(arg, options, {
onFocusTests: onFocusTests
onSpecChanged: onSpecChanged
onSettingsChanged: onSettingsChanged
onWarning: onWarning
})
.call("getConfig")
.then(send)

View File

@@ -67,7 +67,7 @@ class Project extends EE
process.chdir(@projectRoot)
@server.open(cfg, @)
.then (port) =>
.spread (port, warning) =>
## if we didnt have a cfg.port
## then get the port once we
## open the server
@@ -81,6 +81,10 @@ class Project extends EE
## opening the server
@cfg = cfg
if warning
warning.isWarning = true
options.onWarning(warning)
options.onSavedStateChanged = (state) =>
@saveState(state)

View File

@@ -192,16 +192,21 @@ class Server
## and make sure the server is connectable!
if baseUrl
connect.ensureUrl(baseUrl)
.return(null)
.catch (err) =>
reject errors.get("CANNOT_CONNECT_BASE_URL", baseUrl)
.then =>
if config.isHeadless
reject(errors.get("CANNOT_CONNECT_BASE_URL", baseUrl))
else
errors.get("CANNOT_CONNECT_BASE_URL_WARNING", baseUrl)
.then (warning) =>
## once we open set the domain
## to root by default
## which prevents a situation where navigating
## to http sites redirects to /__/ cypress
@_onDomainSet(baseUrl ? "<root>")
resolve(port)
resolve([port, warning])
_port: ->
@_server?.address()?.port

View File

@@ -520,10 +520,11 @@ describe "lib/cypress", ->
.then =>
@expectExitWithErr("SUPPORT_FILE_NOT_FOUND", "Your supportFile is set to '/does/not/exist',")
it "logs error when browser cannot be found", ->
cypress.start(["--project=#{@idsPath}", "--browser=foo"])
.then =>
@expectExitWithErr("BROWSER_NOT_FOUND", "browser foo")
## FIXME
it.skip "logs error when browser cannot be found", ->
cypress.start(["--run-project=#{@idsPath}", "--browser=foo"])
.then =>
@expectExitWithErr("BROWSER_NOT_FOUND", "browser foo")
it "logs error and exits when spec file was specified and does not exist", ->
Project.add(@todosPath)
@@ -1009,7 +1010,7 @@ describe "lib/cypress", ->
it "passes filtered options to Project#open and sets cli config", ->
getConfig = @sandbox.spy(Project.prototype, "getConfig")
open = @sandbox.stub(Server.prototype, "open").resolves()
open = @sandbox.stub(Server.prototype, "open").resolves([])
process.env.CYPRESS_FILE_SERVER_FOLDER = "foo"
process.env.CYPRESS_BASE_URL = "localhost"
@@ -1085,6 +1086,26 @@ describe "lib/cypress", ->
from: "cli"
})
it "sends warning when baseUrl cannot be verified", ->
event = {
sender: {
send: @sandbox.stub()
}
}
warning = {
isWarning: true,
message: "Blah blah baseUrl blah blah"
}
open = @sandbox.stub(Server.prototype, "open").resolves([2121, warning])
cypress.start(["--port=2121", "--config", "pageLoadTimeout=1000", "--foo=bar", "--env=baz=baz"])
.then =>
options = Events.start.firstCall.args[0]
Events.handleEvent(options, {}, event, 123, "open:project", @todosPath)
.then ->
expect(event.sender.send.withArgs("response").firstCall.args[1].__error).to.eql(warning)
context "no args", ->
beforeEach ->
@sandbox.stub(electron.app, "on").withArgs("ready").yieldsAsync()

View File

@@ -134,7 +134,7 @@ describe "lib/project", ->
@sandbox.stub(@project, "watchSupportFile").resolves()
@sandbox.stub(@project, "scaffold").resolves()
@sandbox.stub(@project, "getConfig").resolves(@config)
@sandbox.stub(Server.prototype, "open").resolves()
@sandbox.stub(Server.prototype, "open").resolves([])
it "calls #watchSettingsAndStartWebsockets with options + config", ->
opts = {changeEvents: false, onAutomationRequest: ->}

View File

@@ -9,6 +9,7 @@ config = require("#{root}lib/config")
logger = require("#{root}lib/logger")
Server = require("#{root}lib/server")
Socket = require("#{root}lib/socket")
connect = require("#{root}lib/util/connect")
morganFn = ->
mockery.registerMock("morgan", -> morganFn)
@@ -98,9 +99,16 @@ describe "lib/server", ->
it "resolves with http server port", ->
@server.createServer(@app, {port: @port})
.then (port) =>
.spread (port) =>
expect(port).to.eq(@port)
it "resolves with warning if cannot connect to baseUrl", ->
@sandbox.stub(connect, "ensureUrl").rejects()
@server.createServer(@app, {port: @port, baseUrl: "http://localhost:#{@port}"})
.spread (port, warning) =>
expect(warning.type).to.eq("CANNOT_CONNECT_BASE_URL_WARNING")
expect(warning.message).to.include(@port)
context "errors", ->
it "rejects with portInUse", ->
@server.createServer(@app, {port: @port})