Skip to content

Commit

Permalink
refactor: update to cypress 12
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Apr 9, 2024
1 parent 812f2b6 commit 6866e70
Show file tree
Hide file tree
Showing 72 changed files with 1,107 additions and 2,204 deletions.
50 changes: 50 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// eslint-disable-next-line import/no-unused-modules
const { defineConfig } = require('cypress')
const webpack = require('@cypress/webpack-preprocessor')
const preprocessor = require('@badeball/cypress-cucumber-preprocessor')

/**
* Configuration for the cypress-cucumber preprocessing, see:
* https://github.com/badeball/cypress-cucumber-preprocessor/tree/master/examples/webpack-cjs
*/
async function setupNodeEvents(on, config) {
// This is required for the preprocessor to be able to generate JSON reports after each run, and more,
await preprocessor.addCucumberPreprocessorPlugin(on, config)

on(
'file:preprocessor',
webpack({
webpackOptions: {
resolve: {
extensions: ['.ts', '.js'],
},
module: {
rules: [
{
test: /\.feature$/,
use: [
{
loader: '@badeball/cypress-cucumber-preprocessor/webpack',
options: config,
},
],
},
],
},
},
})
)

// Make sure to return the config object as it might have been modified by the plugin.
return config
}

module.exports = defineConfig({
projectId: 'sc56ms',
video: false,
e2e: {
setupNodeEvents,
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/e2e/**/*.feature',
},
})
6 changes: 3 additions & 3 deletions cypress.env.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dhis2BaseUrl": "http://localhost:8080",
"dhis2Username": "USERNAME_HERE",
"dhis2Password": "PASSWORD_HERE"
"LOGIN_NAME": "login name here",
"LOGIN_PASSWORD": "password here",
"LOGIN_SERVER": "https://debug.dhis2.org/dev"
}
12 changes: 0 additions & 12 deletions cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('the user navigated to the add job route', () => {
cy.visit('/#/job/add')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('the user navigated to the add job route', () => {
cy.visit('/#/job/add')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('the user navigated to the add queue route', () => {
cy.visit('/#/queue/add')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single user job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single cron scheduled user job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single user job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single user job exists', () => {
cy.intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a queue exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

/**
* Local helpers
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single queue exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single system job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single user job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('some user jobs and queues exist', () => {
cy.intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('some user jobs exist', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a queue exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('there are no user jobs', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('the user navigated to the list route', () => {
cy.visit('/')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('the user navigated to the list route', () => {
cy.visit('/')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a disabled user job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, When, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, When, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a disabled queue exists', () => {
cy.intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('an unauthorized user navigates to the app', () => {
cy.intercept(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single system job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

Given('a single system job exists', () => {
cy.intercept(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'
import { Given, Then } from '@badeball/cypress-cucumber-preprocessor'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'
Expand Down
11 changes: 0 additions & 11 deletions cypress/plugins/index.js

This file was deleted.

47 changes: 47 additions & 0 deletions cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* global Cypress */
import '@testing-library/cypress/add-commands'

/**
* Custom login command, can be used to login or switch between sessions.
* Will cache and restore cookies, localStorage, and sessionStorage. See:
* https://docs.cypress.io/api/commands/session
*/
Cypress.Commands.add('login', (user) => {
cy.session(
user,
() => {
// Login via API
cy.request({
url: `${user.server}/dhis-web-commons-security/login.action`,
method: 'POST',
form: true,
followRedirect: true,
body: {
j_username: user.name,
j_password: user.password,
'2fa_code': '',
},
})

// Set base url for the app platform
window.localStorage.setItem('DHIS2_BASE_URL', user.server)
},
{
validate: () => {
cy.request(`${user.server}/api/me`).then((response) => {
expect(response.status).to.eq(200)
expect(response.body.username).to.eq(user.name)
})
},
}
)
})

// Log in before each test, if not already logged in
beforeEach(() => {
cy.login({
name: Cypress.env('LOGIN_NAME'),
password: Cypress.env('LOGIN_PASSWORD'),
server: Cypress.env('LOGIN_SERVER'),
})
})
5 changes: 0 additions & 5 deletions cypress/support/index.js

This file was deleted.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@
"styled-jsx": "^4.0.1"
},
"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^20.0.3",
"@cypress/webpack-preprocessor": "^6.0.1",
"@dhis2/cli-app-scripts": "^10.3.9",
"@dhis2/cli-style": "^10.4.1",
"@dhis2/cli-utils-cypress": "^9.0.2",
"@dhis2/cypress-commands": "^9.0.2",
"@dhis2/cypress-plugins": "^9.0.2",
"@testing-library/cypress": "^7.0.6",
"@testing-library/react-hooks": "^7.0.0",
"cypress": "^9.5.1",
"cypress-cucumber-preprocessor": "^4.3.1",
"cypress": "12",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.6",
"eslint-plugin-compat": "^3.9.0",
Expand Down
Loading

0 comments on commit 6866e70

Please sign in to comment.