Skip to content

Commit

Permalink
🐛 restore timer (fixes #272)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngarbezza committed Feb 12, 2024
1 parent 60f1315 commit 6609311
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 27 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

Everything is released :tada:
[//]: # (Everything is released :tada:)

### Fixed

* [[bug] timer is gone](https://github.com/ngarbezza/testy/issues/272): We restored the timer at the end of the test
report.

## [7.0.0] - 2024-02-05

Expand Down
3 changes: 2 additions & 1 deletion doc/decisions/0012-no-backwards-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ is high for a single person.

## Decision

New major versions might not be backwards compatible, and we will always maintain only the latest major version. We will keep documenting
New major versions might not be backwards compatible, and we will always maintain only the latest major version. We
will keep documenting changes and migration notes, but not solving bugs of previous versions.

## Consequences

Expand Down
6 changes: 3 additions & 3 deletions lib/core/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class TestRunner {
#currentSuite;
#failFastMode;
#randomOrder;
#testExecutiontimeoutMs;
#testExecutionTimeoutMs;

constructor(callbacks) {
this.#suites = [];
Expand Down Expand Up @@ -59,7 +59,7 @@ export class TestRunner {
}

setTestExecutionTimeoutMs(timeoutMs) {
this.#testExecutiontimeoutMs = timeoutMs;
this.#testExecutionTimeoutMs = timeoutMs;
}

// Executing
Expand Down Expand Up @@ -136,7 +136,7 @@ export class TestRunner {
return {
failFastMode: this.#failFastMode,
randomOrderMode: this.#randomOrder,
testExecutionTimeoutMs: this.#testExecutiontimeoutMs,
testExecutionTimeoutMs: this.#testExecutionTimeoutMs,
};
}

Expand Down
6 changes: 3 additions & 3 deletions lib/i18n/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"yes": "yes",
"no": "no",
"total": "Total tests:",
"total_time": "total time",
"total_time": "Total time",
"wip": "WIP",
"skip": "SKIP",
"ok": "OK",
Expand Down Expand Up @@ -60,7 +60,7 @@
"yes": "",
"no": "no",
"total": "Total de tests:",
"total_time": "tiempo total",
"total_time": "Tiempo total",
"wip": "PENDIENTE",
"skip": "NO EJECUTADO",
"ok": "EXITOSO",
Expand Down Expand Up @@ -117,7 +117,7 @@
"yes": "",
"no": "no",
"total": "Test totali:",
"total_time": "tempo totale",
"total_time": "Tempo totale",
"wip": "IN CORSO",
"skip": "SALTA",
"ok": "OK",
Expand Down
10 changes: 7 additions & 3 deletions lib/ui/console_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ConsoleUI {
testRunnerCallbacks() {
return {
onFinish: runner =>
this.#formatter.displayRunnerEnd(runner),
this.onRunnerFinish(runner),
onSuccess: _runner =>
this.#exitWithCode(ConsoleUI.successfulExitCode()),
onFailure: _runner =>
Expand All @@ -64,10 +64,9 @@ export class ConsoleUI {
// application events

async start(configuration, paths, runnerBlock) {
this.#formatter.start();
this.#formatter.startTimer();
this.#formatter.displayInitialInformation(configuration, paths);
await runnerBlock.call();
this.#formatter.end();
}

useLanguage(language) {
Expand All @@ -82,6 +81,11 @@ export class ConsoleUI {
this.#exitWithCode(ConsoleUI.failedExitCode());
}

onRunnerFinish(runner) {
this.#formatter.displayRunnerEnd(runner);
this.#formatter.endTimer();
}

// private

#exitWithCode(exitCode) {
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export class Formatter {
this.#timerName = this.#translated('total_time');
}

start() {
startTimer() {
this.#console.time(this.#timerName);
}

end() {
endTimer() {
this.#console.timeEnd(this.#timerName);
}

Expand Down
11 changes: 8 additions & 3 deletions tests/support/runner_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const noop = async() => {
// intentionally empty function
};

const withRunner = async testBlock => {
const emptyRunnerCallbacks = { onFailure: noop, onSuccess: noop, onFinish: noop };
const runner = new TestRunner(emptyRunnerCallbacks);
const emptyRunnerCallbacks = { onFailure: noop, onSuccess: noop, onFinish: noop };

const withRunner = async testBlock => withRunnerAndCallbacks(emptyRunnerCallbacks, testBlock);

const withRunnerAndCallbacks = async(callbacks, testBlock) => {
const runner = new TestRunner(callbacks);
const asserter = new Asserter(runner);
const failGenerator = new FailureGenerator(runner);
const pendingMarker = new PendingMarker(runner);
Expand Down Expand Up @@ -41,6 +44,8 @@ const resultOfASuiteWith = async(runner, test, before = noop, after = noop) => {

export {
withRunner,
withRunnerAndCallbacks,
resultOfATestWith,
resultOfASuiteWith,
emptyRunnerCallbacks,
};
25 changes: 18 additions & 7 deletions tests/ui/console_ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import { ConsoleUI } from '../../lib/ui/console_ui.js';
import { FakeConsole } from './fake_console.js';
import { FakeProcess } from './fake_process.js';
import { Configuration } from '../../lib/config/configuration.js';
import { emptyRunnerCallbacks, withRunnerAndCallbacks } from '../support/runner_helpers.js';

suite('Console UI', () => {
let fakeProcess, fakeConsole;
let fakeProcess, fakeConsole, console;

before(() => {
fakeProcess = new FakeProcess();
fakeConsole = new FakeConsole();
console = new ConsoleUI(fakeProcess, fakeConsole);
});

test('can exit with error displaying the given message', () => {
const console = new ConsoleUI(fakeProcess, fakeConsole);
console.exitWithError('a message');
assert.that(fakeProcess.lastExitCode()).isEqualTo(ConsoleUI.failedExitCode());
assert.that(fakeConsole.messages().length).isEqualTo(1);
Expand All @@ -31,16 +32,26 @@ suite('Console UI', () => {
assert.areEqual(ConsoleUI.failedExitCode(), 1);
});

test('prints start and end messages', async() => {
const console = new ConsoleUI(fakeProcess, fakeConsole);
test('prints initial configuration on start', async() => {
const config = Configuration.current();
await console.start(config, [], () => {});
assert.that(fakeConsole.messages().length).isEqualTo(8);
assert.that(fakeConsole.messages().at(0)).matches(/timer started/);
assert.that(fakeConsole.messages().length).isEqualTo(7);
assert.that(fakeConsole.messages().at(2)).matches(/Starting Testy!/);
assert.that(fakeConsole.messages().at(3)).matches(/Running tests in/);
assert.that(fakeConsole.messages().at(4)).matches(/Fail fast/);
assert.that(fakeConsole.messages().at(5)).matches(/Random order/);
assert.that(fakeConsole.messages().at(7)).matches(/timer ended/);
});

test('has a timer that ends at the end of the runner', async() => {
const callbacks = {
...emptyRunnerCallbacks,
onFinish: runner => {
console.onRunnerFinish(runner);
},
};
await withRunnerAndCallbacks(callbacks, async runner => {
runner.run();
});
assert.that(fakeConsole.messages().at(-1)).isEqualTo('timer "Total time" ended');
});
});
8 changes: 4 additions & 4 deletions tests/ui/fake_console.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export class FakeConsole {
return Array.from(this._messages);
}

time() {
this.log('timer started');
time(timerName) {
this.log(`timer "${timerName}" started`);
}

timeEnd() {
this.log('timer ended');
timeEnd(timerName) {
this.log(`timer "${timerName}" ended`);
}
}

0 comments on commit 6609311

Please sign in to comment.