Skip to content

Commit

Permalink
fix(list): Do not emit empty stdout when there are no results
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Feb 14, 2019
1 parent 6ff53d6 commit ba54439
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions commands/list/__tests__/list-command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// mocked modules
const output = require("@lerna/output");
const collectUpdates = require("@lerna/collect-updates");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
Expand Down Expand Up @@ -130,6 +131,18 @@ __TEST_ROOTDIR__/packages/package-5:package-5:1.0.0:PRIVATE
await lernaLs(testDir)("--no-private");
expect(output.logged()).not.toMatch("package-5 v1.0.0 (private)");
});

it("does not emit empty stdout", async () => {
collectUpdates.setUpdated(testDir);
await lernaLs(testDir)("--since", "deadbeef");
expect(output).not.toHaveBeenCalled();
expect(collectUpdates).toHaveBeenLastCalledWith(
expect.any(Array),
expect.any(Map),
expect.any(Object),
expect.objectContaining({ since: "deadbeef" })
);
});
});

describe("in a repo with packages outside of packages/", () => {
Expand Down
5 changes: 4 additions & 1 deletion commands/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ class ListCommand extends Command {
}

execute() {
output(this.result.text);
// piping to `wc -l` should not yield 1 when no packages matched
if (this.result.count) {
output(this.result.text);
}

this.logger.success(
"found",
Expand Down

0 comments on commit ba54439

Please sign in to comment.