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;
}
// ...
}
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
ParseOptionswithcontentIntroduce a
contentproperty onParseOptionsso that the user can supply either a set of files or the content.The
index.jsentry point would validate that eitherfiles[]orcontentwas provided, and throw if both or none are supplied. It would also be responsible for callingparseorparseRawon the target parser.Extend the parser with a
parseRawEncapsulate each parser into a class that derives from
BaseParserand add an option to support processing the content usingparseRawParser specific implementations
Each target parser currently exports a
parsefunction that is called from theindex.js. This would be extended to also export theparseRawfunction. 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: