question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add ability to mock out process.stdout calls

See original GitHub issue

Currently 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:closed
  • Created 4 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jasonkarnscommented, Mar 21, 2020

@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)

1reaction
jeffraftercommented, Sep 6, 2019

It is also possible to mock this globally in the jest.config.js:

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)
  }
}
Read more comments on GitHub >

github_iconTop 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 >
API Reference | Vitest
A blazing fast unit test framework powered by Vite.
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found