44 */
55import assert from 'assert'
66import path from 'path'
7+ import sinon from 'sinon'
78import { getTestWorkspaceFolder } from '../integrationTestsUtilities'
89import { fs , getRandomString } from '../../shared'
910import { LspController } from '../../amazonq'
1011import { performanceTest } from '../../shared/performance/performance'
12+ import { FileSystem } from '../../shared/fs/fs'
13+ import { getFsCallsUpperBound } from './utilities'
14+
15+ interface SetupResult {
16+ testFile : string
17+ fsSpy : sinon . SinonSpiedInstance < FileSystem >
18+ }
1119
1220function performanceTestWrapper ( label : string , fileSize : number ) {
1321 return performanceTest (
@@ -37,14 +45,15 @@ function performanceTestWrapper(label: string, fileSize: number) {
3745 const fileContent = getRandomString ( fileSize )
3846 const testFile = path . join ( workspace , 'test-file' )
3947 await fs . writeFile ( testFile , fileContent )
40-
41- return testFile
48+ const fsSpy = sinon . spy ( fs )
49+ return { testFile, fsSpy }
4250 } ,
43- execute : async ( testFile : string ) => {
44- return await LspController . instance . getFileSha384 ( testFile )
51+ execute : async ( setup : SetupResult ) => {
52+ return await LspController . instance . getFileSha384 ( setup . testFile )
4553 } ,
46- verify : async ( _testFile : string , result : string ) => {
54+ verify : async ( setup : SetupResult , result : string ) => {
4755 assert . strictEqual ( result . length , 96 )
56+ assert . ok ( getFsCallsUpperBound ( setup . fsSpy ) <= 1 , 'makes a single call to fs' )
4857 } ,
4958 }
5059 }
@@ -53,6 +62,9 @@ function performanceTestWrapper(label: string, fileSize: number) {
5362
5463describe ( 'getFileSha384' , function ( ) {
5564 describe ( 'performance tests' , function ( ) {
65+ afterEach ( function ( ) {
66+ sinon . restore ( )
67+ } )
5668 performanceTestWrapper ( '1MB' , 1000 )
5769 performanceTestWrapper ( '2MB' , 2000 )
5870 performanceTestWrapper ( '4MB' , 4000 )
0 commit comments