cypress icon indicating copy to clipboard operation
cypress copied to clipboard

@cypress/grep cannot find module cypress-grep or it's corresponding type declarations

Open clazette opened this issue 2 years ago • 8 comments

Current behavior

Support file, Config file, and the tsconfig file installation instructions are incorrect.

Module names and paths are incorrect.

Support file: I am getting a could not find a declaration file for module @cypress/grep/src/support as that's what I have at the moment. Following the readme, the error is Cannot find module 'cypress-grep'. Additionally, the function appears to be cypressGrep and not registerCypressGrep.

Config file registration: require('@cypress/grep/src/plugin')(config)

tsconfig.json: the types array addition should be "@cypress/grep"

I am probably missing something.

Desired behavior

I am able to install the package, follow the configuration instructions, grepping specs works.

Test code to reproduce

n/a

Cypress Version

10.10.0

Node version

16.17.1

Operating System

Windows 10

Debug Logs

No response

Other

No response

clazette avatar Nov 02 '22 21:11 clazette

I actually stumbled across this today as well. @clazette Thanks for reporting!

brianharman avatar Nov 02 '22 23:11 brianharman

You bet, @brianharman.

clazette avatar Nov 03 '22 00:11 clazette

Hi there, did you guys manage to get this working? If yes, how?

sw-tracker avatar Nov 03 '22 15:11 sw-tracker

I've tried several things to no avail.

clazette avatar Nov 03 '22 15:11 clazette

We use typescript in our project. I think this is what we have in our project to make it work and hope it helps you in someway figuring out whats wrong with your setup.

We use the latest version of Cypress 11.1.0

package.json in our devdepencies "@cypress/grep": "^3.1.0"

cypress.config.ts

import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      require('@cypress/grep/src/plugin')(config);
      return config;
    },
  },
  "env": {
    "grepOmitFiltered": true
  }
});

support/e2e.ts

const registerCypressGrep = require('@cypress/grep');
registerCypressGrep();

support/index.d.ts

/// <reference types="cypress" />

declare namespace Cypress {
  // specify additional properties in the TestConfig object
  // in our case we will add "tags" property
  interface TestConfigOverrides {
    /**
     * List of tags for this test
     * @example a single tag
     *  it('logs in', { tags: '@smoke' }, () => { ... })
     * @example multiple tags
     *  it('works', { tags: ['@smoke', '@slow'] }, () => { ... })
     */
    tags?: string | string[]
  }

  interface Cypress {
    grep?: (grep?: string, tags?: string, burn?: string) => void
  }
}

tester-at-bmi avatar Nov 17 '22 15:11 tester-at-bmi

Note if you're on Cypress 11, you'll need to update TestConfigOverrides to SuiteConfigOverrides (unless that's been updated in main/develop)

/// <reference types="cypress" />
declare namespace Cypress {
  // specify additional properties in the TestConfig object
  // in our case we will add "tags" property
  interface SuiteConfigOverrides {
    /**
     * List of tags for this test
     * @example a single tag
     *  it('logs in', { tags: '@smoke' }, () => { ... })
     * @example multiple tags
     *  it('works', { tags: ['@smoke', '@slow'] }, () => { ... })
     */
    tags?: string | string[]
  }

  interface Cypress {
    grep?: (grep?: string, tags?: string, burn?: string) => void
  }
}

samtsai avatar Nov 17 '22 16:11 samtsai

Note if you're on Cypress 11, you'll need to update TestConfigOverrides to SuiteConfigOverrides (unless that's been updated in main/develop)

/// <reference types="cypress" />
declare namespace Cypress {
  // specify additional properties in the TestConfig object
  // in our case we will add "tags" property
  interface SuiteConfigOverrides {
    /**
     * List of tags for this test
     * @example a single tag
     *  it('logs in', { tags: '@smoke' }, () => { ... })
     * @example multiple tags
     *  it('works', { tags: ['@smoke', '@slow'] }, () => { ... })
     */
    tags?: string | string[]
  }

  interface Cypress {
    grep?: (grep?: string, tags?: string, burn?: string) => void
  }
}

@samtsai you're just so wrong here! 😄

SuiteConfigOverrides is used to override describe blocks.

/// <reference types="cypress" />
declare namespace Cypress {
  // specify additional properties in the SuiteConfig object
  // in our case we will add "tags" property
  interface SuiteConfigOverrides {
    /**
     * List of tags for this test
     * @example a single tag
     *  describe('logs in', { tags: '@smoke' }, () => { ... })
     * @example multiple tags
     *  describe('works', { tags: ['@smoke', '@slow'] }, () => { ... })
     */
    tags?: string | string[]
  }

  interface Cypress {
    grep?: (grep?: string, tags?: string, burn?: string) => void
  }
}

tester-at-bmi avatar Nov 25 '22 17:11 tester-at-bmi

Before migration it worked for me without any type override with SuiteConfigOverrides or TestConfigOverrides

richardszanyi-kasa avatar Nov 28 '22 10:11 richardszanyi-kasa

Hey gang! I'll see what we can do to get this looked at by the team asap. I was putting together an example project and very quickly hit a wall following the current documentation.

Our next major release should be coming out this week, but I'll see that this is looked into.

modern-sapien avatar Dec 05 '22 02:12 modern-sapien

The code for this is done in cypress-io/cypress#24844, but has yet to be released. We'll update this issue and reference the changelog when it's released.

cypress-bot[bot] avatar Dec 14 '22 16:12 cypress-bot[bot]

Released in 12.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to Cypress v12.2.0, please open a new issue.

cypress-bot[bot] avatar Dec 20 '22 22:12 cypress-bot[bot]