Skip to content

Commit

Permalink
feat: support context file location in repository
Browse files Browse the repository at this point in the history
  • Loading branch information
aeworxet committed Jul 4, 2023
1 parent 5593db7 commit 4909c8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/models/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion test/commands/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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('');
Expand Down

0 comments on commit 4909c8f

Please sign in to comment.