Add ability to mock out process.stdout calls
See original GitHub issueCurrently issueCommand
always outputs to stdout
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:
> @ test /Users/njero/Code/Examples/example-github-action-typescript
> jest
PASS .github/actions/debug-action/__tests__/debug.test.ts
debug action debug messages
✓ outputs a debug message (5ms)
##[debug]👋 Hello! You are an amazing person! 🙌
##[debug]👋 Hello! You are an amazing person! 🙌
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.423s
Ran all test suites.
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.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
How to mock the process.cwd() function with Jest?
cwd() is called in the testcase it works as expected. In the module I'm testing it returns the original value. What am I...
Read more >Using stdout, stdin, and stderr in Node.js - LogRocket Blog
First, we would create a new JavaScript file called index.js , import ... createInterface({ input: process.stdin, output: process.stdout, }) ...
Read more >inkex.tester.mock module - GitLab
Capture stdout or stderr. Used as with Capture('stdout') as stream: ... Add mocking ability to any test base class, will set up mock...
Read more >sys.stdout.write in Python - GeeksforGeeks
By default, streams are in text mode. In fact, wherever a print function is called within the code, it is first written to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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)
It is also possible to mock this globally in the
jest.config.js
: