diff --git a/x-pack/plugins/code/server/__tests__/lsp_indexer.ts b/x-pack/plugins/code/server/__tests__/lsp_indexer.ts index 9b62f0d8ee3c4..99e1c5510f170 100644 --- a/x-pack/plugins/code/server/__tests__/lsp_indexer.ts +++ b/x-pack/plugins/code/server/__tests__/lsp_indexer.ts @@ -57,7 +57,7 @@ function prepareProject(url: string, p: string) { }); } -const repoUri = 'github.com/Microsoft/TypeScript-Node-Starter'; +const repoUri = 'github.com/elastic/TypeScript-Node-Starter'; const serverOptions = createTestServerOption(); @@ -73,7 +73,7 @@ function setupEsClientSpy() { Promise.resolve({ _source: { [RepositoryGitStatusReservedField]: { - uri: 'github.com/Microsoft/TypeScript-Node-Starter', + uri: repoUri, progress: WorkerReservedProgress.COMPLETED, timestamp: new Date(), cloneProgress: { @@ -125,8 +125,7 @@ function setupLsServiceSendRequestSpy(): sinon.SinonSpy { ); } -// FAILING https://github.com/elastic/kibana/issues/36478 -describe.skip('lsp_indexer unit tests', function(this: any) { +describe('lsp_indexer unit tests', function(this: any) { this.timeout(20000); // @ts-ignore @@ -140,7 +139,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) { // @ts-ignore this.timeout(200000); return await prepareProject( - 'https://github.com/Microsoft/TypeScript-Node-Starter.git', + `https://${repoUri}.git`, path.join(serverOptions.repoPath, repoUri) ); }); @@ -172,10 +171,18 @@ describe.skip('lsp_indexer unit tests', function(this: any) { new RepositoryConfigController(esClient as EsClient) ); - lspservice.sendRequest = setupLsServiceSendRequestSpy(); + const lspSendRequestSpy = setupLsServiceSendRequestSpy(); + lspservice.sendRequest = lspSendRequestSpy; + const supportLanguageSpy = sinon.stub(); + + // Setup supported languages, so that unsupported source files won't be + // sent for lsp requests. + supportLanguageSpy.withArgs('javascript').returns(true); + supportLanguageSpy.withArgs('typescript').returns(true); + lspservice.supportLanguage = supportLanguageSpy; const indexer = new LspIndexer( - 'github.com/Microsoft/TypeScript-Node-Starter', + repoUri, 'master', lspservice, serverOptions, @@ -193,11 +200,13 @@ describe.skip('lsp_indexer unit tests', function(this: any) { assert.strictEqual(createSpy.callCount, 3); assert.strictEqual(putAliasSpy.callCount, 3); - // There are 22 files in the repo. 1 file + 1 symbol + 1 reference = 3 objects to - // index for each file. Total doc indexed should be 3 * 22 = 66, which can be - // fitted into a single batch index. + // There are 22 files which are written in supported languages in the repo. 1 file + 1 symbol + 1 reference = 3 objects to + // index for each file. Total doc indexed for these files should be 3 * 22 = 66. + // The rest 158 files will only be indexed for document. So the total number of index + // requests will be 66 + 158 = 224. assert.ok(bulkSpy.calledOnce); - assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 66 * 2); + assert.strictEqual(lspSendRequestSpy.callCount, 22); + assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 224 * 2); // @ts-ignore }).timeout(20000); @@ -223,7 +232,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) { lspservice.sendRequest = setupLsServiceSendRequestSpy(); const indexer = new LspIndexer( - 'github.com/Microsoft/TypeScript-Node-Starter', + repoUri, 'master', lspservice, serverOptions, @@ -267,11 +276,19 @@ describe.skip('lsp_indexer unit tests', function(this: any) { new RepositoryConfigController(esClient as EsClient) ); - lspservice.sendRequest = setupLsServiceSendRequestSpy(); + const lspSendRequestSpy = setupLsServiceSendRequestSpy(); + lspservice.sendRequest = lspSendRequestSpy; + const supportLanguageSpy = sinon.stub(); + + // Setup supported languages, so that unsupported source files won't be + // sent for lsp requests. + supportLanguageSpy.withArgs('javascript').returns(true); + supportLanguageSpy.withArgs('typescript').returns(true); + lspservice.supportLanguage = supportLanguageSpy; const indexer = new LspIndexer( - 'github.com/Microsoft/TypeScript-Node-Starter', - '46971a8', + repoUri, + '261557d', lspservice, serverOptions, esClient as EsClient, @@ -282,7 +299,7 @@ describe.skip('lsp_indexer unit tests', function(this: any) { await indexer.start(undefined, { repoUri: '', filePath: 'src/public/js/main.ts', - revision: '46971a8', + revision: '261557d', localRepoPath: '', }); @@ -295,12 +312,15 @@ describe.skip('lsp_indexer unit tests', function(this: any) { assert.strictEqual(createSpy.callCount, 0); assert.strictEqual(putAliasSpy.callCount, 0); - // There are 22 files in the repo, but only 11 files after the checkpoint. - // 1 file + 1 symbol + 1 reference = 3 objects to index for each file. - // Total doc indexed should be 3 * 11 = 33, which can be fitted into a - // single batch index. + // There are 22 files with supported language in the repo, but only 11 + // files after the checkpoint. 1 file + 1 symbol + 1 reference = 3 objects + // to index for each file. Total doc indexed for these files should be + // 3 * 11 = 33. Also there are 15 files without supported language. Only one + // document will be index for these files. So total index requests would be + // 33 + 15 = 48. assert.ok(bulkSpy.calledOnce); - assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 33 * 2); + assert.strictEqual(lspSendRequestSpy.callCount, 11); + assert.strictEqual(bulkSpy.getCall(0).args[0].body.length, 48 * 2); // @ts-ignore }).timeout(20000); });