Skip to content

Commit

Permalink
Fix eslint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tolauwae committed Dec 12, 2024
1 parent 9fb4d65 commit 4a2d27b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 67 deletions.
6 changes: 4 additions & 2 deletions .eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

];
20 changes: 10 additions & 10 deletions src/framework/Testee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ export class Testee { // TODO unified with testbed interface
}

private run(name: string, limit: number, fn: () => Promise<any>) {
return timeout<Object | void>(name, limit, fn());
return timeout<object | void>(name, limit, fn());
}

private step(name: string, limit: number, fn: () => Promise<any>) {
return timeout<Object | void>(name, limit, fn());
return timeout<object | void>(name, limit, fn());
}

public async describe(description: TestScenario, suiteResult: SuiteResult, runs: number = 1) {
Expand Down Expand Up @@ -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<Object | void>(`uploading module`, testee.timeout, testee.bed()!.sendRequest(new SourceMap.Mapping(), Message.updateModule(compiled.file))).catch((e) => Promise.reject(e));
await timeout<object | void>(`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));
Expand Down Expand Up @@ -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<Object | void>(`performing action . ${step.title}`, testee.timeout,
actual = await timeout<object | void>(`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<Object | void>(`sending instruction ${req.type}`, testee.timeout,
(testee, req, map) => timeout<object | void>(`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) => {
Expand All @@ -255,10 +255,10 @@ export class Testee { // TODO unified with testbed interface
}

private async recoverable(testee: Testee, step: Request<any>, map: SourceMap.Mapping,
attempt: (t: Testee, req: Request<any>, m: SourceMap.Mapping) => Promise<Object | void>,
attempt: (t: Testee, req: Request<any>, m: SourceMap.Mapping) => Promise<object | void>,

Check failure

Code scanning / ESLint

Disallow the `any` type Error

Unexpected any. Specify a different type.
recover: (t: Testee) => Promise<any>,
retries: number = 0): Promise<Object | void> {
let result: Object | void = undefined;
retries: number = 0): Promise<object | void> {
let result: object | void = undefined;
let error;
while (0 <= retries && result === undefined) {
result = await attempt(testee, step, map).catch(async (err) => {
Expand All @@ -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<Object | void>('resetting vm', this.timeout, this.testbed!.sendRequest(new SourceMap.Mapping(), Message.reset));
await timeout<object | void>('resetting vm', this.timeout, this.testbed!.sendRequest(new SourceMap.Mapping(), Message.reset));
}
}

Expand Down
59 changes: 30 additions & 29 deletions src/framework/Verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
27 changes: 12 additions & 15 deletions src/reporter/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import {

function describer(verbosity: Verbosity, item: SuiteResult): SuiteDescriber {
switch (verbosity) {
case Verbosity.none:
return new SilentDescriber<SuiteResult>(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<SuiteResult>(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);
}
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/reporter/Results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class Skipped implements Result {
return this;
}

public error(clarification: string): Skipped {
public error(): Skipped {
return this;
}
}
20 changes: 10 additions & 10 deletions src/reporter/describers/Describer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export abstract class Describer<R extends Result> implements Describable<R> {
}

export class SilentDescriber<R extends Result> extends Describer<R> {
describe(style: Style): string[] {
describe(): string[] {
return [];
}
}
Expand All @@ -30,15 +30,15 @@ export class StepDescriber extends Describer<StepOutcome> {

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)}`];
}
}
}
Expand Down

0 comments on commit 4a2d27b

Please sign in to comment.