Skip to content

Commit

Permalink
Add new plugin events 'before:spec', 'after:spec', 'before:run', and …
Browse files Browse the repository at this point in the history
…'after:run' (#2331)

* implement before:spec, after:spec, and after:run plugin events

* ensure server events only executed if registered

* don’t execute plugin event if plugins process has been killed

* call default preprocessor directly instead of registering it as plugin

makes things more consistent because now plugins are only registered by the user. this was an exception where we registered it as a plugin, but it’s unnecessary because we can just call it directly

* fix unit tests

* await server events before proceeding

* add before:run plugin event

* pass run details to before:run event

* handle and report errors thrown in server event handlers

* wrap plugin execution in promise

* rename instances of plugin

* more rename fixes

* fix tests

* fix test

* rename events to use ‘start’ instead of ‘before’ and ‘end’ instead of ‘after’

* bump zunder to 6.3.2

* await run & spec events in interactive mode

* fix server unit tests

* fix desktop-gui tests

* fix e2e specs

* fix desktop-gui specs

* fix desktop-gui specs

* add server unit tests for run/spec events in interactive mode

* add/update desktop-gui integration tests for run/spec events

* remove console.log
  • Loading branch information
chrisbreiding authored Jan 23, 2019
1 parent 16f52cc commit ac9340d
Show file tree
Hide file tree
Showing 65 changed files with 1,089 additions and 299 deletions.
23 changes: 17 additions & 6 deletions packages/desktop-gui/cypress/integration/global_mode_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,10 @@ describe "Global Mode", ->

describe "going back", ->
beforeEach ->
cy.contains("Back").click()

it "returns to intro on click of back button", ->
cy.shouldBeOnIntro()
@closeProject = @util.deferred()
@ipc.closeProject.returns(@closeProject.promise)

it "removes project name from title", ->
cy.title().should("equal", "Cypress")
cy.contains("Back").click()

it "removes ipc listeners", ->
expect(@ipc.offOpenProject).to.be.called
Expand All @@ -148,3 +145,17 @@ describe "Global Mode", ->

it "closes project", ->
expect(@ipc.closeProject).to.be.called

it "shows loader", ->
cy.get(".loader")
cy.contains("Closing project...")

describe "when finished closing", ->
beforeEach ->
@closeProject.resolve()

it "goes to intro", ->
cy.shouldBeOnIntro()

it "removes project name from title", ->
cy.title().should("equal", "Cypress")
41 changes: 30 additions & 11 deletions packages/desktop-gui/cypress/integration/project_nav_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ describe "Project Nav", ->
cy.stub(@ipc, "getRuns").resolves(@runs)
cy.stub(@ipc, "getSpecs").yields(null, @specs)
cy.stub(@ipc, "getRecordKeys").resolves([])
cy.stub(@ipc, "launchBrowser")
cy.stub(@ipc, "closeBrowser").resolves(null)
cy.stub(@ipc, "onBrowserClose")
cy.stub(@ipc, "pingApiServer").resolves()
cy.stub(@ipc, "closeProject")
cy.stub(@ipc, "externalOpen")
Expand All @@ -26,6 +26,9 @@ describe "Project Nav", ->
@openProject = @util.deferred()
cy.stub(@ipc, "openProject").returns(@openProject.promise)

@launchBrowser = @util.deferred()
cy.stub(@ipc, "launchBrowser").returns(@launchBrowser.promise)

start()

context "project nav", ->
Expand Down Expand Up @@ -134,8 +137,8 @@ describe "Project Nav", ->

context "browser opened after choosing spec", ->
beforeEach ->
@ipc.launchBrowser.yields(null, {browserOpened: true})
cy.contains(".file", "app_spec").click()
@launchBrowser.resolve()

it "displays browser icon as opened", ->
cy.get(".browsers-list>a").first().find("i")
Expand All @@ -150,25 +153,41 @@ describe "Project Nav", ->

describe "stop browser", ->
beforeEach ->
@closeBrowser = @util.deferred()
@ipc.closeBrowser.returns(@closeBrowser.promise)

cy.get(".close-browser").click()

it "calls close:browser on click of stop button", ->
it "calls ipc close:browser", ->
expect(@ipc.closeBrowser).to.be.called

it "hides close button on click of stop", ->
it "hides close button", ->
cy.get(".close-browser").should("not.exist")

it "re-enables browser dropdown", ->
cy.get(".browsers-list>a").first()
.should("not.have.class", "disabled")
it "blocks the UI and shows closing loader while browser is closing", ->
cy.get(".ui-blocker")
cy.get(".browsers-list").find(".fa-refresh.fa-spin")
cy.contains("Closing Chrome 50")

it "displays default browser icon", ->
cy.get(".browsers-list>a").first()
.find(".fa-chrome")
describe "when browser is finished closing", ->
beforeEach ->
@closeBrowser.resolve()

it "re-enables browser dropdown", ->
cy.get(".browsers-list>a").first()
.should("not.have.class", "disabled")

it "displays default browser icon", ->
cy.get(".browsers-list>a").first()
.find(".fa-chrome")

it "unblocks the UI", ->
cy.get(".ui-blocker").should("not.exist")

describe "browser is closed manually", ->
beforeEach ->
@ipc.launchBrowser.yield(null, {browserClosed: true})
cy.stub(@ipc, "awaitBrowserClose").resolves()
@ipc.onBrowserClose.yield()

it "hides close browser button", ->
cy.get(".close-browser").should("not.be.visible")
Expand Down
14 changes: 12 additions & 2 deletions packages/desktop-gui/cypress/integration/project_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ describe "Project", ->
it "re-opens project if config changes", ->
cy.shouldBeOnProjectSpecs().then =>
@ipc.onConfigChanged.yield()
expect(@ipc.closeProject).to.be.called
expect(@ipc.openProject).to.be.called
cy.wrap(@ipc.closeProject).should("be.called")
cy.wrap(@ipc.openProject).should("be.called")
cy.shouldBeOnProjectSpecs()

describe "opening", ->
beforeEach ->
@openProject = @util.deferred()
@ipc.openProject.returns(@openProject.promise)
@start()

it "shows loader", ->
cy.get(".loader")
cy.contains("Opening project...")

describe "warnings", ->
beforeEach ->
@start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ describe "Projects List", ->
@start()

it "loads projects and shows loader", ->
cy.get(".projects-list .loader").then =>
cy.get(".projects-list .loader")
.should("have.text", "Loading projects...")
.then =>
expect(@ipc.getProjects).to.be.called

describe "when loaded", ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe "Runs List", ->
it "pings api server", ->
expect(@ipc.pingApiServer).to.be.called
cy.get(".loader")
cy.contains("Loading runs...")

describe "success", ->
beforeEach ->
Expand Down Expand Up @@ -425,6 +426,7 @@ describe "Runs List", ->

it "shows loading spinner", ->
cy.get(".loader")
cy.contains("Loading runs...")

it "shows runs when getting runs succeeds", ->
@getRuns.resolve(@runs)
Expand Down
23 changes: 15 additions & 8 deletions packages/desktop-gui/cypress/integration/settings_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,23 @@ describe "Settings", ->
newConfig.browsers = @browsers
@openProject.resolve(newConfig)

@goToSettings()
cy.contains("Configuration").click()
@goToSettings().then =>
@openProject2ndCall = @util.deferred()
@ipc.openProject.onCall(1).returns(@openProject2ndCall.promise)
@ipc.onConfigChanged.yield()

it "displays updated config", ->
newConfig = @util.deepClone(@config)
newConfig.resolved.baseUrl.value = "http://localhost:7777"
@ipc.openProject.onCall(1).resolves(newConfig)
@ipc.onConfigChanged.yield()
it "re-opens the project", ->
cy.wrap(@ipc.openProject).should("be.calledTwice")

cy.contains("http://localhost:7777")
describe "when project re-opens", ->
beforeEach ->
newConfig = @util.deepClone(@config)
newConfig.resolved.baseUrl.value = "http://localhost:7777"
@openProject2ndCall.resolve(newConfig)

it "displays updated config", ->
cy.contains("Configuration").click()
cy.contains("http://localhost:7777")

describe "errors", ->
beforeEach ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ describe "Set Up Project", ->
beforeEach ->
@getCurrentUser.resolve(@user)

it "shows loader while orgs load", ->
cy.get(".btn").contains("Set up project").click()
cy.get(".loader")

describe "general behavior", ->
beforeEach ->
@getOrgs.resolve(@orgs)
Expand Down Expand Up @@ -343,6 +347,7 @@ describe "Set Up Project", ->
beforeEach ->
cy.stub(@ipc, "windowOpen").resolves()
cy.stub(@ipc, "logIn").resolves(@user)
@getOrgs.resolve()
cy.contains("button", "Log In with GitHub").click()

it "shows setup", ->
Expand Down
30 changes: 18 additions & 12 deletions packages/desktop-gui/cypress/integration/specs_list_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ describe "Specs List", ->

cy.stub(@ipc, "getOptions").resolves({projectRoot: "/foo/bar"})
cy.stub(@ipc, "getCurrentUser").resolves(@user)
cy.stub(@ipc, "getSpecs").yields(null, @specs)
cy.stub(@ipc, "getSpecs")
cy.stub(@ipc, "closeBrowser").resolves(null)
cy.stub(@ipc, "launchBrowser")
cy.stub(@ipc, "launchBrowser").resolves()
cy.stub(@ipc, "openFinder")
cy.stub(@ipc, "externalOpen")
cy.stub(@ipc, "onboardingClosed")
Expand All @@ -23,6 +23,11 @@ describe "Specs List", ->

start()

it "shows loader", ->
@openProject.resolve(@config)
cy.get(".loader")
cy.contains("Loading specs...")

describe "no specs", ->
beforeEach ->
@ipc.getSpecs.yields(null, [])
Expand All @@ -47,6 +52,7 @@ describe "Specs List", ->

describe "first time onboarding specs", ->
beforeEach ->
@ipc.getSpecs.yields(null, @specs)
@config.isNewProject = true
@openProject.resolve(@config)

Expand Down Expand Up @@ -123,10 +129,11 @@ describe "Specs List", ->
cy
.contains(".btn", "Run all specs").click()
.then ->
launchArgs = @ipc.launchBrowser.lastCall.args
expect(@ipc.launchBrowser).to.be.called

expect(launchArgs[0].browser.name).to.eq "chrome"
expect(launchArgs[0].spec.name).to.eq "All Specs"
launchArgs = @ipc.launchBrowser.lastCall.args[0]
expect(launchArgs.browser.name).to.eq "chrome"
expect(launchArgs.spec.name).to.eq "All Specs"

describe "all specs running in browser", ->
beforeEach ->
Expand Down Expand Up @@ -266,16 +273,15 @@ describe "Specs List", ->
@openProject.resolve(@config)
cy.contains(".file a", "app_spec.coffee").as("firstSpec")

it "closes then launches browser on click of file", ->
it "launches browser on click of file", ->
cy.get("@firstSpec")
.click()
.then ->
expect(@ipc.closeBrowser).to.be.called
expect(@ipc.launchBrowser).to.be.called

launchArgs = @ipc.launchBrowser.lastCall.args

expect(launchArgs[0].browser.name).to.equal("chrome")
expect(launchArgs[0].spec.relative).to.equal("cypress/integration/app_spec.coffee")
launchArgs = @ipc.launchBrowser.lastCall.args[0]
expect(launchArgs.browser.name).to.equal("chrome")
expect(launchArgs.spec.relative).to.equal("cypress/integration/app_spec.coffee")

it "adds 'active' class on click", ->
cy.get("@firstSpec")
Expand Down Expand Up @@ -315,9 +321,9 @@ describe "Specs List", ->
cy.get("@deepSpec").should("have.class", "active")

context "switching specs", ->

beforeEach ->
@ipc.getSpecs.yields(null, @specs)
@ipc.launchBrowser
@openProject.resolve(@config)
cy
.get(".file").contains("a", "app_spec.coffee").as("firstSpec")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe "Update Banner", ->
{ @start, @ipc } = win.App

cy.stub(@ipc, "getCurrentUser").resolves(@user)
cy.stub(@ipc, "openProject").resolves(@config)
cy.stub(@ipc, "windowOpen")
cy.stub(@ipc, "externalOpen")

Expand Down Expand Up @@ -98,7 +99,6 @@ describe "Update Banner", ->
describe "in specs list", ->
beforeEach ->
cy.stub(@ipc, "getOptions").resolves({version: OLD_VERSION, projectRoot: "/foo/bar"})
cy.stub(@ipc, "openProject").resolves(@config)
cy.stub(@ipc, "getSpecs").yields(null, @specs)
@start()
@updaterCheck.resolve(NEW_VERSION)
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"rebuild-node-sass": "1.1.0",
"react-bootstrap-modal": "4.2.0",
"react-dom": "^16.7.0",
"react-loader": "^2.4.5",
"zunder": "6.3.0"
"zunder": "6.3.2"
}
}
4 changes: 2 additions & 2 deletions packages/desktop-gui/src/app/app.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import _ from 'lodash'
import { observer } from 'mobx-react'
import React, { Component } from 'react'
import Loader from 'react-loader'

import appApi from '../lib/app-api'
import C from '../lib/constants'
Expand All @@ -12,6 +11,7 @@ import viewStore from '../lib/view-store'

import Intro from './intro'
import Layout from './layout'
import Loader from '../lib/loader'
import Project from '../project/project'

@observer
Expand All @@ -30,7 +30,7 @@ class App extends Component {
render () {
switch (viewStore.currentView.name) {
case C.LOADING:
return <Loader color='#888' scale={0.5} />
return <Loader fullscreen />
case C.INTRO:
return (
<Layout>
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-gui/src/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import GlobalError from './global-error'
import Footer from '../footer/footer'
import LoginModal from '../auth/login-modal'
import UpdateBanner from '../update/update-banner'
import UiBlocker from './ui-blocker'

export default ({ children }) => {
return (
Expand All @@ -15,6 +16,7 @@ export default ({ children }) => {
<Footer />
<LoginModal />
<GlobalError />
<UiBlocker />
</div>
)
}
9 changes: 7 additions & 2 deletions packages/desktop-gui/src/app/nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import viewStore from '../lib/view-store'
import ipc from '../lib/ipc'
import { gravatarUrl } from '../lib/utils'
import { Link, routes } from '../lib/routing'
import projectsApi from '../projects/projects-api'

import Dropdown from '../dropdown/dropdown'

Expand Down Expand Up @@ -51,7 +52,7 @@ export default class Nav extends Component {
// global mode, on project page
if (appStore.isGlobalMode && project) {
return (
<Link to={routes.intro()}>
<Link to={routes.intro()} onClick={this._unloadProject}>
<i className='fa fa-chevron-left'></i> Back
</Link>
)
Expand Down Expand Up @@ -122,12 +123,16 @@ export default class Nav extends Component {

}

_select = (item) => {
_select (item) {
if (item.id === 'logout') {
authApi.logOut()
}
}

_unloadProject () {
return projectsApi.closeProject(viewStore.currentView.project)
}

_showLogin () {
authStore.setShowingLogin(true)
}
Expand Down
Loading

0 comments on commit ac9340d

Please sign in to comment.