Commit 6c94972
refactor(config): for-of hook loops, swallow per-hook errors via applyHook
Three changes asked for on the previous hook refactor:
- Replace the for-i loops in Config.create and Config.runPendingHooks
with for-of. Both rely on Array iterator semantics — newly pushed
hooks (e.g. a hook that registers another hook) are still picked up
in the same pass because the iterator re-checks length on each step.
- Centralize hook execution in a single applyHook() helper that wraps
the call in try/finally. A broken hook now logs through
globalThis.codeceptjs.output (or stderr when the runner isn't up
yet) and is marked ran=true regardless, so a poison entry can't
block the rest of the pass or get retried by runPendingHooks.
Callers don't touch hook.ran themselves.
- Tighten the comment over the globalThis.codeceptjs block in
lib/codecept.js. The previous wording implied end-user projects
didn't need it — they do, because @codeceptjs/configure is
typically imported at the top of a user's codecept.conf.js and
registers hooks via the in-process registry before Config.load
even returns. setup.mjs handles the same contract for mocha tests
via .mocharc require.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent ee59b2d commit 6c94972
2 files changed
Lines changed: 37 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
39 | 56 | | |
40 | 57 | | |
41 | 58 | | |
| |||
50 | 67 | | |
51 | 68 | | |
52 | 69 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
59 | 75 | | |
60 | 76 | | |
61 | 77 | | |
| |||
132 | 148 | | |
133 | 149 | | |
134 | 150 | | |
135 | | - | |
| 151 | + | |
136 | 152 | | |
137 | | - | |
| 153 | + | |
| 154 | + | |
138 | 155 | | |
139 | | - | |
140 | | - | |
| 156 | + | |
| 157 | + | |
141 | 158 | | |
142 | 159 | | |
143 | 160 | | |
144 | 161 | | |
145 | 162 | | |
146 | 163 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
152 | 167 | | |
153 | 168 | | |
154 | 169 | | |
| |||
0 commit comments