archfz/cypress-terminal-report

After hook crashes if log files exist

csvan opened this issue · 3 comments

csvan commented

The following code in BaseOutputProcessor.js:

hasSpecChunkWritten(spec) {
    return !!this.specChunksWritten[spec];
}

will throw if a log file for the current spec already exists in the output folder. This is because the following doesn't get invoked:

if (!fs.existsSync(this.file)) {
  this.prepareForWrite();
}

Due to this, this.specChunksWritten is never initialized before hasSpecChunkWritten tries to access it.

Do you have steps to reproduce so we can write a test for this case?

csvan commented
  1. Add a standard Cypress setup with at least one spec file - integration/myTest.spec.js
  2. Add to plugins:
  require('cypress-terminal-report/src/installLogsPrinter')(on, {
    outputRoot: 'cypress/',
    specRoot: 'cypress/integration',
    printLogsToFile: 'always', // <--- so that we always try to access the file
    printLogsToConsole: 'never',
    outputTarget: {
      'logs|txt': 'txt',
      'logs|json': 'json',
    },
  });

Add to support:

require('cypress-terminal-report/src/installLogsCollector')();
  1. add myTest.txt to cypress/logs

  2. run cypress

Released in 2.3.1