Skip to content

Commit

Permalink
Added support for a hash token in the output parameter (#20)
Browse files Browse the repository at this point in the history
* Added support for a hash token in the output parameter as 32 random hex chars

Co-authored-by: beezychru <christian.ruiz@beezy.net>
  • Loading branch information
ChristianRuiz and beezychru authored Oct 23, 2020
1 parent 4ac719c commit 84eae69
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ or you can set `MOCHA_REPORTER_FILE` environment var with the desired filename

- **output** (string)
Outputs as a TRX file into the provided path. If not provided, outputs to stdout.
The path can contain [hash], e.g. ./path_to_your/test-results.[hash].trx. [hash] is replaced by a random 32 hex char hash. This enables support of parallel execution of multiple mocha-trx-reporter's writing test results in separate files.
- **treatPendingAsNotExecuted** (boolean)
Pending tests (tests without implementation, or maked with `.skip`) have an outcome of `NotExecuted` instead of
`Pending` in the TRX file.
Expand Down
7 changes: 6 additions & 1 deletion lib/trx.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const fs = require('fs');
const { reporters } = require('mocha');
const { TestRun } = require('node-trx');
const os = require('os');
const crypto = require('crypto');
const testToTrx = require('./test-to-trx');

const computerName = os.hostname();
Expand Down Expand Up @@ -126,5 +127,9 @@ function ReporterTrx(runner, options) {
* @returns {boolean|*}
*/
function getFilename(reporterOptions) {
return reporterOptions.output || process.env.MOCHA_REPORTER_FILE;
let filePath = reporterOptions.output || process.env.MOCHA_REPORTER_FILE;
if (filePath && filePath.indexOf('[hash]') !== -1) {
filePath = filePath.replace('[hash]', crypto.randomBytes(16).toString('hex'));
}
return filePath;
}

0 comments on commit 84eae69

Please sign in to comment.