fix: Use the same duration formatting as for the tests (#613)
This commit is contained in:
parent
e6a3d5cc78
commit
3aa553fb6a
|
@ -78,9 +78,9 @@ const renderDerived = (tests, collectedItems, isFinished) => {
|
||||||
const accTime = tests.reduce((prev, { duration }) => prev + duration, 0)
|
const accTime = tests.reduce((prev, { duration }) => prev + duration, 0)
|
||||||
const formattedAccTime = formatDuration(accTime)
|
const formattedAccTime = formatDuration(accTime)
|
||||||
const testWord = numberOfTests > 1 ? 'tests' : 'test'
|
const testWord = numberOfTests > 1 ? 'tests' : 'test'
|
||||||
const durationText = formattedAccTime.hasOwnProperty('ms') ? formattedAccTime.ms : formattedAccTime.seconds
|
const durationText = formattedAccTime.hasOwnProperty('ms') ? formattedAccTime.ms : formattedAccTime.formatted
|
||||||
|
|
||||||
document.querySelector('.run-count').innerText = `${numberOfTests} ${testWord} ran in ${durationText}.`
|
document.querySelector('.run-count').innerText = `${numberOfTests} ${testWord} took ${durationText}.`
|
||||||
document.querySelector('.summary__reload__button').classList.add('hidden')
|
document.querySelector('.summary__reload__button').classList.add('hidden')
|
||||||
} else {
|
} else {
|
||||||
document.querySelector('.run-count').innerText = `${numberOfTests} / ${collectedItems} tests done`
|
document.querySelector('.run-count').innerText = `${numberOfTests} / ${collectedItems} tests done`
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const formatedNumber = (number) =>
|
const formattedNumber = (number) =>
|
||||||
number.toLocaleString('en-US', {
|
number.toLocaleString('en-US', {
|
||||||
minimumIntegerDigits: 2,
|
minimumIntegerDigits: 2,
|
||||||
useGrouping: false,
|
useGrouping: false,
|
||||||
|
@ -17,7 +17,7 @@ const formatDuration = ( totalSeconds ) => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
seconds: `${Math.round(totalSeconds)} seconds`,
|
seconds: `${Math.round(totalSeconds)} seconds`,
|
||||||
formatted: `${formatedNumber(hours)}:${formatedNumber(minutes)}:${formatedNumber(seconds)}`,
|
formatted: `${formattedNumber(hours)}:${formattedNumber(minutes)}:${formattedNumber(seconds)}`,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,6 @@ def assert_results(
|
||||||
result = get_text(page, f"span[class={outcome}]")
|
result = get_text(page, f"span[class={outcome}]")
|
||||||
assert_that(result).is_equal_to(f"{number} {OUTCOMES[outcome]}")
|
assert_that(result).is_equal_to(f"{number} {OUTCOMES[outcome]}")
|
||||||
|
|
||||||
# if total_tests is not None:
|
|
||||||
# number_of_tests = total_tests
|
|
||||||
# total = get_text(page, "p[class='run-count']")
|
|
||||||
# expr = r"%d %s ran in \d+.\d+ seconds."
|
|
||||||
# % (number_of_tests, "tests" if number_of_tests > 1 else "test")
|
|
||||||
# assert_that(total).matches(expr)
|
|
||||||
|
|
||||||
|
|
||||||
def get_element(page, selector):
|
def get_element(page, selector):
|
||||||
return page.select_one(selector)
|
return page.select_one(selector)
|
||||||
|
@ -150,12 +143,43 @@ class TestHTML:
|
||||||
)
|
)
|
||||||
page = run(pytester)
|
page = run(pytester)
|
||||||
duration = get_text(page, "#results-table td[class='col-duration']")
|
duration = get_text(page, "#results-table td[class='col-duration']")
|
||||||
|
total_duration = get_text(page, "p[class='run-count']")
|
||||||
if pause < 1:
|
if pause < 1:
|
||||||
assert_that(int(duration.replace("ms", ""))).is_between(
|
assert_that(int(duration.replace("ms", ""))).is_between(
|
||||||
expectation, expectation * 2
|
expectation, expectation * 2
|
||||||
)
|
)
|
||||||
|
assert_that(total_duration).matches(r"\d+\s+ms")
|
||||||
else:
|
else:
|
||||||
assert_that(duration).matches(expectation)
|
assert_that(duration).matches(expectation)
|
||||||
|
assert_that(total_duration).matches(r"\d{2}:\d{2}:\d{2}")
|
||||||
|
|
||||||
|
def test_total_number_of_tests_zero(self, pytester):
|
||||||
|
page = run(pytester)
|
||||||
|
assert_results(page)
|
||||||
|
|
||||||
|
total = get_text(page, "p[class='run-count']")
|
||||||
|
assert_that(total).matches(r"0 test(?!s)")
|
||||||
|
|
||||||
|
def test_total_number_of_tests_singular(self, pytester):
|
||||||
|
pytester.makepyfile("def test_pass(): pass")
|
||||||
|
page = run(pytester)
|
||||||
|
assert_results(page, passed=1)
|
||||||
|
|
||||||
|
total = get_text(page, "p[class='run-count']")
|
||||||
|
assert_that(total).matches(r"1 test(?!s)")
|
||||||
|
|
||||||
|
def test_total_number_of_tests_plural(self, pytester):
|
||||||
|
pytester.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_pass_one(): pass
|
||||||
|
def test_pass_two(): pass
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
page = run(pytester)
|
||||||
|
assert_results(page, passed=2)
|
||||||
|
|
||||||
|
total = get_text(page, "p[class='run-count']")
|
||||||
|
assert_that(total).matches(r"2 tests(?!\S)")
|
||||||
|
|
||||||
def test_pass(self, pytester):
|
def test_pass(self, pytester):
|
||||||
pytester.makepyfile("def test_pass(): pass")
|
pytester.makepyfile("def test_pass(): pass")
|
||||||
|
|
Loading…
Reference in New Issue