diff --git a/src/models/Context.ts b/src/models/Context.ts index 11feaba99f1..be57665e774 100644 --- a/src/models/Context.ts +++ b/src/models/Context.ts @@ -113,13 +113,11 @@ export async function addContext(contextName: string, pathToFile: string) { } export async function editContext(contextName: string, pathToFile: string) { - let fileContent: IContextFile; - // The expression is not wrapped in a `try...catch` block and is allowed to // throw automatically because it is assumed that `loadContextFile()` works // with a 100%-existing valid file in this case, thus if it threw anyway - // some REAL error happened and user should know about it. - fileContent = await loadContextFile(); + const fileContent: IContextFile = await loadContextFile(); fileContent.store[String(contextName)] = pathToFile; await saveContextFile(fileContent); diff --git a/test/commands/context.test.ts b/test/commands/context.test.ts index 69eb7c26a86..03bed6517cd 100644 --- a/test/commands/context.test.ts +++ b/test/commands/context.test.ts @@ -75,6 +75,18 @@ describe('config:context, positive scenario', () => { done(); }); }); + + describe('config:context:edit', () => { + test + .stderr() + .stdout() + .command(['config:context:edit', 'test', './test/specification2.yml']) + .it('should edit existing context "test"', (ctx, done) => { + expect(ctx.stdout).toContain('Edited context "test".'); + expect(ctx.stderr).toEqual(''); + done(); + }); + }); describe('config:context:use', () => { test @@ -215,7 +227,7 @@ describe('config:context, negative scenario', () => { .stdout() .command(['config:context:list']) .it( - 'should throw error on absence of context file.', + 'should output info message (to stdout, NOT stderr) about absence of context file.', (ctx, done) => { expect(ctx.stdout).toContain('You have no context configured. Run "asyncapi config context" to see all available options.'); expect(ctx.stderr).toEqual('');