-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 ability to mock out process.stdout calls #118
Comments
It is also possible to mock this globally in the const processStdoutWrite = process.stdout.write.bind(process.stdout)
process.stdout.write = (str, encoding, cb) => {
// Note: this will soon change to ::
if (!str.match(/^\#\#/)) {
return processStdoutWrite(str, encoding, cb)
}
} |
Thanks for logging this issue! We will implement this (we also take PRs ;) ) |
These log messages from tests are now causing annotations to be created when they shouldn't be. You can see an example of this in my most recent action run here https://github.com/xt0rted/slash-command-action/pull/34/checks?check_run_id=259915650#step:8:9 and here https://github.com/xt0rted/slash-command-action/pull/34/checks?check_run_id=259915650#step:8:63. |
@bryanmacfarlane I meant to post that on #163, both issues a pretty similar in their end goal. |
would mocking the command module make more sense? |
Example here where core is mocked out specifically to capture info. Example here where core is mocked out to control the function results. Users can leverage mocking tools to fit their specific needs. |
@ericsciple I don't think it's just as simple as mocking core. I'm using the tool-cache module and getting all the debug messages triggered by tool-cache. I can't mock @actions/core because tool-cache has its own copy of the module. (@actions/core isn't de-duped in my node_modules tree; but even if it were, that would be a pretty fragile mock to assume they would always de-dupe) |
@jasonkarns good point regarding dedupe |
This is what we do in setup-go tests to mock it. https://github.com/actions/setup-go/blob/master/__tests__/setup-go.test.ts#L49 So, you're not mocking core wit a need for understanding internal. You're getting console writes so mock that. It's not the toolkit's role to add mocking for stdout. There's plenty of mocking frameworks that are capable of mocking stdout (as per above). Action authors should use the testing and mocking framework that suits them. |
Closing this as workarounds are identified and we are unlikely to add it to the toolkit in the near future. |
Currently
issueCommand
always outputs tostdout
here: https://github.com/actions/toolkit/blob/master/packages/core/src/command.ts#L25. This is great but when writing tests for actions it quickly fills up the logs:If the output was wrapped in a call on the
Command
object itself then it could be mocked in the jest setup. Additionally this might pave the way for alternate logging outputs down the road.The text was updated successfully, but these errors were encountered: