kayahr / jest-electron-runner

Custom test runner for Jest that allows tests to be run in Electron environment
https://www.npmjs.com/package/@kayahr/jest-electron-runner
MIT License
19 stars 4 forks source link

console log buffered in render process? #7

Closed unional closed 2 years ago

unional commented 2 years ago

Hi, first of all, thank you for keeping this project alive.

The community needs a real environment to run tests.

Do you notice the console logs do not show up in the output in some cases? Here is an example:

image

I notice this behavior when I'm filtering the test (using the file pattern getServ in the example).

jest is know for eating up console logs but it has improved since 27.2.5 (https://github.com/facebook/jest/issues/8208).

I'm not yet sure if this is caused by jest or there are some buffering within electron.

I checked when running other tests in node the console logs are printing out just fine.

unional commented 2 years ago

Could be related to this

https://github.com/facebook-atom/jest-electron-runner/issues/54

kayahr commented 2 years ago

I noticed this, too. I usually have this problem when I run a single test in which case Jest switches to verbose output. When adding --verbose=false parameter then console output works again. I debugged it a little bit and found this code:

    if (globalConfig.silent === true) {
        testConsole = new NullConsole(consoleOut, consoleOut, consoleFormatter);
    } else if (globalConfig.verbose === true) {
        testConsole = new CustomConsole(consoleOut, consoleOut, consoleFormatter);
    } else {
        testConsole = new BufferedConsole();
    }

So in verbose mode jest-electron uses this CustomConsole thing and looks like this doesn't work in the renderer thread. When I remove this and always use BufferedConsole instead then it works fine in both threads and verbose and non-verbose. I'm not sure for what purpose this CustomConsole was used in the first place... Maybe it is something from the past that want to be ditched which I'll do now.

kayahr commented 2 years ago

Just released version 29.0.0 hopefully with a fix for this issue (works for me at least).

The new version also uses Jest 29 now and I follow their major number from now on for the jest-electron-runner version.

I added a check if tests are running in the render thread and in this case the BufferedConsole is used instead of the CustomConsole in verbose mode. The output is bit different when comparing console logging in main and render thread but at least logging should now no longer be discarded.

If someone knows how to fix this properly so CustomConsole works in the render thread then please let me know.