Skip to content

Commit

Permalink
Fix repeated dbResets so tests run faster
Browse files Browse the repository at this point in the history
* Set config.baseUrl and visit relative URLs to avoid Cypress bug which
  runs "before" hooks twice (github.com/cypress-io/cypress/issues/2777)
* Remove "after" hook dbResets; make tests responsible for their own
  initial state, not that of the subsequent test
  • Loading branch information
rcowsill committed Jan 15, 2021
1 parent f2514a5 commit 38f7011
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 36 deletions.
4 changes: 0 additions & 4 deletions test/e2e/integration/allocations_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/allocations behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/benefits_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/login behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/contributions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/contributions behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/login_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/login behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/logout_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/logout behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

it('Should redirect if the user has not logged in', () => {
cy.visitPage('/logout')
cy.url().should('include', 'login')
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/memos_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/memos behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/profile_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/profile behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
4 changes: 0 additions & 4 deletions test/e2e/integration/signup_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ describe('/signup behaviour', () => {
cy.dbReset()
})

after(() => {
cy.dbReset()
})

afterEach(() => {
cy.visitPage('/logout')
})
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@
// https://on.cypress.io/plugins-guide
// ***********************************************************

const { port, hostName } = require('../../../config/env/all')

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config

config.baseUrl = `http://${hostName}:${port}`

return config
}
6 changes: 2 additions & 4 deletions test/e2e/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { port, hostName } = require('../../../config/env/all')

Cypress.Commands.add('signIn', (usr, pw) => {
cy.visit(`http://${hostName}:${port}/login`)
cy.visitPage('/login')
cy.get('#userName').type(usr)
cy.get('#password').type(pw)
cy.get('[type="submit"]').click()
Expand All @@ -22,7 +20,7 @@ Cypress.Commands.add('userSignIn', () => {
})

Cypress.Commands.add('visitPage', (path = '/', config = {}) => {
cy.visit(`http://${hostName}:${port}${path}`, config)
cy.visit(path, config)
})

Cypress.Commands.add('dbReset', () => {
Expand Down

0 comments on commit 38f7011

Please sign in to comment.