Skip to content

Commit 839cfea

Browse files
authored
fix: fix dry run for base reporter (#827)
1 parent 044a94e commit 839cfea

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/core/runner.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ export default class Runner {
152152
* Set up the corresponding reporter and fallback
153153
* to default reporter if not provided
154154
*/
155-
const { reporter, outfd } = options;
155+
const { reporter, outfd, dryRun } = options;
156156
const Reporter =
157157
typeof reporter === 'function'
158158
? reporter
159159
: reporters[reporter] || reporters['default'];
160-
this.#reporter = new Reporter({ fd: outfd });
160+
this.#reporter = new Reporter({ fd: outfd, dryRun });
161161
}
162162

163163
async runBeforeAllHook(args: HooksArgs) {

src/reporters/base.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,17 @@ function renderDuration(durationMs) {
6666
export default class BaseReporter implements Reporter {
6767
stream: SonicBoom;
6868
fd: number;
69+
dryRun: boolean;
6970
metrics = {
7071
succeeded: 0,
7172
failed: 0,
7273
skipped: 0,
74+
registered: 0,
7375
};
7476

7577
constructor(options: ReporterOptions = {}) {
7678
this.fd = options.fd || process.stdout.fd;
79+
this.dryRun = options.dryRun ?? false;
7780
/**
7881
* minLength is set to 1 byte to make sure we flush the
7982
* content even if its the last byte on the stream buffer
@@ -82,6 +85,11 @@ export default class BaseReporter implements Reporter {
8285
this.stream = new SonicBoom({ fd: this.fd, sync: true, minLength: 1 });
8386
}
8487

88+
onJourneyRegister(journey: Journey): void {
89+
this.write(`\nJourney: ${journey.name}`);
90+
this.metrics.registered++;
91+
}
92+
8593
onJourneyStart(journey: Journey, {}: JourneyStartResult) {
8694
this.write(`\nJourney: ${journey.name}`);
8795
}
@@ -110,9 +118,14 @@ export default class BaseReporter implements Reporter {
110118
}
111119

112120
onEnd() {
113-
const { failed, succeeded, skipped } = this.metrics;
121+
const { failed, succeeded, skipped, registered } = this.metrics;
114122
const total = failed + succeeded + skipped;
115123

124+
if (this.dryRun) {
125+
this.write(`\n${registered} journey(s) registered`);
126+
return;
127+
}
128+
116129
let message = '\n';
117130
if (total === 0) {
118131
message = 'No tests found!';

src/reporters/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ import {
3434
StepEndResult,
3535
} from '../common_types';
3636

37-
export type ReporterOptions = { fd?: number; colors?: boolean };
37+
export type ReporterOptions = {
38+
fd?: number;
39+
colors?: boolean;
40+
dryRun?: boolean;
41+
};
3842
export type BuiltInReporterName = 'default' | 'json' | 'junit';
3943
export type ReporterInstance = new (opts: ReporterOptions) => Reporter;
4044
export const reporters: {

src/reporters/json.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ export default class JSONReporter extends BaseReporter {
317317
});
318318
}
319319

320-
onJourneyRegister(journey: Journey): void {
320+
override onJourneyRegister(journey: Journey): void {
321321
this.writeJSON({
322322
type: 'journey/register',
323323
journey,

0 commit comments

Comments
 (0)