-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
88 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,43 @@ | ||
import {Resolver, RouteRule} from "@bunt/app"; | ||
import {Fields, Nullable, Text} from "@bunt/input"; | ||
import {dispose, Heartbeat, isRunnable} from "@bunt/unit"; | ||
import {dispose, Heartbeat, isDisposable, isRunnable} from "@bunt/unit"; | ||
import {ok} from "assert"; | ||
import {Commander} from "../../src"; | ||
import {BaseTestCommand} from "./action/BaseTestCommand"; | ||
import {command} from "./command"; | ||
import {BaseContext} from "./context/BaseContext"; | ||
import {BaseTestCommand} from "./app/Action/BaseTestCommand"; | ||
import {command} from "./app/command"; | ||
import {BaseContext} from "./app/Context/BaseContext"; | ||
|
||
describe("Command", () => { | ||
test("should return runnable", async () => { | ||
const baseTestCommand = command(BaseTestCommand, new RouteRule( | ||
const testCommand = command(BaseTestCommand, new RouteRule( | ||
"test", | ||
new Fields({name: new Nullable(Text)}), | ||
new Resolver({name: ({context}) => context.args.getOption("name")}), | ||
)); | ||
|
||
const context = new BaseContext(["test", "--name=test"]); | ||
const result = await Commander.execute(context, [baseTestCommand]); | ||
const result = await Commander.execute(context, [testCommand]); | ||
|
||
expect(isRunnable(result)).toBe(true); | ||
ok(isRunnable(result)); | ||
|
||
expect(isDisposable(result)).toBe(true); | ||
ok(isDisposable(result)); | ||
|
||
await dispose(result); | ||
await expect(Heartbeat.watch(result)).resolves.toBeUndefined(); | ||
expect(result.getHeartbeat().beats).toBe(false); | ||
}); | ||
|
||
test("should return void", async () => { | ||
const baseTestCommand = command(BaseTestCommand, new RouteRule( | ||
const testCommand = command(BaseTestCommand, new RouteRule( | ||
"test", | ||
new Fields({name: new Nullable(Text)}), | ||
new Resolver({name: ({context}) => context.args.getOption("name")}), | ||
)); | ||
|
||
const context = new BaseContext(["test"]); | ||
const result = await Commander.execute(context, [baseTestCommand]); | ||
const result = await Commander.execute(context, [testCommand]); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {dispose, isDisposable, isRunnable} from "@bunt/unit"; | ||
import {AsyncState} from "@bunt/util"; | ||
import {ok} from "assert"; | ||
import {Commander} from "../../src"; | ||
import {RunnableTestCommand} from "./app/Action/RunnableTestCommand"; | ||
import {command} from "./app/command"; | ||
import {BaseContext} from "./app/Context/BaseContext"; | ||
|
||
test("Runnable Command", async () => { | ||
const testCommand = command(RunnableTestCommand, "test"); | ||
const result = await Commander.execute(new BaseContext(["test"]), [testCommand]); | ||
expect(isRunnable(result)).toBe(true); | ||
ok(isRunnable(result)); | ||
|
||
const heartbeat = result.getHeartbeat(); | ||
const pending = heartbeat.watch(); | ||
|
||
expect(heartbeat.beats).toBe(true); | ||
expect(pending.then).not.toBeUndefined(); | ||
expect(AsyncState.has(pending)).toBe(true); | ||
expect(AsyncState.isReleased(pending)).toBe(false); | ||
|
||
expect(isDisposable(result)).toBe(true); | ||
ok(isDisposable(result)); | ||
|
||
await dispose(result); | ||
await expect(heartbeat.beats).toBe(false); | ||
}); |
6 changes: 3 additions & 3 deletions
6
...es/cli/test/src/action/BaseTestCommand.ts → ...li/test/src/app/Action/BaseTestCommand.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {IRunnable} from "@bunt/unit"; | ||
import {Command} from "../../../../src"; | ||
import {BaseContext} from "../Context/BaseContext"; | ||
import {RunnableTest} from "../RunnableTest"; | ||
|
||
export class RunnableTestCommand extends Command<BaseContext> { | ||
public run(): IRunnable { | ||
return new RunnableTest(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
packages/cli/test/src/context/BaseContext.ts → ...s/cli/test/src/app/Context/BaseContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {Heartbeat, IDisposable, IRunnable} from "@bunt/unit"; | ||
|
||
export class RunnableTest implements IRunnable, IDisposable { | ||
public async dispose(): Promise<void> { | ||
return; | ||
} | ||
|
||
public getHeartbeat(): Heartbeat { | ||
return Heartbeat.create(this); | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters