-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve our error messages when tests fail (#896)
* Add better error reporting for tests. * Control the streams that a logger writes to * In tests, write a debug log of events and print it when a test fails * Fix a couple little things. * Rename uvu-timeout.ts to rig-test.ts * Rename env variable to WIREIT_DEBUG_LOG_FILE
- Loading branch information
Showing
38 changed files
with
1,215 additions
and
1,087 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {Event} from '../event.js'; | ||
import {Console, Logger} from './logger.js'; | ||
|
||
// To prevent using the global console accidentally, we shadow it with | ||
// undefined | ||
const console = undefined; | ||
function markAsUsed(_: unknown) {} | ||
markAsUsed(console); | ||
|
||
/** | ||
* A {@link Logger} that logs to multiple loggers. | ||
*/ | ||
export class CombinationLogger implements Logger { | ||
readonly console: Console; | ||
readonly #loggers: readonly Logger[]; | ||
|
||
constructor(loggers: readonly Logger[], console: Console) { | ||
this.console = console; | ||
this.#loggers = loggers; | ||
} | ||
|
||
log(event: Event): void { | ||
for (const logger of this.#loggers) { | ||
logger.log(event); | ||
} | ||
} | ||
printMetrics(): void { | ||
for (const logger of this.#loggers) { | ||
logger.printMetrics?.(); | ||
} | ||
} | ||
getWatchLogger?(): Logger { | ||
const watchLoggers = this.#loggers.map( | ||
(logger) => logger.getWatchLogger?.() ?? logger, | ||
); | ||
return new CombinationLogger(watchLoggers, this.console); | ||
} | ||
|
||
[Symbol.dispose](): void { | ||
for (const logger of this.#loggers) { | ||
logger[Symbol.dispose]?.(); | ||
} | ||
this.console[Symbol.dispose](); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @license | ||
* Copyright 2023 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import {DefaultLogger} from './default-logger.js'; | ||
import {Event} from '../event.js'; | ||
import {inspect} from 'node:util'; | ||
|
||
// To prevent using the global console accidentally, we shadow it with | ||
// undefined | ||
const console = undefined; | ||
function markAsUsed(_: unknown) {} | ||
markAsUsed(console); | ||
|
||
/** | ||
* A {@link Logger} for logging debug information, mainly in tests. | ||
*/ | ||
export class DebugLogger extends DefaultLogger { | ||
override log(event: Event) { | ||
switch (event.type) { | ||
case 'info': | ||
this.console.log(`<info> ${event.detail}`); | ||
break; | ||
case 'failure': | ||
this.console.log(`<failure> ${event.reason}`); | ||
break; | ||
case 'output': | ||
// too verbose, log nothing | ||
return; | ||
case 'success': | ||
this.console.log(`<success> ${event.reason}`); | ||
break; | ||
default: { | ||
const never: never = event; | ||
throw new Error(`Unknown event type: ${inspect(never)}`); | ||
} | ||
} | ||
super.log(event); | ||
} | ||
|
||
[Symbol.dispose](): void { | ||
super[Symbol.dispose](); | ||
this.console[Symbol.dispose](); | ||
} | ||
} |
Oops, something went wrong.