-
Notifications
You must be signed in to change notification settings - Fork 630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Testing] Pretty output + Silent mode #314
Conversation
I do not believe this issue is solvable. The correct solution is to just reduce printing to stdout during the tests. |
This is totally possible, here is the Jest way using I think i can solve the problems raised by @bartlomieju . Or you prefer me to abort this? |
About the remaining output of prettier this is due to this: And we can't do anything about it because it's another process running. But IMO the Note: Silent mode is disabled in the CI. |
Last thing, for the silent mode we can make it totally silent by adding an eventlistenner on the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some thought, I think it's worth considering to make a small helper:
function output(s: string) {
Deno.stdout.writeSync(encoder.encode(s));
}
And using it for test purpose so usages of console are not mixed. Then you should be able to disable console globally, without restoring it for each test case. What do you think @zekth?
EDIT: Also, integration test is needed for this
@bartlomieju agreed about the refactor of output. It would be simpler. Added the part of stdout with the 'Running' commit but didn't thought about refactoring it into a helper. Also about testing how you want to test it as we can't stub the functions atm? |
@bartlomieju about RUNNING test FOO About this feature i still have a little problem because i can't attach an event on the
|
Any opinion about it or we close it? |
This functionality is quite useful, IMHO we should land it. @ry? |
@zekth @bartlomieju It does look nice. I will defer to @piscisaureus on this. |
CC @piscisaureus could you take a look? |
I think this is generally a nice feature and it worked when I tested it, but I have two needs:
|
For example having:
Sure will fix this. |
I've fixed the Also just need to adjust for strict mode.
console is @kitsonk any opinion? |
@zekth sorry for delay. How about you write |
added interface SignatureInterface {
[key: string]: unknown
}
export class Console implements SignatureInterface {
indentLevel: number;
collapsedAt: number | null;
[isConsoleInstance]: boolean = false;
.... Or write down the whole console interface. |
@zekth could you merge master into this branch? |
@zekth can you try this patch: diff --git a/testing/mod.ts b/testing/mod.ts
index ea090dc..f6db9c5 100644
--- a/testing/mod.ts
+++ b/testing/mod.ts
@@ -17,31 +17,44 @@ export interface TestDefinition {
name: string;
}
-// TODO: just construct single noop console
-
// Replacement of the global `console` function to be in silent mode
-const noopConsole = function(): void {};
+const noop = function(): void {};
// Save Object of the global `console` in case of silent mode
-let defaultConsole = {};
+type Console = typeof window.console;
+// ref https://console.spec.whatwg.org/#console-namespace
+// For historical web-compatibility reasons, the namespace object for
+// console must have as its [[Prototype]] an empty object, created as if
+// by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
+const disabledConsole = Object.create({}) as Console;
+Object.assign(disabledConsole, {
+ log: noop,
+ debug: noop,
+ info: noop,
+ dir: noop,
+ warn: noop,
+ error: noop,
+ assert: noop,
+ count: noop,
+ countReset: noop,
+ table: noop,
+ time: noop,
+ timeLog: noop,
+ timeEnd: noop,
+ group: noop,
+ groupCollapsed: noop,
+ groupEnd: noop,
+ clear: noop,
+});
+
+const originalConsole = window.console;
function enableConsole(): void {
- for (const key in defaultConsole) {
- // @ts-ignore
- console[key] = defaultConsole[key];
- }
+ window.console = originalConsole;
}
function disableConsole(): void {
- for (const key in console) {
- // @ts-ignore
- if (console[key] instanceof Function) {
- // @ts-ignore
- defaultConsole[key] = console[key];
- // @ts-ignore
- console[key] = noopConsole;
- }
- }
+ window.console = disabledConsole;
}
const encoder = new TextEncoder(); Seems to be working for me |
@piscisaureus you can review it now |
@ry any feedback? |
Please land it, it's very useful for test runner |
Yes - ok. Although I still have hesitations about how this is accomplished. It's certainly much better looking. |
const encoder = new TextEncoder(); | ||
function print(txt: string, carriageReturn: boolean = true): void { | ||
if (carriageReturn) { | ||
txt += "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a carriage return character, this a new line character.
s/carriageReturn/newline/g
testing/mod.ts
Outdated
return `${(time / 1000).toFixed(2)}s`; | ||
} else { | ||
return `${time.toFixed(2)}ms`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer if you use a single time unit (ms)
testing/mod.ts
Outdated
console.groupEnd(); | ||
console.error(err.stack); | ||
if (disableLog) { | ||
print("\x1b[2K\r", false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ANSI escape sequences are hard to read. Ideally you'd define them in a constant. Something like:
const CLEAR_LINE = "\x1b[2K";
(I don't actually know what that ANSI sequence means, I'm just giving an example)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used to erase the the current line: http://ascii-table.com/ansi-escape-sequences-vt-100.php
Agreed - this issue can be addressed better if |
Looks good modulo a couple nits... |
Done the review. Also added the comment about the ASCII table. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Note: At the moment the CI is not quiet. we may want to add the |
Following : #306
Here is a proposal of pretty output for tests (for more readability):
Also added the option for
disableLogs
in the test. It is usefull for CI when there is still debug in the tests, then you directly have information of which tests is buggy and you're not flooded with all the debug logs. Currently it is set tofalse
and only work forserialTesting
. Do you think this is usefull and should i expand it to parallel? (needs a bit more refactor)EDIT
I've added the timers on each tests and on the whole runtime. See:
Added on Silent mode the display of the currently running TEST: