Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions src/framework/Framework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ export class Framework {

public runs: number = 1;

private outputStyle: StyleType = StyleType.plain;

private scheduled: Suite[] = [];

public readonly reporter: Reporter = new Reporter(styling(this.outputStyle));
public readonly reporter: Reporter = new Reporter();

private constructor() {
}
Expand All @@ -73,14 +71,6 @@ export class Framework {
return this.scheduled;
}

public style(style: StyleType): void {
this.outputStyle = style;
}

public styling(): StyleType {
return this.outputStyle;
}

public async sequential(suites: Suite[]) {
this.scheduled.concat(suites);
this.reporter.general();
Expand Down
54 changes: 35 additions & 19 deletions src/reporter/Reporter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {SuiteResult} from './Results';
import {Archiver} from '../framework/Archiver';
import {Style} from './Style';
import {Verbosity} from './index';
import {Style, styling as styleMap} from './Style';
import {StyleType, Verbosity} from './index';
import {version} from '../../package.json';
import {green, red, yellow} from 'ansi-colors';
import {Outcome, SilentDescriber} from './describers/Describer';
Expand Down Expand Up @@ -39,32 +39,44 @@ export class Reporter {

private archiver: Archiver;

private readonly style: Style;
private design: Style;

private readonly verbosity: Verbosity;
private verboseness: Verbosity;

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

private indent(override?: number) {
return indent(override ?? this.indentationLevel, this.style.indentation);
return indent(override ?? this.indentationLevel, this.design.indentation);
}

style(type: StyleType) {
this.design = styleMap(type);
}

styling(): StyleType {
return this.design.type;
}

verbosity(level: Verbosity) {
this.verboseness = level;
}

general() {
console.log(this.indent() + this.style.colors.highlight(this.style.bullet) + this.style.colors.highlight('latch.') + this.style.emph(' General information'));
console.log(this.indent() + this.design.colors.highlight(this.design.bullet) + this.design.colors.highlight('latch.') + this.design.emph(' General information'));
// console.log(blue(`${this.indent()}===================`));
console.log(this.indent() + ' '.repeat(2) + this.style.emph('version') + ' '.repeat(5) + version);
console.log(this.indent() + ' '.repeat(2) + this.style.emph('archive') + ' '.repeat(5) + this.archiver.archive);
console.log(this.indent() + ' '.repeat(2) + this.design.emph('version') + ' '.repeat(5) + version);
console.log(this.indent() + ' '.repeat(2) + this.design.emph('archive') + ' '.repeat(5) + this.archiver.archive);
console.log();
}

report(suiteResult: SuiteResult) {
this.suites.push(suiteResult);
const report: string[] = describer(this.verbosity, suiteResult).describe(this.style);
const report: string[] = describer(this.verboseness, suiteResult).describe(this.design);

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

console.log(this.indent() + this.style.colors.highlight(this.style.bullet) + this.style.colors.highlight('results.') + this.style.emph(' Overview'));
console.log(this.indent() + this.design.colors.highlight(this.design.bullet) + this.design.colors.highlight('results.') + this.design.emph(' Overview'));
console.log();
this.indentationLevel += 1;

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

const len: number = 12;
const pss = [`${sc} passing`, `${passing} passing`, `${psa} passing`]
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)`));
if (this.verbosity > Verbosity.minimal) {
console.log(this.indent() + this.style.emph('Scenarios:') +
' '.repeat(2 + len - pss[1].length) + this.style.emph((passing === scs.length ? green : red)(pss[1])) +
(skipped > 0 ? ', ' + this.style.emph(yellow(`${skipped} skipped`)) : '') + `, ${scs.length} total`);
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`);
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)`));
if (this.verboseness > Verbosity.minimal) {
console.log(this.indent() + this.design.emph('Scenarios:') +
' '.repeat(2 + len - pss[1].length) + this.design.emph((passing === scs.length ? green : red)(pss[1])) +
(skipped > 0 ? ', ' + this.design.emph(yellow(`${skipped} skipped`)) : '') + `, ${scs.length} total`);
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`);
}
this.indentationLevel -= 1;

console.log();
this.archiver.write();
}

info(text: string) {
this.output += `info: ${text}\n`;
}

error(text: string) {
this.output += `error: ${text}\n`;
}
Expand Down
4 changes: 4 additions & 0 deletions src/reporter/Style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export function styling(type: StyleType): Style {

// strategy pattern
export interface Style {
readonly type: StyleType;

indentation: number;

bullet: string;
Expand All @@ -48,6 +50,7 @@ export interface Style {
}

export class Plain implements Style {
type = StyleType.plain;
indentation = 2;
bullet = '● ';
end = '';
Expand All @@ -71,6 +74,7 @@ export class Plain implements Style {
}

export class GitHub extends Plain {
type = StyleType.github;
bullet = '::group::';
end = '::endgroup::';
}
5 changes: 2 additions & 3 deletions tests/examples/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
Invoker,
Kind,
Message,
OutofPlaceSpecification,
Step,
Target,
Verbosity,
WASM
} from '../../src/index';
import dump = Message.dump;
import stepOver = Message.stepOver;
import step = Message.step;

const framework = Framework.getImplementation();

Expand Down Expand Up @@ -94,4 +92,5 @@ debug.test({
steps: [DUMP]
});

framework.reporter.verbosity(Verbosity.debug);
framework.analyse([spec, debug]);
Loading