HS E40: generator removes 7 E40 tests from skip-list; window.addEventListener handler (+1)

This commit is contained in:
2026-04-25 18:55:40 +00:00
parent ea1bdab82c
commit 8e4bdb7216
2 changed files with 79 additions and 19 deletions

View File

@@ -7168,7 +7168,14 @@
;; ── fetch (23 tests) ── ;; ── fetch (23 tests) ──
(defsuite "hs-upstream-fetch" (defsuite "hs-upstream-fetch"
(deftest "Response can be converted to JSON via as JSON" (deftest "Response can be converted to JSON via as JSON"
(error "SKIP (skip-list): Response can be converted to JSON via as JSON")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test as Response then put (it as JSON).name into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "Joe")
))
(deftest "allows the event handler to change the fetch parameters" (deftest "allows the event handler to change the fetch parameters"
(hs-cleanup!) (hs-cleanup!)
(let ((_el-div (dom-create-element "div"))) (let ((_el-div (dom-create-element "div")))
@@ -7179,9 +7186,23 @@
(assert= (dom-text-content _el-div) "yay") (assert= (dom-text-content _el-div) "yay")
)) ))
(deftest "as response does not throw on 404" (deftest "as response does not throw on 404"
(error "SKIP (skip-list): as response does not throw on 404")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test as response then put it.status into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "404")
))
(deftest "can catch an error that occurs when using fetch" (deftest "can catch an error that occurs when using fetch"
(error "SKIP (skip-list): can catch an error that occurs when using fetch")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test catch e log e put \"yay\" into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "yay")
))
(deftest "can do a simple fetch" (deftest "can do a simple fetch"
(hs-cleanup!) (hs-cleanup!)
(let ((_el-div (dom-create-element "div"))) (let ((_el-div (dom-create-element "div")))
@@ -7302,9 +7323,23 @@
(assert= (dom-text-content _el-div) "yay") (assert= (dom-text-content _el-div) "yay")
)) ))
(deftest "do not throw passes through 404 response" (deftest "do not throw passes through 404 response"
(error "SKIP (skip-list): do not throw passes through 404 response")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test do not throw then put it into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "the body")
))
(deftest "don't throw passes through 404 response" (deftest "don't throw passes through 404 response"
(error "SKIP (skip-list): don't throw passes through 404 response")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test don't throw then put it into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "the body")
))
(deftest "submits the fetch parameters to the event handler" (deftest "submits the fetch parameters to the event handler"
(hs-cleanup!) (hs-cleanup!)
(host-set! (host-global "window") "headerCheckPassed" false) (host-set! (host-global "window") "headerCheckPassed" false)
@@ -7316,9 +7351,26 @@
(assert= (dom-text-content _el-div) "yay") (assert= (dom-text-content _el-div) "yay")
)) ))
(deftest "throws on non-2xx response by default" (deftest "throws on non-2xx response by default"
(error "SKIP (skip-list): throws on non-2xx response by default")) (hs-cleanup!)
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch /test catch e put \"caught\" into me")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(dom-dispatch _el-div "click" nil)
(assert= (dom-text-content _el-div) "caught")
))
(deftest "triggers an event just before fetching" (deftest "triggers an event just before fetching"
(error "SKIP (skip-list): triggers an event just before fetching")) (hs-cleanup!)
(host-call (host-global "window") "addEventListener" "hyperscript:beforeFetch" (fn (_event) (dom-set-attr (host-get _event "target") "class" "foo-set")))
(let ((_el-div (dom-create-element "div")))
(dom-set-attr _el-div "_" "on click fetch \"/test\" then put it into my.innerHTML end")
(dom-append (dom-body) _el-div)
(hs-activate! _el-div)
(assert (not (dom-has-class? _el-div "foo-set")))
(dom-dispatch _el-div "click" nil)
(assert (dom-has-class? _el-div "foo-set"))
(assert= (dom-text-content _el-div) "yay")
))
) )
;; ── focus (3 tests) ── ;; ── focus (3 tests) ──

View File

@@ -125,19 +125,9 @@ SKIP_TEST_NAMES = {
"can ignore when target doesn't exist", "can ignore when target doesn't exist",
"can ignore when target doesn\\'t exist", "can ignore when target doesn\\'t exist",
"can handle an or after a from clause", "can handle an or after a from clause",
# upstream 'fetch' category — depend on per-test sinon stubs for 404 / thrown errors, # upstream 'fetch' category — real DocumentFragment semantics (`its childElementCount`
# or on real DocumentFragment semantics (`its childElementCount` after `as html`). # after `as html`) not exercisable with our DOM mock.
# Our generic test-runner mock returns a fixed 200 response, so these cases
# (non-2xx handling, error path, before-fetch event, real DOM fragment) can't be
# exercised here.
"can do a simple fetch w/ html", "can do a simple fetch w/ html",
"triggers an event just before fetching",
"can catch an error that occurs when using fetch",
"throws on non-2xx response by default",
"do not throw passes through 404 response",
"don't throw passes through 404 response",
"as response does not throw on 404",
"Response can be converted to JSON via as JSON",
} }
@@ -963,6 +953,24 @@ def parse_dev_body(body, elements, var_names):
else: else:
pre_setups.append(('__hs_config__', op_expr)) pre_setups.append(('__hs_config__', op_expr))
continue continue
# window.addEventListener(EVT, (param) => { param.target.PROP = 'VAL'; })
wa = re.search(
r"window\.addEventListener\(\s*(['\"])([^'\"]+)\1\s*,\s*"
r"\((\w+)\)\s*=>\s*\{\s*\3\.target\.(\w+)\s*=\s*['\"]([^'\"]+)['\"]\s*;?\s*\}",
m.group(1),
)
if wa:
ev_name = wa.group(2)
prop = wa.group(4)
val = wa.group(5)
attr = 'class' if prop == 'className' else prop
sx = (f'(host-call (host-global "window") "addEventListener" "{ev_name}" '
f'(fn (_event) (dom-set-attr (host-get _event "target") "{attr}" "{val}")))')
if seen_html:
ops.append(sx)
else:
pre_setups.append(('__hs_config__', sx))
continue
# fall through # fall through
# evaluate(() => _hyperscript.config.X = ...) single-line variant. # evaluate(() => _hyperscript.config.X = ...) single-line variant.