You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Cypress v10测试执行时生成cypress/plugins/index.js文件

问题:阻止Cypress自动生成默认cypress文件夹

我们项目的Cypress配置位于自定义文件夹src/而非默认的cypress/,support文件为src/support/index.ts。当前配置可正常运行,但每次测试执行时,Cypress会自动生成cypress文件夹,包含空的download目录和plugins/index.js文件。现有cypress.config.js配置如下:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  (...)
    e2e: {
    setupNodeEvents(on, config) {},
    supportFile: './src/support/index.ts',
    integrationFolder: "./src/integration",
    baseUrl: 'http://localhost:4400'
  }
})

需要修改哪些配置来阻止该现象?

解决方案

需要在配置中明确指定下载目录和插件文件路径,覆盖Cypress的默认值,也可按需禁用不需要的默认目录:

  • 添加downloadsFolder:指定自定义下载目录(比如src/downloads),或设置为false直接禁用该目录生成
  • 添加pluginsFile:指定自定义插件文件路径,或设置为false阻止默认插件文件生成
  • 可选:添加fixturesFolder:如果不需要默认的fixtures目录,设置为false禁用

修改后的完整配置示例:

const { defineConfig } = require('cypress')

module.exports = defineConfig({
  e2e: {
    setupNodeEvents(on, config) {},
    supportFile: './src/support/index.ts',
    integrationFolder: "./src/integration",
    baseUrl: 'http://localhost:4400',
    // 指定自定义下载目录,或设为false禁用
    downloadsFolder: './src/downloads',
    // 禁用默认插件文件生成,或指定自定义插件路径
    pluginsFile: false,
    // 可选:禁用默认fixtures目录
    fixturesFolder: false
  }
})

配置说明

  • pluginsFile: false:直接阻止Cypress自动创建默认的cypress/plugins/index.js文件
  • downloadsFolder:自定义路径会让下载文件存入指定目录,设为false则完全不生成下载目录
  • fixturesFolder: false:不需要fixtures功能时,可避免生成默认的cypress/fixtures目录

内容的提问来源于stack exchange,提问作者Jan and RESTless

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 08:50:36