From df43146b8c04292b657199b3f60dff7415bcd268 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Tue, 5 Aug 2025 16:54:24 -0500 Subject: [PATCH] Improve TypeScript type safety in Cypress tests (#7997) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address Copilot feedback by replacing `any` types with proper TypeScript types in Cypress test files. ## Changes **cypress/support/utils.ts:** - `win: any` → `win: Cypress.AUTWindow` - `$element: any` → `$element: JQuery` - `$body: any` → `$body: JQuery` **cypress/e2e/claude-explain.cy.ts:** - `req: any` → `req: Cypress.Interception` (3 instances) - `url: any` → `url: string` ## Benefits - Improves type safety and catches potential runtime errors at compile time - Follows TypeScript best practices - Addresses all Copilot suggestions for better code quality - No functional changes, purely type improvements All TypeScript checks pass and no functionality is affected. Co-authored-by: Claude --- cypress/e2e/claude-explain.cy.ts | 8 ++++---- cypress/support/utils.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cypress/e2e/claude-explain.cy.ts b/cypress/e2e/claude-explain.cy.ts index 5fe2f8493..4ce9cd7c1 100644 --- a/cypress/e2e/claude-explain.cy.ts +++ b/cypress/e2e/claude-explain.cy.ts @@ -397,7 +397,7 @@ describe('Claude Explain feature', () => { }).as('getOptions'); let explainCallCount = 0; - cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: any) => { + cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: Cypress.Interception) => { explainCallCount++; req.reply({ status: 'success', @@ -470,7 +470,7 @@ describe('Claude Explain feature', () => { mockClaudeExplainAPIWithOptions(); let callCount = 0; - cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: any) => { + cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: Cypress.Interception) => { callCount++; const isBypassCache = req.body.bypassCache === true; req.reply({ @@ -512,7 +512,7 @@ describe('Claude Explain feature', () => { mockClaudeExplainAPIWithOptions(); let explainCount = 0; - cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: any) => { + cy.intercept('POST', 'http://test.localhost/fake-api/explain', (req: Cypress.Interception) => { explainCount++; req.reply({ status: 'success', @@ -576,7 +576,7 @@ describe('Claude Explain feature', () => { cy.wait('@explainRequest'); // Get the current URL (which includes state) - cy.url().then((url: any) => { + cy.url().then((url: string) => { // Clear intercepts from previous test cy.state('routes', []); cy.state('aliases', {}); diff --git a/cypress/support/utils.ts b/cypress/support/utils.ts index 46d5710ff..10fe69921 100644 --- a/cypress/support/utils.ts +++ b/cypress/support/utils.ts @@ -17,7 +17,7 @@ export function assertNoConsoleOutput() { */ export function clearAllIntercepts() { // Clear any existing intercepts by visiting a clean page and resetting - cy.window().then((win: any) => { + cy.window().then((win: Cypress.AUTWindow) => { // Reset any cached state win.compilerExplorerOptions = {}; }); @@ -38,7 +38,7 @@ export function setMonacoEditorContent(content: string, editorIndex = 0) { // Trigger a paste event with our content cy.get('.monaco-editor textarea') .eq(editorIndex) - .then(($element: any) => { + .then(($element: JQuery) => { const el = $element[0]; // Create and dispatch a paste event with our data @@ -56,7 +56,7 @@ export function setMonacoEditorContent(content: string, editorIndex = 0) { }); // Wait for compilation to complete after content change (if compiler exists) - cy.get('body').then(($body: any) => { + cy.get('body').then(($body: JQuery) => { if ($body.find('.compiler-wrapper').length > 0) { cy.get('.compiler-wrapper').should('not.have.class', 'compiling'); }