Skip to content

Commit

Permalink
feat: make progress reporting optional
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 13, 2017
1 parent 82ab7dd commit e6343a2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Options:
- `logLevel` - specifies the log level. By default jest-tap-reporter uses `INFO` log level, which will log the suite path and a summary at the end of a test run. If you want to reduce the reporting to bare minimum you can set the `logLevel` parameter to `ERROR`. available log levels are: `ERROR`, `WARN`, `INFO`.
- `showInternalStackTraces` - shows stack traces from *"internal"* folders, like `/node_modules` and `/internal`, defaults to `false`.
- `filePath` - specifies a file to write the results. If not supplied it will use `process.stdout`.
- `noProgressReporting` - whether to not show intermediate test result summary while testing is in progress. In general, defaults to `false`. When writing to file or in CI environment, it is set to `true`.

## License

Expand Down
44 changes: 31 additions & 13 deletions src/TapReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ const STATUS_PENDING = 'pending';

const sShouldFail = Symbol('shouldFail');

// eslint-disable-next-line no-process-env
const isCI = () => Boolean(process.env.CI);

class TapReporter {
constructor (globalConfig = {}, options = {}) {
const {logLevel = 'INFO'} = options;
this.setOptions(options);
const {logLevel, filePath} = this.options;

let stream = process.stdout;

if (options.filePath) {
if (filePath) {
stream = fs.createWriteStream(options.filePath);
chalk.level = 0;
}
Expand All @@ -27,7 +32,6 @@ class TapReporter {
});

this.globalConfig = globalConfig;
this.options = options;
this[sShouldFail] = false;
this.writer = new LineWriter(logger, globalConfig.rootDir);

Expand All @@ -36,6 +40,18 @@ class TapReporter {
this.onRunStartOptions = {};
}

setOptions (options) {
this.options = options;

if (isCI() || this.options.filePath) {
this.options.noProgressReporting = true;
}

if (!this.options.logLevel) {
this.options.logLevel = 'INFO';
}
}

pathRelativeToRoot (filePath) {
return path.relative(this.globalConfig.rootDir, filePath);
}
Expand Down Expand Up @@ -109,20 +125,22 @@ class TapReporter {
});
}

this.writer.logger.temporary();
if (!this.options.noProgressReporting) {
this.writer.logger.temporary();

this.writer.blank();
this.writer.aggregatedResults(aggregatedResults);
this.writer.blank();
this.writer.aggregatedResults(aggregatedResults);

const {estimatedTime} = this.onRunStartOptions;
const {estimatedTime} = this.onRunStartOptions;

if (estimatedTime) {
const startTime = aggregatedResults.startTime;
const percentage = (Date.now() - startTime) / 1e3 / estimatedTime / 3;
if (estimatedTime) {
const startTime = aggregatedResults.startTime;
const percentage = (Date.now() - startTime) / 1e3 / estimatedTime / 3;

if (percentage <= 1) {
this.writer.blank();
this.writer.timeProgressBar(percentage);
if (percentage <= 1) {
this.writer.blank();
this.writer.timeProgressBar(percentage);
}
}
}

Expand Down

0 comments on commit e6343a2

Please sign in to comment.