@amiceli/vitest-cucumber
Version:
vitest tools to use Gherkin feature in unit tests
27 lines (26 loc) • 802 B
JavaScript
import { FeatureFileNotFoundError } from '../errors/errors';
import { GherkinParser } from '../parser/parser';
export class BrowserFeatureFileReader {
path;
parser;
static fromPath(params) {
return new BrowserFeatureFileReader(params);
}
constructor(params) {
this.path = `/${params.featureFilePath}`;
this.parser = new GherkinParser(params.options);
}
async parseFile() {
try {
const response = await fetch(this.path);
const content = await response.text();
for (const line of content.split('\n')) {
this.parser.addLine(line);
}
return this.parser.finish();
}
catch (e) {
throw new FeatureFileNotFoundError(this.path);
}
}
}