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 ability to mock out process.stdout calls #118

Open
jeffrafter opened this issue Sep 6, 2019 · 4 comments

Comments

@jeffrafter
Copy link

commented Sep 6, 2019

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.

@jeffrafter

This comment has been minimized.

Copy link
Author

commented 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)
  }
}
@bryanmacfarlane bryanmacfarlane self-assigned this Sep 10, 2019
@bryanmacfarlane

This comment has been minimized.

Copy link
Member

commented Sep 10, 2019

Thanks for logging this issue! We will implement this (we also take PRs ;) )

@xt0rted

This comment has been minimized.

Copy link

commented Oct 14, 2019

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

This comment has been minimized.

Copy link
Member

commented Oct 15, 2019

@xt0rted - not related to mocking but I think proper annotations support will fix your issue. I can prioritize the first half of that work (ensuring logging warning / error output doesn't create an annotation). That's a bug and I can fix. Sound ok? #186

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.