Skip to content

Commit

Permalink
feat: test command
Browse files Browse the repository at this point in the history
  • Loading branch information
yjl9903 committed Feb 4, 2023
1 parent 47131be commit 6c27855
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/breadc/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ export function makePluginContainer(plugins: Partial<Plugin>[] = []) {

for (const plugin of plugins) {
for (const [key, fn] of Object.entries(plugin.onPreCommand ?? {})) {
if (key in onPreCommand) {
if (!(key in onPreCommand)) {
onPreCommand[key] = [];
}
onPreCommand[key]!.push(fn);
}
for (const [key, fn] of Object.entries(plugin.onPostCommand ?? {})) {
if (key in onPostCommand) {
if (!(key in onPostCommand)) {
onPostCommand[key] = [];
}
onPostCommand[key]!.push(fn);
Expand Down
25 changes: 25 additions & 0 deletions packages/breadc/test/breadc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,31 @@ describe('Plugin', () => {
expect(output[1]).toBe(2);
expect(output[2]).toBeUndefined();
});

it('should match command', async () => {
const output: number[] = [];
const cli = breadc('cli', {
plugins: [
{
onPreCommand: {
'*': () => {
output.push(1);
}
},
onPostCommand: {
'*': () => {
output.push(2);
}
}
}
]
});
cli.command('').action(() => 0);
await cli.run([]);
expect(output[0]).toBe(1);
expect(output[1]).toBe(2);
expect(output[2]).toBeUndefined();
});
});

// describe('Warnings', () => {
Expand Down

0 comments on commit 6c27855

Please sign in to comment.