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

Default Hyvä cypress is failing #103

Open
MaximGns opened this issue Dec 16, 2022 · 1 comment
Open

Default Hyvä cypress is failing #103

MaximGns opened this issue Dec 16, 2022 · 1 comment

Comments

@MaximGns
Copy link

MaximGns commented Dec 16, 2022

Describe the bug

When I run the cypress tests, several tests fail.
The failing tests:

  • Can add a coupon to the cart
  • Can delete an added coupon from the cart
  • Cannot add an invalid coupon
  • Can visit the category page and filters on color red
  • Can add a product to the wishlist when customer is logged in
  • Can open default CMS pages
  • Can find a single product
  • Can remove an address
  • Can edit the wishlist and remove item

To Reproduce
Steps to reproduce the behavior:

composer.json

    "require": {
        "hyva-themes/magento2-default-theme": "1.1.17",
        "hyva-themes/magento2-email-module": "^1.0",
        "hyva-themes/magento2-graphql-tokens": "^1.0",
        "hyva-themes/magento2-luma-checkout": "^1.1",
        "hyva-themes/magento2-reset-theme": "^1.1",
        "hyva-themes/magento2-theme-module": "1.1.17",
        "magento/product-community-edition": "^2.4",
        "markshust/magento2-module-disabletwofactorauth": "^2.0"
    },

    "require-dev": {
        "magento/magento-cloud-docker": "^1.3",
        "magento/module-bundle-sample-data": "100.4.*",
        "magento/module-catalog-rule-sample-data": "100.4.*",
        "magento/module-catalog-sample-data": "100.4.*",
        "magento/module-cms-sample-data": "100.4.*",
        "magento/module-configurable-sample-data": "100.4.*",
        "magento/module-customer-sample-data": "100.4.*",
        "magento/module-downloadable-sample-data": "100.4.*",
        "magento/module-grouped-product-sample-data": "100.4.*",
        "magento/module-msrp-sample-data": "100.4.*",
        "magento/module-offline-shipping-sample-data": "100.4.*",
        "magento/module-product-links-sample-data": "100.4.*",
        "magento/module-review-sample-data": "100.4.*",
        "magento/module-sales-rule-sample-data": "100.4.*",
        "magento/module-sales-sample-data": "100.4.*",
        "magento/module-swatches-sample-data": "100.4.*",
        "magento/module-tax-sample-data": "100.4.*",
        "magento/module-theme-sample-data": "100.4.*",
        "magento/module-widget-sample-data": "100.4.*",
        "magento/module-wishlist-sample-data": "100.4.*",
        "magento/sample-data-media": "100.4.*"
    },

cypress.config.js

const {defineConfig} = require('cypress');
const {tagify} = require('cypress-tags');
const fs = require('fs');
const envConfig = fs.existsSync('./cypress.env.json') ? require('./cypress.env.json') : {};

// Run "NODE_ENV=develop; npx cypress run" to run tests locally
const defaultBaseUrl = process.env.NODE_ENV === 'develop' ? 'https://hyva.playground.local' : 'https://hyva.playground.local';

// Sometimes our local envs are slow due to dev mode. Raising the timeout decreases flakiness
const defaultCommandTimeout = process.env.NODE_ENV === 'develop' ? 10000 : 4000;

// Customize to use either hyva, luma or custom specs
const defaultSpecPattern = [
    'cypress/integration/hyva/**/*.spec.js',
];

const baseUrl = process.env.CYPRESS_MAGENTO2_BASE_URL || envConfig.MAGENTO2_BASE_URL || defaultBaseUrl;
module.exports = defineConfig({
    projectId: "",
    e2e: {
        baseUrl: baseUrl,
        specPattern: process.env.CYPRESS_MAGENTO2_SPEC_PATTERN || envConfig.MAGENTO2_SPEC_PATTERN || defaultSpecPattern,
        specSuite: process.env.CYPRESS_MAGENTO2_SPEC_SUITE || envConfig.MAGENTO2_SPEC_SUITE || undefined,
        excludeSpecPattern: process.env.CYPRESS_MAGENTO2_EXCLUDE_PATTERN || envConfig.MAGENTO2_EXCLUDE_PATTERN || '',
        defaultCommandTimeout: parseInt(process.env.CYPRESS_MAGENTO2_DEFAULT_TIMEOUT || envConfig.MAGENTO2_DEFAULT_TIMEOUT || defaultCommandTimeout),
        videoUploadOnPasses: !!(process.env.CYPRESS_VIDEO_UPLOAD_ON_PASSES || envConfig.VIDEO_UPLOAD_ON_PASSES || false),
        watchForFileChanges: false,
        supportFile: 'cypress/support/index.js',
        viewportWidth: 1920,
        viewportHeight: 1080,

        env: {
            mobileViewportWidthBreakpoint: 768,
            mobileViewportWidthBreakpointHyva: 1024
        },

        setupNodeEvents(on, config) {

            on('after:spec', (spec, results) => {
                // If a retry failed, save the video, otherwise delete it to save time by not compressing it.
                if (results && results.video) {
                    // Do we have failures for any retry attempts?
                    const failures = results.tests.find(test => {
                        return test.attempts.find(attempt => {
                            return attempt.state === 'failed'
                        })
                    });
                    // Delete the video if the spec passed on all attempts
                    if (!failures) {
                        fs.existsSync(results.video) && fs.unlinkSync(results.video)
                    }
                }
            })

            on('file:preprocessor', tagify(config))

            const applySpecSuiteToSpecPattern = (config) => {
                // If the specSuite is an empty string, add a trailing / to $SPEC_SUITE to avoid // in the pattern
                const regex = config.specSuite === '' ? /\$SPEC_SUITE\//g : /\$SPEC_SUITE/g;
                const fn = (specPattern) => specPattern.replace(regex, config.specSuite)
                config.specPattern = typeof config.specPattern === 'string' ? fn(config.specPattern) : config.specPattern.map(fn);
                return config;
            }

            return config.specSuite === undefined
                ? new Promise((resolve, reject) => {
                    // Do a preflight request to determine which frontend test suite to run depending on the target theme
                    if (baseUrl.startsWith('https')) process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0';
                    const req = (baseUrl.startsWith('https') ? require('https') : require('http')).request(baseUrl);
                    req.on('response', res => {
                        config.specSuite = res.headers['x-built-with'] === 'Hyva Themes' ? 'hyva' : 'luma'
                        resolve(applySpecSuiteToSpecPattern(config));
                    })
                    req.on('error', reject);
                    req.end();
                })
                : applySpecSuiteToSpecPattern(config);
        }
    }
});

cypress.env.json

{
  "MAGENTO2_ADMIN_TOKEN": "eyJraWQiOiIxIiwiYWxnIjoiSFMyNTYifQ.eyJ1aWQiOjEsInV0eXBpZCI6MiwiaWF0IjoxNjcwOTIwNTA1LCJleHAiOjE2NzA5MjQxMDV9.TsFWBeGjERqDdcfZzHuWsWXGI22dMyZgt2XWsizA7ls",
  "MAGENTO2_SKIP_CHECKOUT": true,
  "MAGENTO2_DEFAULT_TIMEOUT": 10000
}
@peterjaap
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants