Repository: cypress-io/cypress
File: packages/server/lib/controllers/files.js (JavaScript)

Code before:

    const specFilter = _.get(extraOptions, 'specFilter')
    const specTypeFilter = _.get(extraOptions, 'specType', 'integration')

    debug('specFilter %o', { specFilter })
    const specFilterContains = (spec) => {
      // only makes sense if there is specFilter string
      // the filter should match the logic in
      // desktop-gui/src/specs/specs-store.js
      return spec.relative.toLowerCase().includes(specFilter.toLowerCase())
    }
    const specFilterFn = specFilter ? specFilterContains : R.T

    const getSpecsHelper = () => {
      // grab all of the specs if this is ci
      const componentTestingEnabled = _.get(config, 'resolved.testingType.value', 'e2e') === 'component'

      if (spec === '__all') {
        debug('returning all specs')

        return specsUtil.find(config)
        .then(R.tap((specs) => {
          return debug('found __all specs %o', specs)
        }))
        .filter(specFilterFn)
        .filter((foundSpec) => {
          if (componentTestingEnabled) {
            return foundSpec.specType === specTypeFilter
          }

          return true
        }).then(R.tap((specs) => {
          return debug('filtered __all specs %o', specs)
        })).map((spec) => {
          // grab the name of each
          return spec.absolute
        }).map(convertSpecPath)
      }

      // normalize by sending in an array of 1
      return [convertSpecPath(spec)]
    }

    return Promise
    .try(() => {
      return getSpecsHelper()
    })
  },

  prepareForBrowser (filePath, projectRoot) {
    filePath = filePath.replace(SPEC_URL_PREFIX, '__CYPRESS_SPEC_URL_PREFIX__')

Review comment (suggestion):
This is the "main" change. Instead of assuming e2e, then doing some CT specific mods IF in CT mode, we do not assume e2e or CT. Instead, we assume you can either be in e2e or CT mode, and are explicit about what spec(s) to get.

Code after:

    const specFilter = _.get(extraOptions, 'specFilter')

    debug('specFilter %o', { specFilter })
    const specFilterContains = (spec) => {
      // only makes sense if there is specFilter string
      // the filter should match the logic in
      // desktop-gui/src/specs/specs-store.js
      return spec.relative.toLowerCase().includes(specFilter.toLowerCase())
    }
    const specFilterFn = specFilter ? specFilterContains : R.T

    const getSpecsHelper = () => {
      // grab all of the specs if this is ci
      const componentTestingEnabled = _.get(config, 'resolved.testingType.value', 'e2e') === 'component'

      if (spec === '__all') {
        debug('returning all specs')

        return specsUtil.default.findSpecs(config)
        .then(R.tap((specs) => {
          return debug('found __all specs %o', specs)
        }))
        .filter(specFilterFn)
        .filter((foundSpec) => {
          return componentTestingEnabled
            ? foundSpec.specType === 'component'
            : foundSpec.specType === 'integration'
        }).then(R.tap((specs) => {
          return debug('filtered __all specs %o', specs)
        })).map((spec) => {
          // grab the name of each
          return spec.absolute
        }).map(convertSpecPath)
      }

      // normalize by sending in an array of 1
      return [convertSpecPath(spec)]
    }

    return Promise
    .try(() => {
      return getSpecsHelper()
    })
  },

  prepareForBrowser (filePath, projectRoot) {
    filePath = filePath.replace(SPEC_URL_PREFIX, '__CYPRESS_SPEC_URL_PREFIX__')
    filePath = escapeFilenameInUrl(filePath).replace('__CYPRESS_SPEC_URL_PREFIX__', SPEC_URL_PREFIX)
    const relativeFilePath = path.relative(projectRoot, filePath)