diff --git a/.eslint.config.mjs b/.eslint.config.mjs index a64161f..771747b 100644 --- a/.eslint.config.mjs +++ b/.eslint.config.mjs @@ -6,15 +6,17 @@ import stylisticJs from '@stylistic/eslint-plugin-js' /** @type {import('eslint').Linter.Config[]} */ export default [ + pluginJs.configs.recommended, + ...tseslint.configs.recommended, { plugins: { '@stylistic/js': stylisticJs }, rules: { '@stylistic/js/indent': ['error', 4], + '@typescript-eslint/no-wrapper-object-types': 'off' } }, {files: ["**/*.{js,mjs,cjs,ts}"]}, {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}}, {languageOptions: { globals: globals.browser }}, - pluginJs.configs.recommended, - ...tseslint.configs.recommended, + ]; diff --git a/src/framework/Testee.ts b/src/framework/Testee.ts index 332f5e6..b326a6b 100644 --- a/src/framework/Testee.ts +++ b/src/framework/Testee.ts @@ -133,11 +133,11 @@ export class Testee { // TODO unified with testbed interface } private run(name: string, limit: number, fn: () => Promise) { - return timeout(name, limit, fn()); + return timeout(name, limit, fn()); } private step(name: string, limit: number, fn: () => Promise) { - return timeout(name, limit, fn()); + return timeout(name, limit, fn()); } public async describe(description: TestScenario, suiteResult: SuiteResult, runs: number = 1) { @@ -170,7 +170,7 @@ export class Testee { // TODO unified with testbed interface const compiled: CompileOutput = await new CompilerFactory(WABT).pickCompiler(description.program).compile(description.program); try { - await timeout(`uploading module`, testee.timeout, testee.bed()!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file))).catch((e) => Promise.reject(e)); + await timeout(`uploading module`, testee.timeout, testee.bed()!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file))).catch((e) => Promise.reject(e)); testee.current = description.program; } catch (e) { await testee.initialize(description.program, description.args ?? []).catch((o) => Promise.reject(o)); @@ -219,16 +219,16 @@ export class Testee { // TODO unified with testbed interface return; } - let actual: Object | void; + let actual: object | void; if (step.instruction.kind === Kind.Action) { - actual = await timeout(`performing action . ${step.title}`, testee.timeout, + actual = await timeout(`performing action . ${step.title}`, testee.timeout, step.instruction.value.act(testee)).catch((err) => { testee.states.set(description.title, verifier.error(err)); return; }); } else { actual = await testee.recoverable(testee, step.instruction.value, map, - (testee, req, map) => timeout(`sending instruction ${req.type}`, testee.timeout, + (testee, req, map) => timeout(`sending instruction ${req.type}`, testee.timeout, testee.bed(step.target ?? Target.supervisor)!.sendRequest(map, req)), (testee) => testee.run(`Recover: re-initialize ${testee.testbed?.name}`, testee.connector.timeout, async function () { await testee.initialize(description.program, description.args ?? []).catch((o) => { @@ -255,10 +255,10 @@ export class Testee { // TODO unified with testbed interface } private async recoverable(testee: Testee, step: Request, map: SourceMap.Mapping, - attempt: (t: Testee, req: Request, m: SourceMap.Mapping) => Promise, + attempt: (t: Testee, req: Request, m: SourceMap.Mapping) => Promise, recover: (t: Testee) => Promise, - retries: number = 0): Promise { - let result: Object | void = undefined; + retries: number = 0): Promise { + let result: object | void = undefined; let error; while (0 <= retries && result === undefined) { result = await attempt(testee, step, map).catch(async (err) => { @@ -279,7 +279,7 @@ export class Testee { // TODO unified with testbed interface if (instance === undefined) { this.framework.reporter.error('Cannot run test: no debugger connection.'); // todo } else { - await timeout('resetting vm', this.timeout, this.testbed!.sendRequest(new SourceMap.Mapping(), Message.reset)); + await timeout('resetting vm', this.timeout, this.testbed!.sendRequest(new SourceMap.Mapping(), Message.reset)); } } diff --git a/src/framework/Verifier.ts b/src/framework/Verifier.ts index d3f7446..81b2d2d 100644 --- a/src/framework/Verifier.ts +++ b/src/framework/Verifier.ts @@ -89,39 +89,40 @@ export class Verifier { private expectBehaviour(actual: any, previous: any, behaviour: Behaviour): StepOutcome { const result: StepOutcome = new StepOutcome(this.step); switch (behaviour) { - case Behaviour.unchanged: - if (deepEqual(actual, previous)) { - result.update(Outcome.succeeded); - } else { - result.update(Outcome.failed, `Expected ${actual} to equal ${previous}`); - } - break; - case Behaviour.changed: - if (!deepEqual(actual, previous)) { - result.update(Outcome.succeeded); - } else { - result.update(Outcome.failed, `Expected ${actual} to be different from ${previous}`); - } - break; - case Behaviour.increased: - if (actual > previous) { - result.update(Outcome.succeeded); - } else { - result.update(Outcome.failed, `Expected ${actual} to be greater than ${previous}`); - } - break; - case Behaviour.decreased: - if (actual < previous) { - result.update(Outcome.succeeded); - } else { - result.update(Outcome.failed, `Expected ${actual} to be less than ${previous}`); - } - break; + case Behaviour.unchanged: + if (deepEqual(actual, previous)) { + result.update(Outcome.succeeded); + } else { + result.update(Outcome.failed, `Expected ${actual} to equal ${previous}`); + } + break; + case Behaviour.changed: + if (!deepEqual(actual, previous)) { + result.update(Outcome.succeeded); + } else { + result.update(Outcome.failed, `Expected ${actual} to be different from ${previous}`); + } + break; + case Behaviour.increased: + if (actual > previous) { + result.update(Outcome.succeeded); + } else { + result.update(Outcome.failed, `Expected ${actual} to be greater than ${previous}`); + } + break; + case Behaviour.decreased: + if (actual < previous) { + result.update(Outcome.succeeded); + } else { + result.update(Outcome.failed, `Expected ${actual} to be less than ${previous}`); + } + break; } return result; } } +/* eslint @typescript-eslint/no-explicit-any: off */ function deepEqual(a: any, b: any): boolean { return a === b || (isNaN(a) && isNaN(b)); -} \ No newline at end of file +} diff --git a/src/reporter/Reporter.ts b/src/reporter/Reporter.ts index 02a4402..f1cdbd7 100644 --- a/src/reporter/Reporter.ts +++ b/src/reporter/Reporter.ts @@ -15,18 +15,18 @@ import { function describer(verbosity: Verbosity, item: SuiteResult): SuiteDescriber { switch (verbosity) { - case Verbosity.none: - return new SilentDescriber(item); - case Verbosity.minimal: - return new MinimalSuiteDescriber(item); - case Verbosity.short: - return new ShortSuiteDescriber(item); - case Verbosity.normal: - case Verbosity.more: - case Verbosity.all: - case Verbosity.debug: - default: - return new NormalSuiteDescriber(item); + case Verbosity.none: + return new SilentDescriber(item); + case Verbosity.minimal: + return new MinimalSuiteDescriber(item); + case Verbosity.short: + return new ShortSuiteDescriber(item); + case Verbosity.normal: + case Verbosity.more: + case Verbosity.all: + case Verbosity.debug: + default: + return new NormalSuiteDescriber(item); } } @@ -98,9 +98,6 @@ export class Reporter { const psa = this.suites.flatMap((suite) => suite.outcomes()).flatMap((scenario) => scenario.outcomes().filter((result) => result.outcome === Outcome.succeeded).length).reduce((acc, val) => acc + val, 0); - const fa = this.suites.flatMap((suite) => suite.outcomes()).flatMap((scenario) => - scenario.outcomes().filter((result) => - result.outcome === Outcome.failed).length).reduce((acc, val) => acc + val, 0); const timeouts = this.suites.flatMap((suite) => suite.outcomes()).flatMap((scenario) => scenario.outcomes().filter((result) => result.outcome === Outcome.timedout).length).reduce((acc, val) => acc + val, 0); diff --git a/src/reporter/Results.ts b/src/reporter/Results.ts index c60c7e1..0704a5f 100644 --- a/src/reporter/Results.ts +++ b/src/reporter/Results.ts @@ -183,7 +183,7 @@ export class Skipped implements Result { return this; } - public error(clarification: string): Skipped { + public error(): Skipped { return this; } } diff --git a/src/reporter/describers/Describer.ts b/src/reporter/describers/Describer.ts index 1216267..b476e71 100644 --- a/src/reporter/describers/Describer.ts +++ b/src/reporter/describers/Describer.ts @@ -18,7 +18,7 @@ export abstract class Describer implements Describable { } export class SilentDescriber extends Describer { - describe(style: Style): string[] { + describe(): string[] { return []; } } @@ -30,15 +30,15 @@ export class StepDescriber extends Describer { describe(style: Style): string[] { switch (this.item.outcome) { - case Outcome.succeeded: - return [`${style.colors.success(style.labels.success)} ${this.item.name}`]; - case Outcome.uncommenced: - case Outcome.skipped: - return [`${style.colors.skipped(style.labels.skipped)} ${this.item.name}`]; - case Outcome.error: - case Outcome.failed: - default: - return [`${style.colors.failure(style.labels.failure)} ${this.item.name}\n ${style.colors.failureMessage(this.item.outcome + this.item.clarification)}`]; + case Outcome.succeeded: + return [`${style.colors.success(style.labels.success)} ${this.item.name}`]; + case Outcome.uncommenced: + case Outcome.skipped: + return [`${style.colors.skipped(style.labels.skipped)} ${this.item.name}`]; + case Outcome.error: + case Outcome.failed: + default: + return [`${style.colors.failure(style.labels.failure)} ${this.item.name}\n ${style.colors.failureMessage(this.item.outcome + this.item.clarification)}`]; } } }