Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/snippet-manager/src/snippet-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ describe('SnippetManager', () => {
});

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

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

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

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

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

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

Expand Down
7 changes: 5 additions & 2 deletions packages/snippet-manager/src/snippet-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,13 @@ export class SnippetManager implements ShellPlugin {
} else {
output = await this.runNpm(args[0]);
}

const firstLineEnd = output.indexOf('\n');
let packages = output.substr(firstLineEnd + 1);
for (const { name, snippetName } of this.snippets) {
output = output.replace(new RegExp(escapeRegexp(name), 'g'), `mongosh:${snippetName}`);
packages = packages.replace(new RegExp(escapeRegexp(name), 'g'), `mongosh:${snippetName}`);
}
return output;
return (firstLineEnd < 0 ? output : output.substr(0, firstLineEnd + 1)) + packages;
}
case 'search':
return await this.search();
Expand Down