-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(956) human readable estimates (#956) #1176
Changes from 8 commits
2f5317b
e5a83e1
833b619
29978f9
106f2ce
d9fb111
3d84327
72ba43a
9732d2c
9caac48
0e3bbcc
c9f4ca8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { MatchedMutant, Reporter, MutantResult } from 'stryker-api/report'; | ||
import { MutantStatus } from 'stryker-api/report'; | ||
import Timer from '../utils/Timer'; | ||
|
||
abstract class ProgressKeeper implements Reporter { | ||
|
||
private timer: Timer; | ||
protected progress = { | ||
survived: 0, | ||
tested: 0, | ||
total: 0 | ||
total: 0, | ||
}; | ||
|
||
private mutantIdsWithoutCoverage: string[]; | ||
|
||
public onAllMutantsMatchedWithTests(matchedMutants: ReadonlyArray<MatchedMutant>): void { | ||
this.timer = new Timer(); | ||
this.mutantIdsWithoutCoverage = matchedMutants.filter(m => m.scopedTestIds.length === 0).map(m => m.id); | ||
this.progress.total = matchedMutants.length - this.mutantIdsWithoutCoverage.length; | ||
} | ||
|
@@ -24,5 +26,23 @@ abstract class ProgressKeeper implements Reporter { | |
this.progress.survived++; | ||
} | ||
} | ||
|
||
protected getEtc() { | ||
const timeLeft = Math.floor(this.timer.elapsedSeconds() / this.progress.tested * (this.progress.total - this.progress.tested)); | ||
|
||
if (isFinite(timeLeft)) { | ||
const hours = Math.floor(timeLeft / 3600); | ||
const minutes = Math.floor((timeLeft / 60) - (hours * 60)); | ||
const seconds = Math.floor(timeLeft - (hours * 3600) - (minutes * 60)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplification suggestion: const hours = Math.floor(totalSecondsLeft / 3600);
const minutes = Math.floor(totalSecondsLeft / 60 % 60);
const seconds = Math.floor(totalSecondsLeft % 60); |
||
|
||
let output = (hours > 0) ? `${hours}h, ` : ''; | ||
output += (minutes > 0) ? `${minutes}m, ` : ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When hours is greater than 0, but minutes is 0 it means that minutes is left out. Though technically correct, i think it would be clearer if minutes is displayed. For example: Suggestion: if (hours > 0) {
return `${hours}h, ${minutes}m, ${seconds}s`;
} else if(minutes > 0) {
return `${minutes}m, ${seconds}s`;
} else {
return `${seconds}s`
} |
||
output += (seconds > 0) ? `${seconds}s` : 0; | ||
|
||
return output; | ||
} else { | ||
return 'n/a'; | ||
} | ||
} | ||
} | ||
export default ProgressKeeper; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,25 @@ import * as progressBarModule from '../../../src/reporters/ProgressBar'; | |
import { matchedMutant, mutantResult, Mock, mock } from '../../helpers/producers'; | ||
import ProgressBar = require('progress'); | ||
|
||
const SECOND = 1000; | ||
const TEN_SECONDS = SECOND * 10; | ||
const HUNDRED_SECONDS = SECOND * 100; | ||
const TEN_THOUSAND_SECONDS = SECOND * 10000; | ||
|
||
describe('ProgressReporter', () => { | ||
|
||
let sut: ProgressReporter; | ||
let sandbox: sinon.SinonSandbox; | ||
let matchedMutants: MatchedMutant[]; | ||
let progressBar: Mock<ProgressBar>; | ||
const progressBarContent: string = | ||
`Mutation testing [:bar] :percent (ETC :etas) :tested/:total tested (:survived survived)`; | ||
const progressBarContent: string = `Mutation testing [:bar] :percent (ETC :etc) :tested/:total tested (:survived survived)`; | ||
|
||
beforeEach(() => { | ||
sut = new ProgressReporter(); | ||
sandbox = sinon.createSandbox(); | ||
sandbox.useFakeTimers(); | ||
|
||
sut = new ProgressReporter(); | ||
|
||
progressBar = mock(ProgressBar); | ||
sandbox.stub(progressBarModule, 'default').returns(progressBar); | ||
}); | ||
|
@@ -78,4 +85,34 @@ describe('ProgressReporter', () => { | |
expect(progressBar.tick).to.have.been.calledWithMatch(progressBarTickTokens); | ||
}); | ||
}); | ||
|
||
describe('ProgressBar estimate time', () => { | ||
beforeEach(() => { | ||
sut.onAllMutantsMatchedWithTests([matchedMutant(1), matchedMutant(1)]); | ||
}); | ||
|
||
it('should show to an estimate of "10s" in the progressBar after ten seconds and 1 mutants tested', () => { | ||
sandbox.clock.tick(TEN_SECONDS); | ||
|
||
sut.onMutantTested(mutantResult({ status: MutantStatus.Killed })); | ||
|
||
expect(progressBar.tick).to.have.been.calledWithMatch({ etc: '10s' }); | ||
}); | ||
|
||
it('should show to an estimate of "1m, 40s" in the progressBar after hundred seconds and 1 mutants tested', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See previous remark about leaving out minutes. |
||
sandbox.clock.tick(HUNDRED_SECONDS); | ||
|
||
sut.onMutantTested(mutantResult({ status: MutantStatus.Killed })); | ||
|
||
expect(progressBar.tick).to.have.been.calledWithMatch({ etc: '1m, 40s' }); | ||
}); | ||
|
||
it('should show to an estimate of "2h, 46m, 40s" in the progressBar after ten thousand seconds and 1 mutants tested', () => { | ||
sandbox.clock.tick(TEN_THOUSAND_SECONDS); | ||
|
||
sut.onMutantTested(mutantResult({ status: MutantStatus.Killed })); | ||
|
||
expect(progressBar.tick).to.have.been.calledWithMatch({ etc: '2h, 46m, 40s' }); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should now be renamed to "totalSecondsLeft", as everything here has to do with "time left"