test(unit): wait for the async call instead of a single macrotask tick - #576
Merged
Merged
Conversation
SecretRequestFill "encrypts on submit and shows the success message" failed once in roughly twenty full-suite runs with AssertionError: expected "Mock" to be called at least once and passed 12 out of 12 times when the file was run on its own. That split is the tell: the failure needs a loaded suite, not a broken component. The helper these specs share is const flush = () => new Promise((resolve) => setTimeout(resolve, 0)) which yields exactly ONE macrotask tick. The submit path awaits an async encryption chain before it posts, and one tick is not guaranteed to drain it. Under parallel workers competing for CPU the assertion can run before the call lands, so the test reports a component that never posted when in fact it had not posted YET. Five sites share that shape: `await flush()` followed immediately by `expect(<mock>).toHaveBeenCalled()`. All five now wait for the call: await vi.waitFor(() => expect(post).toHaveBeenCalled()) This is strictly stronger than the fixed tick. It retries until the call arrives and still fails when it never does, which was verified rather than assumed: removing the submit trigger from the component makes the test fail (exit 1). The first attempt at that control was itself useless and is worth recording, because it looked like it worked. Renaming the event to `submit.prevent-DISABLED` still fires a submit, since Vue Test Utils reads everything after the dot as modifiers, so the sabotage was inert and the suite passed. A negative control that does not actually break the thing proves nothing. flush() is left in place for the many uses that only need a render tick. Also fixes 15 pre-existing import-order errors in the same five files. They are not gating: `npm run lint` covers `src` only. Verified: unit suite 678/678 on four full runs, eslint clean on the changed files, prettier clean.
Contributor
Quality Report — ConductionNL/keepiq @
|
| Check | PHP | Vue | Security | License | Tests |
|---|---|---|---|---|---|
| lint | ✅ | ||||
| phpcs | ✅ | ||||
| phpmd | ✅ | ||||
| psalm | ✅ | ||||
| phpstan | ✅ | ||||
| phpmetrics | ✅ | ||||
| eslint | ✅ | ||||
| stylelint | ✅ | ||||
| build | ✅ | ||||
| check-manifest | ✅ | ||||
| test-l10n | ✅ | ||||
| format | ✅ | ||||
| check-l10n-js | ✅ | ||||
| check-schema-l10n | ✅ | ||||
| composer | ✅ | ✅ 111/111 | |||
| npm | ✅ | ✅ 536/536 | |||
| app:check-code | ⏭️ | ||||
| info.xml | ✅ | ||||
| REUSE | ❌ | ||||
| PHPUnit | ✅ | ||||
| Newman | ✅ | ||||
| Playwright | ⏭️ deferred — runs on the promotion into beta/main, not on a pull request into development | ||||
| Hydra gates | ✅ |
Quality workflow — 2026-08-31 16:29 UTC
Download the full PDF report from the workflow artifacts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SecretRequestFill > encrypts on submit and shows the success messagefailed once in roughly twenty full-suite runs withexpected "Mock" to be called at least once, and passed 12 out of 12 when run on its own. That split is the tell: the failure needs a loaded suite, not a broken component.Cause
The helper these specs share yields exactly one macrotask tick:
The submit path awaits an async encryption chain before it posts, and one tick is not guaranteed to drain it. Under parallel workers competing for CPU the assertion can run before the call lands, so the test reports a component that never posted when it simply had not posted yet.
Five sites share the shape
await flush()followed immediately byexpect(<mock>).toHaveBeenCalled(). All five now wait for the call:This is strictly stronger than the fixed tick: it retries until the call arrives, and still fails when it never does.
The negative control, including the one that proved nothing
A retrying assertion that cannot fail would be worse than the flake, so I checked rather than assumed. Removing the submit trigger from the component makes the test fail (exit 1), so the assertion still has teeth.
The first attempt at that control is worth recording because it looked like it passed cleanly. Renaming the event to
submit.prevent-DISABLEDstill fires a submit, since Vue Test Utils reads everything after the dot as modifiers. The sabotage was inert and the suite went green, which I briefly read as evidence about the test rather than about my control.flush()stays for the many uses that only need a render tick.Also
15 pre-existing import-order errors in the same five files. They are not gating, since
npm run lintcoverssrconly.Verified