Skip to content

Commit

Permalink
chore: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
utsabc committed Dec 3, 2024
1 parent 15e8cb3 commit ba85d23
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion test/integrations/testTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export type ProcessorTestData = {
body: ProcessorTransformationResponse[];
};
};
mockFns?: (mockAdapter: MockAdapter) => {};
mockFns?: (mockAdapter: MockAdapter) => void;
};
export type RouterTestData = {
id: string;
Expand Down
10 changes: 7 additions & 3 deletions test/scripts/migrateTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,17 @@ async function writeTestFile(filePath: string, data: any): Promise<void> {
}
}

async function enhwriteTestFile(filePath: string, testCases: any[]): Promise<void> {
async function enhwriteTestFile(
filePath: string,
testCases: any[],
feature: string,
): Promise<void> {
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);
Expand Down Expand Up @@ -146,7 +150,7 @@ async function migrateTestFiles(): Promise<void> {
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) {
Expand Down
17 changes: 14 additions & 3 deletions test/scripts/migrationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set([]);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ba85d23

Please sign in to comment.