@ply-ct/ply
Version:
REST API Automated Testing
63 lines • 2.17 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlyRunner = void 0;
/**
* Runs ply tests per suite
*/
class PlyRunner {
constructor(options, suiteTests, plyValues, logger) {
this.options = options;
this.suiteTests = suiteTests;
this.plyValues = plyValues;
this.logger = logger;
/**
* Results are for sequential execution
*/
this.results = [];
/**
* Promises are for parallel execution
*/
this.promises = [];
}
async runSuiteTests(values, runOptions) {
if (this.suiteTests.size === 0)
return;
if (this.plyValues.isRows) {
let runNum = 0; // zero-based
// iterate rows
let rowCount = 0; // row count for this batch
for await (const rowVals of await this.plyValues.getRowStream()) {
if (rowCount >= this.options.batchRows && this.options.batchDelay > 0) {
rowCount = 0;
this.logger.info('--------------------');
await this.delay(this.options.batchDelay);
}
rowCount++;
for (const [suite, tests] of this.suiteTests) {
const promise = suite.run(tests, rowVals, runOptions, runNum);
if (this.options.parallel)
this.promises.push(promise);
else
this.results = [...this.results, ...(await promise)];
}
runNum++;
}
}
else {
for (const [suite, tests] of this.suiteTests) {
const promise = suite.run(tests, values, runOptions);
if (this.options.parallel)
this.promises.push(promise);
else
this.results = [...this.results, ...(await promise)];
}
}
}
async delay(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
}
exports.PlyRunner = PlyRunner;
//# sourceMappingURL=runner.js.map