Commit a734d92
fix(test): skip Astro frontmatter in script extraction; drain microtasks before clock advance
CI surfaced two harness bugs the local smoke-tests didn't catch:
1. `extract_script_body` and the discovery walker greedily matched the
first `<script>` substring in the source, which in setup.astro is
actually a frontmatter comment: `// below in the <script> block keyed
off the entry's id.` That made the "script body" start mid-frontmatter
and the extracted text wasn't valid JS — esbuild and JSDOM both
rejected it with "Unexpected identifier 'keyed'".
Fix: strip the `--- ... ---` Astro frontmatter block before searching
for `<script>` tags. Plain .py and .html sources have no frontmatter
and pass through unchanged.
2. `clock.advance(settleMs)` returned immediately when no timers were
yet scheduled, but the script under test often awaits a chain of
stubbed-fetch promises BEFORE hitting its first `setTimeout`. With
only one microtask drain between eval and advance, those promises
hadn't resolved yet, so no timers existed, advance was a no-op, and
the script stayed suspended — `restartAddon`'s POST to
/api/settings/restart never fired and the `alert(msg)` in the 4xx
branch never ran.
Fix: drain microtasks aggressively at the start of advance() so
pending promises get to schedule their timers, and drain again when
the timer queue temporarily empties (a promise resolution may queue
new timers).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 755e448 commit a734d92
2 files changed
Lines changed: 50 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
133 | 144 | | |
134 | 145 | | |
135 | 146 | | |
| |||
142 | 153 | | |
143 | 154 | | |
144 | 155 | | |
145 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
146 | 169 | | |
147 | 170 | | |
148 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
195 | 213 | | |
196 | 214 | | |
197 | 215 | | |
198 | 216 | | |
199 | 217 | | |
200 | 218 | | |
201 | 219 | | |
202 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
203 | 223 | | |
204 | | - | |
| 224 | + | |
| 225 | + | |
205 | 226 | | |
206 | 227 | | |
207 | 228 | | |
208 | 229 | | |
209 | | - | |
| 230 | + | |
210 | 231 | | |
211 | 232 | | |
212 | | - | |
| 233 | + | |
213 | 234 | | |
214 | 235 | | |
215 | 236 | | |
| |||
303 | 324 | | |
304 | 325 | | |
305 | 326 | | |
306 | | - | |
| 327 | + | |
307 | 328 | | |
308 | 329 | | |
309 | 330 | | |
| |||
0 commit comments