Skip to content

Commit 7e11b3b

Browse files
committed
Fix reporter customization (#47)
1 parent 053f58e commit 7e11b3b

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

src/framework/Framework.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@ export class Framework {
5656

5757
public runs: number = 1;
5858

59-
private outputStyle: StyleType = StyleType.plain;
60-
6159
private scheduled: Suite[] = [];
6260

63-
public readonly reporter: Reporter = new Reporter(styling(this.outputStyle));
61+
public readonly reporter: Reporter = new Reporter();
6462

6563
private constructor() {
6664
}
@@ -73,14 +71,6 @@ export class Framework {
7371
return this.scheduled;
7472
}
7573

76-
public style(style: StyleType): void {
77-
this.outputStyle = style;
78-
}
79-
80-
public styling(): StyleType {
81-
return this.outputStyle;
82-
}
83-
8474
public async sequential(suites: Suite[]) {
8575
this.scheduled.concat(suites);
8676
this.reporter.general();

src/reporter/Reporter.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {SuiteResult} from './Results';
22
import {Archiver} from '../framework/Archiver';
3-
import {Style} from './Style';
4-
import {Verbosity} from './index';
3+
import {Style, styling as styleMap} from './Style';
4+
import {StyleType, Verbosity} from './index';
55
import {version} from '../../package.json';
66
import {green, red, yellow} from 'ansi-colors';
77
import {Outcome, SilentDescriber} from './describers/Describer';
@@ -39,32 +39,44 @@ export class Reporter {
3939

4040
private archiver: Archiver;
4141

42-
private readonly style: Style;
42+
private design: Style;
4343

44-
private readonly verbosity: Verbosity;
44+
private verboseness: Verbosity;
4545

46-
constructor(style: Style, verbosity: Verbosity = Verbosity.normal) {
47-
this.style = style;
48-
this.verbosity = verbosity;
46+
constructor(style: StyleType = StyleType.plain, verbosity: Verbosity = Verbosity.normal) {
47+
this.design = styleMap(style);
48+
this.verboseness = verbosity;
4949
this.archiver = new Archiver(`${process.env.TESTFILE?.replace('.asserts.wast', '.wast') ?? 'suite'}.${Date.now()}.log`);
5050
this.archiver.set('date', new Date(Date.now()).toISOString());
5151
}
5252

5353
private indent(override?: number) {
54-
return indent(override ?? this.indentationLevel, this.style.indentation);
54+
return indent(override ?? this.indentationLevel, this.design.indentation);
55+
}
56+
57+
style(type: StyleType) {
58+
this.design = styleMap(type);
59+
}
60+
61+
styling(): StyleType {
62+
return this.design.type;
63+
}
64+
65+
verbosity(level: Verbosity) {
66+
this.verboseness = level;
5567
}
5668

5769
general() {
58-
console.log(this.indent() + this.style.colors.highlight(this.style.bullet) + this.style.colors.highlight('latch.') + this.style.emph(' General information'));
70+
console.log(this.indent() + this.design.colors.highlight(this.design.bullet) + this.design.colors.highlight('latch.') + this.design.emph(' General information'));
5971
// console.log(blue(`${this.indent()}===================`));
60-
console.log(this.indent() + ' '.repeat(2) + this.style.emph('version') + ' '.repeat(5) + version);
61-
console.log(this.indent() + ' '.repeat(2) + this.style.emph('archive') + ' '.repeat(5) + this.archiver.archive);
72+
console.log(this.indent() + ' '.repeat(2) + this.design.emph('version') + ' '.repeat(5) + version);
73+
console.log(this.indent() + ' '.repeat(2) + this.design.emph('archive') + ' '.repeat(5) + this.archiver.archive);
6274
console.log();
6375
}
6476

6577
report(suiteResult: SuiteResult) {
6678
this.suites.push(suiteResult);
67-
const report: string[] = describer(this.verbosity, suiteResult).describe(this.style);
79+
const report: string[] = describer(this.verboseness, suiteResult).describe(this.design);
6880

6981
for (const line of report) {
7082
console.log(this.indent() + line);
@@ -88,7 +100,7 @@ export class Reporter {
88100
this.archiver.set('skipped scenarios', skipped);
89101
this.archiver.set('failed scenarios', failing);
90102

91-
console.log(this.indent() + this.style.colors.highlight(this.style.bullet) + this.style.colors.highlight('results.') + this.style.emph(' Overview'));
103+
console.log(this.indent() + this.design.colors.highlight(this.design.bullet) + this.design.colors.highlight('results.') + this.design.emph(' Overview'));
92104
console.log();
93105
this.indentationLevel += 1;
94106

@@ -106,19 +118,23 @@ export class Reporter {
106118

107119
const len: number = 12;
108120
const pss = [`${sc} passing`, `${passing} passing`, `${psa} passing`]
109-
console.log(this.indent() + this.style.emph('Test suites:') + ' '.repeat(len - pss[0].length) + this.style.emph((sc === tl ? green : red)(pss[0])) + `, ${tl} total` + this.style.emph(` (${time.toFixed(0)}ms)`));
110-
if (this.verbosity > Verbosity.minimal) {
111-
console.log(this.indent() + this.style.emph('Scenarios:') +
112-
' '.repeat(2 + len - pss[1].length) + this.style.emph((passing === scs.length ? green : red)(pss[1])) +
113-
(skipped > 0 ? ', ' + this.style.emph(yellow(`${skipped} skipped`)) : '') + `, ${scs.length} total`);
114-
console.log(this.indent() + this.style.emph('Actions:') + ' '.repeat(4 + len - pss[2].length) + this.style.emph((passing === scs.length ? green : red)(pss[2])) + (timeouts > 0 ? `, ${timeouts} timeouts` : '') + `, ${total} total`);
121+
console.log(this.indent() + this.design.emph('Test suites:') + ' '.repeat(len - pss[0].length) + this.design.emph((sc === tl ? green : red)(pss[0])) + `, ${tl} total` + this.design.emph(` (${time.toFixed(0)}ms)`));
122+
if (this.verboseness > Verbosity.minimal) {
123+
console.log(this.indent() + this.design.emph('Scenarios:') +
124+
' '.repeat(2 + len - pss[1].length) + this.design.emph((passing === scs.length ? green : red)(pss[1])) +
125+
(skipped > 0 ? ', ' + this.design.emph(yellow(`${skipped} skipped`)) : '') + `, ${scs.length} total`);
126+
console.log(this.indent() + this.design.emph('Actions:') + ' '.repeat(4 + len - pss[2].length) + this.design.emph((passing === scs.length ? green : red)(pss[2])) + (timeouts > 0 ? `, ${timeouts} timeouts` : '') + `, ${total} total`);
115127
}
116128
this.indentationLevel -= 1;
117129

118130
console.log();
119131
this.archiver.write();
120132
}
121133

134+
info(text: string) {
135+
this.output += `info: ${text}\n`;
136+
}
137+
122138
error(text: string) {
123139
this.output += `error: ${text}\n`;
124140
}

src/reporter/Style.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export function styling(type: StyleType): Style {
3636

3737
// strategy pattern
3838
export interface Style {
39+
readonly type: StyleType;
40+
3941
indentation: number;
4042

4143
bullet: string;
@@ -48,6 +50,7 @@ export interface Style {
4850
}
4951

5052
export class Plain implements Style {
53+
type = StyleType.plain;
5154
indentation = 2;
5255
bullet = '● ';
5356
end = '';
@@ -71,6 +74,7 @@ export class Plain implements Style {
7174
}
7275

7376
export class GitHub extends Plain {
77+
type = StyleType.github;
7478
bullet = '::group::';
7579
end = '::endgroup::';
7680
}

tests/examples/example.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import {
66
Invoker,
77
Kind,
88
Message,
9-
OutofPlaceSpecification,
109
Step,
11-
Target,
10+
Verbosity,
1211
WASM
1312
} from '../../src/index';
1413
import dump = Message.dump;
1514
import stepOver = Message.stepOver;
16-
import step = Message.step;
1715

1816
const framework = Framework.getImplementation();
1917

@@ -94,4 +92,5 @@ debug.test({
9492
steps: [DUMP]
9593
});
9694

95+
framework.reporter.verbosity(Verbosity.debug);
9796
framework.analyse([spec, debug]);

0 commit comments

Comments
 (0)