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

cli: fix handling of non-TTY environment #6970

Closed
wants to merge 2 commits into from
Closed

Conversation

bajtos
Copy link
Member

@bajtos bajtos commented Jan 4, 2021

An attempt to fix our CLI to correctly work in non-TTY environments, such as GitHub Actions runners.

See also #5110 and #4607

Checklist

  • DCO (Developer Certificate of Origin) signed in all commits
  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • API Documentation in code was updated
  • Documentation in /docs/site was updated
  • Affected artifact templates in packages/cli were updated
  • Affected example projects in examples/* were updated

👉 Check out how to submit a PR 👈

bajtos added 2 commits January 4, 2021 16:57
Replace all remaining places invoking generator from tests via
`helpers.run()` to use `executeGenerator` instead, to ensure that
generator errors are correctly propagated back via a rejected promise.

Before this change, a failed generator behaved as if it succeeded. A
test suite would continue and fail later when one of the assumptions
are not true. As a result, the test error messages were cryptic and
made troubleshooting difficult.

For example, when running the following command from `packages/cli`:

    CI=1 lb-mocha test/acceptance/app-run.acceptance.js < /dev/null

Before my change, the suite would fail as follows:

    1) app-generator (SLOW)
         "before all" hook: install dependencies for·
            "passes `npm test` for the generated project":
       ValidationError: No packages remain after filtering [ '@loopback/sandbox-app' ]
        at filterPackages (node_modules/@lerna/filter-packages/filter-packages.js:54:13)

With my change in place, the suite correctly fails in the scaffolding
step:

    1) app-generator (SLOW)
         "before all" hook: scaffold a new application for
            "passes `npm test` for the generated project":
       SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at AppGenerator._readJSONFromStdin (lib/base-generator.js:132:19)

Signed-off-by: Miroslav Bajtoš <[email protected]>
Before this change, when the config read from `stdin` was an empty
string, the generator would fail with the following message:

    SyntaxError: Unexpected end of JSON input
       at JSON.parse (<anonymous>)
       at AppGenerator._readJSONFromStdin (lib/base-generator.js:132:19)

With this fix in place, an empty JSON string is treated as an empty
config object `{}` and the generator can continue its work.

Please note this change is probably a partial fix only. AFAICT,
the application generator is still not correctly scaffolding the project
when running in a non-TTY mode, despite the fact that it reports success.

Signed-off-by: Miroslav Bajtoš <[email protected]>
if (jsonStr === '') {
debug('Received an empty string, returning back empty config: {}');
return {};
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a test to verify this fix? Such test would have to spawn a new child process to invoke the generator. That seems like a too much effort to me, considering that other parts of _readJSONFromStdin are not covered by tests either, at least AFAIK.

@bajtos bajtos mentioned this pull request Jan 4, 2021
7 tasks
@bajtos bajtos closed this Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant