question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cypress component test autoconfig issue with additionalIgnorePattern

See original GitHub issue

Current behavior

Cypress is already configured to work as e2e testing tool and my cypress.config.ts override the default specPattern to include both cucumber and non cucumber specs:

e2e: {
    async setupNodeEvents(on, config) {
      await addCucumberPreprocessorPlugin(on, config)
      on(
          'file:preprocessor',
          createBundler({
            plugins: [nodePolyfills(), createEsbuildPlugin(config)],
          })
      )
    },
    specPattern: ['tests/e2e/**/*.{feature,features}', 'tests/e2e/**/*.cy.{js,jsx,ts,tsx}'],
    viewportHeight: 1080,
    viewportWidth: 1920,
  },

Problem is that apparently, even though specPattern correctly recognize and accept a list of string, when you try to have cypress autoconfigure the component testing, this is what you get: image

Stack trace:

Error: An invalid configuration value was set.

Expected additionalIgnorePattern to be a string.

Instead the value was: 

[
  "tests/e2e/**/*.{feature,features}",
  "tests/e2e/**/*.cy.{js,jsx,ts,tsx}"
]
    at /home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/server/lib/config.js:151:23
    at /home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/config/src/browser.js:114:24
    at /home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/lodash/lodash.js:4967:15
    at baseForOwn (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/lodash/lodash.js:3032:24)
    at /home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/lodash/lodash.js:4936:18
    at Function.forEach (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/node_modules/lodash/lodash.js:9410:14)
    at Object.validate (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/config/src/browser.js:108:29)
    at mergeDefaults (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/server/lib/config.js:146:17)
    at Object.setupFullConfigWithDefaults (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/server/lib/config.js:78:12)
    at ProjectConfigManager.buildBaseFullConfig (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/data-context/src/data/ProjectConfigManager.js:279:65)
    at ProjectConfigManager.getFullInitialConfig (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/data-context/src/data/ProjectConfigManager.js:322:45)
    at ProjectConfigManager.setupNodeEvents (/home/rsaleri/.cache/Cypress/10.2.0/Cypress/resources/app/packages/data-context/src/data/ProjectConfigManager.js:119:28)

Desired behavior

additionalIgnorePattern should work like specPattern, since apparently it’s what’s using to know which paths discard.

Test code to reproduce

Trying to configure the component testing with a vue2 project and this cypress.config.ts trigger the issue

import {defineConfig} from 'cypress'
const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild').createEsbuildPlugin
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor')
const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill').NodeModulesPolyfillPlugin
const addCucumberPreprocessorPlugin = require('@badeball/cypress-cucumber-preprocessor').addCucumberPreprocessorPlugin
export default defineConfig({
  e2e: {
    async setupNodeEvents(on, config) {
      await addCucumberPreprocessorPlugin(on, config) // to allow json to be produced
      // To use esBuild for the bundler when preprocessing
      on(
          'file:preprocessor',
          createBundler({
            plugins: [nodePolyfills(), createEsbuildPlugin(config)],
          })
      )
    },
    specPattern: ['tests/e2e/**/*.{feature,features}', 'tests/e2e/**/*.cy.{js,jsx,ts,tsx}'],
    viewportHeight: 1080,
    viewportWidth: 1920,
  },
})

Cypress Version

10.2.0, 10.1.0

Other

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tbiethmancommented, Jun 29, 2022

@rsaleri thank you very much for the report. This is occurring because we set the internal config property additionalIgnorePattern to your defined e2e specPattern when you start component testing; we don’t want to accidentally/incorrectly pull in your e2e test files as component test files. However, we’re currently botching the validation here.

I reproduced this bug by updating our internal launchpad project config to use the following E2E spec pattern below and subsequently trying to launch its component tests.

  e2e: {
     ...,
    specPattern: ['cypress/e2e/**/*.cy.{js,ts}', 'cypress/e2e/**/*.cy.{jsx,tsx}'],
  },
1reaction
rsalericommented, Jun 28, 2022

A workaround is to put the entire expanded list in a single string like:

specPattern: 'tests/e2e/**/*.{feature,features,cy.js,cy.jsx,cy.ts,cy.tsx}',

But it’s just that, a workaround.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Component Testing Config - Cypress Documentation
Component Testing Config. When you launch Cypress for the first time in a project, the app will automatically guide you through setup and...
Read more >
Vue Quickstart - Cypress Documentation
Welcome! This tutorial will walk you through creating a Vue app and using Cypress Component Testing to test it. We assume you are...
Read more >
What's New with Cypress Web Testing?
Features. Cypress will throw an error when a user attempts to update a configuration value at run-time using either the Test Configuration or...
Read more >
Svelte Component Testing - Cypress Documentation
Tutorial. Visit the Svelte Quickstart Guide for a step-by-step tutorial on creating a new Svelte app and adding component tests.
Read more >
Troubleshooting | Cypress Documentation
Split large spec files into smaller ones. Split long tests into smaller tests. Run the same test using --browser chrome. The problem might...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found