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.

--stream prints newlines as \n

See original GitHub issue

Expected Behavior

I run my tests with lerna run --stream test, the packages tests are simple Jest tests. The output printed by Lerna doesn’t properly renders the newlines, for instance, this is what I get:

image

Possible Solution

I’m not sure, but it looks like Lerna does something to escape the special characters and forgets to restore them before it prints.

Steps to Reproduce (for bugs)

  1. create a package/something with inside its package.json a Jest test command
  2. run lerna run --stream test in the root of the project
lerna.json

{
  "lerna": "2.1.1",
  "packages": [
    "packages/*"
  ],
  "version": "independent",
  "npmClient": "yarn"
}

lerna-debug.log

<!-- If you have a `lerna-debug.log` available, please paste it here -->
<!-- Otherwise, feel free to delete this <details> block -->

Context

This bug makes it very difficult to read the logs, especially in CI

Your Environment

Executable Version
lerna --version 2.1.1
npm --version 5.3.0
yarn --version 1.0.0-20170815.1425
node --version 8.1.2
OS Version
macOS 10.12.6

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
ptshihcommented, Sep 5, 2017

This also happens with lerna run --parallel

3reactions
charlesbjohnsoncommented, Dec 25, 2017

I also ran into this, but it seems to be an issue primarily with jest. Relevant issues:

jest’s BaseReporter writes output to stderr instead of stdout. See here.

Since lerna run collapses newlines for stderr via strong-log-transformer, we end up with escaped newlines in the output. https://github.com/lerna/lerna/blob/d35c7aa0875013248f55b26487eac99d55b59a78/src/ChildProcessUtilities.js#L52

I’m not entirely sure why this is jest’s default behavior since it doesn’t seem to be consistent with other test runners (notably mocha). As such, I think the fix probably belongs in jest and not in lerna.

Removing mergeMultiline in lerna might not break anything (--parallel?), but it seems like it could also have larger implications since lerna run is not limited to running tests.

There is a very simple workaround to perform the redirection to stdout in bash, though this still probably won’t work well with CI tools that read from stderr to determine build failures.

// /repo/packages/sub/package.json
"scripts": {
  "test": "jest 2>&1"
}
// /repo/package.json
"scripts": {
  "test": "lerna run test"
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

java stream 8, every sixth word print in new line
Now I have all results in one line. How I can make logic in this Java stream 8, to put every 5 words...
Read more >
Python New Line and How to Python Print Without a Newline
The new line character in Python is \n . It is used to indicate the end of a line of text. You can...
Read more >
Creating a New Line in C++
Learn C++ Online With Udacity ... As a programmer, you can use endl or \n to create new line commands in C++. These...
Read more >
Python New Line: How to Print WITHOUT Newline in Python
From Python 3+, there is an additional parameter introduced for print() called end=. This parameter takes care of removing the newline that is ......
Read more >
Python: How to Print Without Newline?
To print without a newline, all you have to do is add an additional argument at the end of your print statement. This...
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