Search code examples
cypress-cucumber-preprocessor

I cannot seem to get a JSON report out of badeball/cypress-cucumber-preprocessor


I get the cucumber-messages.ndjson created no problem, but I do not get a corresponding JSON report.

debug logs:

  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 }

Test code to reproduce

Cypress config:

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,
  },
});

Versions

  • Cypress version: 12.6.0
  • Preprocessor version: 16.0.3
  • Node version: v18.15.0

If anyone out there can help that would be awesome!

It's from a private repo at work so it is difficult to share too many details.


Solution

  • I think you'll find the offending code is output: undefined.

    The output field allows you to specify a name for the json file that is generated. By default it is cucumber-messages.ndjson. Your code is changing the filename to undefined.

    As explained in the docs for @badeball/cypress-cucumber-preprocessor, you should just have the following in your .cypress-cucumber-preprocessorrc.json or package.json file:

    {
      "messages": {
        "enabled": true
      }
    }
    

    Also, the json.output field determines where cypress-cucumber-preprocessor writes the json report file that is used by cucumber.

    By default the report is outputted to cucumber-report.json in the project directory, but as explained in the docs, this can be configured according to your needs. For example, in my project I have set it as follows:

    {
      "json": {
        "enabled": true,
        "output": "test/e2e/cucumber-report.json"
      }
    }