fix: Use the same duration formatting as for the tests (#613)

This commit is contained in:
Jim Brännlund 2023-04-02 02:04:56 +02:00 committed by GitHub
parent e6a3d5cc78
commit 3aa553fb6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 11 deletions

View File

@ -78,9 +78,9 @@ const renderDerived = (tests, collectedItems, isFinished) => {
const accTime = tests.reduce((prev, { duration }) => prev + duration, 0)
const formattedAccTime = formatDuration(accTime)
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')
} else {
document.querySelector('.run-count').innerText = `${numberOfTests} / ${collectedItems} tests done`

View File

@ -1,4 +1,4 @@
const formatedNumber = (number) =>
const formattedNumber = (number) =>
number.toLocaleString('en-US', {
minimumIntegerDigits: 2,
useGrouping: false,
@ -17,7 +17,7 @@ const formatDuration = ( totalSeconds ) => {
return {
seconds: `${Math.round(totalSeconds)} seconds`,
formatted: `${formatedNumber(hours)}:${formatedNumber(minutes)}:${formatedNumber(seconds)}`,
formatted: `${formattedNumber(hours)}:${formattedNumber(minutes)}:${formattedNumber(seconds)}`,
}
}

View File

@ -83,13 +83,6 @@ def assert_results(
result = get_text(page, f"span[class={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):
return page.select_one(selector)
@ -150,12 +143,43 @@ class TestHTML:
)
page = run(pytester)
duration = get_text(page, "#results-table td[class='col-duration']")
total_duration = get_text(page, "p[class='run-count']")
if pause < 1:
assert_that(int(duration.replace("ms", ""))).is_between(
expectation, expectation * 2
)
assert_that(total_duration).matches(r"\d+\s+ms")
else:
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):
pytester.makepyfile("def test_pass(): pass")