feat(tests): add button to update fixtures directly from ui test report

[no changelog]
pull/2689/head
tychovrahe 2 years ago committed by TychoVrahe
parent a11be914cc
commit 550e2a7951

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import http.server
import json
import multiprocessing
import os
import posixpath
@ -13,6 +14,7 @@ import click
ROOT = Path(__file__).resolve().parent.parent
TEST_RESULT_PATH = ROOT / "tests" / "ui_tests" / "reporting" / "reports" / "test"
FIXTURES_PATH = ROOT / "tests" / "ui_tests" / "fixtures.json"
class NoCacheRequestHandler(http.server.SimpleHTTPRequestHandler):
@ -52,6 +54,28 @@ class NoCacheRequestHandler(http.server.SimpleHTTPRequestHandler):
path += "/"
return path
def do_POST(self) -> None:
if self.path == "/fixtures.json" and FIXTURES_PATH.exists():
length = int(self.headers.get("content-length"))
field_data = self.rfile.read(length)
data = json.loads(field_data)
test_name = data.get("test")
test_hash = data.get("hash")
if test_name is not None and test_hash is not None:
with open(FIXTURES_PATH, "r") as jsonFile:
fixtures = json.load(jsonFile)
fixtures[test_name] = test_hash
with open(FIXTURES_PATH, "w") as jsonFile:
json.dump(fixtures, jsonFile, indent=0)
jsonFile.write("\n")
self.send_response(200)
self.send_header("Content-Type", "text/plain")
self.end_headers()
def launch_http_server(port: int) -> None:
http.server.test(HandlerClass=NoCacheRequestHandler, bind="localhost", port=port) # type: ignore [test is defined]

@ -14,7 +14,7 @@ tr.bad a, tr.bad a:visited {
position: fixed;
top: 50px;
right: 5px;
width: 300px;
width: 500px;
padding: 1em;
}
@ -39,6 +39,15 @@ tr.bad a, tr.bad a:visited {
border-color: lightgreen;
}
#markbox #mark-update {
color: green;
border-color: darkgreen;
}
#markbox #mark-update:hover {
border-color: lightgreen;
}
#markbox #mark-bad {
color: darkred;
border-color: darkred;

@ -25,7 +25,25 @@ function itemKeyFromIndexEntry(entry) {
function markState(state) {
window.localStorage.setItem(itemKeyFromOneTest(), state)
if (state === 'update') {
let lastIndex = decodeURIComponent(window.location.href).split("/").reverse()[0].lastIndexOf(".")
let stem = decodeURIComponent(window.location.href).split("/").reverse()[0].slice(0, lastIndex)
fetch('http://localhost:8000/fixtures.json', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
"test": stem,
"hash": document.body.dataset.actualHash
})
}).then(() => {})
window.localStorage.setItem(itemKeyFromOneTest(), 'ok')
} else {
window.localStorage.setItem(itemKeyFromOneTest(), state)
}
if (window.nextHref) {
window.location.assign(window.nextHref)
} else {
@ -36,9 +54,9 @@ function markState(state) {
function resetState(whichState) {
function shouldReset(value) {
if (value == whichState) return true
if (whichState != "all") return false
return (value == "bad" || value == "ok")
if (value === whichState) return true
if (whichState !== "all") return false
return (value === "bad" || value === "ok")
}
let keysToReset = []
@ -64,13 +82,13 @@ function findNextForHref(doc, href) {
let a = tr.querySelector("a")
if (!a) continue
if (foundIt) return a.href
else if (a.href == href) foundIt = true
else if (a.href === href) foundIt = true
}
}
function openLink(ev) {
if (ev.button == 2) {
if (ev.button === 2) {
// let right click through
return true;
}
@ -78,8 +96,7 @@ function openLink(ev) {
// capture other clicks
ev.preventDefault()
let href = ev.target.href
let newWindow = window.open(href)
newWindow
window.open(href)
}
@ -124,7 +141,7 @@ function onLoadTestCase() {
function onLoad() {
if (window.location.protocol == "file") return
if (window.location.protocol === "file") return
for (let elem of document.getElementsByClassName("script-hidden")) {
elem.classList.remove("script-hidden")

@ -271,6 +271,7 @@ def failed(
p("Click a button to mark the test result as:")
with div(id="buttons"):
t.button("OK", id="mark-ok", onclick="markState('ok')")
t.button("OK & UPDATE", id="mark-update", onclick="markState('update')")
t.button("BAD", id="mark-bad", onclick="markState('bad')")
if download_failed:

Loading…
Cancel
Save