Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Update plugin to be compatible with Cypress 10 #127

Closed
admah opened this issue May 26, 2022 · 16 comments
Closed

Update plugin to be compatible with Cypress 10 #127

admah opened this issue May 26, 2022 · 16 comments

Comments

@admah
Copy link
Contributor

admah commented May 26, 2022

Hello 👋 I'm writing on behalf of the Cypress DX team. We wanted to notify you that some changes may need to be made to this plugin to ensure that it works in Cypress 10.

For more information, here is our official plugin update guide.

@fbrandao15
Copy link

I can confirm this is an issue. After updating to cypress 10 if any string pattern is included in the grep or grepTags options it will break the new specPattern config from cypress and it wont load any specs at all.
image

@joshuajtward
Copy link
Contributor

I think this goes some way to getting this working in Cypress 10: #128

Would love to get some thoughts

@samanthablasbalg
Copy link

Also ran into this while trying to add cypress-grep to our repo after upgrading to cypress 10.

Your configFile threw an error from: /Users/samanthablasbalg/repos/wistia/cypress.config.js

The error was thrown while executing your e2e.setupNodeEvents() function:

TypeError: Patterns must be a string or an array of strings
    at assertPatternsInput (/Users/samanthablasbalg/repos/wistia/node_modules/globby/index.js:16:9)
    at generateGlobTasks (/Users/samanthablasbalg/repos/wistia/node_modules/globby/index.js:41:2)
    at AsyncFunction.module.exports.sync (/Users/samanthablasbalg/repos/wistia/node_modules/globby/index.js:139:20)
    at cypressGrepPlugin (/Users/samanthablasbalg/repos/wistia/node_modules/cypress-grep/src/plugin.js:60:32)
    at setupNodeEvents (/Users/samanthablasbalg/repos/wistia/cypress.config.js:33:41)

@lmiller1990
Copy link

Thanks @joshuajtward - will take a look. We should get this working with 10.0 asap.

@reneadamqa
Copy link

Hi! Is there any update on this topic so far? We would like to migrate to Cypress 10 but are blocked by not using cypress-grep as we need filters for our environment. Thanks!

@admah
Copy link
Contributor Author

admah commented Jun 21, 2022

@rene1039 I am planning to look into it this week.

@devim1982
Copy link

is there an estimated time where we could get the plugin working with cypress 10.0.0 ? thank you for your help.

@admah
Copy link
Contributor Author

admah commented Jun 21, 2022

@devim1982 see my comment above. Work towards this is being done in #128.

@joshuajtward
Copy link
Contributor

@admah we can close this issue now that #128 has been merged?

@lmiller1990
Copy link

lmiller1990 commented Jul 15, 2022

Yep, seems this is released and working with Cypress 10 as of 3.x: https://github.com/cypress-io/cypress-grep/releases/tag/v3.0.0

Edit: I do not have permissions on this repo, someone else will need to close it.

@admah admah closed this as completed Jul 22, 2022
@aminao-transformdata
Copy link

Will there be anything cypress releases to work like, from the first try?

@lmiller1990
Copy link

@aminao-transformdata have you tried the v 3 version of this plugin? https://github.com/cypress-io/cypress-grep/releases/tag/v3.0.0

When Cypress 10 came out, this plugin had yet to be updated, but now it is (v3) and should be 💯

@aminao-transformdata
Copy link

@aminao-transformdata have you tried the v 3 version of this plugin? https://github.com/cypress-io/cypress-grep/releases/tag/v3.0.0

When Cypress 10 came out, this plugin had yet to be updated, but now it is (v3) and should be 💯

I don't get what this plugin has to do?

My issue is that after plugins/index.js no longer exist, I have hard time moving this peace to e2e.js file:

const { downloadFile } = require('cypress-downloadfile/lib/addPlugin');
const { isFileExist, findFiles } = require('cy-verify-downloads');

/**

  • @type {Cypress.PluginConfig}
    */
    module.exports = (on) => {
    // on is used to hook into various events Cypress emits
    // config is the resolved Cypress config
    on('task', {
    log(message) {
    console.log(message);
    return null;
    },
    isFileExist,
    findFiles,
    downloadFile,
    });
    };

@lmiller1990
Copy link

Put those things inside of setupNodeEvents in your cypress.config.js:

export default {
  e2e: {
    setupNodeEvents (on, config) {
      on('task' ...
    }
  }
}

@aminao-transformdata
Copy link

Put those things inside of setupNodeEvents in your cypress.config.js:

export default {
  e2e: {
    setupNodeEvents (on, config) {
      on('task' ...
    }
  }
}

I'm running in an issue that I don't see anyone ever had.

Project structure:
Screenshot 2022-12-01 at 20 32 40

cypress.config.js

const { defineConfig } = require("cypress");
const { downloadFile } = require('cypress-downloadfile/lib/addPlugin');
const { isFileExist, findFiles } = require('cy-verify-downloads');


module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      // implement node event listeners here
        on('task', {
    log(message) {
      console.log(message);
      return null;
    },
    isFileExist,
    findFiles,
    downloadFile,
  });
    },
  baseUrl: '',
  specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
  },
});

commands.js

import { addCustomCommand } from 'cy-verify-downloads';
import 'cypress-downloadfile/lib/downloadFileCommand';
import './utils/auth';
import compareColor from './utils/compareColor';
import enableGQLListeners from './utils/enableGQLListeners';
import './utils/inViewPort';
import './utils/localStorage';

Cypress.Commands.add('visitHome', () => {
  cy.visit('/');
});

Cypress.Commands.overwrite('log', (subject, message) =>
  cy.task('log', message)
);

Cypress.Commands.add('enableGQLListeners', enableGQLListeners);

Cypress.Commands.overwrite(
  'should',
  (originalFn, subject, expectation, ...args) => {
    const customMatchers = {
      'have.backgroundColor': compareColor(args[0], 'backgroundColor'),
      'have.color': compareColor(args[0], 'color'),
      'have.borderColor': compareColor(args[0], 'borderColor'),
    };

    // See if the expectation is a string and if it is a member of Jest's expect
    if (typeof expectation === 'string' && customMatchers[expectation]) {
      // @ts-ignore
      return originalFn(subject, customMatchers[expectation]);
    }
    // @ts-ignore
    return originalFn(subject, expectation, ...args);
  }
);

// cy-verify-downloads
addCustomCommand();

e2e.js

// Import commands.js using ES2015 syntax:
// import './commands'

// Alternatively you can use CommonJS syntax:
require('./commands')

const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/;
Cypress.on('uncaught:exception', (err) => {
  /* returning false here prevents Cypress from failing the test */
  if (resizeObserverLoopErrRe.test(err.message)) {
    return false;
  }

  return true;
});

When running script in headless(yarn cypress run --config-file cypress.config.js --spec "cypress/e2e/InstallPage/rendering.js”), in deletes everything I have under cypress folder.

error:

Oops...we found an error preparing this test file:

  > cypress/support/e2e.js

The error was:

Error: Webpack Compilation Error
multi ./cypress/support/e2e.js

Do you see anything wrong with config file?

@lmiller1990
Copy link

It deletes everything? That is VERY unexpected. Is it this plugin that is causing the deletion?

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

No branches or pull requests

8 participants