Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Cypress to version 13 #276

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 92 additions & 75 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"role": "developer"
},
"devDependencies": {
"@10up/cypress-wp-utils": "github:10up/cypress-wp-utils#build",
"@10up/cypress-wp-utils": "^0.2.0",
"@wordpress/dependency-extraction-webpack-plugin": "^4.0.0",
"@wordpress/env": "^5.4.0",
"@wordpress/env": "^8.7.0",
"@wordpress/eslint-plugin": "^10.0.2",
"@wordpress/scripts": "^23.4.0",
"cypress": "^10.3.0",
"cypress": "^13.2.0",
"cypress-file-upload": "^5.0.8",
"eslint": "^8.8.0",
"prettier": "^2.8.7",
Expand Down
12 changes: 6 additions & 6 deletions tests/bin/initialize.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
npm run env run tests-wordpress "chmod -c ugo+w /var/www/html"
wp-env run tests-wordpress chmod -c ugo+w /var/www/html

npm run env run tests-cli "wp core multisite-convert --title='RSA Multisite'"
npm run env run tests-cli "wp post create --post_type=page --post_title='One' --post_status='publish'"
npm run env run tests-cli "wp post create --post_type=page --post_title='Two' --post_status='publish'"
npm run env run tests-cli "wp plugin activate rsa-seeder --network"
npm run env run tests-cli wp rewrite structure '/%postname%/' --hard
wp-env run tests-cli wp core multisite-convert --title='RSA Multisite'
wp-env run tests-cli wp post create --post_type=page --post_title='One' --post_status='publish'
wp-env run tests-cli wp post create --post_type=page --post_title='Two' --post_status='publish'
wp-env run tests-cli wp plugin activate rsa-seeder --network
wp-env run tests-cli wp rewrite structure '/%postname%/' --hard
10 changes: 6 additions & 4 deletions tests/cypress/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { defineConfig } = require('cypress');
const { readConfig } = require('@wordpress/env/lib/config');
const { loadConfig } = require('@wordpress/env/lib/config');
const getCacheDirectory = require('@wordpress/env/lib/config/get-cache-directory');

module.exports = defineConfig({
fixturesFolder: 'tests/cypress/fixtures',
Expand Down Expand Up @@ -41,14 +42,15 @@ module.exports = defineConfig({
* @returns config Updated Cypress Config object.
*/
const setBaseUrl = async (on, config) => {
const wpEnvConfig = await readConfig('wp-env');
const cacheDirectory = await getCacheDirectory();
const wpEnvConfig = await loadConfig(cacheDirectory);

if (wpEnvConfig) {
const port = wpEnvConfig.env.tests.port || null;

if (port) {
config.baseUrl = `http://${wpEnvConfig.env.tests.config.WP_TESTS_DOMAIN}:${port}`;
}
config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL;
}
}

return config;
Expand Down
3 changes: 3 additions & 0 deletions tests/cypress/e2e/activation-deactivation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ describe( 'Activation/Deactivation', () => {
cy.request( {
url: '/wp-json/rsa/v1/seed/activation-deactivation'
} );
} );

beforeEach( () => {
cy.login();
} );

Expand Down
9 changes: 3 additions & 6 deletions tests/cypress/e2e/add-invalid-addresses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ describe( 'Add invalid IPv4, IPv6 addresses', () => {
cy.request( {
url: '/wp-json/rsa/v1/seed/add-invalid-addresses'
} );
cy.login();
} );

beforeEach( () => {
cy.visitAdminPage( 'network/settings.php' );
} );

Expand All @@ -13,31 +15,26 @@ describe( 'Add invalid IPv4, IPv6 addresses', () => {
} );

it( 'Test error for invalid IPv4 subnet', () => {
cy.reload();
cy.addIp( '172.10.23.4/33', 'Invalid IPv4 subnet' );
cy.get( '#rsa-error-container' ).contains( 'The IP entered is invalid.' );
} );

it( 'Test error for invalid IPv4 pattern', () => {
cy.reload();
cy.addIp( '10.256.*', 'Invalid IPv4 pattern' );
cy.get( '#rsa-error-container' ).contains( 'The IP entered is invalid.' );
} );

it( 'Test error for invalid IPv6 single address', () => {
cy.reload();
cy.addIp( '2001:db8:3333:4444:5555:6666:7777:888g', 'Invalid IPv6 single address' );
cy.get( '#rsa-error-container' ).contains( 'The IP entered is invalid.' );
} );

it( 'Test error for invalid IPv6 subnet', () => {
cy.reload();
cy.addIp( '2001:0db8:3333:4444:0000:0000:0000:0000/129', 'Invalid IPv6 subnet' );
cy.get( '#rsa-error-container' ).contains( 'The IP entered is invalid.' );
} );

it( 'Test error for invalid IPv6 pattern', () => {
cy.reload();
cy.addIp( '2001:0db8:3333:4444:0000:0000:0000:::', 'Invalid IPv6 subnet' );
cy.get( '#rsa-error-container' ).contains( 'The IP entered is invalid.' );
} );
Expand Down
8 changes: 5 additions & 3 deletions tests/cypress/e2e/add-valid-addresses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ describe( 'Add & save valid IPv4, IPv6 addresses', () => {
cy.request( {
url: '/wp-json/rsa/v1/seed/add-valid-addresses'
} )
cy.login();
} );

beforeEach( () => {
cy.visitAdminPage( 'network/settings.php' );
} );

Expand All @@ -29,16 +31,16 @@ describe( 'Add & save valid IPv4, IPv6 addresses', () => {

it( 'Add IPv6 pattern', () => {
cy.addIp( '2001:db8:3333:4444:5555:6666:*:*', 'IPv6 pattern' );
cy.wait(300);
} );

after( () => {
afterEach( () => {
cy.saveSettings();
} )
} );

describe( 'Validate save operation', () => {
it( 'Validate each saved IP addresses', () => {
cy.visitAdminPage( 'network/settings.php' );
cy.get( '#ip_list .rsa_unrestricted_ip_row' ).eq( 0 ).find( 'input' ).eq( 0 ).should( 'have.value', '172.10.23.4' );
cy.get( '#ip_list .rsa_unrestricted_ip_row' ).eq( 0 ).find( 'input' ).eq( 1 ).should( 'have.value', 'IPv4 single address' );

Expand Down
16 changes: 1 addition & 15 deletions tests/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,6 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
Cypress.Commands.add(
'login',
( username = 'admin', password = 'password' ) => {
cy.visit( `/wp-admin` );
cy.get( 'body' ).then( ( $body ) => {
if ( $body.find( '#wpwrap' ).length == 0 ) {
cy.get( 'input#user_login' ).clear();
cy.get( 'input#user_login' ).click().type( username );
cy.get( 'input#user_pass' ).type( `${ password }{enter}` );
}
} );
}
);

Cypress.Commands.add( 'visitAdminPage', ( page = 'index.php' ) => {
cy.login();
if ( page.includes( 'http' ) ) {
Expand Down Expand Up @@ -111,4 +97,4 @@ Cypress.Commands.add( 'addIp', ( ip = '', label = '' ) => {
cy.get( '#ip_list .rsa_unrestricted_ip_row .ip.code' ).last().type( ip );
cy.get( '#ip_list .rsa_unrestricted_ip_row .newipcomment' ).last().type( label );
cy.get( '#addip' ).click();
} );
} );
6 changes: 0 additions & 6 deletions tests/cypress/support/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,3 @@ Cypress.on('uncaught:exception', (err, runnable) => {
return true
})

// Preserve WP cookies.
beforeEach(() => {
Cypress.Cookies.defaults({
preserve: /^wordpress.*?/,
});
});