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

Add console support when jest-junit is used as a reporter #96

Merged
merged 1 commit into from Jul 23, 2019

Conversation

palmerj3
Copy link
Collaborator

Fixes #45

Jest made a breaking change which set console to undefined for onRunComplete for reporters in order to address a memory leak.

This change aggregates console output from onTestResult and adds it to the report.

@palmerj3 palmerj3 merged commit 911188f into jest-community:master Jul 23, 2019
@palmerj3 palmerj3 deleted the addConsoleSupportAgain branch July 23, 2019 21:53
@brownbl1
Copy link

Thanks for addressing this. But I think something is still missing. It looks like you are buffering the console output, but still nothing is being done with it. It doesn't look like consoleBuffer is actually read anywhere or written to the file output.

consoleBuffer[testResult.testFilePath] = testResult.console;
}
};

this.onRunComplete = (contexts, results) => {
processor(results, this._options, this._globalConfig.rootDir);

Choose a reason for hiding this comment

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

you could read consoleBuffer here and add it back to each result instance before you pass it to processor.

Choose a reason for hiding this comment

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

Interesting, yep! You're right! Thanks so much for the help there. This is a really helpful feature.
Hi,
I tried executing the test from your repository but still not able to see the console logs on JUnit xml. Did it worked when you tried it?

@palmerj3
Copy link
Collaborator Author

I verified that this works - if something isn't working on your end do me a favor and submit an issue with steps to reproduce.

Keep in mind the caveats to make this work:

  1. Jest cannot be running in verbose mode
  2. You need to have at least two test files

@brownbl1
Copy link

Thanks. I took a closer look, and you're right that the console output is definitely getting injected into the processor. So no issue there, but I still haven't gotten it to work (actually write to the xml file).

Here's my repro: https://github.com/brownbl1/jest-test

Anything look off there?

@palmerj3
Copy link
Collaborator Author

I think the configuration precedence was likely not great in that example. I may create a bug report from this..

But basically the preferred way of setting configurations for jest-junit is via reporter arguments. This makes it work in your setup.

Remove the "jest-junit" key in package.json and replace the "jest" key with this.

  "jest": {
    "reporters": [
      "default",
      ["jest-junit", {"includeConsoleOutput": "true" }]
    ]
  },

@palmerj3
Copy link
Collaborator Author

So turns out your way of configuring was just fine. Just need to switch true to "true" and it works.

@brownbl1
Copy link

Interesting, yep! You're right! Thanks so much for the help there. This is a really helpful feature.

@Ppkd2021
Copy link

HI thanks for the super feature as I need it to work for the test cases to log graphql api failure errors but I am not able to see the console log in junit xml. Please find the jest.config details below and I am using jest 10.0.0 version.
module.exports = {
//verbose: true,
globals: {
'ts-jest': {
tsConfig: './tsconfig.test.json'
}
},
preset: 'jest-playwright-preset',
transform: {
'^.+\.ts$': 'ts-jest'
},
testMatch: ['/playwright/e2e//*.test.ts'],
reporters: [
'default',
[
'jest-junit',
{'includeConsoleOutput': true },
{
outputDirectory: './test-reports',
outputName: 'results.xml',
usePathForSuiteName: true,
classNameTemplate: '{classname}-{title}',

		}
	]
],
testRunner: 'jest-circus/runner',
testEnvironment: './customEnvironment.js',
testTimeout: 100000,
setupFilesAfterEnv: ['expect-playwright']

};

@palmerj3
Copy link
Collaborator Author

Jest has removed the ability for reporters to access console output.

The configuration still exists in jest-junit because we support older versions of jest. But for modern versions of jest this is no longer a possibility. I'll update the docs to make that clear.

@StevenBedoyaB
Copy link

Jest has removed the ability for reporters to access console output.

The configuration still exists in jest-junit because we support older versions of jest. But for modern versions of jest this is no longer a possibility. I'll update the docs to make that clear.

@palmerj3 do you know witch versions of Jest allow the access to console output?

@palmerj3
Copy link
Collaborator Author

I don't recall off hand but I will do the work to dig that up and update the jest-junit README once I know

@Ppkd2021
Copy link

@StevenBedoyaB Jest 7.0.0 I guess it works, I will try it out on that version tomorrow.

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.

console support
4 participants