tapjs / tap-parser

parse the test anything protocol
121 stars 35 forks source link

[docs] - let's advise how to parse JSON.parse style - string-in, object-out #68

Closed revelt closed 4 years ago

revelt commented 4 years ago

Hi all,

Thank you for making the Tap ecosystem. I have a newbie-related readme suggestion; please excuse any ignorance from my side.

Currently we allude this is The Parser:

meaning

But this program seems to me like a terminal-oriented parser, not aimed at Node scripting, à la JSON.parse, "string-in, object-out".

If anybody wonders why am I concerned about parsing into a plain object, I want to compile statistics of a monorepo, from a bunch of packages' raw Tap output files, received via tap -o. It's a seemingly trivial task but I'm still in search how to parse the raw TAP "string-in, object-out".

Again, thank you for any help or advise.

isaacs commented 4 years ago

So, what you're asking for is somewhat at odds with the nature of how TAP works. It is a line-based streaming protocol, not an object serialization notation.

We could pretty easily create a static method to "parse" a string into the array of events and arguments that is output by default by bin/cmd.js, and in the other direction, turn such a nested array into a TAP string. Since the bin has a --tap output option, the code to turn the array back into TAP is there already. Would just be a matter of refactoring it into static methods in the exported class.

If you want to do this today, you can do something like cat my-test-output.tap | tap-parser --json.

dramirez42 commented 4 years ago

Thanks for adding this! I could use this in a project I'm working on. Any chance a new release including this could get published to npm?

revelt commented 4 years ago

@dramirez42 since original posting I wrote tap-parse-string-to-object — it's not comprehensive, it's aimed at extracting total counts but maybe it will do?

isaacs commented 4 years ago

Oh, whoops, I'd forgotten to push it, I guess. Published now as 10.1.