fix(runner): treat await as a regex-literal prefix in the wait guard

The scanner did not list await as a keyword that expects an
expression next, so it read the / in an await-prefixed regex
literal as division. A closing brace inside that regex then closed
template interpolation tracking early and hid a real vi.waitFor(
call from the guard. Add await to the keyword set and add a
regression test for this exact form.

Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Priya RamanandPaperclip committed 2026-09-04 01:55:58 +00:00
1 parent 627c244963
commit 11836700be
2 files changed
+13 -1

No files matched your search

@@ -194,6 +194,18 @@ test("rejects a vi.waitFor( that follows a regex literal with a quantifier's ope
]);
});
test("rejects a vi.waitFor( that follows an await-prefixed regex literal with a closing brace inside a template literal interpolation", () => {
const source = [
"async function example() {",
" const message = `status: ${await /}/.test(x) ? await vi.waitFor(() => expect(x).toBe(1)) : false}`;",
"}",
].join("\n");
assert.deepEqual(findBareRealProcessWaits(source), [
{ line: 2, pattern: "vi.waitFor(" },
]);
});
test("ignores a vi.waitFor( written inside a regex literal's own text, inside a template literal interpolation", () => {
const source = [
"async function example() {",
@@ -59,7 +59,7 @@ async function collectSourceFiles(target) {
// state; this heuristic only needs to hold for the code this guard scans.
const REGEX_PRECEDING_KEYWORDS = new Set([
"return", "typeof", "instanceof", "in", "of", "new", "delete", "void",
"yield", "case", "throw", "do", "else",
"yield", "case", "throw", "do", "else", "await",
]);
function isRegexLiteralStart(source, index) {