tapjs / tap-parser

parse the test anything protocol
121 stars 35 forks source link

looking for use case example - consuming stdout / stderr streams from child process #47

Closed ORESoftware closed 7 years ago

ORESoftware commented 7 years ago

hello @isaacs and co

basically looking to do something like this:

const parser = require('tap-parser');
const cp = require('child_process');
const n = cp.spawn('python',['foo.py']);

const dest = n.stdout.pipe(parser());

dest.on('pass', function(){
   console.log('test passed');
});

dest.on('fail', function(){
   console.log('test failed');
});

is a streaming usage like the one above possible with this module? I would like to print/use the results as they come in, in a streaming fashion.

isaacs commented 7 years ago

https://github.com/tapjs/tap-parser#ponassert-function-assert-

dest.on('assert', function (testpoint) {
  if (testpoint.skip || testpoint.todo) {
    // it is neither ok nor not ok
  } else if (testpoint.ok) {
    // it is ok
  } else {
    // it is not ok
  }
})
isaacs commented 7 years ago

(Note that you can also run non-JS programs with tap if they are executable and have a shebang line.)

ORESoftware commented 7 years ago

got it thanks, I was expecting something like

dest.on('pass') or dest.on('fail') but I guess I don't know TAP that well.

ORESoftware commented 7 years ago

one more question @isaacs - you ever seen any problems with parsing streams with data chunks that don't represent the complete line, etc? I assume you handle that as best you can. I feel like it's mostly up to programming language's std libs to get that right.

isaacs commented 7 years ago

It's fine. You can write it all at once, or one byte at a time, or anything in between. https://github.com/tapjs/tap-parser/blob/master/index.js#L343-L351

ORESoftware commented 7 years ago

thanks, one more question for you maestro - I assume all tap output should be written to stdout - there's no reason tap output would ever be written to stderr. Is that assumption correct?

As you can see my original question was about stdout/stderr streams from child processes. To be exact, I assume I can parse all tap output by just listening to stdout of the child process. I can I assume that if any tap info is coming via stderr, that this is most likely a mistake of the upstream process?

lmk thanks!

isaacs commented 7 years ago

This is really way off topic for this repo.

From tap-parser's point of view, you put text into it, and it spits out events based on that text being a TAP stream. It doesn't care if it's stdout, stderr, a file you're reading, an HTTP connection, etc. It's just text -> events.

From node-tap's point of view, yeah, it spawns child processes that output TAP data to stdout, that's how it works. But you don't have to do it that way, and the parser has no opinions about where its data comes from.

the1mills commented 7 years ago

Well ultimately Isaac my question was - by convention all tap output from child processes should come via stdout and none from stderr? Is that generally true? Not too off topic is it?

isaacs commented 7 years ago

@the1mills This repo is for the parser. The parser doesn't care where the data comes from.

By convention, yes, most tap frameworks write test output to stdout.