Skip to content

Conversation

Benjin
Copy link
Contributor

@Benjin Benjin commented Oct 3, 2025

First batch of TypeMoq -> Sinon test conversions, using AI with a good bit of coaching.

I've rolled most of the prompt/rules I've been using into test/unit/AGENTS.md.

Code Changes Checklist

  • New or updated unit tests added
  • All existing tests pass (npm run test)
  • Code follows contributing guidelines
  • Telemetry/logging updated if relevant
  • No regressions or UX breakage

Reviewers: Please read our reviewer guidelines

Copy link

github-actions bot commented Oct 3, 2025

PR Changes

Category Target Branch PR Branch Difference
Code Coverage 56.20% 56.27% ⚪ 0.00%
VSIX Size 4843 KB 4843 KB ⚪ 0 KB ( 0% )
Webview Bundle Size 3996 KB 3992 KB ⚪ -4 KB ( 0% )

* Avoid unnecessary casts, like `myVar as unknown as MyType` when myVar is already a sinon-stubbed instance of MyType.
* Maintain existing formatting conventions, line endings, and text encoding.
* Nest test suits as necessary to group tests in a logical manner.
- Do not edit application/source files unless the refactor demands it. Confirm before editing files outside of /test/unit, and justify why you need to make those changes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all .md formatting is a side-effect of the new prettier rules. #20275 addresses those separately, and will be pulled into this PR once merged.

searchService = new DatabaseObjectSearchService(client.object);
sandbox = sinon.createSandbox();
client = sandbox.createStubInstance(SqlToolsServiceClient);
searchService = new DatabaseObjectSearchService(client as unknown as SqlToolsServiceClient);
Copy link
Contributor

@lewis-sanchez lewis-sanchez Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the kind of casting you were trying to avoid or is this fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly the kind I was hoping to avoid with the prompts. Not all of them can be eliminated (without some type-system sorcery), but thanks for calling out the ones that have snuck through so I can double-check them!

appendLine: stubber.stub(),
clear: stubber.stub(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
show: stubber.stub() as any,
Copy link
Contributor

@lewis-sanchez lewis-sanchez Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you need to cast this to any, but not for the others?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get rid of this any because show() has several overloads that are confusing sinon's extraction of the valid types through the type system. If OutputChannel was a class, I could just stub that directly, but that isn't an option for interfaces.

return {
extensionUri: vscode.Uri.parse("file://test"),
extensionPath: "path",
} as unknown as vscode.ExtensionContext;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you need to cast to unknown before casting to a specific type?

});

suite("readProfileFromArgs", () => {
test("Should include connection properties that aren't sourced from SQL Tools Service", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these removed tests moved somewhere else or do we not want them anymore?

expect(openConnectionDialogStub).to.not.have.been.called;
});

test("Should ignore partially-matching profile when additional specifiers do not match", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we intentionally remove this test or something Copilot did while making changes?

runnerMock.setHasCompleted();
});

runner = runnerMock as unknown as QueryRunner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as before about casting to unknown as an intermediary cast. Just commenting in case this needs to change.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.42%. Comparing base (65d56c2) to head (ed7a4c0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #20274      +/-   ##
==========================================
+ Coverage   54.34%   54.42%   +0.07%     
==========================================
  Files         196      196              
  Lines       17526    17526              
  Branches     1165     1163       -2     
==========================================
+ Hits         9525     9538      +13     
+ Misses       8001     7988      -13     

see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants