Skip to content

Commit 261a75e

Browse files
authored
add missing sinon restore calls in search (microsoft#187489)
* add missing sinon restore calls * use `teardown(() => sinon.restore())` in search tests to restore stubs
1 parent 6aca75d commit 261a75e

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/vs/workbench/contrib/search/test/browser/searchModel.test.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ const lineOneRange = new OneLineRange(1, 0, 1);
6060
suite('SearchModel', () => {
6161

6262
let instantiationService: TestInstantiationService;
63-
let restoreStubs: sinon.SinonStub[];
6463

6564
const testSearchStats: IFileSearchStats = {
6665
fromCache: false,
@@ -80,7 +79,6 @@ suite('SearchModel', () => {
8079
];
8180

8281
setup(() => {
83-
restoreStubs = [];
8482
instantiationService = new TestInstantiationService();
8583
instantiationService.stub(ITelemetryService, NullTelemetryService);
8684
instantiationService.stub(ILabelService, { getUriBasenameLabel: (uri: URI) => '' });
@@ -92,11 +90,7 @@ suite('SearchModel', () => {
9290
instantiationService.stub(ILogService, new NullLogService());
9391
});
9492

95-
teardown(() => {
96-
restoreStubs.forEach(element => {
97-
element.restore();
98-
});
99-
});
93+
teardown(() => sinon.restore());
10094

10195
function searchServiceWithResults(results: IFileMatch[], complete: ISearchComplete | null = null): ISearchService {
10296
return <ISearchService>{
@@ -174,8 +168,7 @@ suite('SearchModel', () => {
174168
new TextSearchMatch('this is a test', new OneLineRange(1, 11, 15))),
175169
aRawMatch('/3', new TextSearchMatch('test', lineOneRange))];
176170
const searchService = instantiationService.stub(ISearchService, searchServiceWithResults(results));
177-
const addContext = sinon.stub(CellMatch.prototype, 'addContext');
178-
restoreStubs.push(addContext);
171+
sinon.stub(CellMatch.prototype, 'addContext');
179172

180173
const textSearch = sinon.spy(searchService, 'textSearch');
181174
const mdInputCell = {
@@ -264,8 +257,6 @@ suite('SearchModel', () => {
264257
scannedFiles: new ResourceSet([...localResults.keys()]),
265258
});
266259
});
267-
restoreStubs.push(notebookSearch);
268-
269260

270261
await model.search({ contentPattern: { pattern: 'test' }, type: QueryType.Text, folderQueries });
271262
const actual = model.searchResult.matches();
@@ -329,7 +320,7 @@ suite('SearchModel', () => {
329320

330321
test('Search Model: Search reports timed telemetry on search when progress is not called', () => {
331322
const target2 = sinon.spy();
332-
stub(nullEvent, 'stop', target2);
323+
sinon.stub(nullEvent, 'stop').callsFake(target2);
333324
const target1 = sinon.stub().returns(nullEvent);
334325
instantiationService.stub(ITelemetryService, 'publicLog', target1);
335326

@@ -348,7 +339,7 @@ suite('SearchModel', () => {
348339

349340
test('Search Model: Search reports timed telemetry on search when progress is called', () => {
350341
const target2 = sinon.spy();
351-
stub(nullEvent, 'stop', target2);
342+
sinon.stub(nullEvent, 'stop').callsFake(target2);
352343
const target1 = sinon.stub().returns(nullEvent);
353344
instantiationService.stub(ITelemetryService, 'publicLog', target1);
354345

@@ -372,7 +363,7 @@ suite('SearchModel', () => {
372363

373364
test('Search Model: Search reports timed telemetry on search when error is called', () => {
374365
const target2 = sinon.spy();
375-
stub(nullEvent, 'stop', target2);
366+
sinon.stub(nullEvent, 'stop').callsFake(target2);
376367
const target1 = sinon.stub().returns(nullEvent);
377368
instantiationService.stub(ITelemetryService, 'publicLog', target1);
378369

@@ -392,7 +383,7 @@ suite('SearchModel', () => {
392383

393384
test('Search Model: Search reports timed telemetry on search when error is cancelled error', () => {
394385
const target2 = sinon.spy();
395-
stub(nullEvent, 'stop', target2);
386+
sinon.stub(nullEvent, 'stop').callsFake(target2);
396387
const target1 = sinon.stub().returns(nullEvent);
397388
instantiationService.stub(ITelemetryService, 'publicLog', target1);
398389

@@ -491,12 +482,6 @@ suite('SearchModel', () => {
491482
return { resource: createFileUriFromPathFromRoot(resource), cellResults: cells };
492483
}
493484

494-
function stub(arg1: any, arg2: any, arg3: any): sinon.SinonStub {
495-
const stub = sinon.stub(arg1, arg2).callsFake(arg3);
496-
restoreStubs.push(stub);
497-
return stub;
498-
}
499-
500485
function stubModelService(instantiationService: TestInstantiationService): IModelService {
501486
instantiationService.stub(IThemeService, new TestThemeService());
502487
const config = new TestConfigurationService();

src/vs/workbench/contrib/search/test/browser/searchResult.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ suite('SearchResult', () => {
5151
instantiationService.stub(ILogService, new NullLogService());
5252
});
5353

54+
teardown(() => sinon.restore());
55+
5456
test('Line Match', function () {
5557
const fileMatch = aFileMatch('folder/file.txt', null!);
5658
const lineMatch = new Match(fileMatch, ['0 foo bar'], new OneLineRange(0, 2, 5), new OneLineRange(1, 0, 5));
@@ -228,7 +230,7 @@ suite('SearchResult', () => {
228230
const cell1 = { cellKind: CellKind.Code } as ICellViewModel;
229231
const cell2 = { cellKind: CellKind.Code } as ICellViewModel;
230232

231-
const addContext = sinon.stub(CellMatch.prototype, 'addContext');
233+
sinon.stub(CellMatch.prototype, 'addContext');
232234

233235
const addFileMatch = sinon.spy(FolderMatch.prototype, "addFileMatch");
234236
const fileMatch1 = aRawFileMatchWithCells('/1',
@@ -263,7 +265,6 @@ suite('SearchResult', () => {
263265
assert.deepStrictEqual(fileMatch1.cellResults[0].webviewResults, (addFileMatch.getCall(0).args[0][0] as IFileMatchWithCells).cellResults[0].webviewResults);
264266
assert.deepStrictEqual(fileMatch2.cellResults[0].contentResults, (addFileMatch.getCall(0).args[0][1] as IFileMatchWithCells).cellResults[0].contentResults);
265267
assert.deepStrictEqual(fileMatch2.cellResults[0].webviewResults, (addFileMatch.getCall(0).args[0][1] as IFileMatchWithCells).cellResults[0].webviewResults);
266-
addContext.restore();
267268
});
268269

269270
test('Dispose disposes matches', function () {

0 commit comments

Comments
 (0)