@knapsack-pro/core
Version:
Knapsack Pro Core library splits tests across CI nodes and makes sure that tests will run in optimal time on each CI node. This library gives core features like communication with KnapsackPro.com API. This library is a dependency for other projects specif
26 lines (25 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FallbackTestDistributor = void 0;
const config_1 = require("./config");
class FallbackTestDistributor {
executedTestFilePaths;
testFilesPerCiNode;
constructor(allTestFiles, executedTestFiles, ciNodeTotal = config_1.KnapsackProEnvConfig.ciNodeTotal) {
this.executedTestFilePaths = executedTestFiles.map((testFile) => testFile.path);
this.testFilesPerCiNode = this.assignTestFilesPerCiNode(this.orderByTestPath(allTestFiles), ciNodeTotal);
}
testFilesForCiNode(ciNodeIndex = config_1.KnapsackProEnvConfig.ciNodeIndex) {
return this.testFilesPerCiNode[ciNodeIndex].filter((testFile) => !this.executedTestFilePaths.includes(testFile.path));
}
orderByTestPath(testFiles) {
const sortBy = (key) => (a, b) => a[key] > b[key] ? 1 : b[key] > a[key] ? -1 : 0;
return testFiles.sort(sortBy('path'));
}
assignTestFilesPerCiNode(allTestFiles, ciNodeTotal) {
const testFilesPerCiNode = Array.from({ length: ciNodeTotal }, () => []);
allTestFiles.forEach((testFile, index) => testFilesPerCiNode[index % ciNodeTotal].push(testFile));
return testFilesPerCiNode;
}
}
exports.FallbackTestDistributor = FallbackTestDistributor;