Skip to content

Commit

Permalink
fix: simplify template setup
Browse files Browse the repository at this point in the history
  • Loading branch information
varl committed Feb 10, 2020
1 parent 87274ee commit 190e65f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 59 deletions.
8 changes: 5 additions & 3 deletions plugins.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const plugins = require('./src/cypress/plugins.js')

module.exports = plugins
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
const cucumber = require('cypress-cucumber-preprocessor').default
on('file:preprocessor', cucumber())
}
5 changes: 0 additions & 5 deletions src/cypress/plugins.js

This file was deleted.

47 changes: 0 additions & 47 deletions src/cypress/support.js

This file was deleted.

43 changes: 41 additions & 2 deletions support.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
const support = require('./src/cypress/support.js')
const loginEndPoint = 'dhis-web-commons/security/login.action'

module.exports = support
/**
* This is done through cy.request(...)
* because Cypress doesn't allow multiple domains per test:
* https://docs.cypress.io/guides/guides/web-security.html#One-Superdomain-per-Test
*/
Cypress.Commands.add('login', () => {
const username = Cypress.env('dhis2_username')
const password = Cypress.env('dhis2_password')
const loginUrl = Cypress.env('dhis2_base_url')
const loginAuth = `Basic ${btoa(`${username}:${password}`)}`

return cy.request({
url: `${loginUrl}/${loginEndPoint}`,
method: 'POST',
body: {
j_username: username,
j_password: password,
'2fa_code': '',
},
headers: { Authorization: loginAuth },
})
})

Cypress.Commands.add('stubWithFixture', ({ method = 'GET', url, fixture }) => {
return cy.route({
method,
url,
response: `fixture:${fixture}`,
})
})

Cypress.Commands.add('visitWhenStubbed', (url, options = {}) => {
return cy.visit(url, {
...options,
onBeforeLoad: win => {
delete win.fetch
options.onBeforeLoad && options.onBeforeLoad(win)
},
})
})
4 changes: 2 additions & 2 deletions templates/support.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const support = require('@dhis2/cli-utils-cypress/support')
import '@dhis2/cli-utils-cypress/support'

support()
// Add additional support functions here

0 comments on commit 190e65f

Please sign in to comment.