title: How to use the "excludeSpecPattern" in Cypress together with a plugin to exclude from the cypress run one specific test file
body: <p>I'm using the <code>Cypress</code> version <code>10.3.0</code> and I'm trying to exclude a specific test file when I do <code>cypress run</code>.</p>
  <p>The general purpose of this is due to the fact I want to be able to run all tests when I open <code>CY UI</code> and exclude the <code>all.cy.js</code> from running when I do <code>cypress run</code> to avoid running twice the same tests.</p>
  <p>I tried to follow the documentation about <code>excludeSpecPattern</code> which should allow me not to run the test and I implemented this as follow</p>
  <pre><code>defineConfig({
    e2e: {
      chromeWebSecurity: false,
      viewportWidth: 1280,
      viewportHeight: 800,
      screenshotsFolder: 'artifacts',
      video: false,
      reporter: 'junit',
      reporterOptions: {
        mochaFile: 'results/test-results-[hash].xml',
      },
      retries: 1,
      defaultCommandTimeout: 60000,
  
      setupNodeEvents(on, config) {
        if (config.isTextTerminal) {
           // skip the all.cy.js spec in &quot;cypress run&quot; mode
           return {
                excludeSpecPattern: ['cypress/e2e/all.cy.js'],
            }
        }
        return require('./cypress/plugins/index.js')(on, config);
      },
    },
  </code></pre>
  <p>I tried to follow a guide here <a href="https://glebbahmutov.com/blog/run-all-specs-cypress-v10/" rel="nofollow noreferrer">Link to the guide used</a></p>
  <p>However, the above doesn't work as the test immediately fails in 1 sec without even run practically</p>
  <p>I don't know how can I do it in my current setup</p>
  <p>the plugin called file</p>
  <pre><code>const fs = require('fs');
  const path = require('path');
  const gmail = require('gmail-tester');
  
  function getConfigurationFromFile(file, type) {
    const pathToConfigFile = path.resolve('cypress', 'config', type, `${file}.json`);
    return JSON.parse(fs.readFileSync(pathToConfigFile));
  }
  
  // See https://docs.cypress.io/guides/guides/continuous-integration.html#In-Docker
  function disableDevShmUsage(browser = {}, launchOptions) {
    if (browser.family === 'chromium' &amp;&amp; browser.name !== 'electron') {
      launchOptions.args.push('--disable-dev-shm-usage');
    }
    return launchOptions;
  }
  
  /**
   * This function is called when a project is opened or re-opened (e.g. due to the project's config changing)
   *
   * @type {Cypress.PluginConfig}
   * @param on - Used to hook into various events Cypress emits (e.g. `on('before:browser:launch', callback)`)
   * @param config - The resolved Cypress config
   */
  module.exports = (on, config) =&gt; {
    on('before:browser:launch', disableDevShmUsage);
  
    on('task', {
      'gmail:check': async (args) =&gt; {
        const { from, to, subject } = args;
        let fiveMinutesAgo = new Date();
        // Will rollover to yy:55 if minutes is xx:00
        fiveMinutesAgo.setMinutes(fiveMinutesAgo.getMinutes() - 5);
  
        const email = await gmail.check_inbox(
          path.resolve(__dirname, 'credentials.json'), // credentials.json is inside plugins/ directory.
          path.resolve(__dirname, 'gmail_token.json'), // gmail_token.json is inside plugins/ directory.
          {
            subject,
            from,
            to,
            after: fiveMinutesAgo,
            include_body: true,
            wait_time_sec: 6, // Poll interval (in seconds)
            max_wait_time_sec: 60, // Maximum poll interval (in seconds). If reached, return null, indicating the completion of the task().
          },
        );
  
        return email ?? [];
      },
    });
  
    const env = config.env.ENVIRONMENT || 'development';
    const envConfig = getConfigurationFromFile(env, 'env');
  
    const scope = config.env.SCOPE || 'full';
    const scopeConfig = getConfigurationFromFile(scope, 'scope');
  
    return Object.assign(config, envConfig, scopeConfig);
  };
  
  
  </code></pre>
  <p>I thought maybe I need to include that inside the plugin but still, I have no idea whatever I tried so far with that <code>if</code> statement fails the tests</p>