Repository: cypress-io/cypress
File: packages/data-context/src/sources/StorybookDataSource.ts (TypeScript)

Code before:
    const storybook = await this.ctx.storybook.storybookInfo

    if (!storybook) {
      return []
    }

    const config = await this.ctx.project.getConfig(project.projectRoot)
    const files: string[] = []

    for (const storyPattern of storybook.storyGlobs) {
      const res = await asyncGlob(path.join(storybook.storybookRoot, storyPattern))

      files.push(...res)
    }

    // Don't currently support mdx
    return files
    .filter((file) => !file.endsWith('.mdx'))
    .map((file) => this.ctx.file.normalizeFileToSpec(file, project.projectRoot, config.componentFolder || project.projectRoot))
  }

  private storybookInfoLoader = this.ctx.loader<string, StorybookInfo | null>((projectRoots) => this.batchStorybookInfo(projectRoots))

  private batchStorybookInfo (projectRoots: readonly string[]) {
    return Promise.all(projectRoots.map((projectRoot) => this.detectStorybook(projectRoot)))
  }

  private async detectStorybook (projectRoot: string): Promise<StorybookInfo | null> {
    const storybookRoot = path.join(projectRoot, '.storybook')
    const storybookInfo: StorybookInfo = {
      storybookRoot,
      files: [],
      storyGlobs: [],
    }

    try {
      await this.ctx.fs.access(storybookRoot, this.ctx.fs.constants.F_OK)
    } catch {
      return null
    }

    for (const fileName of STORYBOOK_FILES) {
      try {
        const absolute = path.join(storybookRoot, fileName)
        const file = {
          name: fileName,
          relative: path.relative(projectRoot, absolute),
          absolute,
          content: await this.ctx.fs.readFile(absolute, 'utf-8'),
        }


Review comment (suggestion):
Can save a for loop w/ reduce

```suggestion
    return files.reduce((acc, file) => { 
      if (file.endsWith('.mdx')) {
        return acc
      }
      const p = this.ctx.file.normalizeFileToSpec(file, project.projectRoot, config.componentFolder || project.projectRoot))
      return [...acc, p]
    }, [])
  
```

(untested, but something like that)

Code after:
    const storybook = await this.ctx.storybook.loadStorybookInfo()

    if (!storybook) {
      return []
    }

    const config = await this.ctx.project.getConfig(project.projectRoot)
    const files: string[] = []

    for (const storyPattern of storybook.storyGlobs) {
      const res = await asyncGlob(path.join(storybook.storybookRoot, storyPattern))

      files.push(...res)
    }

    // Don't currently support mdx
    return files.reduce((acc, file) => {
      if (file.endsWith('.mdx')) {
        return acc
      }

      const spec = this.ctx.file.normalizeFileToSpec(file, project.projectRoot, config.componentFolder || project.projectRoot)

      return [...acc, spec]
    }, [] as SpecFile[])
  }

  private storybookInfoLoader = this.ctx.loader<string, StorybookInfo | null>((projectRoots) => this.batchStorybookInfo(projectRoots))

  private batchStorybookInfo (projectRoots: readonly string[]) {
    return Promise.all(projectRoots.map((projectRoot) => this.detectStorybook(projectRoot)))
  }

  private async detectStorybook (projectRoot: string): Promise<StorybookInfo | null> {
    const storybookRoot = path.join(projectRoot, '.storybook')
    const storybookInfo: StorybookInfo = {
      storybookRoot,
      files: [],
      storyGlobs: [],
    }

    try {
      await this.ctx.fs.access(storybookRoot, this.ctx.fs.constants.F_OK)
    } catch {
      return null
    }

    for (const fileName of STORYBOOK_FILES) {
      try {
        const absolute = path.join(storybookRoot, fileName)
        const file = {