@@ -23,8 +23,7 @@ import path from 'path'
2323import { ScanAction , scanProgressMessage } from '../../../src/app/amazonqScan/models/constants'
2424import { CodeScanIssue } from 'aws-core-vscode/codewhisperer'
2525import { SecurityIssueProvider } from 'aws-core-vscode/codewhisperer'
26-
27- import { waitUntil } from 'aws-core-vscode/shared'
26+ import { fs , waitUntil , processUtils } from 'aws-core-vscode/shared'
2827
2928function getWorkspaceFolder ( ) : string {
3029 return vscode . workspace . workspaceFolders ! [ 0 ] . uri . fsPath
@@ -387,7 +386,7 @@ describe('Amazon Q Code Review', function () {
387386 }
388387
389388 // Revert the changes
390- await vscode . workspace . fs . writeFile ( uri , Buffer . from ( originalContent ) )
389+ await fs . writeFile ( uri , originalContent )
391390
392391 // Wait a moment for the file system to update
393392 await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
@@ -404,11 +403,12 @@ describe('Amazon Q Code Review', function () {
404403 const testFolder = path . join ( getWorkspaceFolder ( ) , 'QCAFolder' )
405404 const fileName = 'ProblematicCode.java'
406405 const filePath = path . join ( testFolder , fileName )
406+ let document : vscode . TextDocument
407407
408408 beforeEach ( async ( ) => {
409409 await validateInitialChatMessage ( )
410410
411- const document = await vscode . workspace . openTextDocument ( filePath )
411+ document = await vscode . workspace . openTextDocument ( filePath )
412412 await vscode . window . showTextDocument ( document )
413413
414414 const editor = vscode . window . activeTextEditor
@@ -418,6 +418,7 @@ describe('Amazon Q Code Review', function () {
418418 await editor . edit ( ( editBuilder ) => {
419419 editBuilder . insert ( position , '// amazonq-ignore-next-line\n' )
420420 } )
421+ await document . save ( )
421422 }
422423 } )
423424
@@ -449,6 +450,7 @@ describe('Amazon Q Code Review', function () {
449450 const lineRange = editor . document . lineAt ( 20 ) . rangeIncludingLineBreak
450451 editBuilder . delete ( lineRange )
451452 } )
453+ await document . save ( )
452454 }
453455 } )
454456 } )
@@ -527,19 +529,23 @@ describe('Amazon Q Code Review', function () {
527529 } )
528530
529531 it ( 'project scan returns at least 1 LLM findings' , async ( ) => {
530- const fileDir = getWorkspaceFolder ( )
531- const isWindows = process . platform === 'win32'
532- const { exec } = require ( 'child_process' )
533- const util = require ( 'util' )
534- const execPromise = util . promisify ( exec )
532+ const fileDir = path . join ( getWorkspaceFolder ( ) )
535533
536534 try {
537535 // Initialize git repository to make RLinker.java appear in git diff
538- await execPromise ( 'git init' , { cwd : fileDir } )
539- await execPromise ( 'git add QCAFolder/RLinker.java' , { cwd : fileDir } )
540- await execPromise ( 'git config user.name "Test"' , { cwd : fileDir } )
541- await execPromise ( 'git config user.email "[email protected] "' , { cwd :
fileDir } ) 542- await execPromise ( 'git commit -m "Initial commit"' , { cwd : fileDir } )
536+ await processUtils . ChildProcess . run ( 'git' , [ 'init' ] , { spawnOptions : { cwd : fileDir } } )
537+ await processUtils . ChildProcess . run ( 'git' , [ 'add' , 'QCAFolder/RLinker.java' ] , {
538+ spawnOptions : { cwd : fileDir } ,
539+ } )
540+ await processUtils . ChildProcess . run ( 'git' , [ 'config' , 'user.name' , 'Test' ] , {
541+ spawnOptions : { cwd : fileDir } ,
542+ } )
543+ await processUtils . ChildProcess . run ( 'git' , [ 'config' , 'user.email' , '[email protected] ' ] , { 544+ spawnOptions : { cwd : fileDir } ,
545+ } )
546+ await processUtils . ChildProcess . run ( 'git' , [ 'commit' , '-m' , 'Initial commit' ] , {
547+ spawnOptions : { cwd : fileDir } ,
548+ } )
543549
544550 document = await vscode . workspace . openTextDocument ( filePath )
545551 await vscode . window . showTextDocument ( document )
@@ -592,15 +598,8 @@ describe('Amazon Q Code Review', function () {
592598 }
593599 } finally {
594600 // Clean up git repository
595- try {
596- if ( isWindows ) {
597- await execPromise ( 'rmdir /s /q .git' , { cwd : fileDir } )
598- } else {
599- await execPromise ( 'rm -rf .git' , { cwd : fileDir } )
600- }
601- } catch ( err ) {
602- console . error ( 'Failed to clean up git repository:' , err )
603- }
601+ await fs . delete ( path . join ( fileDir , '.git' ) , { recursive : true } )
602+ console . log ( 'done runnign test' )
604603 }
605604 } )
606605 } )
0 commit comments