UNPKG

@zebrunner/javascript-agent-mocha

Version:
96 lines (73 loc) 2.38 kB
class Storage { #runId; #testsMap; #artifactsFinishPromises; constructor() { this.#runId = null; this.#testsMap = new Map(); this.#artifactsFinishPromises = []; } get runId() { return this.#runId; } set runId(value) { this.#runId = value; } setTestStartPromise(uniqueId, startPromise) { this.#testsMap.set(uniqueId, { startPromise, zbrId: null, finishPromise: null, updatePromise: null, revertPromise: null, testCases: [], }); } getTestByUniqueId(uniqueId) { return this.#testsMap.get(uniqueId); } async getTestId(uniqueId) { if (!this.#testsMap.has(uniqueId) || this.getTestByUniqueId(uniqueId).revertPromise) { return; } if (this.getTestByUniqueId(uniqueId).zbrId) { return this.getTestByUniqueId(uniqueId).zbrId; } const { data } = await this.getTestByUniqueId(uniqueId).startPromise; this.getTestByUniqueId(uniqueId).zbrId = data.id; return data.id; } setTestFinishPromise(uniqueId, finishPromise) { this.getTestByUniqueId(uniqueId).finishPromise = finishPromise; } setTestUpdatePromise(uniqueId, updatePromise) { this.getTestByUniqueId(uniqueId).updatePromise = updatePromise; } setTestRevertPromise(uniqueId, revertPromise) { this.getTestByUniqueId(uniqueId).revertPromise = revertPromise; } getAllTestsStartPromises() { return Array.from(this.#testsMap.values()).map((i) => i.startPromise); } getAllTestsFinishPromises() { return Array.from(this.#testsMap.values()).map((i) => i.finishPromise); } get artifactsFinishPromises() { return this.#artifactsFinishPromises; } addArtifactFinishPromise(finishPromise) { this.#artifactsFinishPromises.push(finishPromise); } getTestTestCases(uniqueId) { return this.getTestByUniqueId(uniqueId).testCases; } addTestTestCase(uniqueId, testCase) { // filter test case with the same tcm type and id if it is already present in the array and add its updated version this.getTestByUniqueId(uniqueId).testCases = this.getTestByUniqueId(uniqueId).testCases.filter( (existingTestCase) => existingTestCase.tcmType !== testCase.tcmType || existingTestCase.testCaseId !== testCase.testCaseId, ); this.getTestByUniqueId(uniqueId).testCases.push(testCase); } } module.exports = Storage;