Skip to content

Commit 165ea60

Browse files
committed
lint(e2e): reject floating promises
1 parent 993ebd9 commit 165ea60

5 files changed

Lines changed: 54 additions & 28 deletions

File tree

‎apps/vscode-e2e/eslint.config.mjs‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
import { config } from "@roo-code/config-eslint/base"
22

33
/** @type {import("eslint").Linter.Config} */
4-
export default [...config]
4+
export default [
5+
...config,
6+
{
7+
files: ["src/**/*.ts"],
8+
languageOptions: {
9+
parserOptions: {
10+
project: true,
11+
tsconfigRootDir: import.meta.dirname,
12+
},
13+
},
14+
rules: {
15+
"@typescript-eslint/no-floating-promises": "error",
16+
},
17+
},
18+
]

‎apps/vscode-e2e/src/runTest.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,7 @@ async function main() {
231231
}
232232
}
233233

234-
main()
234+
main().catch((error) => {
235+
console.error("Failed to initialize or clean up tests", error)
236+
process.exitCode = 1
237+
})

‎apps/vscode-e2e/src/suite/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export async function run() {
3535
// for a button that the webview routes to "start new task" rather than "yes".
3636
api.on(RooCodeEventName.Message, ({ message }) => {
3737
if (message.type === "ask" && message.ask === "completion_result") {
38-
api.approveCurrentAsk()
38+
void api.approveCurrentAsk().catch((error) => {
39+
console.error("Failed to approve completion result", error)
40+
})
3941
}
4042
})
4143

‎apps/vscode-e2e/src/suite/utils.ts‎

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,41 @@ export const waitFor = (
99
condition: (() => Promise<boolean>) | (() => boolean),
1010
{ timeout = 30_000, interval = 250 }: WaitForOptions = {},
1111
) => {
12-
let timeoutId: NodeJS.Timeout | undefined = undefined
12+
return new Promise<void>((resolve, reject) => {
13+
let settled = false
14+
let intervalId: NodeJS.Timeout | undefined
15+
const timeoutId = setTimeout(() => {
16+
settled = true
17+
if (intervalId) clearTimeout(intervalId)
18+
reject(new Error(`Timeout after ${Math.floor(timeout / 1000)}s`))
19+
}, timeout)
1320

14-
return Promise.race([
15-
new Promise<void>((resolve) => {
16-
const check = async () => {
17-
const result = condition()
18-
const isSatisfied = result instanceof Promise ? await result : result
21+
const cleanup = () => {
22+
clearTimeout(timeoutId)
23+
if (intervalId) clearTimeout(intervalId)
24+
}
25+
const check = async () => {
26+
try {
27+
const isSatisfied = await condition()
28+
if (settled) return
1929

2030
if (isSatisfied) {
21-
if (timeoutId) {
22-
clearTimeout(timeoutId)
23-
timeoutId = undefined
24-
}
25-
31+
settled = true
32+
cleanup()
2633
resolve()
2734
} else {
28-
setTimeout(check, interval)
35+
intervalId = setTimeout(() => void check(), interval)
2936
}
37+
} catch (error) {
38+
if (settled) return
39+
settled = true
40+
cleanup()
41+
reject(error)
3042
}
43+
}
3144

32-
check()
33-
}),
34-
new Promise((_, reject) => {
35-
timeoutId = setTimeout(() => {
36-
reject(new Error(`Timeout after ${Math.floor(timeout / 1000)}s`))
37-
}, timeout)
38-
}),
39-
])
45+
void check()
46+
})
4047
}
4148

4249
type WaitUntilAbortedOptions = WaitForOptions & {

‎apps/vscode-e2e/src/theme-fixtures/fixtures.test.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const validFixture: WebviewThemeFixture = {
2020
},
2121
}
2222

23-
test("serializeThemeFixture sorts variables and emits stable metadata", () => {
23+
void test("serializeThemeFixture sorts variables and emits stable metadata", () => {
2424
const fixture: WebviewThemeFixture = {
2525
themeId: "Default Dark Modern",
2626
bodyClass: "vscode-dark",
@@ -45,7 +45,7 @@ test("serializeThemeFixture sorts variables and emits stable metadata", () => {
4545
)
4646
})
4747

48-
test("findDriftedFixtures reports missing and changed files in sorted order", () => {
48+
void test("findDriftedFixtures reports missing and changed files in sorted order", () => {
4949
const expected = new Map([
5050
["vscode-theme-light.css", "light"],
5151
["vscode-theme-dark.css", "dark"],
@@ -55,7 +55,7 @@ test("findDriftedFixtures reports missing and changed files in sorted order", ()
5555
assert.deepEqual(findDriftedFixtures(expected, actual), ["vscode-theme-dark.css", "vscode-theme-light.css"])
5656
})
5757

58-
test("createSerializedFixtures rejects incomplete captures", () => {
58+
void test("createSerializedFixtures rejects incomplete captures", () => {
5959
const fixture: WebviewThemeFixture = {
6060
...validFixture,
6161
variables: {
@@ -71,7 +71,7 @@ test("createSerializedFixtures rejects incomplete captures", () => {
7171
)
7272
})
7373

74-
test("createSerializedFixtures rejects an empty capture", () => {
74+
void test("createSerializedFixtures rejects an empty capture", () => {
7575
assert.throws(
7676
() =>
7777
createSerializedFixtures(new Map([["dark", { ...validFixture, variables: {} }]]), "1.100.0", [
@@ -81,7 +81,7 @@ test("createSerializedFixtures rejects an empty capture", () => {
8181
)
8282
})
8383

84-
test("createSerializedFixtures rejects the wrong theme identity", () => {
84+
void test("createSerializedFixtures rejects the wrong theme identity", () => {
8585
assert.throws(
8686
() =>
8787
createSerializedFixtures(

0 commit comments

Comments
 (0)