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

无法通过badeball/cypress-cucumber-preprocessor生成JSON报告求助

问题:生成cucumber-messages.ndjson成功,但无法获取JSON报告

调试日志

cypress-cucumber-preprocessor resolved configuration {
  cypress-cucumber-preprocessor   stepDefinitions: 'cypress/support/step_definitions/**/*.{js,ts}',
  cypress-cucumber-preprocessor   json: { enabled: true, output: undefined },
  cypress-cucumber-preprocessor   messages: { enabled: true, output: undefined },
  cypress-cucumber-preprocessor   filterSpecs: true,
  cypress-cucumber-preprocessor   omitFiltered: false
  cypress-cucumber-preprocessor }

Cypress配置代码

module.exports = defineConfig({
  defaultCommandTimeout: 10000,
  requestTimeout: 20000,
  viewportWidth: 1920,
  viewportHeight: 1080,
  responseTimeout: 20000,
  chromeWebSecurity: false,
  waitForAnimations: true,
  animationDistanceThreshold: 50,
  retries: {
    runMode: 3,
    openMode: 0,
  },
  video: false,
  watchForFileChanges: false,
  e2e: {
    async setupNodeEvents(on, cypressConf) {
      await addCucumberPreprocessorPlugin(on, cypressConf);

      on(
        'file:preprocessor',
        createBundler({
          plugins: [createEsbuildPlugin(cypressConf)],
        }),
      );

      // eslint-disable-next-line global-require
      require('dd-trace/ci/cypress/plugin')(on, cypressConf);
      // Add fail fast plugin
      // eslint-disable-next-line global-require
      require('cypress-fail-fast/plugin')(on, cypressConf);

      const pathToFixtureFile = path.resolve('.', 'cypress', 'fixtures');
      function isFileExist(filename) {
        return !!fs.existsSync(`${pathToFixtureFile}/${filename}`);
      }
      on('task', {
        deleteFileIfExist: filename => {
          if (isFileExist(filename)) {
            fs.removeSync(`${pathToFixtureFile}/${filename}`, 'utf8');
          }
          return true;
        },
        isFileExist,
        ...dbQueries,
      });

      const mergedConfig = await getConfigurationByFile(cypressConf)
        .then(getConfigurationFromEnv)
        .then(getConfigurationFromSecretsManager);

      console.dir({ mergedConfig }, { depth: null });
      console.log(`TAGS: ${mergedConfig.env.TAGS}`);
      console.log(`tags: ${mergedConfig.env.tags}`);

      return mergedConfig;
    },
    specPattern: 'cypress/e2e/**/features/*.{feature,features}',
    excludeSpecPattern: '**/integration/modules/*.js',
    experimentalWebKitSupport: true,
    experimentalRunAllSpecs: true,
  },
});

版本信息

  • Cypress版本:12.6.0
  • cypress-cucumber-preprocessor版本:16.0.3
  • Node版本:v18.15.0

解决建议

  1. 明确指定JSON报告输出路径
    调试日志显示json.output为undefined,preprocessor可能因缺少输出路径导致未生成JSON报告。可在Cypress配置顶层添加preprocessor配置:

    module.exports = defineConfig({
      // 其他原有配置...
      env: {
        'cypress-cucumber-preprocessor': {
          json: {
            enabled: true,
            output: 'cypress/reports/cucumber-json/report.json'
          },
          messages: {
            enabled: true,
            output: 'cypress/reports/cucumber-messages.ndjson'
          }
        }
      },
      // 其他原有配置...
    })
    
  2. 检查配置合并逻辑是否覆盖preprocessor设置
    你使用getConfigurationByFile等方法合并配置,需确保这些方法不会覆盖cypress-cucumber-preprocessor的JSON配置项。可查看console.dir({ mergedConfig })的输出,确认其中包含正确的JSON报告配置。

  3. 调整插件初始化顺序
    当前先初始化preprocessor插件再合并配置,尝试先完成配置合并,再初始化preprocessor插件:

    async setupNodeEvents(on, cypressConf) {
      // 先完成所有配置合并
      const mergedConfig = await getConfigurationByFile(cypressConf)
        .then(getConfigurationFromEnv)
        .then(getConfigurationFromSecretsManager);
    
      // 基于合并后的配置初始化preprocessor
      await addCucumberPreprocessorPlugin(on, mergedConfig);
    
      // 初始化其他插件...
    }
    
  4. 排查插件冲突
    暂时禁用dd-trace和cypress-fail-fast插件,运行测试看是否能生成JSON报告,排除第三方插件干扰的可能。

  5. 验证输出目录权限
    手动创建指定的JSON输出目录(如cypress/reports/cucumber-json),确保目录存在且有写入权限后再运行测试。


内容的提问来源于stack exchange,提问作者Lee Morris

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 15:53:12