cypress-io/cypress · error · RunSpecError

NO_SPEC_PATTERN_MATCH

NO_SPEC_PATTERN_MATCH

Error message

Unable to determine testing type, spec does not match any configured specPattern

What it means

Thrown by ProjectActions.runSpec (ProjectActions.ts:538-540) with code NO_SPEC_PATTERN_MATCH after path.relative(currentProject, specPath) is checked against both the e2e specPattern and the component specPattern via matchesSpecPattern and matches neither. The specPattern globs (from cypress.config e2e.specPattern / component.specPattern) define which files count as specs for each testing type; a path that fits neither cannot be assigned a testing type and is rejected. Returned as { code: 'NO_SPEC_PATTERN_MATCH', detailMessage }.

Source

Thrown at packages/data-context/src/actions/ProjectActions.ts:539

      }

      if (!specPath) {
        throw new RunSpecError('NO_SPEC_PATH', '`specPath` must be a non-empty string')
      }

      let targetTestingType: TestingType

      // Get relative path from the specPath to determine which testing type from the specPattern
      const relativeSpecPath = path.relative(this.ctx.currentProject, specPath)

      // Check to see whether input specPath matches the specPattern for one or the other testing type
      // If it matches neither then we can't run the spec and we should error
      if (await this.ctx.project.matchesSpecPattern(relativeSpecPath, 'e2e')) {
        targetTestingType = 'e2e'
      } else if (await this.ctx.project.matchesSpecPattern(relativeSpecPath, 'component')) {
        targetTestingType = 'component'
      } else {
        throw new RunSpecError('NO_SPEC_PATTERN_MATCH', 'Unable to determine testing type, spec does not match any configured specPattern')
      }

      debug(`Spec %s matches '${targetTestingType}' pattern`, specPath)

      debug('Attempting to launch spec %s', specPath)

      // Look to see if there's actually a file at the target location
      // This helps us avoid switching testingType *then* finding out the spec doesn't exist
      if (!this.ctx.fs.existsSync(specPath)) {
        throw new RunSpecError('SPEC_NOT_FOUND', `No file exists at path ${specPath}`)
      }

      // We now know what testingType we need to be in - if we're already there, great
      // If not, verify that type is configured then switch (or throw an error if not configured)
      if (this.ctx.coreData.currentTestingType !== targetTestingType) {
        if (!this.ctx.lifecycleManager.isTestingTypeConfigured(targetTestingType)) {
          throw new RunSpecError('TESTING_TYPE_NOT_CONFIGURED', `Input path matched specPattern for '${targetTestingType}' testing type, but it is not configured.`)
        }

View on GitHub (pinned to 0d85fdc912)

Solutions

  1. Check your cypress.config e2e.specPattern / component.specPattern and move the file into a directory the glob matches.
  2. Adjust the specPattern to include the file's location/extension, or restore the default (cypress/e2e for e2e, and the CT src root).
  3. Confirm specPath is absolute and relative-to-project resolves to the intended file (a wrong project root makes every path 'not match').
  4. If you intended to run a file Cypress doesn't treat as a spec, rename it to match the pattern (e.g. add the .cy.* suffix).

Example fix

// before (cypress.config.js)
// e2e: { specPattern: 'cypress/e2e/**/*.cy.{js,ts}' }
// spec at ./tests/login.spec.ts -> NO_SPEC_PATTERN_MATCH

// after
// e2e: { specPattern: ['cypress/e2e/**/*.cy.{js,ts}', 'tests/**/*.spec.{js,ts}'] }
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check the specPattern match before calling runSpec
const projectRoot = ctx.currentProject
if (projectRoot) {
  const rel = path.relative(projectRoot, specPath)
  const isE2E = await ctx.project.matchesSpecPattern(rel, 'e2e')
  const isCT = await ctx.project.matchesSpecPattern(rel, 'component')
  if (!isE2E && !isCT) {
    // tell the user the file is outside both specPatterns; do not call runSpec
  }
}

Prevention

When it happens

Trigger: Passing runSpec a specPath whose path relative to the project root does not match either the configured e2e.specPattern or component.specPattern globs. Example: spec lives outside cypress/e2e (or src for CT), or has an extension the pattern excludes.

Common situations: Custom specPattern in cypress.config that narrows which files are specs; a file placed in a directory not covered by the pattern; renamed/moved spec whose new location is outside the glob; mismatched file extension (e.g. *.spec.ts when pattern is *.cy.*); pointing runSpec at a non-spec helper file.

Related errors


AI-assisted analysis of cypress-io/cypress@0d85fdc912 (2026-08-12). Data as JSON: /api/errors/3b4cefd7e7dd85e8. Report an issue: GitHub.