Skip to content

Proposal: support parsing raw data instead of files #112

Description

@bryanbcook

I'd like to propose an option to allow the test-results-parser to process raw data in addition to parsing data from one or more files. I was experimenting with a React single-page-website that could process the data from a textbox and show you the common result format, but that would require a backend that can write the files to disk, etc. If the parser didn't have file system dependencies, it could work in a web page as native JavaScript.

Here's how this could be realized:

Extend ParseOptions with content

Introduce a content property on ParseOptions so that the user can supply either a set of files or the content.

export interface ParseOptions {
  type: string;
  files: string[];
  content: string;
}

const parser = require('test-results-parser');
let data = // get data from user
const options = { type: 'xunit'; content: data };
let result = parser.parse( options );
// or
let result = parser.parseV2( options );

The index.js entry point would validate that either files[] or content was provided, and throw if both or none are supplied. It would also be responsible for calling parse or parseRaw on the target parser.

Extend the parser with a parseRaw

Encapsulate each parser into a class that derives from BaseParser and add an option to support processing the content using parseRaw

export interface BaseParser {
  parse( file: string ) : string
  parseRaw( content: string ) : string
}

Parser specific implementations

Each target parser currently exports a parse function that is called from the index.js. This would be extended to also export the parseRaw function. As some parsers have file-system specific activities (e.g. extracting embedded attachments and saving them to disk), the parser could be configured to bypass those capabilities when processing the raw data:

function parse( file, options ) {
   const parser = new CucumberParser();
   return parser.parse( file );
}
function parseRaw( content, options ) {
   const parser = new CucumberParser();
   parser.processAttachments = false;
   return parser.parseRaw( content );
}

module.exports = { parse, parseRaw };

class CucumberParser extends BaseParser
{
   parse( file ) {
      this.raw_result = this.#getCucumberResult(file);
      return this.#parse();
   }
   parseRaw( content ) {
      this.raw_result = JSON.parse(content);
      return this.#parse();
   }
   #parse() {
      this.#setTestResults();
      return this.result;
   }

   // ...
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions