Skip to content

Commit 329cb5d

Browse files
authored
fix(test): flaky snippet manager tests (#954)
1 parent 103414d commit 329cb5d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/snippet-manager/src/snippet-manager.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ describe('SnippetManager', () => {
386386
});
387387

388388
it('will fail when the index URI is inaccessible', async() => {
389+
await snippetManager.inflightFetchIndexPromise;
389390
try {
390391
indexURL = `${baseURL}/404`;
391392
await snippetManager.runSnippetCommand(['refresh']);
@@ -396,6 +397,7 @@ describe('SnippetManager', () => {
396397
});
397398

398399
it('will fail when the index URI returns data in the wrong format (not .br)', async() => {
400+
await snippetManager.inflightFetchIndexPromise;
399401
try {
400402
indexURL = `${baseURL}/notindexfile`;
401403
await snippetManager.runSnippetCommand(['refresh']);
@@ -406,6 +408,7 @@ describe('SnippetManager', () => {
406408
});
407409

408410
it('will fail when the index URI returns data in the wrong format (not .bson.br)', async() => {
411+
await snippetManager.inflightFetchIndexPromise;
409412
try {
410413
indexURL = `${baseURL}/notindexfile2`;
411414
await snippetManager.runSnippetCommand(['refresh']);
@@ -537,13 +540,15 @@ describe('SnippetManager', () => {
537540
});
538541

539542
it('can install from a tarball', async() => {
543+
await snippetManager.inflightFetchIndexPromise;
540544
indexURL = `${baseURL}/index.bson.br;${baseURL}/index2.bson.br;`;
541545
(evaluationListener.onPrompt as any).resolves('yes');
542546
await snippetManager.runSnippetCommand(['install', 'tarballed-example']);
543547
expect(contextObject.load).to.have.been.calledWith(path.resolve(installdir, 'node_modules', 'tarballed-example-snippet-name', 'index.js'));
544548
});
545549

546550
it('reports back errors if npm fails', async() => {
551+
await snippetManager.inflightFetchIndexPromise;
547552
indexURL = `${baseURL}/index.bson.br;${baseURL}/index2.bson.br;`;
548553
(evaluationListener.onPrompt as any).resolves('yes');
549554
try {
@@ -724,6 +729,7 @@ describe('SnippetManager', () => {
724729

725730
describe('interruption support', () => {
726731
it('commands methods like load-all perform interruption checkpoints', async() => {
732+
await snippetManager.inflightFetchIndexPromise;
727733
indexURL = `${baseURL}/index.bson.br;${baseURL}/index2.bson.br;`;
728734
await snippetManager.runSnippetCommand(['refresh']);
729735

packages/snippet-manager/src/snippet-manager.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,13 @@ export class SnippetManager implements ShellPlugin {
414414
} else {
415415
output = await this.runNpm(args[0]);
416416
}
417+
418+
const firstLineEnd = output.indexOf('\n');
419+
let packages = output.substr(firstLineEnd + 1);
417420
for (const { name, snippetName } of this.snippets) {
418-
output = output.replace(new RegExp(escapeRegexp(name), 'g'), `mongosh:${snippetName}`);
421+
packages = packages.replace(new RegExp(escapeRegexp(name), 'g'), `mongosh:${snippetName}`);
419422
}
420-
return output;
423+
return (firstLineEnd < 0 ? output : output.substr(0, firstLineEnd + 1)) + packages;
421424
}
422425
case 'search':
423426
return await this.search();

0 commit comments

Comments
 (0)