Skip to content
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

feat: add ability to show user log in component tests #905

Merged
merged 1 commit into from
Apr 16, 2024

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Apr 16, 2024

What is done

Added the ability to show user log in nodejs environment when tests run in browser environment

@DudaGod DudaGod force-pushed the HERMIONE-1509.handle_console branch from 47d7401 to 9d6e735 Compare April 16, 2024 11:38
@@ -33,6 +34,8 @@ export class MochaWrapper {
}

this._socket.emit(BrowserEventNames.initialize, getErrorsOnPageLoad(error));

wrapConsoleMethods();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do it before run any runnable. I do not call it earlier so that all sorts of browser system logs are not displayed

socket.on(BrowserEventNames.callConsoleMethod, payload => {
const { runUuid } = socket.handshake.auth;

io.to(runUuid).except(socket.id).emit(BrowserEventNames.callConsoleMethod, payload);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could call the console log right here (in master), but to my mind it's better to call it in the worker, that runs the test

Copy link
Member

@KuznetsovRoman KuznetsovRoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/ok

@@ -22,3 +22,5 @@ export const MAX_ARGS_LENGTH = 50;
// used from - https://github.com/jestjs/jest/blob/726ca20752e38c18e20aa21740cec7aba7891946/packages/pretty-format/src/plugins/AsymmetricMatcher.ts#L11-L14
export const ASYMMETRIC_MATCHER =
typeof Symbol === "function" && Symbol.for ? Symbol.for("jest.asymmetricMatcher") : 0x13_57_a5;

export const CONSOLE_METHODS = ["log", "info", "warn", "error", "debug"] as const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about trace? Would it work?

table also could be usefull.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about trace? Would it work?

It works, but stack trace is not quite helpful, because it called inside worker.

table also could be usefull.

Ok, I add it.

console[method] = (...args: unknown[]): void => {
socket.emit(BrowserEventNames.callConsoleMethod, { method, args });

origCommand(...args);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I suggest to use return origCommand(...args) to preserve original API, just in case if sombody would overwrite console method too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a synchronous event here. It means I can't return anything to browser. I don't see the point in such an implementation, since the real console methods is still running in the browser. Here I just show arguments in terminal.

@DudaGod DudaGod force-pushed the HERMIONE-1509.handle_console branch from 9d6e735 to b1f1b7c Compare April 16, 2024 12:02
@DudaGod DudaGod merged commit 310447a into component_testing Apr 16, 2024
2 checks passed
@DudaGod DudaGod deleted the HERMIONE-1509.handle_console branch April 16, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants