Skip to content

Commit

Permalink
Merge pull request #6008 from Ocelot-Social-Community/cypress-migrate…
Browse files Browse the repository at this point in the history
…-to-v10

test(other): migrate cypress to v12
  • Loading branch information
mahula authored Jun 6, 2023
2 parents 13f17f8 + bda5ac9 commit f040b2a
Show file tree
Hide file tree
Showing 156 changed files with 2,430 additions and 2,926 deletions.
49 changes: 33 additions & 16 deletions backend/src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
// NOTE: We cannot use `fs` here to clean up the code. Cypress breaks on any npm
// module that is not browser-compatible. Node's `fs` module is server-side only
export default {
Image: require('./Image.js').default,
Badge: require('./Badge.js').default,
User: require('./User.js').default,
Group: require('./Group.js').default,
EmailAddress: require('./EmailAddress.js').default,
UnverifiedEmailAddress: require('./UnverifiedEmailAddress.js').default,
SocialMedia: require('./SocialMedia.js').default,
Post: require('./Post.js').default,
Comment: require('./Comment.js').default,
Category: require('./Category.js').default,
Tag: require('./Tag.js').default,
Location: require('./Location.js').default,
Donations: require('./Donations.js').default,
Report: require('./Report.js').default,
Migration: require('./Migration.js').default,
InviteCode: require('./InviteCode.js').default,
Image: typeof Cypress !== 'undefined' ? require('./Image.js') : require('./Image.js').default,
Badge: typeof Cypress !== 'undefined' ? require('./Badge.js') : require('./Badge.js').default,
User: typeof Cypress !== 'undefined' ? require('./User.js') : require('./User.js').default,
Group: typeof Cypress !== 'undefined' ? require('./Group.js') : require('./Group.js').default,
EmailAddress:
typeof Cypress !== 'undefined'
? require('./EmailAddress.js')
: require('./EmailAddress.js').default,
UnverifiedEmailAddress:
typeof Cypress !== 'undefined'
? require('./UnverifiedEmailAddress.js')
: require('./UnverifiedEmailAddress.js').default,
SocialMedia:
typeof Cypress !== 'undefined'
? require('./SocialMedia.js')
: require('./SocialMedia.js').default,
Post: typeof Cypress !== 'undefined' ? require('./Post.js') : require('./Post.js').default,
Comment:
typeof Cypress !== 'undefined' ? require('./Comment.js') : require('./Comment.js').default,
Category:
typeof Cypress !== 'undefined' ? require('./Category.js') : require('./Category.js').default,
Tag: typeof Cypress !== 'undefined' ? require('./Tag.js') : require('./Tag.js').default,
Location:
typeof Cypress !== 'undefined' ? require('./Location.js') : require('./Location.js').default,
Donations:
typeof Cypress !== 'undefined' ? require('./Donations.js') : require('./Donations.js').default,
Report: typeof Cypress !== 'undefined' ? require('./Report.js') : require('./Report.js').default,
Migration:
typeof Cypress !== 'undefined' ? require('./Migration.js') : require('./Migration.js').default,
InviteCode:
typeof Cypress !== 'undefined'
? require('./InviteCode.js')
: require('./InviteCode.js').default,
}
53 changes: 53 additions & 0 deletions cypress/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const dotenv = require('dotenv')
const { defineConfig } = require("cypress");
const browserify = require("@badeball/cypress-cucumber-preprocessor/browserify");
const { addCucumberPreprocessorPlugin } = require("@badeball/cypress-cucumber-preprocessor");

// Test persistent(between commands) store
const testStore = {}

async function setupNodeEvents(on, config) {
await addCucumberPreprocessorPlugin(on, config);

on("file:preprocessor", browserify.default(config));

on("task", {
pushValue({ name, value }) {
testStore[name] = value
return true
},
getValue(name) {
console.log("getValue",name,testStore)
return testStore[name]
},
});

on("after:run", (results) => {
if (results) {
console.log(results.status);
}
});

return config;
}

// Import backend .env (smart)?
const { parsed } = dotenv.config({ path: '../backend/.env' })

module.exports = defineConfig({
e2e: {
projectId: "qa7fe2",
defaultCommandTimeout: 10000,
chromeWebSecurity: false,
baseUrl: "http://localhost:3000",
specPattern: "cypress/e2e/**/*.feature",
supportFile: "cypress/support/e2e.js",
retries: {
runMode: 2,
openMode: 0,
},
video: false,
setupNodeEvents,
},
env: parsed
});
12 changes: 0 additions & 12 deletions cypress/cypress.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Feature: User authentication

Scenario: Log out
Given I am logged in as "peter-pan"
When I log out
When I navigate to page "/"
And I log out
Then I am on page "login"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions cypress/integration/User.SettingNotifications/I_click_save.js

This file was deleted.

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/integration/common/I_navigate_to_page_{string}.js

This file was deleted.

6 changes: 0 additions & 6 deletions cypress/integration/common/I_refresh_the_page.js

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/integration/common/I_wait_for_{int}_milliseconds.js

This file was deleted.

4 changes: 2 additions & 2 deletions cypress/parallel-features.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ CUR_JOB=$(expr $1 - 1)
MAX_JOBS=$2

# Features
FEATURE_LIST=( $(find cypress/integration/ -maxdepth 1 -name "*.feature") )
FEATURE_LIST=( $(find cypress/e2e/ -maxdepth 1 -name "*.feature") )

# Calculation
MAX_FEATURES=$(find cypress/integration/ -maxdepth 1 -name "*.feature" -print | wc -l)
MAX_FEATURES=$(find cypress/e2e/ -maxdepth 1 -name "*.feature" -print | wc -l)
# adds overhead features to the first jobs
if [[ $CUR_JOB -lt $(expr ${MAX_FEATURES} % ${MAX_JOBS}) ]]
then
Expand Down
41 changes: 0 additions & 41 deletions cypress/plugins/index.js

This file was deleted.

6 changes: 3 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* globals Cypress cy */
import "cypress-file-upload";
import { GraphQLClient, request } from 'graphql-request'
import config from '../../backend/src/config'
import CONFIG from '../../backend/src/config'

const authenticatedHeaders = (variables) => {
const mutation = `
Expand All @@ -24,7 +24,7 @@ const authenticatedHeaders = (variables) => {
}
`
return new Cypress.Promise((resolve, reject) => {
request(config.GRAPHQL_URI, mutation, variables).then((response) => {
request(CONFIG.GRAPHQL_URI, mutation, variables).then((response) => {
resolve({ authorization: `Bearer ${response.login}` })
})
})
Expand All @@ -40,7 +40,7 @@ Cypress.Commands.add(
({email, password}) => {
return new Cypress.Promise((resolve, reject) => {
authenticatedHeaders({ email, password }).then((headers) => {
resolve(new GraphQLClient(config.GRAPHQL_URI, { headers }))
resolve(new GraphQLClient(CONFIG.GRAPHQL_URI, { headers }))
})
})
})
Expand Down
File renamed without changes.
10 changes: 2 additions & 8 deletions cypress/support/factories.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import Factory from '../../backend/src/db/factories'
import { getNeode } from '../../backend/src/db/neo4j'


const neo4jConfigs = {
uri: Cypress.env('NEO4J_URI'),
username: Cypress.env('NEO4J_USERNAME'),
password: Cypress.env('NEO4J_PASSWORD')
}
const neodeInstance = getNeode(neo4jConfigs)
const neodeInstance = getNeode()

beforeEach(() => cy.then(() => neodeInstance.cypher('MATCH (everything) DETACH DELETE everything;')))

Expand All @@ -16,7 +10,7 @@ Cypress.Commands.add('neode', () => {
})

Cypress.Commands.add(
'first',
'firstOf',
{ prevSubject: true },
(neode, model, properties) => {
return neode.first(model, properties)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { When } from "cypress-cucumber-preprocessor/steps";
import { When } from "@badeball/cypress-cucumber-preprocessor";

When("the donation info contains goal {string} and progress {string}", (goal, progress) => {
cy.get('.top-info-bar')
.should('contain', goal)
cy.get('.top-info-bar')
.should('contain', progress)
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { Then } from "@badeball/cypress-cucumber-preprocessor";

Then("the donation info is {string}", (visibility) => {
cy.get('.top-info-bar')
.should(visibility === 'visible' ? 'exist' : 'not.exist')
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { When } from "cypress-cucumber-preprocessor/steps";
import { When } from "@badeball/cypress-cucumber-preprocessor";

When("I open the content menu of post {string}", (title) => {
cy.contains('.post-teaser', title)
.find('.content-menu .base-button')
.click()
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { Then } from "@badeball/cypress-cucumber-preprocessor";

Then("the post with title {string} has a ribbon for pinned posts", (title) => {
cy.get(".post-teaser").contains(title)
.parent()
.parent()
.find(".ribbon.--pinned")
.should("contain", "Announcement")
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { Then } from "@badeball/cypress-cucumber-preprocessor";

Then("there is no button to pin a post", () => {
cy.get("a.ds-menu-item-link")
.should('contain', "Report Post") // sanity check
.should('not.contain', "Pin post")
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { Then } from "@badeball/cypress-cucumber-preprocessor";

Then("I see a button with the label {string}", label => {
cy.contains("button", label);
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { When } from "cypress-cucumber-preprocessor/steps";
import { When } from "@badeball/cypress-cucumber-preprocessor";

When("I select {string} in the language menu", language => {
cy.get(".locale-menu")
.click();
cy.contains(".locale-menu-popover a", language)
.click();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import locales from '../../../webapp/locales'
import { Then } from "@badeball/cypress-cucumber-preprocessor";
import locales from '../../../../webapp/locales'

Then("the whole user interface appears in {string}", language => {
const { code } = locales.find((entry) => entry.name === language);
cy.get(`html[lang=${code}]`);
cy.getCookie("locale").should("have.property", "value", code);
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Then } from "cypress-cucumber-preprocessor/steps";
import { Then } from "@badeball/cypress-cucumber-preprocessor";

Then("I should see only {int} posts on the newsfeed", posts => {
cy.get(".post-teaser")
.should("have.length", posts);
});


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

Then("the page {string} returns a 404 error with a message:", (route, message) => {
cy.request({
Expand All @@ -11,4 +11,4 @@ Then("the page {string} returns a 404 error with a message:", (route, message) =
failOnStatusCode: false
});
cy.get(".error-message").should("contain", message);
});
});
Loading

0 comments on commit f040b2a

Please sign in to comment.