From ba85d230f2fb684606f026b3e6dda875f8ce4672 Mon Sep 17 00:00:00 2001 From: Utsab Chowdhury Date: Tue, 3 Dec 2024 20:23:18 +0530 Subject: [PATCH] chore: update types --- test/integrations/testTypes.ts | 2 +- test/scripts/migrateTest.ts | 10 +++++++--- test/scripts/migrationUtils.ts | 17 ++++++++++++++--- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/test/integrations/testTypes.ts b/test/integrations/testTypes.ts index 81e51d8ce7..52cf73dfa1 100644 --- a/test/integrations/testTypes.ts +++ b/test/integrations/testTypes.ts @@ -102,7 +102,7 @@ export type ProcessorTestData = { body: ProcessorTransformationResponse[]; }; }; - mockFns?: (mockAdapter: MockAdapter) => {}; + mockFns?: (mockAdapter: MockAdapter) => void; }; export type RouterTestData = { id: string; diff --git a/test/scripts/migrateTest.ts b/test/scripts/migrateTest.ts index 1753e09ca3..9fc7ba8d96 100644 --- a/test/scripts/migrateTest.ts +++ b/test/scripts/migrateTest.ts @@ -75,13 +75,17 @@ async function writeTestFile(filePath: string, data: any): Promise { } } -async function enhwriteTestFile(filePath: string, testCases: any[]): Promise { +async function enhwriteTestFile( + filePath: string, + testCases: any[], + feature: string, +): Promise { try { // Extract common values const commonValues = extractCommonValues(testCases); // Generate optimized content - const content = generateOptimizedTestFile(testCases, commonValues); + const content = generateOptimizedTestFile(testCases, commonValues, feature); // Format with prettier const formattedContent = await formatWithPrettier(content, filePath); @@ -146,7 +150,7 @@ async function migrateTestFiles(): Promise { console.log(`Created backup at: ${backupPath}`); // Write migrated tests - await enhwriteTestFile(filePath, migratedTests); + await enhwriteTestFile(filePath, migratedTests, feature.toLowerCase()); console.log(`Successfully migrated ${migratedTests.length} test cases in ${filePath}`); migratedCount += migratedTests.length; } catch (error) { diff --git a/test/scripts/migrationUtils.ts b/test/scripts/migrationUtils.ts index ce6582429b..9e1e4a928f 100644 --- a/test/scripts/migrationUtils.ts +++ b/test/scripts/migrationUtils.ts @@ -357,7 +357,11 @@ export function extractCommonValues(testCases: any[]): CommonValues { return commonValues; } -export function generateOptimizedTestFile(testCases: any[], commonValues: CommonValues): string { +export function generateOptimizedTestFile( + testCases: any[], + commonValues: CommonValues, + feature: string, +): string { const variables: string[] = []; const imports: Set = new Set([]); @@ -434,18 +438,25 @@ const baseDestination: Destination = ${JSON.stringify(commonValues.destination, // return value; // }; + let type = ''; + if (feature === 'processor') { + type = 'ProcessorTestData'; + } else if (feature === 'router') { + type = 'RouterTestData'; + } + // Generate the final file content const content = `/** * Auto-migrated and optimized test cases * Generated on: ${new Date().toISOString()} */ - import { TestCaseData } from '../../../testTypes'; + import { ${type} } from '../../../testTypes'; import { ${Array.from(imports).join(', ')} } from '../../../../../src/types'; ${variables.join('\n')} - export const data: TestCaseData[] = ${JSON.stringify(processedTests, null, 2)}; + export const data: ${type}[] = ${JSON.stringify(processedTests, null, 2)}; `; // Replace our special markers with actual variable references