Skip to content

Commit

Permalink
chore: Adding functionName under Flag to Keploy (#83)
Browse files Browse the repository at this point in the history
* chore:adding functionName under Flag to keploy_Binary

Signed-off-by: Aditya-eddy <[email protected]>

* chore:seprating codelense for the function and testFile

Signed-off-by: Aditya-eddy <[email protected]>

* chore: version bump

Signed-off-by: shivamsouravjha <[email protected]>

* chore: version bump

Signed-off-by: shivamsouravjha <[email protected]>

---------

Signed-off-by: Aditya-eddy <[email protected]>
Signed-off-by: shivamsouravjha <[email protected]>
Signed-off-by: Shivam Sourav Jha <[email protected]>
Co-authored-by: shivamsouravjha <[email protected]>
Co-authored-by: Shivam Sourav Jha <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent f8d6654 commit 3002466
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ First Release for Vs Code Extension.
- Optimised keploy config screen

## [1.0.19]
- Enhanced UT generation
- Added support to create unit tests for individual function.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion scripts/utg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ testFilePath=$2
coverageReportPath=$3
command=$4
additional_prompts=$5

CodeLensefunctionName=$6
# Get the file extension
extension="${sourceFilePath##*.}"

Expand Down Expand Up @@ -77,6 +77,10 @@ if [ -n "$additional_prompts" ] && [ "$additional_prompts" != " " ]; then
keployCommand="$keployCommand --additional-prompt \"$additional_prompts\""
fi

if [ -n "$CodeLensefunctionName" ] && [ "$CodeLensefunctionName" != " " ]; then
keployCommand="$keployCommand --function-under-test \"$CodeLensefunctionName\""
fi

# Run the keploy command
# echo "Running: $keployCommand"
eval $keployCommand
2 changes: 1 addition & 1 deletion src/SidebarProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
console.log("additional prompts and uri: ", additional_prompts );
await vscode.commands.executeCommand('keploy.runAdditionalPrompts',additional_prompts);
}catch(error){
console.error("Error executing keploy.utg command:", error);
console.error("Error executing keploy.runAdditionalPrompts command:", error);
}
}
case "progressStatus":{
Expand Down
8 changes: 6 additions & 2 deletions src/Utg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { exec } from 'child_process';
import axios, { AxiosResponse } from 'axios';


async function Utg(context: vscode.ExtensionContext , additional_prompts?:string,testFilesPath?: vscode.Uri[] | undefined) {
async function Utg(context: vscode.ExtensionContext , CodeLensefunctionName?:string, additional_prompts?:string,testFilesPath?: vscode.Uri[] | undefined ) {

try {
return new Promise<void>(async (resolve, reject) => {
Expand Down Expand Up @@ -224,9 +224,13 @@ async function Utg(context: vscode.ExtensionContext , additional_prompts?:string
if(!additional_prompts){
additional_prompts = "";
}

if(!CodeLensefunctionName){
CodeLensefunctionName = ""

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 229 in src/Utg.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
}

// Adjust the terminal command to include the test file path
terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePaths[0]}" "${coverageReportPath}" "${command}" "${additional_prompts}";`);
terminal.sendText(`sh "${scriptPath}" "${sourceFilePath}" "${testFilePaths[0]}" "${coverageReportPath}" "${command}" "${additional_prompts}" "${CodeLensefunctionName}";`);

const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

Expand Down
73 changes: 59 additions & 14 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,14 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
console.log('🐰 Found function:', node.childForFieldName('name')?.text);
const functionName = node.childForFieldName('name')?.text || '';
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
Expand All @@ -172,9 +177,15 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
const line = document.positionAt(node.startIndex).line;
const range = new vscode.Range(line, 0, line, 0);
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
Expand All @@ -191,9 +202,15 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
const functionNameNode = node.childForFieldName('name');
const functionName = functionNameNode?.text || '';
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension, undefined,false]
}));
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
Expand All @@ -207,10 +224,17 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
const functionName = functionNameNode?.text || '';
//just adding it for the sake of testing will change it later.
codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
Expand All @@ -224,10 +248,17 @@ class KeployCodeLensProvider implements vscode.CodeLensProvider {
const functionName = functionNameNode?.text || '';

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit tests',
title: '🐰 Generate unit test for this function ',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension]
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,true]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Generate unit test for entire file',
command: 'keploy.utg',
arguments: [document.uri.fsPath, functionName, fileExtension,undefined,false]
}));

codeLenses.push(new vscode.CodeLens(range, {
title: '🐰 Additional Prompts',
command: 'keploy.showSidebar',
Expand Down Expand Up @@ -734,13 +765,13 @@ export function activate(context: vscode.ExtensionContext) {

let runAdditionalPrompts = vscode.commands.registerCommand('keploy.runAdditionalPrompts', async (additionalPrompts: string) => {
console.log("value inside the function: ", functionName, ExtentionName, additionalPrompts);
await vscode.commands.executeCommand('keploy.utg', FunctionFilePath, functionName, ExtentionName, additionalPrompts);
await vscode.commands.executeCommand('keploy.utg', FunctionFilePath, functionName, ExtentionName, additionalPrompts , false);
})

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 769 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon

context.subscriptions.push(runAdditionalPrompts);

// Register the command
let disposable = vscode.commands.registerCommand('keploy.utg', async (filePath: string, functionName: string, fileExtension: string, additional_prompts?: string) => {
let disposable = vscode.commands.registerCommand('keploy.utg', async (filePath: string, functionName: string, fileExtension: string, additional_prompts?: string , singleUtgTest?:boolean ) => {
// Check if the user is already signed in
const signedIn = await context.globalState.get('accessToken');
const signedInOthers = await context.globalState.get('SignedOthers');
Expand Down Expand Up @@ -811,11 +842,25 @@ export function activate(context: vscode.ExtensionContext) {
console.log("No test files found for any functions in the file.");
}
}

switch(singleUtgTest){
case true:
console.log("Executing for the Single Function");
break;
case false:
console.log("Executing for the Whole Test File");
functionName = "";
break;
case undefined:
console.log("Executing with singleUnitTest parameter as undefined")

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Missing semicolon

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Missing semicolon

Check warning on line 854 in src/extension.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Missing semicolon
default:
console.log("Going the default in generating the Utg");
break;

}
// Ensure that Utg is called with the correct parameters
console.log("additional prompts inside the keploy.utg ", additional_prompts);
vscode.window.showInformationMessage('Welcome to Keploy!');
await Utg(context, additional_prompts, testFilesPath);
await Utg(context,functionName, additional_prompts, testFilesPath);
}
}
});
Expand Down

0 comments on commit 3002466

Please sign in to comment.