Skip to content

Commit 3a11a85

Browse files
committed
add spy to file hash test
1 parent 74dc701 commit 3a11a85

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

packages/core/src/testInteg/perf/getFileSha384.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
*/
55
import assert from 'assert'
66
import path from 'path'
7+
import sinon from 'sinon'
78
import { getTestWorkspaceFolder } from '../integrationTestsUtilities'
89
import { fs, getRandomString } from '../../shared'
910
import { LspController } from '../../amazonq'
1011
import { 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

1220
function 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

5463
describe('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

Comments
 (0)