Repository navigation
[AI Improvement] [Task] Await chai-as-promised assertions in 6 spec files that never run today (lint: no-floating-promises, spec slice) - #11469
Conversation
…in spec files (b/582885987)
There was a problem hiding this comment.
Code Review
This pull request refactors several test files to properly handle asynchronous operations, converting test cases to async, awaiting expectations, and handling floating promises. The review feedback suggests adding defensive checks in fakeRemoveRemote.spec.ts to safely handle potentially undefined paths, and removing a redundant .to in the assertion chain within throttler.spec.ts.
| async deleteSubPath(path: string, subPaths: string[]): Promise<boolean> { | ||
| const d = this._dataAtpath(path); | ||
| let size = 0; | ||
| for (const p of subPaths) { | ||
| size += this._size(d[p]); | ||
| } |
There was a problem hiding this comment.
If d is null/undefined, or if a subpath does not exist in d (making d[p] undefined), accessing properties or calling _size will throw a TypeError. Adding defensive checks ensures the fake database helper is robust against non-existent paths.
async deleteSubPath(path: string, subPaths: string[]): Promise<boolean> {
const d = this._dataAtpath(path);
if (!d) {
return true;
}
let size = 0;
for (const p of subPaths) {
if (d[p] !== undefined) {
size += this._size(d[p]);
}
}References
- Use strict null checks and handle undefined/null explicitly. (link)
| await expect(q.run(2)).to.eventually.to.equal("result: 2"); | ||
| await expect(q.run(3)).to.eventually.to.equal("result: 3"); |
There was a problem hiding this comment.
The assertion chain contains a redundant .to after .eventually. It should be simplified to .to.eventually.equal for better readability and consistency with other assertions in the codebase.
| await expect(q.run(2)).to.eventually.to.equal("result: 2"); | |
| await expect(q.run(3)).to.eventually.to.equal("result: 3"); | |
| await expect(q.run(2)).to.eventually.equal("result: 2"); | |
| await expect(q.run(3)).to.eventually.equal("result: 3"); |
Description
Resolves Buganizer b/582885987 (parent goal b/565072516).
Fixes all 13
@typescript-eslint/no-floating-promiseswarnings across 6 spec files so that async chai-as-promised assertions and helper calls are properly awaited or handled:src/deploy/functions/validate.spec.ts: Converted 5 synchronousitcallbacks callingexpect(validate.secretsAreValid(...)).to.(not.)be.rejected(With)toasyncand awaited each assertion.src/deploy/extensions/planner.spec.ts: Converted the parameterizeditcallback inresolveSemvertoasyncand awaited bothexpect(planner.resolveVersion(...)).to.eventually...branches.src/throttler/throttler.spec.ts: Convertedit("should return the result of task")toasyncand awaited bothexpect(q.run(...)).to.eventually.to.equal(...)assertions.src/deploy/functions/remoteSource.spec.ts: Attached.catch(reject)toarchive.finalize()insidecreateZipBuffer.src/emulator/workQueue.spec.ts: Markedqueue.start()calls inbeforeEachhooks withvoidand explanatory comments sincestart()loops untilafterEachcallsstop().src/database/fakeRemoveRemote.spec.ts: MadeFakeRemoveRemote.deleteSubPathasync, awaitedthis.deletePath(...)in the loop, and returned boolean literals directly.Scenarios Tested
npx eslint --config .eslintrc.js --rule '@typescript-eslint/no-floating-promises: error'on all 6 modified spec files (0 errors).npx prettier --checkon all 6 modified spec files.npm run test:compile(0 errors).npm run build(0 errors).npm run lint:quiet(0 errors).npx mocha src/deploy/functions/validate.spec.ts src/deploy/extensions/planner.spec.ts src/throttler/throttler.spec.ts src/deploy/functions/remoteSource.spec.ts src/emulator/workQueue.spec.ts src/database/remove.spec.ts(184 passing, 3 pending).npm run mochasuite (5934 passing, 11 pending; only failure was unrelated local port 52672EADDRINUSEinsrc/apiv2.spec.tsproxy hook).Sample Commands
N/A