UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

109 lines (76 loc) 3 kB
/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Class('Siesta.Launcher.Dispatcher.Element', { does : [ Siesta.Util.Role.HasUniqueGeneratedId ], has : { descId : null, inProgress : false, processed : false, processedCount : 0, maxProcessedCount : 2, result : null, belongsTo : { required : true }, resultPrinted : false }, methods : { startProgress : function () { if (this.processed) throw new Error("Element already processed" + this.descId) if (this.inProgress) throw new Error("Element already in progress" + this.descId) this.inProgress = true }, canRunAgain : function (withThisTime) { return this.processedCount + (withThisTime ? 1 : 0) < this.maxProcessedCount }, // thereWasNoError means the element was not even attempted to launch, for example, it is at the end of the // tests list, and chunk has been terminated in the middle, this does not count as an attempt to run the // element reset : function (thereWasNoError) { if (!this.inProgress) throw new Error("Element is not in progress" + this.descId) if (this.processed) throw new Error("Element already processed" + this.descId) if (thereWasNoError) { this.inProgress = false } else { if (!this.canRunAgain(true)) { this.endProgress({ url : this.descId, ERROR : "Failed to run the test: " + this.descId }) return true } else { this.processedCount++ this.inProgress = false } } }, setProcessed : function (value) { if (this.processed != value) { this.processed = value value ? this.belongsTo.done++ : this.belongsTo.done-- } }, endProgress : function (result) { if (this.processed) throw new Error("Element already processed" + this.descId) if (!this.inProgress) throw new Error("Element is not in progress: " + this.descId) this.processedCount++ this.inProgress = false this.result = result this.setProcessed(true) }, asJSON : function () { return { automationElementId : this.id, descId : this.descId } }, canPrintResultImmediately : function () { var result = this.result return Boolean(result.ERROR || result.passed || result.isTodo) } } })