Repository: nvim-lua/plenary.nvim (lua)

Issue:
job on_stdout is not retrieving all data
Hi and thanks for this awesome project!

I have been using the `plenary.curl` module recently, especially it's capability to stream http responses using the underlying `plenary.job` `on_stdout` mechanism.

While using it, I discovered a few weired edge-cases where the last chunks of streamed data is only available via `job:result()`, but not the `on_stdout` callback.

Looking at the tests I found [two related test cases that are marked as `pending`](https://github.com/nvim-lua/plenary.nvim/blob/master/tests/plenary/job_spec.lua#L102), so it seems like this has been a known issue.

As this is unnecessarily complicating my usage of the `plenary.curl` streaming functionality, as I would have to use both `on_stdout` and then at the end compare what has not yet been processed from the `job:result()`, I would like to resolve this bug.

Please let me know if I have misunderstood anything or you have further thoughts.
I will open a PR with a potential solution.

Thanks a lot!

Pull request description:
The current condition prematurely quits processing of data in on_output
in some edge-cases.

In these cases `job:result()` will have all data, but not everyting was
sent through the `on_output` pipes.

Closes https://github.com/nvim-lua/plenary.nvim/issues/634

Thanks for your support, please let me know your thoughts!

Patch:
diff --git a/lua/plenary/job.lua b/lua/plenary/job.lua
index 44a73483..7f549719 100644
--- a/lua/plenary/job.lua
+++ b/lua/plenary/job.lua
@@ -361,7 +361,7 @@ local on_output = function(self, result_key, cb)
         cb(err, result_line, self)
       end
 
-      if data == nil or is_complete then
+      if is_complete then
         return
       end
 


Test patch:
diff --git a/tests/plenary/job_spec.lua b/tests/plenary/job_spec.lua
index d9213be3..c2edde04 100644
--- a/tests/plenary/job_spec.lua
+++ b/tests/plenary/job_spec.lua
@@ -99,7 +99,7 @@ describe("Job", function()
       assert.are.same(job:result(), results)
     end)
 
-    pending("should split stdin across newlines with no ending newline", function()
+    it("should split stdin across newlines with no ending newline", function()
       local results = {}
       local job = Job:new {
         -- writer = "hello\nword\nthis is\ntj",
@@ -113,6 +113,8 @@ describe("Job", function()
       job:start()
       job:send "hello\nwor"
       job:send "ld"
+
+      wait_for_result(job, { "hello", "world" })
       job:shutdown()
 
       assert.are.same(job:result(), { "hello", "world" })
@@ -137,7 +139,7 @@ describe("Job", function()
       assert.are.same(job:result(), results)
     end)
 
-    pending("should return last line when there is no ending newline", function()
+    it("should return last line when there is no ending newline", function()
       local results = {}
       local job = Job:new {
         command = "printf",