mirror of
https://github.com/Microsoft/vscode
synced 2024-09-20 19:18:03 +00:00
add missing sinon restore calls in search (#187489)
* add missing sinon restore calls * use `teardown(() => sinon.restore())` in search tests to restore stubs
This commit is contained in:
parent
6aca75d9d0
commit
261a75e3a4
|
@ -60,7 +60,6 @@ const lineOneRange = new OneLineRange(1, 0, 1);
|
|||
suite('SearchModel', () => {
|
||||
|
||||
let instantiationService: TestInstantiationService;
|
||||
let restoreStubs: sinon.SinonStub[];
|
||||
|
||||
const testSearchStats: IFileSearchStats = {
|
||||
fromCache: false,
|
||||
|
@ -80,7 +79,6 @@ suite('SearchModel', () => {
|
|||
];
|
||||
|
||||
setup(() => {
|
||||
restoreStubs = [];
|
||||
instantiationService = new TestInstantiationService();
|
||||
instantiationService.stub(ITelemetryService, NullTelemetryService);
|
||||
instantiationService.stub(ILabelService, { getUriBasenameLabel: (uri: URI) => '' });
|
||||
|
@ -92,11 +90,7 @@ suite('SearchModel', () => {
|
|||
instantiationService.stub(ILogService, new NullLogService());
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
restoreStubs.forEach(element => {
|
||||
element.restore();
|
||||
});
|
||||
});
|
||||
teardown(() => sinon.restore());
|
||||
|
||||
function searchServiceWithResults(results: IFileMatch[], complete: ISearchComplete | null = null): ISearchService {
|
||||
return <ISearchService>{
|
||||
|
@ -174,8 +168,7 @@ suite('SearchModel', () => {
|
|||
new TextSearchMatch('this is a test', new OneLineRange(1, 11, 15))),
|
||||
aRawMatch('/3', new TextSearchMatch('test', lineOneRange))];
|
||||
const searchService = instantiationService.stub(ISearchService, searchServiceWithResults(results));
|
||||
const addContext = sinon.stub(CellMatch.prototype, 'addContext');
|
||||
restoreStubs.push(addContext);
|
||||
sinon.stub(CellMatch.prototype, 'addContext');
|
||||
|
||||
const textSearch = sinon.spy(searchService, 'textSearch');
|
||||
const mdInputCell = {
|
||||
|
@ -264,8 +257,6 @@ suite('SearchModel', () => {
|
|||
scannedFiles: new ResourceSet([...localResults.keys()]),
|
||||
});
|
||||
});
|
||||
restoreStubs.push(notebookSearch);
|
||||
|
||||
|
||||
await model.search({ contentPattern: { pattern: 'test' }, type: QueryType.Text, folderQueries });
|
||||
const actual = model.searchResult.matches();
|
||||
|
@ -329,7 +320,7 @@ suite('SearchModel', () => {
|
|||
|
||||
test('Search Model: Search reports timed telemetry on search when progress is not called', () => {
|
||||
const target2 = sinon.spy();
|
||||
stub(nullEvent, 'stop', target2);
|
||||
sinon.stub(nullEvent, 'stop').callsFake(target2);
|
||||
const target1 = sinon.stub().returns(nullEvent);
|
||||
instantiationService.stub(ITelemetryService, 'publicLog', target1);
|
||||
|
||||
|
@ -348,7 +339,7 @@ suite('SearchModel', () => {
|
|||
|
||||
test('Search Model: Search reports timed telemetry on search when progress is called', () => {
|
||||
const target2 = sinon.spy();
|
||||
stub(nullEvent, 'stop', target2);
|
||||
sinon.stub(nullEvent, 'stop').callsFake(target2);
|
||||
const target1 = sinon.stub().returns(nullEvent);
|
||||
instantiationService.stub(ITelemetryService, 'publicLog', target1);
|
||||
|
||||
|
@ -372,7 +363,7 @@ suite('SearchModel', () => {
|
|||
|
||||
test('Search Model: Search reports timed telemetry on search when error is called', () => {
|
||||
const target2 = sinon.spy();
|
||||
stub(nullEvent, 'stop', target2);
|
||||
sinon.stub(nullEvent, 'stop').callsFake(target2);
|
||||
const target1 = sinon.stub().returns(nullEvent);
|
||||
instantiationService.stub(ITelemetryService, 'publicLog', target1);
|
||||
|
||||
|
@ -392,7 +383,7 @@ suite('SearchModel', () => {
|
|||
|
||||
test('Search Model: Search reports timed telemetry on search when error is cancelled error', () => {
|
||||
const target2 = sinon.spy();
|
||||
stub(nullEvent, 'stop', target2);
|
||||
sinon.stub(nullEvent, 'stop').callsFake(target2);
|
||||
const target1 = sinon.stub().returns(nullEvent);
|
||||
instantiationService.stub(ITelemetryService, 'publicLog', target1);
|
||||
|
||||
|
@ -491,12 +482,6 @@ suite('SearchModel', () => {
|
|||
return { resource: createFileUriFromPathFromRoot(resource), cellResults: cells };
|
||||
}
|
||||
|
||||
function stub(arg1: any, arg2: any, arg3: any): sinon.SinonStub {
|
||||
const stub = sinon.stub(arg1, arg2).callsFake(arg3);
|
||||
restoreStubs.push(stub);
|
||||
return stub;
|
||||
}
|
||||
|
||||
function stubModelService(instantiationService: TestInstantiationService): IModelService {
|
||||
instantiationService.stub(IThemeService, new TestThemeService());
|
||||
const config = new TestConfigurationService();
|
||||
|
|
|
@ -51,6 +51,8 @@ suite('SearchResult', () => {
|
|||
instantiationService.stub(ILogService, new NullLogService());
|
||||
});
|
||||
|
||||
teardown(() => sinon.restore());
|
||||
|
||||
test('Line Match', function () {
|
||||
const fileMatch = aFileMatch('folder/file.txt', null!);
|
||||
const lineMatch = new Match(fileMatch, ['0 foo bar'], new OneLineRange(0, 2, 5), new OneLineRange(1, 0, 5));
|
||||
|
@ -228,7 +230,7 @@ suite('SearchResult', () => {
|
|||
const cell1 = { cellKind: CellKind.Code } as ICellViewModel;
|
||||
const cell2 = { cellKind: CellKind.Code } as ICellViewModel;
|
||||
|
||||
const addContext = sinon.stub(CellMatch.prototype, 'addContext');
|
||||
sinon.stub(CellMatch.prototype, 'addContext');
|
||||
|
||||
const addFileMatch = sinon.spy(FolderMatch.prototype, "addFileMatch");
|
||||
const fileMatch1 = aRawFileMatchWithCells('/1',
|
||||
|
@ -263,7 +265,6 @@ suite('SearchResult', () => {
|
|||
assert.deepStrictEqual(fileMatch1.cellResults[0].webviewResults, (addFileMatch.getCall(0).args[0][0] as IFileMatchWithCells).cellResults[0].webviewResults);
|
||||
assert.deepStrictEqual(fileMatch2.cellResults[0].contentResults, (addFileMatch.getCall(0).args[0][1] as IFileMatchWithCells).cellResults[0].contentResults);
|
||||
assert.deepStrictEqual(fileMatch2.cellResults[0].webviewResults, (addFileMatch.getCall(0).args[0][1] as IFileMatchWithCells).cellResults[0].webviewResults);
|
||||
addContext.restore();
|
||||
});
|
||||
|
||||
test('Dispose disposes matches', function () {
|
||||
|
|
Loading…
Reference in a new issue