diff --git a/.bun-version b/.bun-version new file mode 100644 index 00000000..c69d0b1d --- /dev/null +++ b/.bun-version @@ -0,0 +1 @@ +1.x diff --git a/.deno-version b/.deno-version new file mode 100644 index 00000000..e1d8d3c4 --- /dev/null +++ b/.deno-version @@ -0,0 +1 @@ +v1.x diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml index ad3a5889..2dd94a1f 100644 --- a/.github/workflows/canary.yml +++ b/.github/workflows/canary.yml @@ -4,24 +4,54 @@ on: - cron: 0 3 * * * jobs: canary: - name: Deno Canary runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: + runtime: + - name: deno + deno-version: canary + - name: node + deno-version: canary + node-version: latest + # - name: bun + # deno-version: canary + # bun-version: canary os: [macOS-latest, windows-latest, ubuntu-latest] - deno_version: [canary] env: RUST_BACKTRACE: full DENO_FUTURE: 1 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: ${{ matrix.deno_version }} + deno-version: ${{ matrix.runtime.deno-version }} + + - name: Create package.json + if: ${{ matrix.runtime.name == 'node' || matrix.runtime.name == 'bun' }} + run: deno task setup:${{ matrix.runtime.name }} --no-install + + - name: Setup Node + if: matrix.runtime.name == 'node' + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.runtime.node-version }} + check-latest: true + + - name: Setup Bun + if: matrix.runtime.name == 'bun' + uses: oven-sh/setup-bun@v2 + with: + bun-version: ${{ matrix.runtime.bun-version }} + + - name: Setup pnpm + if: ${{ matrix.runtime.name == 'node' }} + uses: pnpm/action-setup@v4 + with: + run_install: true - name: Run tests - run: deno task test + run: deno task test:${{ matrix.runtime.name }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 03001f72..e006ddaf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,19 +5,23 @@ on: pull_request: jobs: lint: - name: Lint source + name: Lint source deno-${{ matrix.deno_version }} runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + deno_version: [v1.x, v2.x] env: RUST_BACKTRACE: full DENO_FUTURE: 1 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: v1.x + deno-version: ${{ matrix.deno_version }} - name: Setup shellcheck run: > @@ -37,5 +41,10 @@ jobs: - name: Run zsh check run: ./shellcheck --shell bash <(deno run -r ./examples/command/shell-completions.ts completions zsh) - - name: Type-check examples - run: deno task check:examples + - name: Type-check + if: matrix.deno_version == 'rc' + run: deno task check + + - name: Type-check + if: matrix.deno_version == 'v1.x' + run: deno task check:deno-v1 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b72ed2e4..8c068d60 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,7 +24,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 - name: Publish (dry run) if: github.event_name != 'release' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0dce10e2..199468e2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,34 +5,74 @@ on: pull_request: jobs: test: - name: ${{ matrix.module }} ${{ matrix.os }} deno-${{ matrix.deno }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - module: [ansi, command, flags, keycode, keypress, prompt, table, testing] + runtime: + - name: deno + deno-version: v1.x + - name: deno + deno-version: v2.x + - name: node + # - name: bun os: [macOS-latest, windows-latest, ubuntu-latest] - deno: [v1.x] env: RUST_BACKTRACE: full DENO_FUTURE: 1 CLIFFY_SNAPSHOT_DELAY: 2000 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: ${{ matrix.deno }} + deno-version: ${{ matrix.runtime.deno-version }} + # deno-version-file: ".deno-version" - - name: Test ${{ matrix.module }} - run: deno task coverage:${{ matrix.module }} + - name: Create package.json + if: ${{ matrix.runtime.name == 'node' || matrix.runtime.name == 'bun' }} + run: deno task setup:${{ matrix.runtime.name }} --no-install - - name: Upload ${{ matrix.module }} coverage + - name: Setup Node + if: ${{ matrix.runtime.name == 'node' }} + uses: actions/setup-node@v4 + with: + node-version-file: ".node-version" + + - name: Setup Bun + if: ${{ matrix.runtime.name == 'bun' }} + uses: oven-sh/setup-bun@v2 + with: + bun-version-file: ".bun-version" + + - name: Setup pnpm + if: ${{ matrix.runtime.name == 'node' }} + uses: pnpm/action-setup@v4 + with: + run_install: true + + - name: Run tests + if: matrix.runtime.name == 'deno' && matrix.runtime.deno-version == 'v1.x' + shell: bash + run: deno task coverage:deno-v1 + + - name: Run tests + if: matrix.runtime.name == 'deno' && matrix.runtime.deno-version == 'rc' + shell: bash + run: deno task coverage:deno-v2 + + - name: Run tests + if: matrix.runtime != 'deno' + shell: bash + run: deno task coverage:${{ matrix.runtime.name }} + + - name: Upload coverage uses: codecov/codecov-action@v4 with: - name: ${{ matrix.module }}-${{ matrix.os }}-${{ matrix.deno }} - files: dist/coverage/${{ matrix.module }}/cov.lcov - flags: ${{ matrix.module }} + fail_ci_if_error: true + name: ${{ matrix.runtime.name }}-${{ matrix.os }} + files: dist/coverage/${{ matrix.runtime.name }}/cov.lcov + flags: ${{ matrix.runtime.name }} token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 2f831fc3..25c7cab2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,11 @@ dist testing/__snapshots__/snapshot_test_fixture.ts.snap testing/__snapshots__/snapshot_test_fixture_2.ts.snap __snapshots_test__ + +# Node files +node_modules +.npmrc +bun.lockb +package.json +pnpm-lock.yaml +tsconfig.json diff --git a/.node-version b/.node-version new file mode 100644 index 00000000..4f0b2ab3 --- /dev/null +++ b/.node-version @@ -0,0 +1 @@ +v22.x diff --git a/CHANGELOG.md b/CHANGELOG.md index 93d86d26..09ff1733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,56 @@ +# [v1.0.0-rc.7](https://github.com/c4spar/deno-cliffy/compare/v1.0.0-rc.6...v1.0.0-rc.7) (Sep 28, 2024) + +No changes, i only forgot that deno needs an annoying version number in +deno.json. + +# [v1.0.0-rc.6](https://github.com/c4spar/deno-cliffy/compare/v1.0.0-rc.5...v1.0.0-rc.6) (Sep 28, 2024) + +### Features + +- add support for deno v2 ( #745) + ([64fff28](https://github.com/c4spar/deno-cliffy/commit/64fff28)) +- **command:** add support for disabling spinner in upgrade command ( #749) + ([62fa792](https://github.com/c4spar/deno-cliffy/commit/62fa792)) +- **command:** add support for npm package without scope to npm provider ( #748) + ([f882fa0](https://github.com/c4spar/deno-cliffy/commit/f882fa0)) + +### Bug Fixes + +- **command:** directly print example text w/o capitalization ( #741) + ([b0f1942](https://github.com/c4spar/deno-cliffy/commit/b0f1942)) +- **command:** new version info is displayed if no stable version is available ( + #726) ([3295c7a](https://github.com/c4spar/deno-cliffy/commit/3295c7a)) +- **internal:** resolve null instead of returning null ( #752) + ([779cf08](https://github.com/c4spar/deno-cliffy/commit/779cf08)) +- **internal:** fix readSync method ( #747) + ([2d8aa19](https://github.com/c4spar/deno-cliffy/commit/2d8aa19)) +- **prompt:** increase buffer size of input prompts for nodejs to allow paste of + more than 8 chars ( #739) + ([dd9aab0](https://github.com/c4spar/deno-cliffy/commit/dd9aab0)) + +### Code Refactoring + +- **command:** remove unused files ( #751) + ([ced45fc](https://github.com/c4spar/deno-cliffy/commit/ced45fc)) +- **prompt:** set list index to 0 instead of 1 when selecting a group option ( + #727) ([09c8c7a](https://github.com/c4spar/deno-cliffy/commit/09c8c7a)) + +### Chore + +- setup tests for node ( #729) + ([a036cac](https://github.com/c4spar/deno-cliffy/commit/a036cac)) +- use workspace property and fix some type and lint errors ( #725) + ([e9dae18](https://github.com/c4spar/deno-cliffy/commit/e9dae18)) +- **deno:** add test:all, node and bun task ( #750) + ([1bee870](https://github.com/c4spar/deno-cliffy/commit/1bee870)) +- **deps:** upgrade @std to latest version ( #746) + ([2a32a37](https://github.com/c4spar/deno-cliffy/commit/2a32a37)) + +### Documentation Updates + +- **examples:** use workspace specifier for imports ( #728) + ([33b01f8](https://github.com/c4spar/deno-cliffy/commit/33b01f8)) + # [v1.0.0-rc.5](https://github.com/c4spar/deno-cliffy/compare/v1.0.0-rc.4...v1.0.0-rc.5) (Jul 1, 2024) ### Features diff --git a/ansi/ansi_escapes_test.ts b/ansi/ansi_escapes_test.ts index 1dbe7cac..7862af6e 100644 --- a/ansi/ansi_escapes_test.ts +++ b/ansi/ansi_escapes_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { cursorBackward, cursorDown, @@ -16,7 +17,7 @@ import { } from "./ansi_escapes.ts"; import { assertEquals } from "@std/assert"; -Deno.test({ +test({ name: "ansi - ansi escapes - cursorTo x", fn() { assertEquals( @@ -26,7 +27,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorTo x y", fn() { assertEquals( @@ -36,7 +37,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorMove right down", fn() { assertEquals( @@ -46,7 +47,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorMove left up", fn() { assertEquals( @@ -56,7 +57,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorUp", fn() { assertEquals( @@ -66,7 +67,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorDown", fn() { assertEquals( @@ -76,7 +77,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorForward", fn() { assertEquals( @@ -86,7 +87,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorBackward", fn() { assertEquals( @@ -96,7 +97,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorNextLine", fn() { assertEquals( @@ -106,7 +107,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - cursorPrevLine", fn() { assertEquals( @@ -116,7 +117,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - scrollUp", fn() { assertEquals( @@ -126,7 +127,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - scrollDown", fn() { assertEquals( @@ -136,7 +137,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - eraseUp", fn() { assertEquals( @@ -146,7 +147,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - eraseUp", fn() { assertEquals( @@ -156,7 +157,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - link", fn() { assertEquals( @@ -166,7 +167,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - image", fn() { assertEquals( @@ -180,7 +181,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - ansi escapes - image preserveAspectRatio", fn() { assertEquals( diff --git a/ansi/ansi_test.ts b/ansi/ansi_test.ts index 9b059137..8c500fcd 100644 --- a/ansi/ansi_test.ts +++ b/ansi/ansi_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { ansi } from "./ansi.ts"; -Deno.test({ +test({ name: "ansi - chainable ansi escapes", fn() { assertEquals( @@ -11,7 +12,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - toArray", fn() { assertEquals( @@ -21,7 +22,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - chainable ansi escape custom instance", fn() { const myAnsi = ansi(); @@ -39,7 +40,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - empty ansi chain", fn() { assertEquals(ansi().toString(), ""); diff --git a/ansi/colors_test.ts b/ansi/colors_test.ts index 2932655d..bad6daef 100644 --- a/ansi/colors_test.ts +++ b/ansi/colors_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { bold, red, underline } from "@std/fmt/colors"; import { colors } from "./colors.ts"; -Deno.test({ +test({ name: "ansi - colors - chainable colors", fn() { assertEquals( @@ -12,7 +13,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - colors - chainable colors theme", fn() { const theme = colors.red.underline; @@ -27,7 +28,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - colors - chainable colors custom instance", fn() { const myColors = colors(); @@ -43,7 +44,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - colors - empty string argument", fn() { assertEquals( diff --git a/ansi/tty_test.ts b/ansi/tty_test.ts index 1e1fedad..719b1325 100644 --- a/ansi/tty_test.ts +++ b/ansi/tty_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { tty } from "./tty.ts"; -Deno.test({ +test({ name: "ansi - tty - chainable tty", fn() { assertEquals( @@ -11,7 +12,7 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - tty - chainable tty custom instance", fn() { assertEquals( @@ -21,13 +22,16 @@ Deno.test({ }, }); -Deno.test({ +test({ name: "ansi - empty ansi chain", + ignore: ["node", "bun"], fn() { assertEquals( typeof tty({ - writer: Deno.stdout, - reader: Deno.stdin, + // deno-lint-ignore no-explicit-any + writer: (globalThis as any).Deno.stdout, + // deno-lint-ignore no-explicit-any + reader: (globalThis as any).Deno.stdin, })() === "function", true, ); diff --git a/command/_runtime/inspect.ts b/command/_runtime/inspect.ts deleted file mode 100644 index dd5d6dde..00000000 --- a/command/_runtime/inspect.ts +++ /dev/null @@ -1,9 +0,0 @@ -export function inspect(value: unknown, colors: boolean): string { - // deno-lint-ignore no-explicit-any - const { Deno } = globalThis as any; - - return Deno?.inspect( - value, - { depth: 1, colors, trailingComma: false }, - ) ?? JSON.stringify(value, null, 2); -} diff --git a/command/help/_help_generator.ts b/command/help/_help_generator.ts index 3cdff558..0de96c2b 100644 --- a/command/help/_help_generator.ts +++ b/command/help/_help_generator.ts @@ -293,7 +293,7 @@ export class HelpGenerator { } return this.label("Examples") + Table.from(examples.map((example: Example) => [ - dim(bold(`${capitalize(example.name)}:`)), + dim(bold(example.name)), dedent(example.description), ])) .padding(1) @@ -358,10 +358,6 @@ export class HelpGenerator { } } -function capitalize(string: string): string { - return string.charAt(0).toUpperCase() + string.slice(1); -} - /** * Colorize arguments string. * @param argsDefinition Arguments definition: ` ` diff --git a/command/test/command/action_test.ts b/command/test/command/action_test.ts index 9d1549f6..8845941e 100644 --- a/command/test/command/action_test.ts +++ b/command/test/command/action_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { assertSpyCall, assertSpyCalls, spy } from "@std/testing/mock"; import { assertType, type IsExact } from "@std/testing/types"; @@ -18,7 +19,7 @@ function createStats(): IStats { }; } -Deno.test("flags allowEmpty enabled", async () => { +test("flags allowEmpty enabled", async () => { const stats: IStats = createStats(); const cmd = new Command() @@ -40,7 +41,7 @@ Deno.test("flags allowEmpty enabled", async () => { assertEquals(stats.args, args); }); -Deno.test("flags allowEmpty enabled", async () => { +test("flags allowEmpty enabled", async () => { const stats: IStats = createStats(); // deno-lint-ignore no-explicit-any let subCmd: Command; @@ -68,7 +69,7 @@ Deno.test("flags allowEmpty enabled", async () => { assertEquals(stats.args, args); }); -Deno.test("[flags] should call global action handler", async () => { +test("[flags] should call global action handler", async () => { const mainGlobalSpy = spy(); const mainSpy = spy(); const fooGlobalSpy = spy(); @@ -177,7 +178,7 @@ Deno.test("[flags] should call global action handler", async () => { assertSpyCall(barSpy, 0, { args }); }); -Deno.test("[flags] should call global and base action handler", async () => { +test("[flags] should call global and base action handler", async () => { const globalSpy = spy(); const baseSpy = spy(); @@ -198,7 +199,7 @@ Deno.test("[flags] should call global and base action handler", async () => { assertSpyCall(baseSpy, 0, { args }); }); -Deno.test("[flags] should not call global action handler with noGlobals", async () => { +test("[flags] should not call global action handler with noGlobals", async () => { const globalSpy = spy(); const baseSpy = spy(); const fooGlobalSpy = spy(); diff --git a/command/test/command/alias_test.ts b/command/test/command/alias_test.ts index 5caf0a24..ecfecb28 100644 --- a/command/test/command/alias_test.ts +++ b/command/test/command/alias_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command - alias - command with alias 1", async () => { +test("command - alias - command with alias 1", async () => { const cmd = new Command() .throwErrors() .command("foo, bar") @@ -14,7 +15,7 @@ Deno.test("command - alias - command with alias 1", async () => { assertEquals(barOptions, { baz: true }); }); -Deno.test("command - alias - command with alias 2", async () => { +test("command - alias - command with alias 2", async () => { const cmd = new Command() .throwErrors() .command("foo") @@ -28,7 +29,7 @@ Deno.test("command - alias - command with alias 2", async () => { assertEquals(barOptions, { baz: true }); }); -Deno.test("command - alias - duplicate command alias name 1", async () => { +test("command - alias - duplicate command alias name 1", async () => { await assertRejects( async () => { await new Command() @@ -41,7 +42,7 @@ Deno.test("command - alias - duplicate command alias name 1", async () => { ); }); -Deno.test("command - alias - duplicate command alias name 2", async () => { +test("command - alias - duplicate command alias name 2", async () => { await assertRejects( async () => { await new Command() diff --git a/command/test/command/allow_empty_test.ts b/command/test/command/allow_empty_test.ts index 75adf04c..67c3fd96 100644 --- a/command/test/command/allow_empty_test.ts +++ b/command/test/command/allow_empty_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -9,7 +10,7 @@ function cmd() { }); } -Deno.test("[flags] should not allow empty by default", async () => { +test("[flags] should not allow empty by default", async () => { await assertRejects( () => cmd().parse([]), Error, @@ -17,7 +18,7 @@ Deno.test("[flags] should not allow empty by default", async () => { ); }); -Deno.test("[flags] should not allow empty if disabled", async () => { +test("[flags] should not allow empty if disabled", async () => { await assertRejects( () => cmd().allowEmpty(false).parse([]), Error, @@ -25,7 +26,7 @@ Deno.test("[flags] should not allow empty if disabled", async () => { ); }); -Deno.test("[flags] should allow empty if enabled", async () => { +test("[flags] should allow empty if enabled", async () => { const { options, args } = await cmd() .allowEmpty() .parse([]); @@ -34,7 +35,7 @@ Deno.test("[flags] should allow empty if enabled", async () => { assertEquals(args, []); }); -Deno.test("[flags] should allow empty if enabled with true", async () => { +test("[flags] should allow empty if enabled with true", async () => { const { options, args } = await cmd() .allowEmpty(true) .parse([]); diff --git a/command/test/command/arguments_test.ts b/command/test/command/arguments_test.ts index 68576a09..c3aa6563 100644 --- a/command/test/command/arguments_test.ts +++ b/command/test/command/arguments_test.ts @@ -1,5 +1,5 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; -import { describe, it } from "@std/testing/bdd"; import type { ArgumentValue } from "@cliffy/flags"; import { ValidationError } from "../../_errors.ts"; import { Command } from "../../command.ts"; @@ -38,135 +38,133 @@ function cmd2() { .option("-f, --foo ", "..."); } -describe("command arguments", () => { - it("should accept a dash as argument", async () => { - const { args } = await new Command() - .arguments("") - .parse(["-"]); - assertEquals(args, ["-"]); - }); - - it("should parse correctly argument types", async () => { - const { args } = await cmd().parse([ - "abc", - "123", - "true", - "red", - "1,2,3,4", - ]); - assertEquals(args, ["abc", 123, true, "red", [1, 2, 3, 4]]); - }); - - it("should parse correctly an isolated variadic argument", async () => { - const { args } = await new Command() - .throwErrors() - .arguments("<...foo:string>") - .parse(["foo", "bar", "baz"]); - - assertEquals(args, ["foo", "bar", "baz"]); - }); - - it("should parse correctly argument types with sub command arguments", async () => { - const { args } = await cmd2().parse([ - "foo", - "abc", - "123", - "true", - "red", - "1,2,3,4", - ]); - assertEquals(args, ["abc", 123, true, "red", [1, 2, 3, 4]]); - }); - - it("should not throw for missing optional values", async () => { - const { args } = await cmd().parse(["abc", "0"]); - assertEquals(args, ["abc", 0]); - }); - - it("should parse multi argument option", async () => { - const { options, args } = await cmd().parse([ - "-f", - "1", - "2", - "3", - "mod.ts", - ]); - assertEquals(options, { foo: ["1", "2", "3"] }); - assertEquals(args, ["mod.ts"]); - }); - - it("should throw an error for invalid number types", async () => { - await assertRejects( - async () => { - await cmd().parse(["abc", "xyz", "true", "red"]); - }, - ValidationError, - `Argument "bar" must be of type "number", but got "xyz".`, - ); - }); - - it("should throw an error for invalid list types", async () => { - await assertRejects( - async () => { - await cmd().parse(["abc", "123", "true", "red", "1,2,3,four"]); - }, - ValidationError, - `Argument "list" must be of type "number", but got "four".`, - ); - }); - - it("should throw an error for invalid list types with sub command arguments", async () => { - await assertRejects( - async () => { - await cmd2().parse(["foo", "abc", "123", "true", "red", "1,2,3,four"]); - }, - ValidationError, - `Argument "list" must be of type "number", but got "four".`, - ); - }); - - it("should throw an error for missing required arguments", async () => { - await assertRejects( - async () => { - await cmd().parse([]); - }, - ValidationError, - "Missing argument(s): foo", - ); - }); - - it("should throw an error for invalid boolean types", async () => { - await assertRejects( - async () => { - await cmd().parse(["abc", "123", "xyz", "red"]); - }, - ValidationError, - `Argument "baz" must be of type "boolean", but got "xyz".`, - ); - }); - - it("should throw an error for invalid custom type value", async () => { - await assertRejects( - async () => { - await cmd().parse(["abc", "123", "true", "xyz"]); - }, - ValidationError, - `Argument "color" must be a valid "color", but got "xyz".`, - ); - }); - - it("should throw to many arguments error for global & none global option before a sub-command", async () => { - await assertRejects( - async () => { - await new Command() - .noExit() - .globalOption("--foo", "foo...") - .option("--bar", "...") - .command("foo", "...") - .parse(["--foo", "--bar", "foo"]); - }, - ValidationError, - `Too many arguments: foo`, - ); - }); +test("should accept a dash as argument", async () => { + const { args } = await new Command() + .arguments("") + .parse(["-"]); + assertEquals(args, ["-"]); +}); + +test("should parse correctly argument types", async () => { + const { args } = await cmd().parse([ + "abc", + "123", + "true", + "red", + "1,2,3,4", + ]); + assertEquals(args, ["abc", 123, true, "red", [1, 2, 3, 4]]); +}); + +test("should parse correctly an isolated variadic argument", async () => { + const { args } = await new Command() + .throwErrors() + .arguments("<...foo:string>") + .parse(["foo", "bar", "baz"]); + + assertEquals(args, ["foo", "bar", "baz"]); +}); + +test("should parse correctly argument types with sub command arguments", async () => { + const { args } = await cmd2().parse([ + "foo", + "abc", + "123", + "true", + "red", + "1,2,3,4", + ]); + assertEquals(args, ["abc", 123, true, "red", [1, 2, 3, 4]]); +}); + +test("should not throw for missing optional values", async () => { + const { args } = await cmd().parse(["abc", "0"]); + assertEquals(args, ["abc", 0]); +}); + +test("should parse multi argument option", async () => { + const { options, args } = await cmd().parse([ + "-f", + "1", + "2", + "3", + "mod.ts", + ]); + assertEquals(options, { foo: ["1", "2", "3"] }); + assertEquals(args, ["mod.ts"]); +}); + +test("should throw an error for invalid number types", async () => { + await assertRejects( + async () => { + await cmd().parse(["abc", "xyz", "true", "red"]); + }, + ValidationError, + `Argument "bar" must be of type "number", but got "xyz".`, + ); +}); + +test("should throw an error for invalid list types", async () => { + await assertRejects( + async () => { + await cmd().parse(["abc", "123", "true", "red", "1,2,3,four"]); + }, + ValidationError, + `Argument "list" must be of type "number", but got "four".`, + ); +}); + +test("should throw an error for invalid list types with sub command arguments", async () => { + await assertRejects( + async () => { + await cmd2().parse(["foo", "abc", "123", "true", "red", "1,2,3,four"]); + }, + ValidationError, + `Argument "list" must be of type "number", but got "four".`, + ); +}); + +test("should throw an error for missing required arguments", async () => { + await assertRejects( + async () => { + await cmd().parse([]); + }, + ValidationError, + "Missing argument(s): foo", + ); +}); + +test("should throw an error for invalid boolean types", async () => { + await assertRejects( + async () => { + await cmd().parse(["abc", "123", "xyz", "red"]); + }, + ValidationError, + `Argument "baz" must be of type "boolean", but got "xyz".`, + ); +}); + +test("should throw an error for invalid custom type value", async () => { + await assertRejects( + async () => { + await cmd().parse(["abc", "123", "true", "xyz"]); + }, + ValidationError, + `Argument "color" must be a valid "color", but got "xyz".`, + ); +}); + +test("should throw to many arguments error for global & none global option before a sub-command", async () => { + await assertRejects( + async () => { + await new Command() + .noExit() + .globalOption("--foo", "foo...") + .option("--bar", "...") + .command("foo", "...") + .parse(["--foo", "--bar", "foo"]); + }, + ValidationError, + `Too many arguments: foo`, + ); }); diff --git a/command/test/command/command_test.ts b/command/test/command/command_test.ts index 6e209fd6..b70efa54 100644 --- a/command/test/command/command_test.ts +++ b/command/test/command/command_test.ts @@ -1,5 +1,6 @@ // deno-fmt-ignore-file +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; @@ -15,7 +16,7 @@ function command() { .hidden(); } -Deno.test("command - command - has commands", () => { +test("command - command - has commands", () => { const cmd = command(); assertEquals(cmd.hasCommands(), true); assertEquals(cmd.hasCommands(true), true); @@ -23,7 +24,7 @@ Deno.test("command - command - has commands", () => { assertEquals(new Command().hasCommands(true), false); }); -Deno.test("command - command - get commands", () => { +test("command - command - get commands", () => { const cmd = command(); assertEquals(cmd.getCommands().length, 2); assertEquals(cmd.getCommands(true).length, 4); @@ -37,7 +38,7 @@ Deno.test("command - command - get commands", () => { assertEquals(!!cmd.getCommands(true).find((cmd) => cmd.getName() === "foo-hidden"), true); }); -Deno.test("command - command - get base commands", () => { +test("command - command - get base commands", () => { const cmd = command(); assertEquals(cmd.getBaseCommands().length, 2); assertEquals(cmd.getBaseCommands(true).length, 4); @@ -51,7 +52,7 @@ Deno.test("command - command - get base commands", () => { assertEquals(!!cmd.getBaseCommands(true).find((cmd) => cmd.getName() === "foo-hidden"), true); }); -Deno.test("command - command - get global commands", () => { +test("command - command - get global commands", () => { const cmd = command(); assertEquals(cmd.getCommand("foo")?.getGlobalCommands().length, 1); assertEquals(cmd.getCommand("foo")?.getGlobalCommands(true).length, 2); @@ -65,7 +66,7 @@ Deno.test("command - command - get global commands", () => { assertEquals(!!cmd.getCommand("foo")?.getGlobalCommands(true).find((cmd) => cmd.getName() === "foo-hidden"), false); }); -Deno.test("command - command - has command", () => { +test("command - command - has command", () => { const cmd = command(); assertEquals(cmd.hasCommand("global"), true); assertEquals(cmd.hasCommand("global-hidden"), false); @@ -84,7 +85,7 @@ Deno.test("command - command - has command", () => { assertEquals(cmd.getCommand("foo")?.getCommand("three")?.hasCommand("unknown"), false); }); -Deno.test("command - command - get command", () => { +test("command - command - get command", () => { const cmd = command(); assertEquals(cmd.getCommand("global")?.getName(), "global"); assertEquals(cmd.getCommand("global-hidden")?.getName(), undefined); @@ -99,7 +100,7 @@ Deno.test("command - command - get command", () => { assertEquals(cmd.getCommand("foo")?.getCommand("unknown")?.getName(), undefined); }); -Deno.test("command - command - get base command", () => { +test("command - command - get base command", () => { const cmd = command(); assertEquals(cmd.getBaseCommand("global")?.getName(), "global"); assertEquals(cmd.getBaseCommand("global-hidden")?.getName(), undefined); @@ -114,7 +115,7 @@ Deno.test("command - command - get base command", () => { assertEquals(cmd.getCommand("foo")?.getBaseCommand("unknown")?.getName(), undefined); }); -Deno.test("command - command - get global command", () => { +test("command - command - get global command", () => { const cmd = command(); assertEquals(cmd.getGlobalCommand("global")?.getName(), undefined); assertEquals(cmd.getGlobalCommand("global-hidden")?.getName(), undefined); @@ -136,7 +137,7 @@ Deno.test("command - command - get global command", () => { assertEquals(cmd.getCommand("foo")?.getCommand("three")?.getGlobalCommand("unknown")?.getName(), undefined); }); -Deno.test("command - command - remove command", () => { +test("command - command - remove command", () => { const cmd = command(); assertEquals(cmd.getCommand("foo")?.getName(), "foo"); assertEquals(cmd.removeCommand("foo")?.getName(), "foo"); diff --git a/command/test/command/completion_test.ts b/command/test/command/completion_test.ts index b5cea0ab..ef336874 100644 --- a/command/test/command/completion_test.ts +++ b/command/test/command/completion_test.ts @@ -1,5 +1,6 @@ // deno-fmt-ignore-file +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { snapshotTest } from "../../../testing/snapshot.ts"; import { Command } from "../../command.ts"; @@ -20,7 +21,7 @@ function command() { ); } -Deno.test("command - completion - completion properties", () => { +test("command - completion - completion properties", () => { const cmd = new Command() .throwErrors() .complete("foo", () => ["foo1", "foo2"]) @@ -36,28 +37,28 @@ Deno.test("command - completion - completion properties", () => { assertEquals(barCompletion.global, true); }); -Deno.test("command - completion - get completions", () => { +test("command - completion - get completions", () => { const cmd = command(); assertEquals(cmd.getCompletions().length, 2); assertEquals(!!cmd.getCompletions().find((opt) => opt.name === "global"), true); assertEquals(!!cmd.getCompletions().find((opt) => opt.name === "foo"), true); }); -Deno.test("command - completion - get base completions", () => { +test("command - completion - get base completions", () => { const cmd = command(); assertEquals(cmd.getBaseCompletions().length, 2); assertEquals(!!cmd.getBaseCompletions().find((opt) => opt.name === "global"), true); assertEquals(!!cmd.getBaseCompletions().find((opt) => opt.name === "foo"), true); }); -Deno.test("command - completion - get global completions", () => { +test("command - completion - get global completions", () => { const cmd = command(); assertEquals(cmd.getCommand("bar")?.getGlobalCompletions().length, 1); assertEquals(!!cmd.getCommand("bar")?.getGlobalCompletions().find((opt) => opt.name === "global"), true); assertEquals(!!cmd.getCommand("bar")?.getGlobalCompletions().find((opt) => opt.name === "foo"), false); }); -Deno.test("command - completion - get completion", () => { +test("command - completion - get completion", () => { const cmd = command(); assertEquals(cmd.getCompletion("global")?.name, "global"); assertEquals(cmd.getCompletion("foo")?.name, "foo"); @@ -70,7 +71,7 @@ Deno.test("command - completion - get completion", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getCompletion("unknown")?.name, undefined); }); -Deno.test("command - completion - get base completion", () => { +test("command - completion - get base completion", () => { const cmd = command(); assertEquals(cmd.getBaseCompletion("global")?.name, "global"); assertEquals(cmd.getBaseCompletion("foo")?.name, "foo"); @@ -83,7 +84,7 @@ Deno.test("command - completion - get base completion", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseCompletion("unknown")?.name, undefined); }); -Deno.test("command - completion - get global completion", () => { +test("command - completion - get global completion", () => { const cmd = command(); assertEquals(cmd.getGlobalCompletion("global")?.name, undefined); assertEquals(cmd.getGlobalCompletion("foo")?.name, undefined); diff --git a/command/test/command/default_command_test.ts b/command/test/command/default_command_test.ts index 5a30ab9d..f9ab53e9 100644 --- a/command/test/command/default_command_test.ts +++ b/command/test/command/default_command_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command - raw args - command with usRawArgs disabled", async () => { +test("command - raw args - command with usRawArgs disabled", async () => { let action = 0; const { options, args, literal } = await new Command() .throwErrors() diff --git a/command/test/command/dotted_options_test.ts b/command/test/command/dotted_options_test.ts index c9987d2a..15e7979b 100644 --- a/command/test/command/dotted_options_test.ts +++ b/command/test/command/dotted_options_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -21,7 +22,7 @@ function cmd() { .action(() => {}); } -Deno.test("command: dotted short options", async () => { +test("command: dotted short options", async () => { const { options, args, literal } = await cmd().parse( ["-b.a", "300", "-b.v", "900"], ); @@ -31,7 +32,7 @@ Deno.test("command: dotted short options", async () => { assertEquals(literal, []); }); -Deno.test("command: dotted long options", async () => { +test("command: dotted long options", async () => { const { options, args, literal } = await cmd().parse( ["--bitrate.audio", "300", "--bitrate.video", "900"], ); @@ -41,7 +42,7 @@ Deno.test("command: dotted long options", async () => { assertEquals(literal, []); }); -Deno.test("command: dotted aliases", async () => { +test("command: dotted aliases", async () => { const { options, args, literal } = await cmd().parse( ["--audio-bitrate", "300", "--video-bitrate", "900"], ); @@ -51,7 +52,7 @@ Deno.test("command: dotted aliases", async () => { assertEquals(literal, []); }); -Deno.test("command: dotted aliases", async () => { +test("command: dotted aliases", async () => { await assertRejects( () => cmd().parse(["--audio-bitrate", "300"]), Error, @@ -59,7 +60,7 @@ Deno.test("command: dotted aliases", async () => { ); }); -Deno.test("command: dotted option with invalid value", async () => { +test("command: dotted option with invalid value", async () => { await assertRejects( () => cmd().parse(["--bitrate.audio", "300", "--bitrate.video", "900k"]), Error, diff --git a/command/test/command/env_var_test.ts b/command/test/command/env_var_test.ts index 45af2ce5..9001de53 100644 --- a/command/test/command/env_var_test.ts +++ b/command/test/command/env_var_test.ts @@ -1,5 +1,8 @@ // deno-fmt-ignore-file +import { test } from "@cliffy/internal/testing/test"; +import { deleteEnv } from "@cliffy/internal/runtime/delete-env"; +import { setEnv } from "@cliffy/internal/runtime/set-env"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import type { EnvVar } from "../../types.ts"; @@ -56,42 +59,42 @@ function command() { } function setupEnv() { - Deno.env.set("global", "true"); - Deno.env.set("prefix_global_prefixed", "global"); - Deno.env.set("global_hidden", "global"); - Deno.env.set("global_required", "1"); - Deno.env.set("prefix_foo_prefixed", "foo"); - Deno.env.set("foo", "true"); - Deno.env.set("foo_hidden", "foo"); - Deno.env.set("foo_required", "1"); - - Deno.env.set("bar", "true"); - Deno.env.set("bar_hidden", "bar"); - Deno.env.set("bar_required", "1"); - Deno.env.set("baz", "true"); - Deno.env.set("baz_hidden", "baz"); - Deno.env.set("baz_required", "1"); + setEnv("global", "true"); + setEnv("prefix_global_prefixed", "global"); + setEnv("global_hidden", "global"); + setEnv("global_required", "1"); + setEnv("prefix_foo_prefixed", "foo"); + setEnv("foo", "true"); + setEnv("foo_hidden", "foo"); + setEnv("foo_required", "1"); + + setEnv("bar", "true"); + setEnv("bar_hidden", "bar"); + setEnv("bar_required", "1"); + setEnv("baz", "true"); + setEnv("baz_hidden", "baz"); + setEnv("baz_required", "1"); } function clearEnv() { - Deno.env.delete("global"); - Deno.env.delete("prefix_global_prefixed"); - Deno.env.delete("global_hidden"); - Deno.env.delete("global_required"); - Deno.env.delete("foo"); - Deno.env.delete("prefix_foo_prefixed"); - Deno.env.delete("foo_hidden"); - Deno.env.delete("foo_required"); - - Deno.env.delete("bar"); - Deno.env.delete("bar_hidden"); - Deno.env.delete("bar_required"); - Deno.env.delete("baz"); - Deno.env.delete("baz_hidden"); - Deno.env.delete("baz_required"); + deleteEnv("global"); + deleteEnv("prefix_global_prefixed"); + deleteEnv("global_hidden"); + deleteEnv("global_required"); + deleteEnv("foo"); + deleteEnv("prefix_foo_prefixed"); + deleteEnv("foo_hidden"); + deleteEnv("foo_required"); + + deleteEnv("bar"); + deleteEnv("bar_hidden"); + deleteEnv("bar_required"); + deleteEnv("baz"); + deleteEnv("baz_hidden"); + deleteEnv("baz_required"); } -Deno.test("[command] - env var - missing required env var", async () => { +test("[command] - env var - missing required env var", async () => { await assertRejects( async () => { await new Command() @@ -104,30 +107,42 @@ Deno.test("[command] - env var - missing required env var", async () => { ); }); -Deno.test("[command] - env var - ignores required env vars for help", async () => { - await new Command() - .noExit() - .env("foo", "...", { required: true }) - .parse(["--help"]); +test({ + name: "[command] - env var - ignores required env vars for help", + ignore: ["node"], + fn: async () => { + await new Command() + .noExit() + .env("foo", "...", { required: true }) + .parse(["--help"]); + }, }); -Deno.test("[command] - env var - ignores required env vars for help", async () => { - await new Command() - .noExit() - .globalEnv("foo", "...", { required: true }) - .command("foo") - .parse(["foo", "--help"]); +test({ + name: "[command] - env var - ignores required env vars for help", + ignore: ["node"], + fn: async () => { + await new Command() + .noExit() + .globalEnv("foo", "...", { required: true }) + .command("foo") + .parse(["foo", "--help"]); + }, }); -Deno.test("[command] - env var - ignores required env vars for version", async () => { - await new Command() - .noExit() - .version("1.0.0") - .env("foo", "...", { required: true }) - .parse(["--version"]); +test({ + name: "[command] - env var - ignores required env vars for version", + ignore: ["node"], + fn: async () => { + await new Command() + .noExit() + .version("1.0.0") + .env("foo", "...", { required: true }) + .parse(["--version"]); + }, }); -Deno.test("[command] - env var - should map the value", async () => { +test("[command] - env var - should map the value", async () => { setupEnv(); const { options } = await new Command() .throwErrors() @@ -137,7 +152,7 @@ Deno.test("[command] - env var - should map the value", async () => { clearEnv(); }); -Deno.test("[command] - env var - expect valid values", async () => { +test("[command] - env var - expect valid values", async () => { setupEnv(); const { options } = await command().parse([]); assertEquals(options, { @@ -153,7 +168,7 @@ Deno.test("[command] - env var - expect valid values", async () => { clearEnv(); }); -Deno.test("[command] - env var - override env vars with option", async () => { +test("[command] - env var - override env vars with option", async () => { setupEnv(); const { options } = await command().parse(["--global-prefixed", "global2"]); assertEquals(options, { @@ -169,9 +184,9 @@ Deno.test("[command] - env var - override env vars with option", async () => { clearEnv(); }); -Deno.test("[command] - env var - expect option to throw if value is not a boolean", async () => { +test("[command] - env var - expect option to throw if value is not a boolean", async () => { setupEnv(); - Deno.env.set("global", "foo"); + setEnv("global", "foo"); await assertRejects( async () => { await command().parse([]); @@ -182,9 +197,9 @@ Deno.test("[command] - env var - expect option to throw if value is not a boolea clearEnv(); }); -Deno.test("[command] - env var - expect option to throw if value is not a number", async () => { +test("[command] - env var - expect option to throw if value is not a number", async () => { setupEnv(); - Deno.env.set("global_required", "foo"); + setEnv("global_required", "foo"); await assertRejects( async () => { await command().parse([]); @@ -195,9 +210,9 @@ Deno.test("[command] - env var - expect option to throw if value is not a number clearEnv(); }); -Deno.test("[command] - env var - expect global option to throw if value is not a boolean", async () => { +test("[command] - env var - expect global option to throw if value is not a boolean", async () => { setupEnv(); - Deno.env.set("global", "foo"); + setEnv("global", "foo"); await assertRejects( async () => { await command().parse(["bar"]); @@ -208,9 +223,9 @@ Deno.test("[command] - env var - expect global option to throw if value is not a clearEnv(); }); -Deno.test("[command] - env var - expect global option to throw if value is not a number", async () => { +test("[command] - env var - expect global option to throw if value is not a number", async () => { setupEnv(); - Deno.env.set("global_required", "foo"); + setEnv("global_required", "foo"); await assertRejects( async () => { await command().parse(["bar"]); @@ -221,7 +236,7 @@ Deno.test("[command] - env var - expect global option to throw if value is not a clearEnv(); }); -Deno.test("[command] - env var - env var properties", () => { +test("[command] - env var - env var properties", () => { const cmd = new Command() .throwErrors() .globalEnv("global, global2", "global ...") @@ -247,7 +262,7 @@ Deno.test("[command] - env var - env var properties", () => { assertEquals(fooEnvVar.hidden, true); }); -Deno.test("[command] - env var - has env vars", () => { +test("[command] - env var - has env vars", () => { const cmd = command(); assertEquals(cmd.hasEnvVars(), true); assertEquals(cmd.hasEnvVars(true), true); @@ -255,9 +270,9 @@ Deno.test("[command] - env var - has env vars", () => { assertEquals(new Command().hasEnvVars(true), false); }); -Deno.test("[command] - env var - get env vars", () => { +test("[command] - env var - get env vars", () => { const cmd = command(); - assertEquals(cmd.getEnvVars().map(env => env.name), [ + assertEquals(cmd.getEnvVars().map((env) => env.name), [ "global", "global_required", "prefix_global_prefixed", @@ -265,7 +280,7 @@ Deno.test("[command] - env var - get env vars", () => { "foo_required", "prefix_foo_prefixed", ]); - assertEquals(cmd.getEnvVars(true).map(env => env.name), [ + assertEquals(cmd.getEnvVars(true).map((env) => env.name), [ "global", "global_hidden", "global_required", @@ -277,9 +292,9 @@ Deno.test("[command] - env var - get env vars", () => { ]); }); -Deno.test("[command] - env var - get base env vars", () => { +test("[command] - env var - get base env vars", () => { const cmd = command(); - assertEquals(cmd.getBaseEnvVars().map(env => env.name), [ + assertEquals(cmd.getBaseEnvVars().map((env) => env.name), [ "global", "global_required", "prefix_global_prefixed", @@ -287,7 +302,7 @@ Deno.test("[command] - env var - get base env vars", () => { "foo_required", "prefix_foo_prefixed", ]); - assertEquals(cmd.getBaseEnvVars(true).map(env => env.name), [ + assertEquals(cmd.getBaseEnvVars(true).map((env) => env.name), [ "global", "global_hidden", "global_required", @@ -299,14 +314,14 @@ Deno.test("[command] - env var - get base env vars", () => { ]); }); -Deno.test("[command] - env var - get global env vars", () => { +test("[command] - env var - get global env vars", () => { const cmd = command().getCommand("bar") as Command; - assertEquals(cmd.getGlobalEnvVars().map(env => env.name), [ + assertEquals(cmd.getGlobalEnvVars().map((env) => env.name), [ "global", "global_required", "prefix_global_prefixed", ]); - assertEquals(cmd.getGlobalEnvVars(true).map(env => env.name), [ + assertEquals(cmd.getGlobalEnvVars(true).map((env) => env.name), [ "global", "global_hidden", "global_required", @@ -314,7 +329,7 @@ Deno.test("[command] - env var - get global env vars", () => { ]); }); -Deno.test("[command] - env var - has env var", () => { +test("[command] - env var - has env var", () => { const cmd = command(); assertEquals(cmd.hasEnvVar("global"), true); assertEquals(cmd.hasEnvVar("global_hidden"), false); @@ -330,16 +345,37 @@ Deno.test("[command] - env var - has env var", () => { assertEquals(cmd.getCommand("bar")?.hasEnvVar("bar_hidden"), false); assertEquals(cmd.getCommand("bar")?.hasEnvVar("bar_hidden", true), true); assertEquals(cmd.getCommand("bar")?.hasEnvVar("unknown"), false); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global"), true); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global_hidden"), false); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global_hidden", true), true); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz"), true); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz_hidden"), false); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz_hidden", true), true); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("unknown"), false); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global"), + true, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global_hidden"), + false, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("global_hidden", true), + true, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz"), + true, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz_hidden"), + false, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("baz_hidden", true), + true, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.hasEnvVar("unknown"), + false, + ); }); -Deno.test("[command] - env var - get env var", () => { +test("[command] - env var - get env var", () => { const cmd = command(); assertEquals(cmd.getEnvVar("global")?.name, "global"); assertEquals(cmd.getEnvVar("global_hidden")?.name, undefined); @@ -349,22 +385,54 @@ Deno.test("[command] - env var - get env var", () => { assertEquals(cmd.getEnvVar("foo_hidden", true)?.name, "foo_hidden"); assertEquals(cmd.getEnvVar("unknown")?.name, undefined); assertEquals(cmd.getCommand("bar")?.getEnvVar("global")?.name, "global"); - assertEquals(cmd.getCommand("bar")?.getEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getEnvVar("global_hidden", true)?.name, "global_hidden"); + assertEquals( + cmd.getCommand("bar")?.getEnvVar("global_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getEnvVar("global_hidden", true)?.name, + "global_hidden", + ); assertEquals(cmd.getCommand("bar")?.getEnvVar("bar")?.name, "bar"); assertEquals(cmd.getCommand("bar")?.getEnvVar("bar_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getEnvVar("bar_hidden", true)?.name, "bar_hidden"); + assertEquals( + cmd.getCommand("bar")?.getEnvVar("bar_hidden", true)?.name, + "bar_hidden", + ); assertEquals(cmd.getCommand("bar")?.getEnvVar("unknown")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global")?.name, "global"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global_hidden", true)?.name, "global_hidden"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz")?.name, "baz"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz_hidden", true)?.name, "baz_hidden"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("unknown")?.name, undefined); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global")?.name, + "global", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("global_hidden", true) + ?.name, + "global_hidden", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz")?.name, + "baz", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("baz_hidden", true) + ?.name, + "baz_hidden", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getEnvVar("unknown")?.name, + undefined, + ); }); -Deno.test("[command] - env var - get base env var", () => { +test("[command] - env var - get base env var", () => { const cmd = command(); assertEquals(cmd.getBaseEnvVar("global")?.name, "global"); assertEquals(cmd.getBaseEnvVar("global_hidden")?.name, undefined); @@ -374,22 +442,63 @@ Deno.test("[command] - env var - get base env var", () => { assertEquals(cmd.getBaseEnvVar("foo_hidden", true)?.name, "foo_hidden"); assertEquals(cmd.getBaseEnvVar("unknown")?.name, undefined); assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("global")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("global_hidden", true)?.name, undefined); + assertEquals( + cmd.getCommand("bar")?.getBaseEnvVar("global_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getBaseEnvVar("global_hidden", true)?.name, + undefined, + ); assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("bar")?.name, "bar"); - assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("bar_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("bar_hidden", true)?.name, "bar_hidden"); - assertEquals(cmd.getCommand("bar")?.getBaseEnvVar("unknown")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("global")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("global_hidden", true)?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz")?.name, "baz"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz_hidden", true)?.name, "baz_hidden"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("unknown")?.name, undefined); + assertEquals( + cmd.getCommand("bar")?.getBaseEnvVar("bar_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getBaseEnvVar("bar_hidden", true)?.name, + "bar_hidden", + ); + assertEquals( + cmd.getCommand("bar")?.getBaseEnvVar("unknown")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("global")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("global_hidden") + ?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar( + "global_hidden", + true, + )?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz")?.name, + "baz", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("baz_hidden", true) + ?.name, + "baz_hidden", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getBaseEnvVar("unknown")?.name, + undefined, + ); }); -Deno.test("[command] - env var - get global env var", () => { +test("[command] - env var - get global env var", () => { const cmd = command(); assertEquals(cmd.getGlobalEnvVar("global")?.name, undefined); assertEquals(cmd.getGlobalEnvVar("global_hidden")?.name, undefined); @@ -398,59 +507,106 @@ Deno.test("[command] - env var - get global env var", () => { assertEquals(cmd.getGlobalEnvVar("foo_hidden")?.name, undefined); assertEquals(cmd.getGlobalEnvVar("foo_hidden", true)?.name, undefined); assertEquals(cmd.getGlobalEnvVar("unknown")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("global")?.name, "global"); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("global_hidden", true)?.name, "global_hidden"); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("global")?.name, + "global", + ); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("global_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("global_hidden", true)?.name, + "global_hidden", + ); assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("bar")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("bar_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("bar_hidden", true)?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getGlobalEnvVar("unknown")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("global")?.name, "global"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("global_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("global_hidden", true)?.name, "global_hidden"); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("baz")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("baz_hidden")?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("baz_hidden", true)?.name, undefined); - assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("unknown")?.name, undefined); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("bar_hidden")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("bar_hidden", true)?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getGlobalEnvVar("unknown")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("global")?.name, + "global", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("global_hidden") + ?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar( + "global_hidden", + true, + )?.name, + "global_hidden", + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("baz")?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("baz_hidden") + ?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar( + "baz_hidden", + true, + )?.name, + undefined, + ); + assertEquals( + cmd.getCommand("bar")?.getCommand("baz")?.getGlobalEnvVar("unknown")?.name, + undefined, + ); }); -Deno.test({ +test({ name: "[command] - env var - should override default value from option", async fn() { - Deno.env.set("FOO_BAR", "baz"); + setEnv("FOO_BAR", "baz"); const { options } = await new Command() - .env("FOO_BAR=", "...", {prefix: "FOO_"}) - .option("--bar ", "...", {default: "beep"}) + .env("FOO_BAR=", "...", { prefix: "FOO_" }) + .option("--bar ", "...", { default: "beep" }) .parse([]); - Deno.env.delete("FOO_BAR"); - assertEquals(options, {bar: "baz"}) - } + deleteEnv("FOO_BAR"); + assertEquals(options, { bar: "baz" }); + }, }); -Deno.test({ +test({ name: "[command] - env var - should parse list type", async fn() { - Deno.env.set("FOO_BAR", "1,2,3"); - Deno.env.set("FOO_BAR_BAZ", "1,2,3"); + setEnv("FOO_BAR", "1,2,3"); + setEnv("FOO_BAR_BAZ", "1,2,3"); const { options } = await new Command() .type("test", (type) => [type.value + "!"]) .env("FOO_BAR=", "...") .env("FOO_BAR_BAZ=", "...") .parse([]); - Deno.env.delete("FOO_BAR"); - Deno.env.delete("FOO_BAR_BAZ"); + deleteEnv("FOO_BAR"); + deleteEnv("FOO_BAR_BAZ"); assertEquals(options, { fooBar: [1, 2, 3], fooBarBaz: [["1!"], ["2!"], ["3!"]], }); - } + }, }); -Deno.test({ +test({ name: "[command] - env var - should disable global env vars with noGlobals", async fn() { - Deno.env.set("FOO_BAR", "1,2,3"); - Deno.env.set("FOO_BAR_BAZ", "1,2,3"); + setEnv("FOO_BAR", "1,2,3"); + setEnv("FOO_BAR_BAZ", "1,2,3"); const { options } = await new Command() .globalType("test", (type) => [type.value + "!"]) @@ -461,9 +617,9 @@ Deno.test({ .env("beep", "...") .parse(["biz"]); - Deno.env.delete("FOO_BAR"); - Deno.env.delete("FOO_BAR_BAZ"); + deleteEnv("FOO_BAR"); + deleteEnv("FOO_BAR_BAZ"); assertEquals(options, {}); - } + }, }); diff --git a/command/test/command/error_handler_test.ts b/command/test/command/error_handler_test.ts index 24ee2ab9..0e5bed28 100644 --- a/command/test/command/error_handler_test.ts +++ b/command/test/command/error_handler_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertInstanceOf, assertRejects } from "@std/assert"; import { assertSpyCalls, spy } from "@std/testing/mock"; import { Command, type ErrorHandler, ValidationError } from "../../mod.ts"; -Deno.test("[command] should call error handler on error", async () => { +test("[command] should call error handler on error", async () => { let error: unknown; const errorHandler = (): ErrorHandler => (error, cmd) => { assertInstanceOf(error, ValidationError); @@ -40,7 +41,7 @@ Deno.test("[command] should call error handler on error", async () => { assertEquals(error.cmd.getName(), "child"); }); -Deno.test("[command] should call child error handler on child error", async () => { +test("[command] should call child error handler on child error", async () => { let error: unknown; const errorHandler = (): ErrorHandler => (error, cmd) => { assertInstanceOf(error, ValidationError); @@ -78,7 +79,7 @@ Deno.test("[command] should call child error handler on child error", async () = assertEquals(error.cmd.getName(), "child2"); }); -Deno.test("[command] should handle error with useRawArgs enabled", async () => { +test("[command] should handle error with useRawArgs enabled", async () => { const errorHandlerSpy = spy(); await assertRejects( @@ -103,7 +104,7 @@ Deno.test("[command] should handle error with useRawArgs enabled", async () => { assertSpyCalls(errorHandlerSpy, 1); }); -Deno.test("[command] should handle error on sub command with useRawArgs enabled", async () => { +test("[command] should handle error on sub command with useRawArgs enabled", async () => { const errorHandlerSpy = spy(); await assertRejects( diff --git a/command/test/command/example_test.ts b/command/test/command/example_test.ts index a36fdc9f..a2a05cc1 100644 --- a/command/test/command/example_test.ts +++ b/command/test/command/example_test.ts @@ -1,5 +1,6 @@ // deno-fmt-ignore-file +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; import type { Example } from "../../types.ts"; @@ -11,7 +12,7 @@ function command() { .command("bar"); } -Deno.test("command - example - example properties", () => { +test("command - example - example properties", () => { const cmd = new Command() .throwErrors() .example("foo", "foo ..."); @@ -20,19 +21,19 @@ Deno.test("command - example - example properties", () => { assertEquals(example.description, "foo ..."); }); -Deno.test("command - example - has examples", () => { +test("command - example - has examples", () => { const cmd = command(); assertEquals(cmd.hasExamples(), true); assertEquals(new Command().hasExamples(), false); }); -Deno.test("command - example - get examples", () => { +test("command - example - get examples", () => { const cmd = command(); assertEquals(cmd.getExamples().length, 1); assertEquals(!!cmd.getExamples().find((opt) => opt.name === "foo"), true); }); -Deno.test("command - example - has example", () => { +test("command - example - has example", () => { const cmd = command(); assertEquals(cmd.hasExample("foo"), true); assertEquals(cmd.hasExample("unknown"), false); @@ -40,7 +41,7 @@ Deno.test("command - example - has example", () => { assertEquals(cmd.getCommand("bar")?.hasExample("unknown"), false); }); -Deno.test("command - example - get example", () => { +test("command - example - get example", () => { const cmd = command(); assertEquals(cmd.getExample("foo")?.name, "foo"); assertEquals(cmd.getExample("unknown")?.name, undefined); diff --git a/command/test/command/generic_types_test.ts b/command/test/command/generic_types_test.ts index 94744815..3169e9a3 100644 --- a/command/test/command/generic_types_test.ts +++ b/command/test/command/generic_types_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cliffy/internal/testing/test"; import { Command, EnumType } from "../../mod.ts"; import { assertType, type IsAny, type IsExact } from "@std/testing/types"; // Not required to execute this code, only type check. (() => { - Deno.test({ + test({ name: "[command] - generic types - options and args should be of type any bay default", fn() { @@ -17,7 +18,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - options and args should be of type any with options and arguments", fn() { @@ -34,7 +35,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command with void options", fn() { new Command() @@ -55,7 +56,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command with void options and arguments", fn() { new Command() @@ -66,7 +67,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command with void options and predefined arguments", fn() { @@ -78,7 +79,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command with predefined options and arguments", fn() { @@ -101,7 +102,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - pre-defined constructor types with options", fn() { @@ -142,7 +143,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - chained command", fn() { const cmd = new Command() @@ -216,7 +217,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - add child commands", fn() { const foo = new Command<{ debug?: true; logLevel?: true }>() @@ -323,7 +324,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - simple child command with parent option", fn() { const fooCommand = new Command<{ main?: true }>(); @@ -334,7 +335,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - child command with parent option", fn() { const foo = new Command() @@ -385,7 +386,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - unkown parent option on empty command", fn() { new Command() @@ -394,7 +395,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - unkown parent option", fn() { new Command() @@ -404,7 +405,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - unkown parent option with sub command", fn() { new Command() @@ -419,7 +420,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - global parent option with sub command", fn() { new Command() @@ -433,7 +434,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - incompatible parent option type", fn() { const fooCommand = new Command<{ main?: number }>(); @@ -445,7 +446,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - unkown parent option on command with global option", fn() { @@ -458,7 +459,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - unkown parent option on command with global option 2", fn() { @@ -471,7 +472,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - simple extended command", fn() { class Foo extends Command {} @@ -480,7 +481,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - extended command", fn() { class Foo @@ -501,7 +502,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - extended command with incompatible parent option type", fn() { @@ -514,7 +515,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - return types", fn() { new Command() @@ -542,7 +543,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - just a variadic arg", fn() { new Command() @@ -556,7 +557,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - many arguments", fn() { enum Lang { @@ -591,7 +592,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command arguments", fn() { const colorType = new EnumType(["red", "blue"]); @@ -614,7 +615,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command arguments", fn() { new Command() @@ -626,7 +627,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command arguments with just a variadic argument", fn() { @@ -639,7 +640,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - command arguments with custom types", fn() { const colorType = new EnumType(["red", "blue"]); @@ -662,7 +663,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - environment variables", fn() { const colorType = new EnumType(["red", "blue"]); @@ -696,7 +697,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - env var prefix", fn() { new Command() @@ -712,7 +713,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - option with multiple values", fn() { new Command() @@ -730,7 +731,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - option with equal sign", fn() { new Command() @@ -748,7 +749,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - default value", fn() { const colorType = new EnumType(["red", "blue"]); @@ -781,7 +782,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - value option", fn() { new Command() @@ -860,7 +861,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - collect option", fn() { new Command() @@ -927,7 +928,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - negatable option", fn() { new Command() @@ -950,7 +951,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - parse() return value", async fn() { const { args, cmd, literal, options } = await new Command() @@ -999,7 +1000,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - parse() return value with child commands", async fn() { @@ -1033,7 +1034,7 @@ import { assertType, type IsAny, type IsExact } from "@std/testing/types"; }, }); - Deno.test({ + test({ name: "[command] - generic types - useRawArgs()", fn() { new Command() diff --git a/command/test/command/global_command_test.ts b/command/test/command/global_command_test.ts index a7d18804..ca89d46d 100644 --- a/command/test/command/global_command_test.ts +++ b/command/test/command/global_command_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import { ValidationError } from "../../_errors.ts"; @@ -29,21 +30,21 @@ const cmd = () => ), ); -Deno.test("[command] should execute global command", async () => { +test("[command] should execute global command", async () => { const { options, args } = await cmd().parse(["global", "halo"]); assertEquals(options, {}); assertEquals(args, ["halo"]); }); -Deno.test("[command] should execute global command on sub command", async () => { +test("[command] should execute global command on sub command", async () => { const { options, args } = await cmd().parse(["command1", "global", "halo"]); assertEquals(options, {}); assertEquals(args, ["halo"]); }); -Deno.test("[command] should execute global command on nested sub command", async () => { +test("[command] should execute global command on nested sub command", async () => { const { options, args } = await cmd().parse( ["command1", "command2", "global", "halo"], ); @@ -52,19 +53,27 @@ Deno.test("[command] should execute global command on nested sub command", async assertEquals(args, ["halo"]); }); -Deno.test("[command] should disable global commands with noGlobals", async () => { - await assertRejects( - () => - cmd().parse( - ["command1", "command3", "global", "halo"], - ), - ValidationError, - 'Unknown command "global". Did you mean command "help"?', - ); +test({ + name: "[command] should disable global commands with noGlobals", + ignore: ["node"], + fn: async () => { + await assertRejects( + () => + cmd().parse( + ["command1", "command3", "global", "halo"], + ), + ValidationError, + 'Unknown command "global". Did you mean command "help"?', + ); + }, }); -Deno.test("[command] should not disable global help command with noGlobals", async () => { - await cmd().parse( - ["command1", "command3", "help"], - ); +test({ + name: "[command] should not disable global help command with noGlobals", + ignore: ["node"], + fn: async () => { + await cmd().parse( + ["command1", "command3", "help"], + ); + }, }); diff --git a/command/test/command/help_command_test.ts b/command/test/command/help_command_test.ts index 375f60c7..3962c646 100644 --- a/command/test/command/help_command_test.ts +++ b/command/test/command/help_command_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { CompletionsCommand } from "../../completions/completions_command.ts"; import { HelpCommand } from "../../help/help_command.ts"; @@ -69,7 +70,7 @@ function command(defaultOptions?: boolean, hintOption?: boolean) { return cmd; } -Deno.test({ +test({ name: "command: help command with line break", fn() { const output: string = command(true, true).getHelp(); @@ -112,7 +113,7 @@ Environment variables: }, }); -Deno.test({ +test({ name: "command: help command with line break but without default options", fn() { const output: string = command(false, true).getHelp(); diff --git a/command/test/command/help_test.ts b/command/test/command/help_test.ts index 55c583c2..e78bad32 100644 --- a/command/test/command/help_test.ts +++ b/command/test/command/help_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("[command] help - help string", () => { +test("[command] help - help string", () => { const cmd = new Command() .throwErrors() .help("help: xxx") @@ -13,7 +14,7 @@ Deno.test("[command] help - help string", () => { assertEquals(cmd.getCommand("bar")?.getHelp(), "help: xxx"); }); -Deno.test("[command] help - help handler", () => { +test("[command] help - help handler", () => { const cmd = new Command() .throwErrors() .name("main") @@ -29,7 +30,7 @@ Deno.test("[command] help - help handler", () => { assertEquals(cmd.getCommand("bar")?.getHelp(), "help: bar"); }); -Deno.test("[command] help - override help handler", () => { +test("[command] help - override help handler", () => { const cmd = new Command() .throwErrors() .name("main") @@ -47,7 +48,7 @@ Deno.test("[command] help - override help handler", () => { assertEquals(cmd.getCommand("bar")?.getHelp(), "bar help"); }); -Deno.test("[command] help - help option", async () => { +test("[command] help - help option", async () => { let called = 0; const cmd = new Command() .throwErrors() @@ -69,7 +70,7 @@ Deno.test("[command] help - help option", async () => { assertEquals(called, 4); }); -Deno.test("[command] help - help option action", async () => { +test("[command] help - help option action", async () => { let called = 0; const cmd = new Command() .throwErrors() @@ -93,39 +94,46 @@ Deno.test("[command] help - help option action", async () => { assertEquals(called, 4); }); -Deno.test("[command] help - should set usage", () => { - const cmd = new Command() - .throwErrors() - .help({ colors: false }) - .usage("foo bar") - .arguments(" [bar]"); - - assertEquals( - ` +test({ + name: "[command] help - should set usage", + ignore: ["node"], + fn: () => { + const cmd = new Command() + .throwErrors() + .help({ colors: false }) + .usage("foo bar") + .arguments(" [bar]"); + + assertEquals( + ` Usage: COMMAND foo bar Options: -h, --help - Show this help. `, - cmd.getHelp(), - ); + cmd.getHelp(), + ); + }, }); -Deno.test("[command] help - should group options", () => { - const cmd = new Command() - .throwErrors() - .help({ colors: false }) - .option("--foo", "Foo option.") - .group("Other options") - .option("--bar", "Bar option.") - .option("--baz", "Baz option.") - .group("Other options 2") - .option("--beep", "Beep option.") - .option("--boop", "Boop option."); - - assertEquals( - ` +test({ + name: "[command] help - should group options", + ignore: ["node"], + fn: () => { + const cmd = new Command() + .throwErrors() + .help({ colors: false }) + .option("--foo", "Foo option.") + .group("Other options") + .option("--bar", "Bar option.") + .option("--baz", "Baz option.") + .group("Other options 2") + .option("--beep", "Beep option.") + .option("--boop", "Boop option."); + + assertEquals( + ` Usage: COMMAND Options: @@ -143,21 +151,26 @@ Other options 2: --beep - Beep option. --boop - Boop option. `, - cmd.getHelp(), - ); + cmd.getHelp(), + ); + }, }); -Deno.test("[command] help - should ignore required options for help option", async () => { - const ctx = await new Command() - .noExit() - .name("bug-with-help-and-required-options") - .version("0.1.0") - .description("Help does not work if you have required option(s).") - .command("bar") - .description("Help doesn't work, because -f is required.") - .option("-f, --file ", "file path", { required: true }) - .action((options) => console.log(options)) - .parse(["bar", "--help"]); - - assertEquals(ctx.options, { help: true }); +test({ + name: "[command] help - should ignore required options for help option", + ignore: ["node"], + fn: async () => { + const ctx = await new Command() + .noExit() + .name("bug-with-help-and-required-options") + .version("0.1.0") + .description("Help does not work if you have required option(s).") + .command("bar") + .description("Help doesn't work, because -f is required.") + .option("-f, --file ", "file path", { required: true }) + // .action((options) => console.log(options)) + .parse(["bar", "--help"]); + + assertEquals(ctx.options, { help: true }); + }, }); diff --git a/command/test/command/hidden_command_test.ts b/command/test/command/hidden_command_test.ts index 6f76e73f..81be30f7 100644 --- a/command/test/command/hidden_command_test.ts +++ b/command/test/command/hidden_command_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { stripAnsiCode } from "@std/fmt/colors"; import { CompletionsCommand } from "../../completions/completions_command.ts"; @@ -19,7 +20,7 @@ function command() { .hidden(); } -Deno.test("hidden command", async () => { +test("hidden command", async () => { // deno-lint-ignore no-explicit-any const cmd: Command = command(); const { options, args } = await cmd.parse( @@ -31,7 +32,7 @@ Deno.test("hidden command", async () => { assertEquals(args[1], "output-path"); }); -Deno.test("hidden command help", () => { +test("hidden command help", () => { const cmd = command(); const output: string = cmd.getHelp(); diff --git a/command/test/command/literal_arguments_test.ts b/command/test/command/literal_arguments_test.ts index 554b1f2e..ec97385b 100644 --- a/command/test/command/literal_arguments_test.ts +++ b/command/test/command/literal_arguments_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command literal arguments", async () => { +test("command literal arguments", async () => { const { options, args, literal } = await new Command() .throwErrors() .option("-f, --flag [val:string]", "...") diff --git a/command/test/command/option_test.ts b/command/test/command/option_test.ts index 400f756f..ebe7f9ac 100644 --- a/command/test/command/option_test.ts +++ b/command/test/command/option_test.ts @@ -1,5 +1,6 @@ // deno-fmt-ignore-file +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { bold } from "@std/fmt/colors"; import { Command } from "../../command.ts"; @@ -24,7 +25,7 @@ function command() { ); } -Deno.test("command - option - option properties", () => { +test("command - option - option properties", () => { const option: Option = new Command() .throwErrors() .option("-F, --foo-bar [baz:string]", "test ...", { @@ -74,7 +75,7 @@ Deno.test("command - option - option properties", () => { }]); }); -Deno.test("command - option - has options", () => { +test("command - option - has options", () => { const cmd = command(); assertEquals(cmd.hasOptions(), true); assertEquals(cmd.hasOptions(true), true); @@ -82,7 +83,7 @@ Deno.test("command - option - has options", () => { assertEquals(new Command().hasOptions(true), false); }); -Deno.test("command - option - get options", () => { +test("command - option - get options", () => { const cmd = command(); assertEquals(cmd.getOptions().length, 2); assertEquals(cmd.getOptions(true).length, 4); @@ -96,7 +97,7 @@ Deno.test("command - option - get options", () => { assertEquals(!!cmd.getOptions(true).find((opt) => opt.name === "foo-hidden"), true); }); -Deno.test("command - option - get base options", () => { +test("command - option - get base options", () => { const cmd = command(); assertEquals(cmd.getBaseOptions().length, 2); assertEquals(cmd.getBaseOptions(true).length, 4); @@ -110,7 +111,7 @@ Deno.test("command - option - get base options", () => { assertEquals(!!cmd.getBaseOptions(true).find((opt) => opt.name === "foo-hidden"), true); }); -Deno.test("command - option - get global options", () => { +test("command - option - get global options", () => { const cmd = command(); assertEquals(cmd.getCommand("bar")?.getGlobalOptions().length, 1); assertEquals(cmd.getCommand("bar")?.getGlobalOptions(true).length, 2); @@ -124,7 +125,7 @@ Deno.test("command - option - get global options", () => { assertEquals(!!cmd.getCommand("bar")?.getGlobalOptions(true).find((opt) => opt.name === "foo-hidden"), false); }); -Deno.test("command - option - has option", () => { +test("command - option - has option", () => { const cmd = command(); assertEquals(cmd.hasOption("global"), true); assertEquals(cmd.hasOption("global-hidden"), false); @@ -149,7 +150,7 @@ Deno.test("command - option - has option", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.hasOption("unknown"), false); }); -Deno.test("command - option - get option", () => { +test("command - option - get option", () => { const cmd = command(); assertEquals(cmd.getOption("global")?.name, "global"); assertEquals(cmd.getOption("global-hidden")?.name, undefined); @@ -174,7 +175,7 @@ Deno.test("command - option - get option", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getOption("unknown")?.name, undefined); }); -Deno.test("command - option - get base option", () => { +test("command - option - get base option", () => { const cmd = command(); assertEquals(cmd.getBaseOption("global")?.name, "global"); assertEquals(cmd.getBaseOption("global-hidden")?.name, undefined); @@ -199,7 +200,7 @@ Deno.test("command - option - get base option", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getBaseOption("unknown")?.name, undefined); }); -Deno.test("command - option - get global option", () => { +test("command - option - get global option", () => { const cmd = command(); assertEquals(cmd.getGlobalOption("global")?.name, undefined); assertEquals(cmd.getGlobalOption("global-hidden")?.name, undefined); @@ -224,7 +225,7 @@ Deno.test("command - option - get global option", () => { assertEquals(cmd.getCommand("bar")?.getCommand("baz")?.getGlobalOption("unknown")?.name, undefined); }); -Deno.test("command - option - remove option", () => { +test("command - option - remove option", () => { const cmd = command(); assertEquals(cmd.getOption("foo")?.name, "foo"); assertEquals(cmd.removeOption("foo")?.name, "foo"); @@ -232,7 +233,7 @@ Deno.test("command - option - remove option", () => { assertEquals(cmd.removeOption("foo"), undefined); }); -Deno.test("command - option - duplicate option", () => { +test("command - option - duplicate option", () => { assertThrows( () => { new Command() @@ -250,7 +251,7 @@ Deno.test("command - option - duplicate option", () => { ); }); -Deno.test("command - option - override existing option", async () => { +test("command - option - override existing option", async () => { const { options } = await new Command() .option("-f, --foo", "...") .option("-x, --foo, --foo-override", "...", { override: true }) @@ -258,14 +259,14 @@ Deno.test("command - option - override existing option", async () => { assertEquals(options, { foo: true }); }); -Deno.test("command - option - option value handler", async () => { +test("command - option - option value handler", async () => { const { options } = await new Command() .option("-f, --foo ", "...", (value) => ({ value })) .parse(["--foo", "bar"]); assertEquals(options, { foo: { value: "bar" } }); }); -Deno.test("command - option - global option value handler", async () => { +test("command - option - global option value handler", async () => { const { options } = await new Command() .globalOption("-f, --foo ", "...", (value) => ({ value })) .command("foo") diff --git a/command/test/command/raw_args_test.ts b/command/test/command/raw_args_test.ts index 892d2c5c..18fa70ff 100644 --- a/command/test/command/raw_args_test.ts +++ b/command/test/command/raw_args_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command - raw args - command with useRawArgs disabled", async () => { +test("command - raw args - command with useRawArgs disabled", async () => { const { options, args, literal } = await new Command() .throwErrors() .option("-f, --flag [value:boolean]", "description ...") @@ -26,7 +27,7 @@ Deno.test("command - raw args - command with useRawArgs disabled", async () => { assertEquals(literal, ["--literal-arg1", "--literal-arg2"]); }); -Deno.test("command - raw args - command with useRawArgs enabled", async () => { +test("command - raw args - command with useRawArgs enabled", async () => { const { options, args, literal } = await new Command() .throwErrors() .option("-f, --flag [value:boolean]", "description ...") diff --git a/command/test/command/standalone_test.ts b/command/test/command/standalone_test.ts index 0d43cf4f..d4c81eb4 100644 --- a/command/test/command/standalone_test.ts +++ b/command/test/command/standalone_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { assertSpyCalls, spy } from "@std/testing/mock"; import { Command } from "../../command.ts"; -Deno.test("[command] should execute standalone option action", async () => { +test("[command] should execute standalone option action", async () => { const actionSpy = spy(); const optionActionSpy = spy(); @@ -21,7 +22,7 @@ Deno.test("[command] should execute standalone option action", async () => { assertEquals(options, { standalone: true }); }); -Deno.test("[command] should execute main action with standalone option", async () => { +test("[command] should execute main action with standalone option", async () => { const actionSpy = spy(); const cmd = new Command() @@ -37,7 +38,7 @@ Deno.test("[command] should execute main action with standalone option", async ( assertEquals(options, { standalone: true }); }); -Deno.test("[command] should throw an error if standalone option is combined with other options", async () => { +test("[command] should throw an error if standalone option is combined with other options", async () => { const actionSpy = spy(); const cmd = new Command() diff --git a/command/test/command/stop_early_test.ts b/command/test/command/stop_early_test.ts index 37884977..c94611a0 100644 --- a/command/test/command/stop_early_test.ts +++ b/command/test/command/stop_early_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command stopEarly disable", async () => { +test("command stopEarly disable", async () => { const { options, args, literal } = await new Command() .throwErrors() .option("-f, --flag [value:boolean]", "description ...") @@ -26,7 +27,7 @@ Deno.test("command stopEarly disable", async () => { assertEquals(literal, ["--literal-arg1", "--literal-arg2"]); }); -Deno.test("command stopEarly enabled", async () => { +test("command stopEarly enabled", async () => { const { options, args, literal } = await new Command() .throwErrors() .stopEarly() @@ -56,7 +57,7 @@ Deno.test("command stopEarly enabled", async () => { assertEquals(literal, ["--literal-arg1", "--literal-arg2"]); }); -Deno.test("command stopEarly unknown option", async () => { +test("command stopEarly unknown option", async () => { const cmd = new Command() .throwErrors() .stopEarly() diff --git a/command/test/command/sub_command_test.ts b/command/test/command/sub_command_test.ts index 33c5d42e..efff8163 100644 --- a/command/test/command/sub_command_test.ts +++ b/command/test/command/sub_command_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects, assertThrows } from "@std/assert"; import { Command } from "../../command.ts"; @@ -36,7 +37,7 @@ function command(states: States = {}) { ); } -Deno.test("command - sub command - sub-command with arguments", async () => { +test("command - sub command - sub-command with arguments", async () => { const stats: States = {}; // deno-lint-ignore no-explicit-any const cmd: Command = command(stats); @@ -52,7 +53,7 @@ Deno.test("command - sub command - sub-command with arguments", async () => { assertEquals(stats.action3, undefined); }); -Deno.test("command - sub command - sub-command2 with arguments", async () => { +test("command - sub command - sub-command2 with arguments", async () => { const stats: States = {}; // deno-lint-ignore no-explicit-any const cmd: Command = command(stats); @@ -68,7 +69,7 @@ Deno.test("command - sub command - sub-command2 with arguments", async () => { assertEquals(stats.action3, undefined); }); -Deno.test("command - sub command - nested child command with arguments", async () => { +test("command - sub command - nested child command with arguments", async () => { const stats: States = {}; // deno-lint-ignore no-explicit-any const cmd: Command = command(stats); @@ -84,7 +85,7 @@ Deno.test("command - sub command - nested child command with arguments", async ( assertEquals(stats.action3, true); }); -Deno.test("[command] sub command - sub-command with missing argument", async () => { +test("[command] sub command - sub-command with missing argument", async () => { await assertRejects( async () => { await command().parse(["sub-command", "input-path", "-f"]); @@ -94,7 +95,7 @@ Deno.test("[command] sub command - sub-command with missing argument", async () ); }); -Deno.test("[command] sub command - sub-command with missing flag", async () => { +test("[command] sub command - sub-command with missing flag", async () => { await assertRejects( async () => { await command().parse(["sub-command", "input-path"]); @@ -104,7 +105,7 @@ Deno.test("[command] sub command - sub-command with missing flag", async () => { ); }); -Deno.test("[command] sub command - sub-command 2 with missing argument", async () => { +test("[command] sub command - sub-command 2 with missing argument", async () => { await assertRejects( async () => { await command().parse(["sub-command2", "input-path"]); @@ -114,7 +115,7 @@ Deno.test("[command] sub command - sub-command 2 with missing argument", async ( ); }); -Deno.test("[command] sub command - nested sub-command with missing argument", async () => { +test("[command] sub command - nested sub-command with missing argument", async () => { await assertRejects( async () => { await command().parse(["sub-command2", "sub-command3", "input-path"]); @@ -124,7 +125,7 @@ Deno.test("[command] sub command - nested sub-command with missing argument", as ); }); -Deno.test("[command] sub command - command with empty name", async () => { +test("[command] sub command - command with empty name", async () => { await assertRejects( async () => { await new Command() @@ -136,14 +137,14 @@ Deno.test("[command] sub command - command with empty name", async () => { ); }); -Deno.test("[command] sub command - override child command", async () => { +test("[command] sub command - override child command", async () => { await new Command() .command("foo") .command("foo", "...", true) .parse(["foo"]); }); -Deno.test("[command] sub command - duplicate command name", async () => { +test("[command] sub command - duplicate command name", async () => { await assertRejects( async () => { await new Command() @@ -156,7 +157,7 @@ Deno.test("[command] sub command - duplicate command name", async () => { ); }); -Deno.test("[command] sub command - select sub-command", async () => { +test("[command] sub command - select sub-command", async () => { const cmd = new Command() .command("foo") .command("bar"); diff --git a/command/test/command/throw_test.ts b/command/test/command/throw_test.ts index cd70ac87..e9f3e053 100644 --- a/command/test/command/throw_test.ts +++ b/command/test/command/throw_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertThrows } from "@std/assert"; import { Command, ValidationError } from "../../mod.ts"; -Deno.test("[command] should throw error", () => { +test("[command] should throw error", () => { assertThrows( () => new Command() @@ -12,7 +13,7 @@ Deno.test("[command] should throw error", () => { ); }); -Deno.test("[command] should throw validation error", () => { +test("[command] should throw validation error", () => { assertThrows( () => new Command() diff --git a/command/test/command/version_test.ts b/command/test/command/version_test.ts index d239527a..8fae286f 100644 --- a/command/test/command/version_test.ts +++ b/command/test/command/version_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command - version - version string", () => { +test("command - version - version string", () => { const cmd = new Command() .throwErrors() .version("version: xxx") @@ -13,7 +14,7 @@ Deno.test("command - version - version string", () => { assertEquals(cmd.getCommand("bar")?.getVersion(), "version: xxx"); }); -Deno.test("command - version - version handler", () => { +test("command - version - version handler", () => { const cmd = new Command() .throwErrors() .name("main") @@ -28,7 +29,7 @@ Deno.test("command - version - version handler", () => { assertEquals(cmd.getCommand("bar")?.getVersion(), "version: bar"); }); -Deno.test("command - version - override version", () => { +test("command - version - override version", () => { const cmd = new Command() .throwErrors() .name("main") @@ -46,7 +47,7 @@ Deno.test("command - version - override version", () => { assertEquals(cmd.getCommand("bar")?.getVersion(), "bar version"); }); -Deno.test("command - version - version option", async () => { +test("command - version - version option", async () => { let called = 0; const cmd = new Command() .throwErrors() @@ -67,7 +68,7 @@ Deno.test("command - version - version option", async () => { ); }); -Deno.test("command - version - global version option", async () => { +test("command - version - global version option", async () => { let called = 0; const cmd = new Command() .throwErrors() diff --git a/command/test/integration/command.ts b/command/test/integration/command.ts deleted file mode 100644 index d04c60ac..00000000 --- a/command/test/integration/command.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { - Command, - CompletionsCommand, - HelpCommand, - ValidationError, -} from "../../mod.ts"; -import { EnumType } from "../../types/enum.ts"; - -const cmd = new Command() - .version("1.0.0") - .name("completions-test") - .description(` - Completions test. - - Completions test. - Completions test. - `) - .meta("meta1", "value1") - .meta("meta2", "value2") - .meta("meta3", "value3") - .globalType("color", new EnumType(["blue", "yellow", "red"])) - .globalOption("-g, --global ", "Foo option.") - .option( - "-m, --main ", - ` - Bar option. - foo bar baz. foo bar baz. - - foo bar baz. - foo bar baz. - `, - ) - .option( - "--color=", - "Color option with \"'quotes'\" and ([{brackets}]) \n and line breaks.", - ) - .option("-C, --colors ", "Color option.") - .arguments(" [path...:file]") - .default("help") - // foo - .command( - "foo", - new Command() - .description( - "Foo command with \"'quotes'\" and ([{brackets}]) \n and line breaks.", - ) - .option("-f, --foo", "Foo option.") - // bar - .command("bar", "Bar command.") - .option("-b, --bar", "Bar option.") - .reset(), - ) - .command("bar") - .command("foo:bar") - .option("-f, --file ", "...", { required: true }) - .command("validation-error") - .action(() => { - throw new ValidationError("Validation error message.", { exitCode: 1 }); - }) - .command("help", new HelpCommand().global()) - .command("completions", new CompletionsCommand()); - -if (import.meta.main) { - await cmd.parse(); -} diff --git a/command/test/integration/test.ts b/command/test/integration/test.ts index a76fba26..34ce2c7c 100644 --- a/command/test/integration/test.ts +++ b/command/test/integration/test.ts @@ -1,4 +1,5 @@ -import { snapshotTest } from "../../../testing/snapshot.ts"; +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { snapshotTest } from "@cliffy/testing"; import { CompletionsCommand } from "../../completions/mod.ts"; import { HelpCommand } from "../../help/mod.ts"; import { Command, EnumType, ValidationError } from "../../mod.ts"; @@ -6,7 +7,7 @@ import { Command, EnumType, ValidationError } from "../../mod.ts"; await snapshotTest({ name: "command integration", meta: import.meta, - ignore: Deno.build.os === "windows", + ignore: getOs() === "windows", colors: true, steps: { "should complete boolean arg": { diff --git a/command/test/option/action_test.ts b/command/test/option/action_test.ts index 6cecac0a..b618b348 100644 --- a/command/test/option/action_test.ts +++ b/command/test/option/action_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { assertSpyCall, assertSpyCalls, spy } from "@std/testing/mock"; import sinon from "sinon"; import { Command } from "../../command.ts"; -Deno.test("[command] should execute the action from an option", async () => { +test("[command] should execute the action from an option", async () => { const optionSpy = sinon.spy(); const cmd = new Command() @@ -19,7 +20,7 @@ Deno.test("[command] should execute the action from an option", async () => { assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should execute the action from an child command option", async () => { +test("[command] should execute the action from an child command option", async () => { const optionSpy = sinon.spy(); const subCmd = new Command() @@ -38,7 +39,7 @@ Deno.test("[command] should execute the action from an child command option", as assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should execute the action from an option with dashed option name", async () => { +test("[command] should execute the action from an option with dashed option name", async () => { const optionSpy = sinon.spy(); const cmd = new Command() @@ -54,7 +55,7 @@ Deno.test("[command] should execute the action from an option with dashed option assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should execute the action from an option with dashed option name and a value", async () => { +test("[command] should execute the action from an option with dashed option name and a value", async () => { const optionSpy = sinon.spy(); const cmd = new Command() @@ -72,7 +73,7 @@ Deno.test("[command] should execute the action from an option with dashed option assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should execute the action from an option and the command action", async () => { +test("[command] should execute the action from an option and the command action", async () => { const commandSpy = sinon.spy(); const optionSpy = sinon.spy(); @@ -95,7 +96,7 @@ Deno.test("[command] should execute the action from an option and the command ac assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should not execute the command action when executing an option action", async () => { +test("[command] should not execute the command action when executing an option action", async () => { const commandSpy = sinon.spy(); const optionSpy = sinon.spy(); @@ -118,7 +119,7 @@ Deno.test("[command] should not execute the command action when executing an opt assertEquals(optionSpy.firstCall.args, [options, ...args]); }); -Deno.test("[command] should execute multiple option actions", async () => { +test("[command] should execute multiple option actions", async () => { const commandSpy = spy(); const fooOptionSpy = spy(); const barOptionSpy = spy(); diff --git a/command/test/option/aliases_test.ts b/command/test/option/aliases_test.ts index 7b244336..2eb9b537 100644 --- a/command/test/option/aliases_test.ts +++ b/command/test/option/aliases_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -6,35 +7,35 @@ const cmd = new Command() .option("-f, --flag, --fl, --flags [value:boolean]", "description ...") .action(() => {}); -Deno.test("command optionAliases f", async () => { +test("command optionAliases f", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command optionAliases fl", async () => { +test("command optionAliases fl", async () => { const { options, args } = await cmd.parse(["--fl"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command optionAliases flag", async () => { +test("command optionAliases flag", async () => { const { options, args } = await cmd.parse(["--flag"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command optionAliases flags", async () => { +test("command optionAliases flags", async () => { const { options, args } = await cmd.parse(["--flags"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command optionAliases fInvalidValie", async () => { +test("command optionAliases fInvalidValie", async () => { await assertRejects( async () => { await cmd.parse(["-f", "value"]); @@ -44,7 +45,7 @@ Deno.test("command optionAliases fInvalidValie", async () => { ); }); -Deno.test("command optionAliases flInvalidValue", async () => { +test("command optionAliases flInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["--fl", "value"]); @@ -54,7 +55,7 @@ Deno.test("command optionAliases flInvalidValue", async () => { ); }); -Deno.test("command optionAliases flagInvalidValue", async () => { +test("command optionAliases flagInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["--flag", "value"]); @@ -64,7 +65,7 @@ Deno.test("command optionAliases flagInvalidValue", async () => { ); }); -Deno.test("command optionAliases flagsInvalidValue", async () => { +test("command optionAliases flagsInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["--flags", "value"]); diff --git a/command/test/option/conflicts_test.ts b/command/test/option/conflicts_test.ts index e3d57f79..8bcd6713 100644 --- a/command/test/option/conflicts_test.ts +++ b/command/test/option/conflicts_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -25,7 +26,7 @@ const cmd = new Command() }) .action(() => {}); -Deno.test("command optionConflicts noArguments", async () => { +test("command optionConflicts noArguments", async () => { await assertRejects( async () => { await cmd.parse([]); @@ -35,14 +36,14 @@ Deno.test("command optionConflicts noArguments", async () => { ); }); -Deno.test("command optionConflicts type", async () => { +test("command optionConflicts type", async () => { const { options, args } = await cmd.parse(["-t", "value"]); assertEquals(options, { type: "value" }); assertEquals(args, []); }); -Deno.test("command optionConflicts videoAudioImageType", async () => { +test("command optionConflicts videoAudioImageType", async () => { const { options, args } = await cmd.parse( ["-v", "value", "-a", "value", "--image-type", "value"], ); @@ -54,7 +55,7 @@ Deno.test("command optionConflicts videoAudioImageType", async () => { assertEquals(args, []); }); -Deno.test("command optionConflicts videoAudioImageType", async () => { +test("command optionConflicts videoAudioImageType", async () => { await assertRejects( async () => { await cmd.parse(["-v", "value", "-a", "value"]); diff --git a/command/test/option/default_test.ts b/command/test/option/default_test.ts index e4511579..041ec785 100644 --- a/command/test/option/default_test.ts +++ b/command/test/option/default_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; -Deno.test("command: option -> default", async () => { +test("command: option -> default", async () => { const { options, args } = await new Command() .throwErrors() .option("--flag1", "flag 1") @@ -12,7 +13,7 @@ Deno.test("command: option -> default", async () => { assertEquals(args, []); }); -Deno.test("command: option -> default", async () => { +test("command: option -> default", async () => { const { options, args } = await new Command() .throwErrors() .option("--flag1", "flag 1") @@ -23,7 +24,7 @@ Deno.test("command: option -> default", async () => { assertEquals(args, []); }); -Deno.test("command: option -> default", async () => { +test("command: option -> default", async () => { const { options, args } = await new Command() .throwErrors() .option("--flag1", "flag 1") @@ -34,7 +35,7 @@ Deno.test("command: option -> default", async () => { assertEquals(args, []); }); -Deno.test("command: option -> default", async () => { +test("command: option -> default", async () => { const { options, args } = await new Command() .throwErrors() .option("--flag1", "flag 1") diff --git a/command/test/option/depends_test.ts b/command/test/option/depends_test.ts index a8c829c3..a9afa75d 100644 --- a/command/test/option/depends_test.ts +++ b/command/test/option/depends_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -12,29 +13,33 @@ function command() { ); } -Deno.test("command depends option with default value: should accept no arguments", async () => { +test("command depends option with default value: should accept no arguments", async () => { const { options, args } = await command().parse([]); assertEquals(options, { flag2: "example" }); assertEquals(args, []); }); -Deno.test("command depends option with default value: should accept -h", async () => { - const { options, args } = await command().noExit().parse(["-h"]); +test({ + name: "command depends option with default value: should accept -h", + ignore: ["node"], + fn: async () => { + const { options, args } = await command().noExit().parse(["-h"]); - // @TODO: add help & version option types to command. - assertEquals(options, { flag2: "example", help: true } as unknown); - assertEquals(args, []); + // @TODO: add help & version option types to command. + assertEquals(options, { flag2: "example", help: true } as unknown); + assertEquals(args, []); + }, }); -Deno.test("command depends option with default value: should accept --flag1", async () => { +test("command depends option with default value: should accept --flag1", async () => { const { options, args } = await command().parse(["--flag1"]); assertEquals(options, { flag1: true, flag2: "example" }); assertEquals(args, []); }); -Deno.test("command depends option with default value: should accept --flag1 --flag2 test", async () => { +test("command depends option with default value: should accept --flag1 --flag2 test", async () => { const { options, args } = await command().parse( ["--flag1", "--flag2", "test"], ); @@ -43,7 +48,7 @@ Deno.test("command depends option with default value: should accept --flag1 --fl assertEquals(args, []); }); -Deno.test("command depends option with default value: should not accept --flag2 test", async () => { +test("command depends option with default value: should not accept --flag2 test", async () => { await assertRejects( async () => { await command().parse(["--flag2", "test"]); diff --git a/command/test/option/duplicate_test.ts b/command/test/option/duplicate_test.ts index 30b1f04d..60c7bb54 100644 --- a/command/test/option/duplicate_test.ts +++ b/command/test/option/duplicate_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -7,12 +8,12 @@ const cmd = new Command() .option("--no-flag", "description ...") .action(() => {}); -Deno.test("should not throw an error if single flag is used", async () => { +test("should not throw an error if single flag is used", async () => { const parsedArgs = await cmd.parse(["-f", "true"]); assert(parsedArgs.options.flag === true); }); -Deno.test("command optionDuplicate flag", async () => { +test("command optionDuplicate flag", async () => { await assertRejects( async () => { await cmd.parse(["-f", "-f", "true"]); @@ -22,7 +23,7 @@ Deno.test("command optionDuplicate flag", async () => { ); }); -Deno.test("command optionDuplicate flagLong", async () => { +test("command optionDuplicate flagLong", async () => { await assertRejects( async () => { await cmd.parse(["-f", "--flag"]); @@ -32,7 +33,7 @@ Deno.test("command optionDuplicate flagLong", async () => { ); }); -Deno.test("command optionDuplicate flagTrueLongFalse", async () => { +test("command optionDuplicate flagTrueLongFalse", async () => { await assertRejects( async () => { await cmd.parse(["-f", "true", "--flag", "false"]); @@ -42,7 +43,7 @@ Deno.test("command optionDuplicate flagTrueLongFalse", async () => { ); }); -Deno.test("command optionDuplicate flagTrueNoFlag", async () => { +test("command optionDuplicate flagTrueNoFlag", async () => { await assertRejects( async () => { await cmd.parse(["-f", "true", "--no-flag"]); @@ -52,7 +53,7 @@ Deno.test("command optionDuplicate flagTrueNoFlag", async () => { ); }); -Deno.test("command optionDuplicate flagTrueNoFlagTrue", async () => { +test("command optionDuplicate flagTrueNoFlagTrue", async () => { await assertRejects( async () => { await cmd.parse(["-f", "true", "--no-flag", "true"]); diff --git a/command/test/option/global_test.ts b/command/test/option/global_test.ts index bfa434a5..6a5b7d24 100644 --- a/command/test/option/global_test.ts +++ b/command/test/option/global_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import type { ArgumentValue } from "../../types.ts"; @@ -47,14 +48,14 @@ const cmd = () => .reset(), ); -Deno.test("[command] should parse global options", async () => { +test("[command] should parse global options", async () => { const { options, args } = await cmd().parse(["-g", "halo", "-G", "halo"]); assertEquals(options, { global: "HALO", global2: "halo" }); assertEquals(args, []); }); -Deno.test("[command] should parse global options on sub command", async () => { +test("[command] should parse global options on sub command", async () => { const { options, args } = await cmd().parse([ "cmd1", "-g", @@ -69,7 +70,7 @@ Deno.test("[command] should parse global options on sub command", async () => { assertEquals(args, []); }); -Deno.test("[command] should parse global options on nested sub command", async () => { +test("[command] should parse global options on nested sub command", async () => { const { options, args } = await cmd().parse( ["cmd1", "cmd2", "-g", "foo", "-G", "bar", "-o", "baz"], ); @@ -78,7 +79,7 @@ Deno.test("[command] should parse global options on nested sub command", async ( assertEquals(args, []); }); -Deno.test("[command] should parse global options before sub commands", async () => { +test("[command] should parse global options before sub commands", async () => { const { options, args } = await cmd().parse( ["-g", "foo", "cmd1", "-G", "bar", "cmd2", "-o", "baz"], ); @@ -87,7 +88,7 @@ Deno.test("[command] should parse global options before sub commands", async () assertEquals(args, []); }); -Deno.test("[command] should collect global options before sub commands", async () => { +test("[command] should collect global options before sub commands", async () => { const { options, args } = await new Command() .noExit() .globalOption("--collect ", "...", { collect: true }) @@ -109,7 +110,7 @@ Deno.test("[command] should collect global options before sub commands", async ( assertEquals(args, []); }); -Deno.test("[command] should parse global options before and after normal option", async () => { +test("[command] should parse global options before and after normal option", async () => { const { options, args } = await new Command() .noExit() .globalOption("--global", "...", { collect: true }) @@ -123,7 +124,7 @@ Deno.test("[command] should parse global options before and after normal option" assertEquals(args, []); }); -Deno.test("[command] should disable global options with noGlobals", async () => { +test("[command] should disable global options with noGlobals", async () => { await assertRejects( () => cmd().parse( @@ -134,16 +135,24 @@ Deno.test("[command] should disable global options with noGlobals", async () => ); }); -Deno.test("[command] should not disable global -h option with noGlobals", async () => { - await cmd().parse( - ["cmd1", "cmd3", "-h"], - ); +test({ + name: "[command] should not disable global -h option with noGlobals", + ignore: ["node"], + fn: async () => { + await cmd().parse( + ["cmd1", "cmd3", "-h"], + ); + }, }); -Deno.test("[command] should not disable global --help option with noGlobals", async () => { - await cmd().parse( - ["cmd1", "cmd3", "--help"], - ); +test({ + name: "[command] should not disable global --help option with noGlobals", + ignore: ["node"], + fn: async () => { + await cmd().parse( + ["cmd1", "cmd3", "--help"], + ); + }, }); const cmdWithDefaults = () => @@ -181,7 +190,7 @@ const cmdWithDefaults = () => ), ); -Deno.test("[command] should parse options when used interchangeable and global options have defaults", async () => { +test("[command] should parse options when used interchangeable and global options have defaults", async () => { const { options, args } = await cmdWithDefaults().parse([ "cmd1", "cmd2", diff --git a/command/test/option/hidden_test.ts b/command/test/option/hidden_test.ts index 723ea39c..61f73ffe 100644 --- a/command/test/option/hidden_test.ts +++ b/command/test/option/hidden_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { stripAnsiCode } from "@std/fmt/colors"; import { Command } from "../../command.ts"; @@ -15,7 +16,7 @@ function command() { .hidden(); } -Deno.test("hidden option", async () => { +test("hidden option", async () => { const cmd = command(); const { options, args } = await cmd.parse(["--hidden", "test"]); @@ -23,7 +24,7 @@ Deno.test("hidden option", async () => { assertEquals(args, []); }); -Deno.test("hidden option help", () => { +test("hidden option help", () => { const cmd = command(); const output: string = cmd.getHelp(); diff --git a/command/test/option/list_test.ts b/command/test/option/list_test.ts index be474232..8de80d0c 100644 --- a/command/test/option/list_test.ts +++ b/command/test/option/list_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; @@ -12,14 +13,14 @@ const cmd = new Command() { separator: " " }, ); -Deno.test("command: list option", async () => { +test("command: list option", async () => { const { options, args } = await cmd.parse(["-l", "1,2,3"]); assertEquals(options, { list: [1, 2, 3] }); assertEquals(args, []); }); -Deno.test("command: list option separator", async () => { +test("command: list option separator", async () => { const { options, args } = await cmd.parse(["-o", "1 2 3"]); assertEquals(options, { otherList: ["1", "2", "3"] }); diff --git a/command/test/option/negatable_test.ts b/command/test/option/negatable_test.ts index fdf52606..311cdc8f 100644 --- a/command/test/option/negatable_test.ts +++ b/command/test/option/negatable_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -12,7 +13,7 @@ function command() { .option("--no-remote", "No remote."); } -Deno.test("negatable options with no arguments", async () => { +test("negatable options with no arguments", async () => { const { options, args, literal } = await command().parse([]); assertEquals(options, { @@ -23,7 +24,7 @@ Deno.test("negatable options with no arguments", async () => { assertEquals(literal, []); }); -Deno.test("negatable options with arguments", async () => { +test("negatable options with arguments", async () => { const { options, args, literal } = await command().parse( ["--color", "blue", "--remote", "foo"], ); @@ -37,7 +38,7 @@ Deno.test("negatable options with arguments", async () => { assertEquals(literal, []); }); -Deno.test("negatable flag --no-remote should not depend on --color", async () => { +test("negatable flag --no-remote should not depend on --color", async () => { const { options, args, literal } = await command().parse(["--no-remote"]); assertEquals(options, { @@ -49,7 +50,7 @@ Deno.test("negatable flag --no-remote should not depend on --color", async () => assertEquals(literal, []); }); -Deno.test("negatable flags should negate value", async () => { +test("negatable flags should negate value", async () => { const { options, args, literal } = await command().parse( ["--no-check", "--no-color", "--no-remote"], ); @@ -63,7 +64,7 @@ Deno.test("negatable flags should negate value", async () => { assertEquals(literal, []); }); -Deno.test("negatable options should not be combinable with positive options", async () => { +test("negatable options should not be combinable with positive options", async () => { await assertRejects( async () => { await command().parse(["--color", "--no-color", "--no-check"]); diff --git a/command/test/option/required_test.ts b/command/test/option/required_test.ts index 5a12c568..031d816f 100644 --- a/command/test/option/required_test.ts +++ b/command/test/option/required_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -7,14 +8,14 @@ const cmd = new Command() .option("-f, --flag [value:string]", "description ...", { required: true }) .action(() => {}); -Deno.test("command optionRequired", async () => { +test("command optionRequired", async () => { const { options, args } = await cmd.parse(["-f", "value"]); assertEquals(options, { flag: "value" }); assertEquals(args, []); }); -Deno.test("command optionRequired noArguments", async () => { +test("command optionRequired noArguments", async () => { await assertRejects( async () => { await cmd.parse([]); diff --git a/command/test/option/requires_test.ts b/command/test/option/requires_test.ts index a2bd9a12..9e6c0174 100644 --- a/command/test/option/requires_test.ts +++ b/command/test/option/requires_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -20,7 +21,7 @@ const cmd = new Command() ) .action(() => {}); -Deno.test("command optionRequire videoAudioImageType", async () => { +test("command optionRequire videoAudioImageType", async () => { const { options, args } = await cmd.parse( ["-v", "value", "-a", "value", "--image-type", "value"], ); @@ -32,7 +33,7 @@ Deno.test("command optionRequire videoAudioImageType", async () => { assertEquals(args, []); }); -Deno.test("command optionRequire videoType", async () => { +test("command optionRequire videoType", async () => { await assertRejects( async () => { await cmd.parse(["-v", "value"]); @@ -42,7 +43,7 @@ Deno.test("command optionRequire videoType", async () => { ); }); -Deno.test("command optionRequire audioType", async () => { +test("command optionRequire audioType", async () => { await assertRejects( async () => { await cmd.parse(["-a", "value"]); @@ -52,7 +53,7 @@ Deno.test("command optionRequire audioType", async () => { ); }); -Deno.test("command optionRequire imageType", async () => { +test("command optionRequire imageType", async () => { await assertRejects( async () => { await cmd.parse(["-i", "value"]); @@ -62,7 +63,7 @@ Deno.test("command optionRequire imageType", async () => { ); }); -Deno.test("command optionRequire videoAudio", async () => { +test("command optionRequire videoAudio", async () => { await assertRejects( async () => { await cmd.parse(["-v", "value", "-a", "value"]); @@ -72,7 +73,7 @@ Deno.test("command optionRequire videoAudio", async () => { ); }); -Deno.test("command optionRequire audioVideo", async () => { +test("command optionRequire audioVideo", async () => { await assertRejects( async () => { await cmd.parse(["-a", "value", "-v", "value"]); @@ -82,7 +83,7 @@ Deno.test("command optionRequire audioVideo", async () => { ); }); -Deno.test("command optionRequire imageVideo", async () => { +test("command optionRequire imageVideo", async () => { await assertRejects( async () => { await cmd.parse(["-i", "value", "-v", "value"]); diff --git a/command/test/option/standalone_test.ts b/command/test/option/standalone_test.ts index 90977fc7..da8d8edc 100644 --- a/command/test/option/standalone_test.ts +++ b/command/test/option/standalone_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -7,14 +8,14 @@ const cmd = new Command() .option("-a, --all [value:boolean]", "description ...") .action(() => {}); -Deno.test("command optionStandalone flag", async () => { +test("command optionStandalone flag", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command optionStandalone flagCombine", async () => { +test("command optionStandalone flagCombine", async () => { await assertRejects( async () => { await cmd.parse(["-f", "-a"]); @@ -24,7 +25,7 @@ Deno.test("command optionStandalone flagCombine", async () => { ); }); -Deno.test("command optionStandalone flagCombineLong", async () => { +test("command optionStandalone flagCombineLong", async () => { await assertRejects( async () => { await cmd.parse(["--flag", "--all"]); diff --git a/command/test/option/value_test.ts b/command/test/option/value_test.ts index 7179c07d..858ba7d3 100644 --- a/command/test/option/value_test.ts +++ b/command/test/option/value_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -36,25 +37,25 @@ function cmd() { }); } -Deno.test("command - option - value - collect boolean", async () => { +test("command - option - value - collect boolean", async () => { const { options } = await cmd().parse(["-bbb"]); assertEquals(options, { boolean: [true, true, true], default: "bar" }); }); -Deno.test("command - option - value - function validator with no value", async () => { +test("command - option - value - function validator with no value", async () => { const { options } = await cmd().parse(["-f", "-d"]); assertEquals(options, { function: true, default: "bar" }); }); -Deno.test("command - option - value - function validator with valid value", async () => { +test("command - option - value - function validator with valid value", async () => { const { options } = await cmd().parse(["-f", "foo", "-d"]); assertEquals(options, { function: ["foo"], default: "bar" }); }); -Deno.test("command - option - value - function validator with collected values", async () => { +test("command - option - value - function validator with collected values", async () => { const { options } = await cmd().parse([ "-f", "foo", @@ -68,7 +69,7 @@ Deno.test("command - option - value - function validator with collected values", assertEquals(options, { function: ["foo", "bar", "baz"], default: "bar" }); }); -Deno.test("command - option - value - function validator with invalid value", async () => { +test("command - option - value - function validator with invalid value", async () => { await assertRejects( () => cmd().parse(["-f", "fo", "-d"]), Error, @@ -76,7 +77,7 @@ Deno.test("command - option - value - function validator with invalid value", as ); }); -Deno.test("command - option - value - function validator with incremental value", async () => { +test("command - option - value - function validator with incremental value", async () => { const { options } = await cmd().parse(["-iii"]); assertEquals(options, { incremental: 3, default: "bar" }); diff --git a/command/test/option/variadic_test.ts b/command/test/option/variadic_test.ts index 46826873..0d8ba0b3 100644 --- a/command/test/option/variadic_test.ts +++ b/command/test/option/variadic_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -15,7 +16,7 @@ const cmd = new Command() // Optional: -Deno.test("command optionVariadic optional", async () => { +test("command optionVariadic optional", async () => { const { options, args } = await cmd.parse(["-o"]); assertEquals(options, { optional: true }); @@ -24,14 +25,14 @@ Deno.test("command optionVariadic optional", async () => { // Boolean: -Deno.test("command optionVariadic boolean", async () => { +test("command optionVariadic boolean", async () => { const { options, args } = await cmd.parse(["-b", "1", "0", "true", "false"]); assertEquals(options, { boolean: [true, false, true, false] }); assertEquals(args, []); }); -Deno.test("command optionVariadic booleanInvalidValue", async () => { +test("command optionVariadic booleanInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["-b", "1", "0", "true", "false", "2"]); @@ -43,7 +44,7 @@ Deno.test("command optionVariadic booleanInvalidValue", async () => { // String: -Deno.test("command optionVariadic string", async () => { +test("command optionVariadic string", async () => { const { options, args } = await cmd.parse(["-s", "1", "0", "true", "false"]); assertEquals(options, { string: ["1", "0", "true", "false"] }); @@ -52,14 +53,14 @@ Deno.test("command optionVariadic string", async () => { // Number: -Deno.test("command optionVariadic number", async () => { +test("command optionVariadic number", async () => { const { options, args } = await cmd.parse(["-n", "1", "0", "654", "1.2"]); assertEquals(options, { number: [1, 0, 654, 1.2] }); assertEquals(args, []); }); -Deno.test("command optionVariadic numberInvalidValue", async () => { +test("command optionVariadic numberInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["-n", "1", "0", "654", "abc", "1,2"]); @@ -71,14 +72,14 @@ Deno.test("command optionVariadic numberInvalidValue", async () => { // Exact: -Deno.test("command optionVariadic exact", async () => { +test("command optionVariadic exact", async () => { const { options, args } = await cmd.parse(["-v", "1", "abc", "1"]); assertEquals(options, { variadicOption: [1, "abc", true] }); assertEquals(args, []); }); -Deno.test("command optionVariadic exactInvalidValue", async () => { +test("command optionVariadic exactInvalidValue", async () => { await assertRejects( async () => { await cmd.parse(["-v", "abc", "abc", "1"]); @@ -88,7 +89,7 @@ Deno.test("command optionVariadic exactInvalidValue", async () => { ); }); -Deno.test("command optionVariadic exactMissingValue", async () => { +test("command optionVariadic exactMissingValue", async () => { await assertRejects( async () => { await cmd.parse(["-v", "1"]); @@ -98,14 +99,14 @@ Deno.test("command optionVariadic exactMissingValue", async () => { ); }); -Deno.test("command optionVariadic exactLastOptional", async () => { +test("command optionVariadic exactLastOptional", async () => { const { options, args } = await cmd.parse(["-v", "1", "abc"]); assertEquals(options, { variadicOption: [1, "abc"] }); assertEquals(args, []); }); -Deno.test("command optionVariadic exactLastOptionalVariadic", async () => { +test("command optionVariadic exactLastOptionalVariadic", async () => { const { options, args } = await cmd.parse( ["-v", "1", "abc", "1", "0", "true", "false"], ); diff --git a/command/test/option/wildcard_test.ts b/command/test/option/wildcard_test.ts index f0ef59a6..e02d0d85 100644 --- a/command/test/option/wildcard_test.ts +++ b/command/test/option/wildcard_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -8,13 +9,13 @@ function cmd() { .option("--option2.*.*", "..."); } -Deno.test("[command] wildcard - should allow second level wildcard option", async () => { +test("[command] wildcard - should allow second level wildcard option", async () => { const { options, args } = await cmd().parse(["--option1.foo"]); assertEquals(options, { option1: { foo: true } }); assertEquals(args, []); }); -Deno.test("[command] wildcard - should not allow second level wildcard option", async () => { +test("[command] wildcard - should not allow second level wildcard option", async () => { await assertRejects( () => cmd().parse(["--option2.foo"]), Error, @@ -22,13 +23,13 @@ Deno.test("[command] wildcard - should not allow second level wildcard option", ); }); -Deno.test("[command] wildcard - should allow third level wildcard option", async () => { +test("[command] wildcard - should allow third level wildcard option", async () => { const { options, args } = await cmd().parse(["--option2.foo.bar"]); assertEquals(options, { option2: { foo: { bar: true } } }); assertEquals(args, []); }); -Deno.test("[command] wildcard - should not allow third level wildcard option", async () => { +test("[command] wildcard - should not allow third level wildcard option", async () => { await assertRejects( () => cmd().parse(["--option1.foo.bar"]), Error, diff --git a/command/test/type/boolean_test.ts b/command/test/type/boolean_test.ts index 0d579ed7..2c988a4b 100644 --- a/command/test/type/boolean_test.ts +++ b/command/test/type/boolean_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -23,84 +24,84 @@ const cmd3 = new Command() .option("-a, --color ", "description ...") .action(() => {}); -Deno.test("command - type - boolean - with no value", async () => { +test("command - type - boolean - with no value", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - long flag with no value", async () => { +test("command - type - boolean - long flag with no value", async () => { const { options, args } = await cmd.parse(["--flag"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - with true value", async () => { +test("command - type - boolean - with true value", async () => { const { options, args } = await cmd.parse(["-f", "true"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - long flag with true value", async () => { +test("command - type - boolean - long flag with true value", async () => { const { options, args } = await cmd.parse(["--flag", "true"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - with false value", async () => { +test("command - type - boolean - with false value", async () => { const { options, args } = await cmd.parse(["-f", "false"]); assertEquals(options, { flag: false }); assertEquals(args, []); }); -Deno.test("command - type - boolean - long flag with false value and argument", async () => { +test("command - type - boolean - long flag with false value and argument", async () => { const { options, args } = await cmd.parse(["--flag", "false", "unknown"]); assertEquals(options, { flag: false }); assertEquals(args, ["unknown"]); }); -Deno.test("command - type - boolean - with 1 value", async () => { +test("command - type - boolean - with 1 value", async () => { const { options, args } = await cmd.parse(["-f", "1"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - long flag with 1 value", async () => { +test("command - type - boolean - long flag with 1 value", async () => { const { options, args } = await cmd.parse(["--flag", "1"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - boolean - with 0 value", async () => { +test("command - type - boolean - with 0 value", async () => { const { options, args } = await cmd.parse(["-f", "0"]); assertEquals(options, { flag: false }); assertEquals(args, []); }); -Deno.test("command - type - boolean - long flag with 0 value and argument", async () => { +test("command - type - boolean - long flag with 0 value and argument", async () => { const { options, args } = await cmd.parse(["--flag", "0", "unknown"]); assertEquals(options, { flag: false }); assertEquals(args, ["unknown"]); }); -Deno.test("command - type - boolean - negatable option with argument", async () => { +test("command - type - boolean - negatable option with argument", async () => { const { options, args } = await cmd.parse(["--no-flag", "unknown"]); assertEquals(options, { flag: false }); assertEquals(args, ["unknown"]); }); -Deno.test("command - type - boolean - with invalid value", async () => { +test("command - type - boolean - with invalid value", async () => { await assertRejects( async () => { await cmd.parse(["-f", "unknown"]); @@ -110,7 +111,7 @@ Deno.test("command - type - boolean - with invalid value", async () => { ); }); -Deno.test("command - type - boolean - no arguments allowed", async () => { +test("command - type - boolean - no arguments allowed", async () => { await assertRejects( async () => { await cmd2.parse(["-f", "true", "unknown"]); @@ -120,14 +121,14 @@ Deno.test("command - type - boolean - no arguments allowed", async () => { ); }); -Deno.test("command - type - boolean - negatable option last", async () => { +test("command - type - boolean - negatable option last", async () => { const { options, args } = await cmd3.parse(["--color", "red", "--no-check"]); assertEquals(options, { color: "red", check: false }); assertEquals(args, []); }); -Deno.test("command - type - boolean - negatable option first", async () => { +test("command - type - boolean - negatable option first", async () => { const { options, args } = await cmd3.parse(["--no-check", "--color", "red"]); assertEquals(options, { color: "red", check: false }); diff --git a/command/test/type/custom_test.ts b/command/test/type/custom_test.ts index 128b088e..800c95b0 100644 --- a/command/test/type/custom_test.ts +++ b/command/test/type/custom_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import type { ArgumentValue, TypeHandler } from "../../types.ts"; @@ -30,28 +31,28 @@ const cmd = new Command() .description("...") .action(() => {}); -Deno.test("command - type - custom - with valid value", async () => { +test("command - type - custom - with valid value", async () => { const { options, args } = await cmd.parse(["-e", "my@email.com"]); assertEquals(options, { email: "my@email.com" }); assertEquals(args, []); }); -Deno.test("command - type - custom - long flag with valid value", async () => { +test("command - type - custom - long flag with valid value", async () => { const { options, args } = await cmd.parse(["-E", "my@email.com"]); assertEquals(options, { email2: "my@email.com" }); assertEquals(args, []); }); -Deno.test("command - type - custom - child command with valid value", async () => { +test("command - type - custom - child command with valid value", async () => { const { options, args } = await cmd.parse(["init", "-E", "my@email.com"]); assertEquals(options, { email2: "my@email.com" }); assertEquals(args, []); }); -Deno.test("command - type - custom - with unknown type", async () => { +test("command - type - custom - with unknown type", async () => { await assertRejects( () => cmd.parse(["init", "-e", "my@email.com"]), Error, @@ -59,7 +60,7 @@ Deno.test("command - type - custom - with unknown type", async () => { ); }); -Deno.test("command - type - custom - with invalid value", async () => { +test("command - type - custom - with invalid value", async () => { await assertRejects( () => cmd.parse(["-E", "my @email.com"]), Error, @@ -67,7 +68,7 @@ Deno.test("command - type - custom - with invalid value", async () => { ); }); -Deno.test("command - type - custom - with invalid value on child command", async () => { +test("command - type - custom - with invalid value on child command", async () => { await assertRejects( () => cmd.parse(["init", "-E", "my @email.com"]), Error, @@ -88,7 +89,7 @@ class CustomType extends Type { } } -Deno.test("command - type - custom - generic custom type", async () => { +test("command - type - custom - generic custom type", async () => { const cmd = new Command() .throwErrors() .type("format", new CustomType(["foo", "bar"])) diff --git a/command/test/type/enum_test.ts b/command/test/type/enum_test.ts index 830d904a..ae16581e 100644 --- a/command/test/type/enum_test.ts +++ b/command/test/type/enum_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import { EnumType } from "../../types/enum.ts"; @@ -17,42 +18,42 @@ const cmd = () => .option("--enum-color [value:enum-color]", "description ...") .reset(); -Deno.test("command - type - enum - with no value", async () => { +test("command - type - enum - with no value", async () => { const { options, args } = await cmd().parse(["--array-color"]); assertEquals(options, { arrayColor: true }); assertEquals(args, []); }); -Deno.test("command - type - enum - with array and string value", async () => { +test("command - type - enum - with array and string value", async () => { const { options, args } = await cmd().parse(["--array-color", "red"]); assertEquals(options, { arrayColor: "red" }); assertEquals(args, []); }); -Deno.test("command - type - enum - with array and number value", async () => { +test("command - type - enum - with array and number value", async () => { const { options, args } = await cmd().parse(["--array-color", "1"]); assertEquals(options, { arrayColor: 1 }); assertEquals(args, []); }); -Deno.test("command - type - enum - with array and boolean value", async () => { +test("command - type - enum - with array and boolean value", async () => { const { options, args } = await cmd().parse(["--array-color", "true"]); assertEquals(options, { arrayColor: true }); assertEquals(args, []); }); -Deno.test("command - type - enum - with enum", async () => { +test("command - type - enum - with enum", async () => { const { options, args } = await cmd().parse(["--enum-color", "red"]); assertEquals(options, { enumColor: Color.Red }); assertEquals(args, []); }); -Deno.test("command - type - enum - with array value", async () => { +test("command - type - enum - with array value", async () => { await assertRejects( async () => { await cmd().parse(["--array-color", "green"]); @@ -62,7 +63,7 @@ Deno.test("command - type - enum - with array value", async () => { ); }); -Deno.test("command - type - enum - with enum value", async () => { +test("command - type - enum - with enum value", async () => { await assertRejects( async () => { await cmd().parse(["--enum-color", "green"]); diff --git a/command/test/type/file_test.ts b/command/test/type/file_test.ts index 215bc789..8cc61296 100644 --- a/command/test/type/file_test.ts +++ b/command/test/type/file_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertType, type IsExact } from "@std/testing/types"; import { assertEquals } from "@std/assert"; import { Command } from "../../command.ts"; @@ -13,7 +14,7 @@ function cmd() { }); } -Deno.test("command - type - file - with option", async () => { +test("command - type - file - with option", async () => { const { options, args } = await cmd().parse(["--path", "foo/bar/baz"]); assertType>(true); @@ -23,7 +24,7 @@ Deno.test("command - type - file - with option", async () => { assertEquals(args, []); }); -Deno.test("command - type - file - sub-command with option", async () => { +test("command - type - file - sub-command with option", async () => { const { options, args } = await cmd() .command("foo") .action((options, ...args) => { @@ -39,7 +40,7 @@ Deno.test("command - type - file - sub-command with option", async () => { assertEquals(args, []); }); -Deno.test("command - type - file - with argument", async () => { +test("command - type - file - with argument", async () => { const { options, args } = await cmd().parse(["foo/bar/baz"]); assertType>(true); diff --git a/command/test/type/integer_test.ts b/command/test/type/integer_test.ts index 287fb44a..4bcb7cf0 100644 --- a/command/test/type/integer_test.ts +++ b/command/test/type/integer_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -7,21 +8,21 @@ const cmd = new Command() .option("-F, --flag2 ", "description ...") .action(() => {}); -Deno.test("command - type - integer - with no value", async () => { +test("command - type - integer - with no value", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - integer - with valid value", async () => { +test("command - type - integer - with valid value", async () => { const { options, args } = await cmd.parse(["--flag", "123"]); assertEquals(options, { flag: 123 }); assertEquals(args, []); }); -Deno.test("command - type - integer - with argument", async () => { +test("command - type - integer - with argument", async () => { await assertRejects( async () => { await cmd.parse(["-f", "123", "unknown"]); @@ -31,7 +32,7 @@ Deno.test("command - type - integer - with argument", async () => { ); }); -Deno.test("command - type - integer - with missing value", async () => { +test("command - type - integer - with missing value", async () => { await assertRejects( async () => { await cmd.parse(["-F"]); @@ -41,7 +42,7 @@ Deno.test("command - type - integer - with missing value", async () => { ); }); -Deno.test("command - type - integer - with invalid string value", async () => { +test("command - type - integer - with invalid string value", async () => { await assertRejects( async () => { await cmd.parse(["-f", "abc"]); @@ -51,7 +52,7 @@ Deno.test("command - type - integer - with invalid string value", async () => { ); }); -Deno.test("command - type - integer - with invalid float value", async () => { +test("command - type - integer - with invalid float value", async () => { await assertRejects( async () => { await cmd.parse(["-f", "1.23"]); diff --git a/command/test/type/no_value_test.ts b/command/test/type/no_value_test.ts index 350303b4..a3a5c17a 100644 --- a/command/test/type/no_value_test.ts +++ b/command/test/type/no_value_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; import { HelpCommand } from "../../help/help_command.ts"; @@ -8,19 +9,19 @@ const cmd = new Command() .action(() => {}) .command("help", new HelpCommand()); -Deno.test("command - type - no value - short flag without argument", async () => { +test("command - type - no value - short flag without argument", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - no value - long flag without argument", async () => { +test("command - type - no value - long flag without argument", async () => { const { options, args } = await cmd.parse(["--flag"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - no value - short flag with argument", async () => { +test("command - type - no value - short flag with argument", async () => { await assertRejects( async () => { await cmd.parse(["-f", "true"]); @@ -30,7 +31,7 @@ Deno.test("command - type - no value - short flag with argument", async () => { ); }); -Deno.test("command - type - no value - long flag with argument", async () => { +test("command - type - no value - long flag with argument", async () => { await assertRejects( async () => { await cmd.parse(["--flag", "true"]); diff --git a/command/test/type/number_test.ts b/command/test/type/number_test.ts index 6ea7fbb7..911d89af 100644 --- a/command/test/type/number_test.ts +++ b/command/test/type/number_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -8,21 +9,21 @@ const cmd = new Command() .option("--no-flag", "description ...") .action(() => {}); -Deno.test("command - type - number - with no value", async () => { +test("command - type - number - with no value", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - number - with valid value", async () => { +test("command - type - number - with valid value", async () => { const { options, args } = await cmd.parse(["--flag", "123"]); assertEquals(options, { flag: 123 }); assertEquals(args, []); }); -Deno.test("command - type - number - with argument", async () => { +test("command - type - number - with argument", async () => { await assertRejects( async () => { await cmd.parse(["-f", "123", "unknown"]); @@ -32,7 +33,7 @@ Deno.test("command - type - number - with argument", async () => { ); }); -Deno.test("command - type - number - with missing value", async () => { +test("command - type - number - with missing value", async () => { await assertRejects( async () => { await cmd.parse(["-F"]); @@ -42,7 +43,7 @@ Deno.test("command - type - number - with missing value", async () => { ); }); -Deno.test("command - type - number - with invalid string value", async () => { +test("command - type - number - with invalid string value", async () => { await assertRejects( async () => { await cmd.parse(["-f", "abc"]); diff --git a/command/test/type/string_test.ts b/command/test/type/string_test.ts index e41ed80c..417d60e7 100644 --- a/command/test/type/string_test.ts +++ b/command/test/type/string_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { Command } from "../../command.ts"; @@ -7,21 +8,21 @@ const cmd = new Command() .option("--no-flag", "description ...") .action(() => {}); -Deno.test("command - type - string - with no value", async () => { +test("command - type - string - with no value", async () => { const { options, args } = await cmd.parse(["-f"]); assertEquals(options, { flag: true }); assertEquals(args, []); }); -Deno.test("command - type - string - with valid value", async () => { +test("command - type - string - with valid value", async () => { const { options, args } = await cmd.parse(["--flag", "value"]); assertEquals(options, { flag: "value" }); assertEquals(args, []); }); -Deno.test("command - type - string - no arguments allowed", async () => { +test("command - type - string - no arguments allowed", async () => { await assertRejects( async () => { await cmd.parse(["-f", "value", "unknown"]); diff --git a/command/type.ts b/command/type.ts index 2e654cc7..a7bf8a4c 100644 --- a/command/type.ts +++ b/command/type.ts @@ -25,7 +25,7 @@ import type { * return value; * } * - * public complete(): string[] { + * public override complete(): string[] { * return ["red", "blue"]; * } * } diff --git a/command/types/action_list.ts b/command/types/action_list.ts index 7895413e..3c1dc0f2 100644 --- a/command/types/action_list.ts +++ b/command/types/action_list.ts @@ -8,7 +8,7 @@ export class ActionListType extends StringType { } /** Complete action names. */ - public complete(): string[] { + public override complete(): string[] { return this.cmd.getCompletions() .map((type) => type.name) // filter unique values diff --git a/command/types/boolean.ts b/command/types/boolean.ts index a0818736..f953c375 100644 --- a/command/types/boolean.ts +++ b/command/types/boolean.ts @@ -10,7 +10,7 @@ export class BooleanType extends Type { } /** Complete boolean type. */ - public complete(): string[] { + public override complete(): string[] { return ["true", "false"]; } } diff --git a/command/types/child_command.ts b/command/types/child_command.ts index 542e841f..e7c4efe8 100644 --- a/command/types/child_command.ts +++ b/command/types/child_command.ts @@ -11,7 +11,7 @@ export class ChildCommandType extends StringType { } /** Complete child command names. */ - public complete(cmd: Command): string[] { + public override complete(cmd: Command): string[] { return (this.#cmd ?? cmd)?.getCommands(false) .map((cmd: Command) => cmd.getName()) || []; } diff --git a/command/types/command.ts b/command/types/command.ts index 4722782b..a10e6a0c 100644 --- a/command/types/command.ts +++ b/command/types/command.ts @@ -4,7 +4,7 @@ import { StringType } from "./string.ts"; /** String type with auto completion of sibling command names. */ export class CommandType extends StringType { /** Complete sub-command names of global parent command. */ - public complete(_cmd: Command, parent?: Command): string[] { + public override complete(_cmd: Command, parent?: Command): string[] { return parent?.getCommands(false) .map((cmd: Command) => cmd.getName()) || []; } diff --git a/command/upgrade/get_runtime.ts b/command/upgrade/get_runtime.ts index 36fdd8aa..5fa1d250 100644 --- a/command/upgrade/get_runtime.ts +++ b/command/upgrade/get_runtime.ts @@ -1,8 +1,6 @@ +import type { RuntimeName } from "@cliffy/internal/runtime/runtime-name"; import type { Runtime } from "./runtime.ts"; -/** Names of supported runtimes. */ -export type RuntimeName = "deno" | "node" | "bun"; - /** Result of getRuntime(). */ export interface GetRuntimeResult { runtimeName: RuntimeName; diff --git a/command/upgrade/provider/deno_land_test.ts b/command/upgrade/provider/deno_land_test.ts index 31c25046..43ce3351 100644 --- a/command/upgrade/provider/deno_land_test.ts +++ b/command/upgrade/provider/deno_land_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { mockFetch, @@ -15,123 +16,128 @@ import { DenoLandProvider } from "./deno_land.ts"; import type { Versions } from "../provider.ts"; import { upgrade } from "../upgrade.ts"; -Deno.test("DenoLandProvider", async (ctx) => { - mockGlobalFetch(); - mockGlobalCommand(); - - const provider = new DenoLandProvider({ - main: "foo.ts", - }); - - await ctx.step({ - name: "should return registry url", - fn() { - assertEquals( - provider.getRegistryUrl("foo", "1.0.0"), - "https://deno.land/x/foo@1.0.0", - ); - }, - }); - - await ctx.step({ - name: "should return repository url", - fn() { - assertEquals( - provider.getRepositoryUrl("foo"), - "https://deno.land/x/foo", - ); - }, - }); - - await ctx.step({ - name: "should return versions", - async fn() { - const expectedVersions: Versions = { - latest: "1.0.1", - versions: ["1.0.1", "1.0.0"], - }; - - mockFetch("https://cdn.deno.land/foo/meta/versions.json", { - body: JSON.stringify(expectedVersions), - }); - const versions = await provider.getVersions("foo"); - - assertEquals(versions, expectedVersions); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should check if version is outdated", - async fn() { - const mock = { - body: JSON.stringify({ +test({ + name: "DenoLandProvider", + ignore: ["node"], + fn: async (ctx) => { + mockGlobalFetch(); + mockGlobalCommand(); + + const provider = new DenoLandProvider({ + main: "foo.ts", + }); + + await ctx.step({ + name: "should return registry url", + fn() { + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "https://deno.land/x/foo@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return repository url", + fn() { + assertEquals( + provider.getRepositoryUrl("foo"), + "https://deno.land/x/foo", + ); + }, + }); + + await ctx.step({ + name: "should return versions", + async fn() { + const expectedVersions: Versions = { latest: "1.0.1", versions: ["1.0.1", "1.0.0"], - }), - }; - - mockFetch("https://cdn.deno.land/foo/meta/versions.json", mock); - const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); - assert(isOutdated); - - mockFetch("https://cdn.deno.land/foo/meta/versions.json", mock); - const isNotOutdated = !await provider.isOutdated( - "foo", - "1.0.1", - "latest", - ); - assert(isNotOutdated); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should upgrade to latest version", - async fn() { - const versionsResponse = { - body: JSON.stringify({ - latest: "1.0.1", - versions: ["1.0.1", "1.0.0"], - }), - }; - mockFetch( - "https://cdn.deno.land/foo/meta/versions.json", - versionsResponse, - ); - mockFetch( - "https://cdn.deno.land/foo/meta/versions.json", - versionsResponse, - ); - - mockCommand({ - command: Deno.execPath(), - args: [ - "install", - "--name=foo", - "--global", - "--force", - "--quiet", - "https://deno.land/x/foo@1.0.1/foo.ts", - ], - stdout: "piped", - stderr: "piped", - }); - - await upgrade({ - name: "foo", - from: "1.0.0", - to: "latest", - provider, - }); - - resetFetch(); - resetCommand(); - }, - }); - - resetGlobalFetch(); - resetGlobalCommand(); + }; + + mockFetch("https://cdn.deno.land/foo/meta/versions.json", { + body: JSON.stringify(expectedVersions), + }); + const versions = await provider.getVersions("foo"); + + assertEquals(versions, expectedVersions); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should check if version is outdated", + async fn() { + const mock = { + body: JSON.stringify({ + latest: "1.0.1", + versions: ["1.0.1", "1.0.0"], + }), + }; + + mockFetch("https://cdn.deno.land/foo/meta/versions.json", mock); + const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); + assert(isOutdated); + + mockFetch("https://cdn.deno.land/foo/meta/versions.json", mock); + const isNotOutdated = !await provider.isOutdated( + "foo", + "1.0.1", + "latest", + ); + assert(isNotOutdated); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should upgrade to latest version", + ignore: ["node"], + async fn() { + const versionsResponse = { + body: JSON.stringify({ + latest: "1.0.1", + versions: ["1.0.1", "1.0.0"], + }), + }; + mockFetch( + "https://cdn.deno.land/foo/meta/versions.json", + versionsResponse, + ); + mockFetch( + "https://cdn.deno.land/foo/meta/versions.json", + versionsResponse, + ); + + mockCommand({ + command: Deno.execPath(), + args: [ + "install", + "--name=foo", + "--global", + "--force", + "--quiet", + "https://deno.land/x/foo@1.0.1/foo.ts", + ], + stdout: "piped", + stderr: "piped", + }); + + await upgrade({ + name: "foo", + from: "1.0.0", + to: "latest", + provider, + }); + + resetFetch(); + resetCommand(); + }, + }); + + resetGlobalFetch(); + resetGlobalCommand(); + }, }); diff --git a/command/upgrade/provider/github.ts b/command/upgrade/provider/github.ts index 90edca72..39c8f158 100644 --- a/command/upgrade/provider/github.ts +++ b/command/upgrade/provider/github.ts @@ -73,7 +73,10 @@ export class GithubProvider extends Provider { return new URL(`${this.repositoryName}/${version}`, this.registryUrl).href; } - async listVersions(name: string, currentVersion?: string): Promise { + override async listVersions( + name: string, + currentVersion?: string, + ): Promise { const { tags, branches } = await this.getVersions(name); const showBranches: boolean = !!this.listBranches && branches.length > 0; const indent = showBranches ? 2 : 0; diff --git a/command/upgrade/provider/github_test.ts b/command/upgrade/provider/github_test.ts index e27f342b..9a2fa09d 100644 --- a/command/upgrade/provider/github_test.ts +++ b/command/upgrade/provider/github_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { mockFetch, @@ -14,176 +15,181 @@ import { resetGlobalCommand, } from "@c4spar/mock-command"; -Deno.test("GithubProvider", async (ctx) => { - mockGlobalFetch(); - mockGlobalCommand(); - - const provider = new GithubProvider({ repository: "repo/user" }); - - await ctx.step({ - name: "should return registry url", - fn() { - assertEquals( - provider.getRegistryUrl("foo", "1.0.0"), - "https://raw.githubusercontent.com/repo/user/1.0.0", - ); - }, - }); - - await ctx.step({ - name: "should return repository url", - fn() { - assertEquals( - provider.getRepositoryUrl("foo"), - "https://github.com/repo/user", - ); - }, - }); - - await ctx.step({ - name: "should return versions", - async fn() { - mockFetch("https://api.github.com/repos/repo/user/git/refs/tags", { - body: JSON.stringify([ - { ref: "1.0.0" }, - { ref: "1.0.1" }, - ]), - }); - mockFetch("https://api.github.com/repos/repo/user/branches", { - body: JSON.stringify([ - { name: "branch-1", protected: true }, - { name: "branch-2", protected: false }, - ]), - }); - const versions = await provider.getVersions("foo"); - - assertEquals(versions, { - latest: "1.0.1", - versions: [ +test({ + name: "GithubProvider", + ignore: ["node"], + fn: async (ctx) => { + mockGlobalFetch(); + mockGlobalCommand(); + + const provider = new GithubProvider({ repository: "repo/user" }); + + await ctx.step({ + name: "should return registry url", + fn() { + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "https://raw.githubusercontent.com/repo/user/1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return repository url", + fn() { + assertEquals( + provider.getRepositoryUrl("foo"), + "https://github.com/repo/user", + ); + }, + }); + + await ctx.step({ + name: "should return versions", + async fn() { + mockFetch("https://api.github.com/repos/repo/user/git/refs/tags", { + body: JSON.stringify([ + { ref: "1.0.0" }, + { ref: "1.0.1" }, + ]), + }); + mockFetch("https://api.github.com/repos/repo/user/branches", { + body: JSON.stringify([ + { name: "branch-1", protected: true }, + { name: "branch-2", protected: false }, + ]), + }); + const versions = await provider.getVersions("foo"); + + assertEquals(versions, { + latest: "1.0.1", + versions: [ + "1.0.1", + "1.0.0", + "branch-1 (\x1b[1mProtected\x1b[22m)", + "branch-2 ", + ], + tags: [ + "1.0.1", + "1.0.0", + ], + branches: [ + "branch-1 (\x1b[1mProtected\x1b[22m)", + "branch-2 ", + ], + }); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should check if version is outdated", + async fn() { + const tagsMock = { + body: JSON.stringify([ + { ref: "1.0.0" }, + { ref: "1.0.1" }, + ]), + }; + const branchesMock = { + body: JSON.stringify([ + { name: "branch-1", protected: true }, + { name: "branch-2", protected: false }, + ]), + }; + + mockFetch( + "https://api.github.com/repos/repo/user/git/refs/tags", + tagsMock, + ); + mockFetch( + "https://api.github.com/repos/repo/user/branches", + branchesMock, + ); + const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); + assert(isOutdated); + + mockFetch( + "https://api.github.com/repos/repo/user/git/refs/tags", + tagsMock, + ); + mockFetch( + "https://api.github.com/repos/repo/user/branches", + branchesMock, + ); + const isNotOutdated = !await provider.isOutdated( + "foo", "1.0.1", - "1.0.0", - "branch-1 (\x1b[1mProtected\x1b[22m)", - "branch-2 ", - ], - tags: [ - "1.0.1", - "1.0.0", - ], - branches: [ - "branch-1 (\x1b[1mProtected\x1b[22m)", - "branch-2 ", - ], - }); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should check if version is outdated", - async fn() { - const tagsMock = { - body: JSON.stringify([ - { ref: "1.0.0" }, - { ref: "1.0.1" }, - ]), - }; - const branchesMock = { - body: JSON.stringify([ - { name: "branch-1", protected: true }, - { name: "branch-2", protected: false }, - ]), - }; - - mockFetch( - "https://api.github.com/repos/repo/user/git/refs/tags", - tagsMock, - ); - mockFetch( - "https://api.github.com/repos/repo/user/branches", - branchesMock, - ); - const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); - assert(isOutdated); - - mockFetch( - "https://api.github.com/repos/repo/user/git/refs/tags", - tagsMock, - ); - mockFetch( - "https://api.github.com/repos/repo/user/branches", - branchesMock, - ); - const isNotOutdated = !await provider.isOutdated( - "foo", - "1.0.1", - "latest", - ); - assert(isNotOutdated); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should upgrade to latest version", - async fn() { - const tagsResponse = { - body: JSON.stringify([ - { ref: "1.0.0" }, - { ref: "1.0.1" }, - ]), - }; - mockFetch( - "https://api.github.com/repos/repo/user/git/refs/tags", - tagsResponse, - ); - mockFetch( - "https://api.github.com/repos/repo/user/git/refs/tags", - tagsResponse, - ); - - const branchesResponse = { - body: JSON.stringify([ - { name: "branch-1", protected: true }, - { name: "branch-2", protected: false }, - ]), - }; - mockFetch( - "https://api.github.com/repos/repo/user/branches", - branchesResponse, - ); - mockFetch( - "https://api.github.com/repos/repo/user/branches", - branchesResponse, - ); - - mockCommand({ - command: Deno.execPath(), - args: [ - "install", - "--name=foo", - "--global", - "--force", - "--quiet", - "https://raw.githubusercontent.com/repo/user/1.0.1", - ], - stdout: "piped", - stderr: "piped", - }); - - await upgrade({ - name: "foo", - from: "1.0.0", - to: "latest", - provider, - }); - - resetFetch(); - resetCommand(); - }, - }); - - resetGlobalFetch(); - resetGlobalCommand(); + "latest", + ); + assert(isNotOutdated); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should upgrade to latest version", + ignore: ["node"], + async fn() { + const tagsResponse = { + body: JSON.stringify([ + { ref: "1.0.0" }, + { ref: "1.0.1" }, + ]), + }; + mockFetch( + "https://api.github.com/repos/repo/user/git/refs/tags", + tagsResponse, + ); + mockFetch( + "https://api.github.com/repos/repo/user/git/refs/tags", + tagsResponse, + ); + + const branchesResponse = { + body: JSON.stringify([ + { name: "branch-1", protected: true }, + { name: "branch-2", protected: false }, + ]), + }; + mockFetch( + "https://api.github.com/repos/repo/user/branches", + branchesResponse, + ); + mockFetch( + "https://api.github.com/repos/repo/user/branches", + branchesResponse, + ); + + mockCommand({ + command: Deno.execPath(), + args: [ + "install", + "--name=foo", + "--global", + "--force", + "--quiet", + "https://raw.githubusercontent.com/repo/user/1.0.1", + ], + stdout: "piped", + stderr: "piped", + }); + + await upgrade({ + name: "foo", + from: "1.0.0", + to: "latest", + provider, + }); + + resetFetch(); + resetCommand(); + }, + }); + + resetGlobalFetch(); + resetGlobalCommand(); + }, }); diff --git a/command/upgrade/provider/jsr_test.ts b/command/upgrade/provider/jsr_test.ts index 75d35fc3..88443915 100644 --- a/command/upgrade/provider/jsr_test.ts +++ b/command/upgrade/provider/jsr_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { mockFetch, @@ -14,127 +15,132 @@ import { resetGlobalCommand, } from "@c4spar/mock-command"; -Deno.test("JsrProvider", async (ctx) => { - mockGlobalFetch(); - mockGlobalCommand(); - - const provider = new JsrProvider({ - scope: "example", - }); - - await ctx.step({ - name: "should return registry url", - fn() { - assertEquals( - provider.getRegistryUrl("foo", "1.0.0"), - "jsr:@example/foo@1.0.0", - ); - }, - }); - - await ctx.step({ - name: "should return repository url", - fn() { - assertEquals( - provider.getRepositoryUrl("foo"), - "https://jsr.io/@example/foo", - ); - }, - }); - - await ctx.step({ - name: "should return versions", - async fn() { - mockFetch("https://jsr.io/@example/foo/meta.json", { - body: JSON.stringify({ +test({ + name: "JsrProvider", + ignore: ["node"], + fn: async (ctx) => { + mockGlobalFetch(); + mockGlobalCommand(); + + const provider = new JsrProvider({ + scope: "example", + }); + + await ctx.step({ + name: "should return registry url", + fn() { + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "jsr:@example/foo@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return repository url", + fn() { + assertEquals( + provider.getRepositoryUrl("foo"), + "https://jsr.io/@example/foo", + ); + }, + }); + + await ctx.step({ + name: "should return versions", + async fn() { + mockFetch("https://jsr.io/@example/foo/meta.json", { + body: JSON.stringify({ + latest: "1.0.1", + versions: { + "1.0.1": null, + "1.0.0": null, + }, + }), + }); + const versions = await provider.getVersions("foo"); + + assertEquals(versions, { latest: "1.0.1", - versions: { - "1.0.1": null, - "1.0.0": null, - }, - }), - }); - const versions = await provider.getVersions("foo"); - - assertEquals(versions, { - latest: "1.0.1", - versions: ["1.0.1", "1.0.0"], - }); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should check if version is outdated", - async fn() { - const mock = { - body: JSON.stringify({ - latest: "1.0.1", - versions: { - "1.0.1": null, - "1.0.0": null, - }, - }), - }; - - mockFetch("https://jsr.io/@example/foo/meta.json", mock); - const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); - assert(isOutdated); - - mockFetch("https://jsr.io/@example/foo/meta.json", mock); - const isNotOutdated = !await provider.isOutdated( - "foo", - "1.0.1", - "latest", - ); - assert(isNotOutdated); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should upgrade to latest version", - async fn() { - const versionsResponse = { - body: JSON.stringify({ - latest: "1.0.1", - versions: { - "1.0.1": null, - "1.0.0": null, - }, - }), - }; - mockFetch("https://jsr.io/@example/foo/meta.json", versionsResponse); - mockFetch("https://jsr.io/@example/foo/meta.json", versionsResponse); - - mockCommand({ - command: Deno.execPath(), - args: [ - "install", - "--name=foo", - "--global", - "--force", - "--quiet", - "jsr:@example/foo@1.0.1", - ], - stdout: "piped", - stderr: "piped", - }); - - await upgrade({ - name: "foo", - from: "1.0.0", - to: "latest", - provider, - }); - - resetFetch(); - resetCommand(); - }, - }); - - resetGlobalFetch(); - resetGlobalCommand(); + versions: ["1.0.1", "1.0.0"], + }); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should check if version is outdated", + async fn() { + const mock = { + body: JSON.stringify({ + latest: "1.0.1", + versions: { + "1.0.1": null, + "1.0.0": null, + }, + }), + }; + + mockFetch("https://jsr.io/@example/foo/meta.json", mock); + const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); + assert(isOutdated); + + mockFetch("https://jsr.io/@example/foo/meta.json", mock); + const isNotOutdated = !await provider.isOutdated( + "foo", + "1.0.1", + "latest", + ); + assert(isNotOutdated); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should upgrade to latest version", + ignore: ["node"], + async fn() { + const versionsResponse = { + body: JSON.stringify({ + latest: "1.0.1", + versions: { + "1.0.1": null, + "1.0.0": null, + }, + }), + }; + mockFetch("https://jsr.io/@example/foo/meta.json", versionsResponse); + mockFetch("https://jsr.io/@example/foo/meta.json", versionsResponse); + + mockCommand({ + command: Deno.execPath(), + args: [ + "install", + "--name=foo", + "--global", + "--force", + "--quiet", + "jsr:@example/foo@1.0.1", + ], + stdout: "piped", + stderr: "piped", + }); + + await upgrade({ + name: "foo", + from: "1.0.0", + to: "latest", + provider, + }); + + resetFetch(); + resetCommand(); + }, + }); + + resetGlobalFetch(); + resetGlobalCommand(); + }, }); diff --git a/command/upgrade/provider/nest_land_test.ts b/command/upgrade/provider/nest_land_test.ts index 366bc063..1acb2504 100644 --- a/command/upgrade/provider/nest_land_test.ts +++ b/command/upgrade/provider/nest_land_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { mockFetch, @@ -14,124 +15,129 @@ import { resetGlobalCommand, } from "@c4spar/mock-command"; -Deno.test("NestLandProvider", async (ctx) => { - mockGlobalFetch(); - mockGlobalCommand(); - - const provider = new NestLandProvider({ - main: "foo.ts", - }); - - await ctx.step({ - name: "should return registry url", - fn() { - assertEquals( - provider.getRegistryUrl("foo", "1.0.0"), - "https://x.nest.land/foo@1.0.0", - ); - }, - }); - - await ctx.step({ - name: "should return repository url", - fn() { - assertEquals( - provider.getRepositoryUrl("foo"), - "https://nest.land/package/foo", - ); - }, - }); - - await ctx.step({ - name: "should return versions", - async fn() { - mockFetch("https://nest.land/api/package-client", { - body: JSON.stringify({ - body: { - latestVersion: "foo@1.0.1", - packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], - }, - }), - }); - const versions = await provider.getVersions("foo"); - - assertEquals(versions, { - latest: "1.0.1", - versions: ["1.0.1", "1.0.0"], - }); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should check if version is outdated", - async fn() { - const mock = { - body: JSON.stringify({ - body: { - latestVersion: "foo@1.0.1", - packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], - }, - }), - }; - - mockFetch("https://nest.land/api/package-client", mock); - const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); - assert(isOutdated); - - mockFetch("https://nest.land/api/package-client", mock); - const isNotOutdated = !await provider.isOutdated( - "foo", - "1.0.1", - "latest", - ); - assert(isNotOutdated); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should upgrade to latest version", - async fn() { - const versionsResponse = { - body: JSON.stringify({ - body: { - latestVersion: "1.0.1", - packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], - }, - }), - }; - mockFetch("https://nest.land/api/package-client", versionsResponse); - mockFetch("https://nest.land/api/package-client", versionsResponse); - - mockCommand({ - command: Deno.execPath(), - args: [ - "install", - "--name=foo", - "--global", - "--force", - "--quiet", - "https://x.nest.land/foo@1.0.1/foo.ts", - ], - stdout: "piped", - stderr: "piped", - }); - - await upgrade({ - name: "foo", - from: "1.0.0", - to: "latest", - provider, - }); - - resetFetch(); - resetCommand(); - }, - }); - - resetGlobalFetch(); - resetGlobalCommand(); +test({ + name: "NestLandProvider", + ignore: ["node"], + fn: async (ctx) => { + mockGlobalFetch(); + mockGlobalCommand(); + + const provider = new NestLandProvider({ + main: "foo.ts", + }); + + await ctx.step({ + name: "should return registry url", + fn() { + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "https://x.nest.land/foo@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return repository url", + fn() { + assertEquals( + provider.getRepositoryUrl("foo"), + "https://nest.land/package/foo", + ); + }, + }); + + await ctx.step({ + name: "should return versions", + async fn() { + mockFetch("https://nest.land/api/package-client", { + body: JSON.stringify({ + body: { + latestVersion: "foo@1.0.1", + packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], + }, + }), + }); + const versions = await provider.getVersions("foo"); + + assertEquals(versions, { + latest: "1.0.1", + versions: ["1.0.1", "1.0.0"], + }); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should check if version is outdated", + async fn() { + const mock = { + body: JSON.stringify({ + body: { + latestVersion: "foo@1.0.1", + packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], + }, + }), + }; + + mockFetch("https://nest.land/api/package-client", mock); + const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); + assert(isOutdated); + + mockFetch("https://nest.land/api/package-client", mock); + const isNotOutdated = !await provider.isOutdated( + "foo", + "1.0.1", + "latest", + ); + assert(isNotOutdated); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should upgrade to latest version", + ignore: ["node"], + async fn() { + const versionsResponse = { + body: JSON.stringify({ + body: { + latestVersion: "1.0.1", + packageUploadNames: ["foo@1.0.0", "foo@1.0.1"], + }, + }), + }; + mockFetch("https://nest.land/api/package-client", versionsResponse); + mockFetch("https://nest.land/api/package-client", versionsResponse); + + mockCommand({ + command: Deno.execPath(), + args: [ + "install", + "--name=foo", + "--global", + "--force", + "--quiet", + "https://x.nest.land/foo@1.0.1/foo.ts", + ], + stdout: "piped", + stderr: "piped", + }); + + await upgrade({ + name: "foo", + from: "1.0.0", + to: "latest", + provider, + }); + + resetFetch(); + resetCommand(); + }, + }); + + resetGlobalFetch(); + resetGlobalCommand(); + }, }); diff --git a/command/upgrade/provider/npm.ts b/command/upgrade/provider/npm.ts index 731611cb..c9f66c8f 100644 --- a/command/upgrade/provider/npm.ts +++ b/command/upgrade/provider/npm.ts @@ -5,7 +5,7 @@ export type NpmProviderOptions = & ({ package: string; } | { - scope: string; + scope?: string; name?: string; }); @@ -14,23 +14,28 @@ export class NpmProvider extends Provider { private readonly repositoryUrl = "https://npmjs.org/"; private readonly apiUrl = "https://registry.npmjs.org/"; private readonly packageName?: string; - private readonly packageScope: string; + private readonly packageScope?: string; - constructor({ main, logger, ...options }: NpmProviderOptions) { + constructor({ main, logger, ...options }: NpmProviderOptions = {}) { super({ main, logger }); - this.packageScope = "package" in options - ? options.package.split("/")[0].slice(1) - : options.scope; - this.packageName = "package" in options - ? options.package.split("/")[1] - : options.name; + if ("package" in options) { + if (options.package.startsWith("@")) { + this.packageScope = options.package.split("/")[0].slice(1); + this.packageName = options.package.split("/")[1]; + } else { + this.packageName = options.package; + } + } else { + this.packageScope = options.scope; + this.packageName = options.name; + } } async getVersions( name: string, ): Promise { const response = await fetch( - new URL(`@${this.packageScope}/${this.packageName ?? name}`, this.apiUrl), + new URL(this.#getPackageName(name), this.apiUrl), ); if (!response.ok) { throw new Error( @@ -49,15 +54,19 @@ export class NpmProvider extends Provider { getRepositoryUrl(name: string, version?: string): string { return new URL( - `package/@${this.packageScope}/${this.packageName ?? name}${ - version ? `/v/${version}` : "" - }`, + `package/${this.#getPackageName(name)}${version ? `/v/${version}` : ""}`, this.repositoryUrl, ).href; } getRegistryUrl(name: string, version: string): string { - return `npm:@${this.packageScope}/${this.packageName ?? name}@${version}`; + return `npm:${this.#getPackageName(name)}@${version}`; + } + + #getPackageName(name: string): string { + return `${this.packageScope ? `@${this.packageScope}/` : ""}${ + this.packageName ?? name + }`; } } diff --git a/command/upgrade/provider/npm_test.ts b/command/upgrade/provider/npm_test.ts index 24e44f49..cbe502e3 100644 --- a/command/upgrade/provider/npm_test.ts +++ b/command/upgrade/provider/npm_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assert, assertEquals } from "@std/assert"; import { mockFetch, @@ -14,133 +15,166 @@ import { import { upgrade } from "../upgrade.ts"; import { NpmProvider } from "./npm.ts"; -Deno.test("NpmProvider", async (ctx) => { - mockGlobalFetch(); - mockGlobalCommand(); - - const provider = new NpmProvider({ - scope: "example", - }); - - await ctx.step({ - name: "should return registry url", - fn() { - assertEquals( - provider.getRegistryUrl("foo", "1.0.0"), - "npm:@example/foo@1.0.0", - ); - }, - }); - - await ctx.step({ - name: "should return repository url", - fn() { - assertEquals( - provider.getRepositoryUrl("foo"), - "https://npmjs.org/package/@example/foo", - ); - }, - }); - - await ctx.step({ - name: "should return versions", - async fn() { - mockFetch("https://registry.npmjs.org/@example/foo", { - body: JSON.stringify({ - "dist-tags": { - latest: "1.0.1", - }, - versions: { - "1.0.0": null, - "1.0.1": null, - }, - }), - }); - const versions = await provider.getVersions("foo"); - - assertEquals(versions, { - latest: "1.0.1", - versions: ["1.0.1", "1.0.0"], - }); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should check if version is outdated", - async fn() { - const mock = { - body: JSON.stringify({ - "dist-tags": { - latest: "1.0.1", - }, - versions: { - "1.0.1": null, - "1.0.0": null, - }, - }), - }; - - mockFetch("https://registry.npmjs.org/@example/foo", mock); - const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); - assert(isOutdated); - - mockFetch("https://registry.npmjs.org/@example/foo", mock); - const isNotOutdated = !await provider.isOutdated( - "foo", - "1.0.1", - "latest", - ); - assert(isNotOutdated); - - resetFetch(); - }, - }); - - await ctx.step({ - name: "should upgrade to latest version", - async fn() { - const versionResponse = { - body: JSON.stringify({ - "dist-tags": { - latest: "1.0.1", - }, - versions: { - "1.0.0": null, - "1.0.1": null, - }, - }), - }; - mockFetch("https://registry.npmjs.org/@example/foo", versionResponse); - mockFetch("https://registry.npmjs.org/@example/foo", versionResponse); - - mockCommand({ - command: Deno.execPath(), - args: [ - "install", - "--name=foo", - "--global", - "--force", - "--quiet", - "npm:@example/foo@1.0.1", - ], - stdout: "piped", - stderr: "piped", - }); - - await upgrade({ - name: "foo", - from: "1.0.0", - to: "latest", - provider, - }); - - resetFetch(); - resetCommand(); - }, - }); - - resetGlobalFetch(); - resetGlobalCommand(); +test({ + name: "NpmProvider", + ignore: ["node"], + fn: async (ctx) => { + mockGlobalFetch(); + mockGlobalCommand(); + + const provider = new NpmProvider({ + scope: "example", + }); + + await ctx.step({ + name: "should return registry url", + fn() { + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "npm:@example/foo@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return registry url with package option", + fn() { + const provider = new NpmProvider({ + package: "example", + }); + + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "npm:example@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return registry url with packageName option", + fn() { + const provider = new NpmProvider({ + package: "example", + }); + + assertEquals( + provider.getRegistryUrl("foo", "1.0.0"), + "npm:example@1.0.0", + ); + }, + }); + + await ctx.step({ + name: "should return repository url", + fn() { + assertEquals( + provider.getRepositoryUrl("foo"), + "https://npmjs.org/package/@example/foo", + ); + }, + }); + + await ctx.step({ + name: "should return versions", + async fn() { + mockFetch("https://registry.npmjs.org/@example/foo", { + body: JSON.stringify({ + "dist-tags": { + latest: "1.0.1", + }, + versions: { + "1.0.0": null, + "1.0.1": null, + }, + }), + }); + const versions = await provider.getVersions("foo"); + + assertEquals(versions, { + latest: "1.0.1", + versions: ["1.0.1", "1.0.0"], + }); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should check if version is outdated", + async fn() { + const mock = { + body: JSON.stringify({ + "dist-tags": { + latest: "1.0.1", + }, + versions: { + "1.0.1": null, + "1.0.0": null, + }, + }), + }; + + mockFetch("https://registry.npmjs.org/@example/foo", mock); + const isOutdated = await provider.isOutdated("foo", "1.0.0", "latest"); + assert(isOutdated); + + mockFetch("https://registry.npmjs.org/@example/foo", mock); + const isNotOutdated = !await provider.isOutdated( + "foo", + "1.0.1", + "latest", + ); + assert(isNotOutdated); + + resetFetch(); + }, + }); + + await ctx.step({ + name: "should upgrade to latest version", + ignore: ["node"], + async fn() { + const versionResponse = { + body: JSON.stringify({ + "dist-tags": { + latest: "1.0.1", + }, + versions: { + "1.0.0": null, + "1.0.1": null, + }, + }), + }; + mockFetch("https://registry.npmjs.org/@example/foo", versionResponse); + mockFetch("https://registry.npmjs.org/@example/foo", versionResponse); + + mockCommand({ + command: Deno.execPath(), + args: [ + "install", + "--name=foo", + "--global", + "--force", + "--quiet", + "npm:@example/foo@1.0.1", + ], + stdout: "piped", + stderr: "piped", + }); + + await upgrade({ + name: "foo", + from: "1.0.0", + to: "latest", + provider, + }); + + resetFetch(); + resetCommand(); + }, + }); + + resetGlobalFetch(); + resetGlobalCommand(); + }, }); diff --git a/command/upgrade/runtime/bun_runtime.ts b/command/upgrade/runtime/bun_runtime.ts index f9ce2f46..3160476b 100644 --- a/command/upgrade/runtime/bun_runtime.ts +++ b/command/upgrade/runtime/bun_runtime.ts @@ -3,7 +3,7 @@ import type { Logger } from "../logger.ts"; import { NodeRuntime } from "./node_runtime.ts"; export class BunRuntime extends NodeRuntime { - protected async execute( + protected override async execute( cmdArgs: string[], isJsr: boolean, logger?: Logger, diff --git a/command/upgrade/upgrade_command.ts b/command/upgrade/upgrade_command.ts index c670893e..8e542463 100644 --- a/command/upgrade/upgrade_command.ts +++ b/command/upgrade/upgrade_command.ts @@ -17,6 +17,7 @@ export interface UpgradeCommandOptions< > extends RuntimeOptions { provider: TProvider | Array; runtime?: RuntimeOptionsMap; + spinner?: boolean; } /** @@ -58,7 +59,8 @@ export class UpgradeCommand extends Command { private readonly providers: ReadonlyArray; constructor( - { provider, ...options }: UpgradeCommandOptions, + { provider, spinner: withSpinner = true, ...options }: + UpgradeCommandOptions, ) { super(); this.providers = Array.isArray(provider) ? provider : [provider]; @@ -108,7 +110,9 @@ export class UpgradeCommand extends Command { "-v, --verbose", "Log verbose output.", ) - .option("--no-spinner", "Disable spinner.") + .option("--no-spinner", "Disable spinner.", { + hidden: !withSpinner, + }) .complete("version", () => this.getAllVersions()) .action( async ( @@ -123,7 +127,7 @@ export class UpgradeCommand extends Command { const name: string = this.getMainCommand().getName(); const currentVersion: string | undefined = this.getVersion(); - const spinner = spinnerEnabled + const spinner = withSpinner && spinnerEnabled ? new Spinner({ message: brightBlue( `Upgrading ${bold(name)} from version ${ diff --git a/deno.json b/deno.json new file mode 100644 index 00000000..0bf421a3 --- /dev/null +++ b/deno.json @@ -0,0 +1,68 @@ +{ + "workspace": [ + "ansi", + "command", + "flags", + "internal", + "keycode", + "keypress", + "prompt", + "table", + "testing" + ], + "lock": false, + "exclude": ["dist"], + "tasks": { + "lint": "deno lint && deno fmt --check", + "fmt": "deno fmt", + "node": "pnpm tsx", + "bun": "bun run", + "test": "deno task test:deno", + "test:all": "deno task clean && deno task test:deno && deno task setup:node && deno task test:node && deno task clean", + "test:deno": "deno task test:deno-v2", + "test:deno-v1": "deno task test:deno-v2 --doc --ignore=./CHANGELOG.md", + "test:deno-v2": "deno test --allow-run=deno --allow-env --allow-read --allow-write=./ --parallel", + "test:node": "pnpm tsx --test '!(testing|node_modules)/**/*test.ts'", + "test:bun": "bun test", + "coverage:deno": "deno task coverage:deno-v2", + "coverage:deno-v1": "deno task test:deno-v1 --coverage=./dist/coverage/deno/result $COVERAGE_FILES && deno coverage --lcov ./dist/coverage/deno/result > ./dist/coverage/deno/cov.lcov", + "coverage:deno-v2": "deno task test:deno-v2 --coverage=./dist/coverage/deno/result $COVERAGE_FILES && deno coverage --lcov ./dist/coverage/deno/result > ./dist/coverage/deno/cov.lcov", + "coverage:node": "mkdir -p dist/coverage/node && pnpm tsx --test --experimental-test-coverage --test-reporter=spec --test-reporter=lcov --test-reporter-destination=stdout --test-reporter-destination=./dist/coverage/node/cov.lcov '!(testing|node_modules)/**/*test.ts'", + "coverage:bun": "deno task test:bun --coverage --coverage-reporter=lcov --coverage-dir=./dist/coverage", + "snapshot": "deno task test -- --update", + "check": "deno task check:deno-v2", + "check:deno-v1": "deno check .", + "check:deno-v2": "deno check --doc .", + "setup:deno": "echo nothing todo", + "setup:node": "deno run -A ./tasks/setup_node.ts", + "setup:bun": "deno run -A ./tasks/setup_node.ts --bun", + "clean": "rm -rf dist node_modules .npmrc bun.lockb package.json pnpm-lock.yaml tsconfig.json", + "update": "deno run --allow-read=./ --allow-net --allow-write=./ https://deno.land/x/deno_outdated@0.2.5/cli.ts --ignore README.md CHANGELOG.md CONTRIBUTING.md" + }, + "imports": { + "@c4spar/mock-command": "jsr:@c4spar/mock-command@^1.0.1", + "@c4spar/mock-fetch": "jsr:@c4spar/mock-fetch@^1.0.0", + "@cliffy/ansi": "jsr:@cliffy/ansi@1.0.0-rc.7", + "@cliffy/command": "jsr:@cliffy/command@1.0.0-rc.7", + "@cliffy/flags": "jsr:@cliffy/flags@1.0.0-rc.7", + "@cliffy/internal": "jsr:@cliffy/internal@1.0.0-rc.7", + "@cliffy/keycode": "jsr:@cliffy/keycode@1.0.0-rc.7", + "@cliffy/keypress": "jsr:@cliffy/keypress@1.0.0-rc.7", + "@cliffy/prompt": "jsr:@cliffy/prompt@1.0.0-rc.7", + "@cliffy/table": "jsr:@cliffy/table@1.0.0-rc.7", + "@cliffy/testing": "jsr:@cliffy/testing@1.0.0-rc.7", + "@std/assert": "jsr:@std/assert@~1.0.6", + "@std/async": "jsr:@std/async@~1.0.5", + "@std/cli": "jsr:@std/cli@~1.0.6", + "@std/datetime": "jsr:@std/datetime@~0.225.2", + "@std/encoding": "jsr:@std/encoding@~1.0.5", + "@std/fmt": "jsr:@std/fmt@~1.0.2", + "@std/fs": "jsr:@std/fs@~1.0.4", + "@std/http": "jsr:@std/http@~1.0.7", + "@std/io": "jsr:@std/io@~0.224.9", + "@std/path": "jsr:@std/path@~1.0.6", + "@std/testing": "jsr:@std/testing@1.0.0", + "@std/text": "jsr:@std/text@~1.0.7", + "sinon": "npm:sinon@13.0.2" + } +} diff --git a/examples/ansi/demo.ts b/examples/ansi/demo.ts index 7bc05f1a..03f89af4 100755 --- a/examples/ansi/demo.ts +++ b/examples/ansi/demo.ts @@ -47,7 +47,7 @@ const colorNames1: Array = [ "yellow", "white", "underline", - "stripColor", + "stripAnsiCode", "strikethrough", "reset", "red", diff --git a/examples/ansi/image.ts b/examples/ansi/image.ts index 5a51d4e6..ce67aad0 100755 --- a/examples/ansi/image.ts +++ b/examples/ansi/image.ts @@ -2,6 +2,8 @@ import { image } from "@cliffy/ansi/ansi-escapes"; -const response = await fetch("https://deno.land/images/hashrock_simple.png"); +const response = await fetch( + "https://raw.githubusercontent.com/c4spar/deno-cliffy/main/logo.png", +); const imageBuffer: ArrayBuffer = await response.arrayBuffer(); console.log(image(imageBuffer)); diff --git a/examples/command/custom_option_type_class_completion.ts b/examples/command/custom_option_type_class_completion.ts index b9e61eb8..8ee59927 100755 --- a/examples/command/custom_option_type_class_completion.ts +++ b/examples/command/custom_option_type_class_completion.ts @@ -3,7 +3,7 @@ import { Command, StringType } from "@cliffy/command"; class EmailType extends StringType { - complete(): string[] { + override complete(): string[] { return ["aaa@example.com", "bbb@example.com", "ccc@example.com"]; } } diff --git a/flags/deno.json b/flags/deno.json index 3a0989f8..20c74d38 100644 --- a/flags/deno.json +++ b/flags/deno.json @@ -1,5 +1,5 @@ { - "name": "@windmill-labs/cliffy-flags", - "version": "1.0.0-rc.5", + "name": "@cliffy/flags", + "version": "1.0.0-rc.7", "exports": "./mod.ts" } diff --git a/flags/test/flags/dotted_options_test.ts b/flags/test/flags/dotted_options_test.ts index 8b53a5b6..c26cc332 100644 --- a/flags/test/flags/dotted_options_test.ts +++ b/flags/test/flags/dotted_options_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { ValidationError } from "../../_errors.ts"; import { OptionType } from "../../deprecated.ts"; @@ -18,7 +19,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("[flags] should parse dotted short options", () => { +test("[flags] should parse dotted short options", () => { const { flags, unknown, literal } = parseFlags( ["-b.a", "300", "-b.v", "900"], options, @@ -29,7 +30,7 @@ Deno.test("[flags] should parse dotted short options", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse dotted long options", () => { +test("[flags] should parse dotted long options", () => { const { flags, unknown, literal } = parseFlags( ["--bitrate.audio", "300", "--bitrate.video", "900"], options, @@ -40,7 +41,7 @@ Deno.test("[flags] should parse dotted long options", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse dotted alias options", () => { +test("[flags] should parse dotted alias options", () => { const { flags, unknown, literal } = parseFlags( ["--audio-bitrate", "300", "--video-bitrate", "900"], options, @@ -51,7 +52,7 @@ Deno.test("[flags] should parse dotted alias options", () => { assertEquals(literal, []); }); -Deno.test("[flags] should not parse dotted options with dotted options disabled", () => { +test("[flags] should not parse dotted options with dotted options disabled", () => { const { flags, unknown, literal } = parseFlags( ["-b.a", "300", "-b.v", "900"], { ...options, dotted: false }, @@ -62,7 +63,7 @@ Deno.test("[flags] should not parse dotted options with dotted options disabled" assertEquals(literal, []); }); -Deno.test("[flags] should throw error for missing depending options with dotted option", () => { +test("[flags] should throw error for missing depending options with dotted option", () => { assertThrows( () => parseFlags(["--bitrate.audio", "300"], options), ValidationError, @@ -70,7 +71,7 @@ Deno.test("[flags] should throw error for missing depending options with dotted ); }); -Deno.test("[flags] should throw error for missing depending options with dotted alias option", () => { +test("[flags] should throw error for missing depending options with dotted alias option", () => { assertThrows( () => parseFlags(["--audio-bitrate", "300"], options), ValidationError, @@ -78,7 +79,7 @@ Deno.test("[flags] should throw error for missing depending options with dotted ); }); -Deno.test("[flags] should throw an error for dotted option with invalid value", () => { +test("[flags] should throw an error for dotted option with invalid value", () => { assertThrows( () => parseFlags( diff --git a/flags/test/option/aliases_test.ts b/flags/test/option/aliases_test.ts index e161b1ca..f19d0e0a 100644 --- a/flags/test/option/aliases_test.ts +++ b/flags/test/option/aliases_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -14,7 +15,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags optionAliases f", () => { +test("flags optionAliases f", () => { const { flags, unknown, literal } = parseFlags(["-f"], options); assertEquals(flags, { flag: true }); @@ -22,7 +23,7 @@ Deno.test("flags optionAliases f", () => { assertEquals(literal, []); }); -Deno.test("flags optionAliases fl", () => { +test("flags optionAliases fl", () => { const { flags, unknown, literal } = parseFlags(["--fl"], options); assertEquals(flags, { flag: true }); @@ -30,7 +31,7 @@ Deno.test("flags optionAliases fl", () => { assertEquals(literal, []); }); -Deno.test("flags optionAliases flag", () => { +test("flags optionAliases flag", () => { const { flags, unknown, literal } = parseFlags(["--flag"], options); assertEquals(flags, { flag: true }); @@ -38,7 +39,7 @@ Deno.test("flags optionAliases flag", () => { assertEquals(literal, []); }); -Deno.test("flags optionAliases flags", () => { +test("flags optionAliases flags", () => { const { flags, unknown, literal } = parseFlags(["--flags"], options); assertEquals(flags, { flag: true }); @@ -46,7 +47,7 @@ Deno.test("flags optionAliases flags", () => { assertEquals(literal, []); }); -Deno.test("flags optionAliases InvalidValue f", () => { +test("flags optionAliases InvalidValue f", () => { assertThrows( () => parseFlags(["-f", "value"], options), Error, @@ -54,7 +55,7 @@ Deno.test("flags optionAliases InvalidValue f", () => { ); }); -Deno.test("flags optionAliases InvalidValue fl", () => { +test("flags optionAliases InvalidValue fl", () => { assertThrows( () => parseFlags(["--fl", "value"], options), Error, @@ -62,7 +63,7 @@ Deno.test("flags optionAliases InvalidValue fl", () => { ); }); -Deno.test("flags optionAliases InvalidValue flag", () => { +test("flags optionAliases InvalidValue flag", () => { assertThrows( () => parseFlags(["--flag", "value"], options), Error, @@ -70,7 +71,7 @@ Deno.test("flags optionAliases InvalidValue flag", () => { ); }); -Deno.test("flags optionAliases InvalidValue flags", () => { +test("flags optionAliases InvalidValue flags", () => { assertThrows( () => parseFlags(["--flags", "value"], options), Error, diff --git a/flags/test/option/collect_test.ts b/flags/test/option/collect_test.ts index da63167b..e2d42c71 100644 --- a/flags/test/option/collect_test.ts +++ b/flags/test/option/collect_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -31,7 +32,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags - option - collect - short flag can only occur once", () => { +test("flags - option - collect - short flag can only occur once", () => { assertThrows( () => parseFlags(["-f", "-f"], options), Error, @@ -39,7 +40,7 @@ Deno.test("flags - option - collect - short flag can only occur once", () => { ); }); -Deno.test("flags - option - collect - long flag can only occur once", () => { +test("flags - option - collect - long flag can only occur once", () => { assertThrows( () => parseFlags(["-f", "--flag"], options), Error, @@ -47,7 +48,7 @@ Deno.test("flags - option - collect - long flag can only occur once", () => { ); }); -Deno.test("flags - option - collect - long and short flag can not occur together", () => { +test("flags - option - collect - long and short flag can not occur together", () => { assertThrows( () => parseFlags(["-f", "true", "--flag", "false"], options), Error, @@ -55,7 +56,7 @@ Deno.test("flags - option - collect - long and short flag can not occur together ); }); -Deno.test("flags - option - collect - flag and negatable flag can not occur together", () => { +test("flags - option - collect - flag and negatable flag can not occur together", () => { assertThrows( () => parseFlags(["-f", "--no-flag"], options), Error, @@ -63,7 +64,7 @@ Deno.test("flags - option - collect - flag and negatable flag can not occur toge ); }); -Deno.test("flags - option - collect - collect boolean value", () => { +test("flags - option - collect - collect boolean value", () => { const { flags, unknown, literal } = parseFlags( ["-b", "1", "--boolean", "0"], options, @@ -74,7 +75,7 @@ Deno.test("flags - option - collect - collect boolean value", () => { assertEquals(literal, []); }); -Deno.test("flags - option - collect - collect string value", () => { +test("flags - option - collect - collect string value", () => { const { flags, unknown, literal } = parseFlags( ["-s", "1", "--string", "0"], options, @@ -85,7 +86,7 @@ Deno.test("flags - option - collect - collect string value", () => { assertEquals(literal, []); }); -Deno.test("flags - option - collect - collect number value", () => { +test("flags - option - collect - collect number value", () => { const { flags, unknown, literal } = parseFlags( ["-n", "1", "--number", "0"], options, @@ -96,7 +97,7 @@ Deno.test("flags - option - collect - collect number value", () => { assertEquals(literal, []); }); -Deno.test("flags - option - collect - collect values by default", () => { +test("flags - option - collect - collect values by default", () => { const { flags, unknown, literal } = parseFlags([ "--foo", "1", diff --git a/flags/test/option/conflicts_test.ts b/flags/test/option/conflicts_test.ts index 71142d7d..e806b3b0 100644 --- a/flags/test/option/conflicts_test.ts +++ b/flags/test/option/conflicts_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -35,7 +36,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags optionConflicts noArguments", () => { +test("flags optionConflicts noArguments", () => { assertThrows( () => parseFlags([], options), Error, @@ -43,7 +44,7 @@ Deno.test("flags optionConflicts noArguments", () => { ); }); -Deno.test("flags optionConflicts type", () => { +test("flags optionConflicts type", () => { const { flags, unknown, literal } = parseFlags(["-t", "value"], options); assertEquals(flags, { type: "value" }); @@ -51,7 +52,7 @@ Deno.test("flags optionConflicts type", () => { assertEquals(literal, []); }); -Deno.test("flags optionConflicts videoAudioImageType", () => { +test("flags optionConflicts videoAudioImageType", () => { const { flags, unknown, literal } = parseFlags( ["-v", "value", "-a", "value", "--image-type", "value"], options, @@ -65,7 +66,7 @@ Deno.test("flags optionConflicts videoAudioImageType", () => { assertEquals(literal, []); }); -Deno.test("flags optionConflicts videoTypeDependsOnImageType", () => { +test("flags optionConflicts videoTypeDependsOnImageType", () => { assertThrows( () => parseFlags(["-v", "value", "-a", "value"], options), Error, diff --git a/flags/test/option/default_test.ts b/flags/test/option/default_test.ts index bdae1fee..ccc83f70 100644 --- a/flags/test/option/default_test.ts +++ b/flags/test/option/default_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -45,7 +46,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("[flags] should set default args with empty arguments", () => { +test("[flags] should set default args with empty arguments", () => { const { flags, unknown, literal } = parseFlags([], options); assertEquals(flags, { @@ -61,7 +62,7 @@ Deno.test("[flags] should set default args with empty arguments", () => { assertEquals(literal, []); }); -Deno.test("[flags] should override default values", () => { +test("[flags] should override default values", () => { const { flags, unknown, literal } = parseFlags( [ "-b", @@ -95,7 +96,7 @@ Deno.test("[flags] should override default values", () => { assertEquals(literal, []); }); -Deno.test("[flags] should override default value with optional value", () => { +test("[flags] should override default value with optional value", () => { const { flags, unknown, literal } = parseFlags(["-b"], options); assertEquals(flags, { @@ -111,7 +112,7 @@ Deno.test("[flags] should override default value with optional value", () => { assertEquals(literal, []); }); -Deno.test("[flags] should ignore defaults", () => { +test("[flags] should ignore defaults", () => { const { flags, unknown, literal } = parseFlags([], { ...options, ignoreDefaults: { @@ -131,7 +132,7 @@ Deno.test("[flags] should ignore defaults", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse from context", () => { +test("[flags] should parse from context", () => { const { flags, unknown, literal } = parseFlags({ flags: { bar: true }, unknown: ["--foo"], @@ -154,7 +155,7 @@ Deno.test("[flags] should parse from context", () => { assertEquals(literal, []); }); -Deno.test("[flags] should ignore missing required options which are already parsed", () => { +test("[flags] should ignore missing required options which are already parsed", () => { const { flags, unknown, literal } = parseFlags({ flags: { required: true, diff --git a/flags/test/option/depends_test.ts b/flags/test/option/depends_test.ts index b247b53a..0bd307a4 100644 --- a/flags/test/option/depends_test.ts +++ b/flags/test/option/depends_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -23,7 +24,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags optionDepends noArguments", () => { +test("flags optionDepends noArguments", () => { const { flags, unknown, literal } = parseFlags([], options); assertEquals(flags, {}); @@ -31,7 +32,7 @@ Deno.test("flags optionDepends noArguments", () => { assertEquals(literal, []); }); -Deno.test("flags optionDepends videoAudioImageType", () => { +test("flags optionDepends videoAudioImageType", () => { const { flags, unknown, literal } = parseFlags( ["-v", "value", "-a", "value", "--image-type", "value"], options, @@ -45,7 +46,7 @@ Deno.test("flags optionDepends videoAudioImageType", () => { assertEquals(literal, []); }); -Deno.test("flags optionDepends videoType", () => { +test("flags optionDepends videoType", () => { assertThrows( () => parseFlags(["-v", "value"], options), Error, @@ -53,7 +54,7 @@ Deno.test("flags optionDepends videoType", () => { ); }); -Deno.test("flags optionDepends audioType", () => { +test("flags optionDepends audioType", () => { assertThrows( () => parseFlags(["-a", "value"], options), Error, @@ -61,7 +62,7 @@ Deno.test("flags optionDepends audioType", () => { ); }); -Deno.test("flags optionDepends imageType", () => { +test("flags optionDepends imageType", () => { assertThrows( () => parseFlags(["-i", "value"], options), Error, @@ -69,7 +70,7 @@ Deno.test("flags optionDepends imageType", () => { ); }); -Deno.test("flags optionDepends videoAudio", () => { +test("flags optionDepends videoAudio", () => { assertThrows( () => parseFlags(["-v", "value", "-a", "value"], options), Error, @@ -77,7 +78,7 @@ Deno.test("flags optionDepends videoAudio", () => { ); }); -Deno.test("flags optionDepends audioVideo", () => { +test("flags optionDepends audioVideo", () => { assertThrows( () => parseFlags(["-a", "value", "-v", "value"], options), Error, @@ -85,7 +86,7 @@ Deno.test("flags optionDepends audioVideo", () => { ); }); -Deno.test("flags optionDepends imageVideo", () => { +test("flags optionDepends imageVideo", () => { assertThrows( () => parseFlags(["-i", "value", "-v", "value"], options), Error, @@ -118,7 +119,7 @@ const options2 = { }], }; -Deno.test("flags depends: should accept no arguments", () => { +test("flags depends: should accept no arguments", () => { const { flags, unknown, literal } = parseFlags([], options2); assertEquals(flags, { flag2: false }); @@ -126,7 +127,7 @@ Deno.test("flags depends: should accept no arguments", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --standalone", () => { +test("flags depends: should accept --standalone", () => { const { flags, unknown, literal } = parseFlags(["--standalone"], options2); assertEquals(flags, { standalone: true, flag2: false }); @@ -134,7 +135,7 @@ Deno.test("flags depends: should accept --standalone", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should not accept --flag2", () => { +test("flags depends: should not accept --flag2", () => { assertThrows( () => parseFlags(["--flag2"], options2), Error, @@ -142,7 +143,7 @@ Deno.test("flags depends: should not accept --flag2", () => { ); }); -Deno.test("flags depends: should accept --flag1 --no-flag2", () => { +test("flags depends: should accept --flag1 --no-flag2", () => { const { flags, unknown, literal } = parseFlags( ["--flag1", "--no-flag2"], options2, @@ -153,7 +154,7 @@ Deno.test("flags depends: should accept --flag1 --no-flag2", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --no-flag1 --no-flag2", () => { +test("flags depends: should accept --no-flag1 --no-flag2", () => { const { flags, unknown, literal } = parseFlags( ["--no-flag1", "--no-flag2"], options2, @@ -164,7 +165,7 @@ Deno.test("flags depends: should accept --no-flag1 --no-flag2", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --flag1", () => { +test("flags depends: should accept --flag1", () => { const { flags, unknown, literal } = parseFlags(["--flag1"], options2); assertEquals(flags, { flag1: true, flag2: false }); @@ -172,7 +173,7 @@ Deno.test("flags depends: should accept --flag1", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --flag1 --flag2", () => { +test("flags depends: should accept --flag1 --flag2", () => { const { flags, unknown, literal } = parseFlags( ["--flag1", "--flag2"], options2, @@ -183,7 +184,7 @@ Deno.test("flags depends: should accept --flag1 --flag2", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --flag1 --flag2", () => { +test("flags depends: should accept --flag1 --flag2", () => { const { flags, unknown, literal } = parseFlags( ["--flag1", "--flag2", "true"], options2, @@ -194,7 +195,7 @@ Deno.test("flags depends: should accept --flag1 --flag2", () => { assertEquals(literal, []); }); -Deno.test("flags depends: should accept --flag1 --flag2 false", () => { +test("flags depends: should accept --flag1 --flag2 false", () => { const { flags, unknown, literal } = parseFlags( ["--flag1", "--flag2", "false"], options2, diff --git a/flags/test/option/equls_sign_test.ts b/flags/test/option/equls_sign_test.ts index 39aec34c..cf59ec69 100644 --- a/flags/test/option/equls_sign_test.ts +++ b/flags/test/option/equls_sign_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { parseFlags } from "../../flags.ts"; -Deno.test("[flags] should parse required value with equals sign", () => { +test("[flags] should parse required value with equals sign", () => { const { flags, unknown, literal } = parseFlags(["--foo=bar"], { flags: [{ name: "foo", @@ -15,7 +16,7 @@ Deno.test("[flags] should parse required value with equals sign", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse optional value with equals sign", () => { +test("[flags] should parse optional value with equals sign", () => { const { flags, unknown, literal } = parseFlags(["--foo=bar"], { flags: [{ name: "foo", @@ -30,7 +31,7 @@ Deno.test("[flags] should parse optional value with equals sign", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse required value without equals sign", () => { +test("[flags] should parse required value without equals sign", () => { const { flags, unknown, literal } = parseFlags(["--foo", "bar"], { flags: [{ name: "foo", @@ -44,7 +45,7 @@ Deno.test("[flags] should parse required value without equals sign", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse optional value without equals sign as argument", () => { +test("[flags] should parse optional value without equals sign as argument", () => { const { flags, unknown, literal } = parseFlags(["--foo", "bar"], { flags: [{ name: "foo", @@ -59,7 +60,7 @@ Deno.test("[flags] should parse optional value without equals sign as argument", assertEquals(literal, []); }); -Deno.test("[flags] should parse optional value with leading dash with equals sign", () => { +test("[flags] should parse optional value with leading dash with equals sign", () => { const { flags, unknown, literal } = parseFlags(["--foo=-bar"], { flags: [{ name: "foo", @@ -74,7 +75,7 @@ Deno.test("[flags] should parse optional value with leading dash with equals sig assertEquals(literal, []); }); -Deno.test("[flags] should parse multi short flag with equals sign", () => { +test("[flags] should parse multi short flag with equals sign", () => { const { flags, unknown, literal } = parseFlags(["-abc=foo"]); assertEquals(flags, { a: true, b: true, c: "foo" }); @@ -82,7 +83,7 @@ Deno.test("[flags] should parse multi short flag with equals sign", () => { assertEquals(literal, []); }); -Deno.test("[flags] should parse multi short flag with required equals sign", () => { +test("[flags] should parse multi short flag with required equals sign", () => { const { flags, unknown, literal } = parseFlags(["-abc=foo"], { flags: [{ name: "a", diff --git a/flags/test/option/negatable_test.ts b/flags/test/option/negatable_test.ts index f92efa7d..85e03c96 100644 --- a/flags/test/option/negatable_test.ts +++ b/flags/test/option/negatable_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { parseFlags } from "../../flags.ts"; import type { ParseFlagsOptions } from "../../types.ts"; @@ -15,7 +16,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("negatable flags with no arguments", () => { +test("negatable flags with no arguments", () => { const { flags, unknown, literal } = parseFlags([], options); assertEquals(flags, { @@ -25,7 +26,7 @@ Deno.test("negatable flags with no arguments", () => { assertEquals(literal, []); }); -Deno.test("negatable flags", () => { +test("negatable flags", () => { const { flags, unknown, literal } = parseFlags( ["--no-color", "--no-check"], options, @@ -39,7 +40,7 @@ Deno.test("negatable flags", () => { assertEquals(literal, []); }); -Deno.test("Option with name with negatable flags", () => { +test("Option with name with negatable flags", () => { assertThrows( () => parseFlags(["--color", "--no-color", "--no-check"], options), Error, @@ -47,7 +48,7 @@ Deno.test("Option with name with negatable flags", () => { ); }); -Deno.test("unknown negatable flag", () => { +test("unknown negatable flag", () => { assertThrows( () => parseFlags(["--no-remote"], options), Error, diff --git a/flags/test/option/required_test.ts b/flags/test/option/required_test.ts index 909bff39..5a7d1212 100644 --- a/flags/test/option/required_test.ts +++ b/flags/test/option/required_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -18,7 +19,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags - option - required - required option", () => { +test("flags - option - required - required option", () => { const { flags, unknown, literal } = parseFlags( ["--required", "foo"], options, @@ -29,7 +30,7 @@ Deno.test("flags - option - required - required option", () => { assertEquals(literal, []); }); -Deno.test("flags - option - required - missing required option", () => { +test("flags - option - required - missing required option", () => { assertThrows( () => parseFlags([], options), Error, @@ -37,7 +38,7 @@ Deno.test("flags - option - required - missing required option", () => { ); }); -Deno.test("flags - option - required - required option value", () => { +test("flags - option - required - required option value", () => { const { flags, unknown, literal } = parseFlags( ["--required", "foo", "--required-value", "bar"], options, @@ -52,7 +53,7 @@ Deno.test("flags - option - required - required option value", () => { assertEquals(literal, []); }); -Deno.test("flags - option - required - missing required option value", () => { +test("flags - option - required - missing required option value", () => { assertThrows( () => parseFlags(["--required", "foo", "--required-value"], options), Error, @@ -60,7 +61,7 @@ Deno.test("flags - option - required - missing required option value", () => { ); }); -Deno.test("flags - option - required - required option value with default value", () => { +test("flags - option - required - required option value with default value", () => { const { flags, unknown, literal } = parseFlags( ["--required", "foo", "--required-default", "baz"], options, @@ -71,7 +72,7 @@ Deno.test("flags - option - required - required option value with default value" assertEquals(literal, []); }); -Deno.test("flags - option - required - missing required option value with default value", () => { +test("flags - option - required - missing required option value with default value", () => { assertThrows( () => parseFlags(["--required", "foo", "--required-default"], options), Error, diff --git a/flags/test/option/requires_test.ts b/flags/test/option/requires_test.ts index a34ec820..898e5947 100644 --- a/flags/test/option/requires_test.ts +++ b/flags/test/option/requires_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -23,7 +24,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags optionRequire noArguments", () => { +test("flags optionRequire noArguments", () => { const { flags, unknown, literal } = parseFlags([], options); assertEquals(flags, {}); @@ -31,7 +32,7 @@ Deno.test("flags optionRequire noArguments", () => { assertEquals(literal, []); }); -Deno.test("flags optionRequire videoAudioImageType", () => { +test("flags optionRequire videoAudioImageType", () => { const { flags, unknown, literal } = parseFlags( ["-v", "value", "-a", "value", "--image-type", "value"], options, @@ -45,7 +46,7 @@ Deno.test("flags optionRequire videoAudioImageType", () => { assertEquals(literal, []); }); -Deno.test("flags optionRequire videoType", () => { +test("flags optionRequire videoType", () => { assertThrows( () => parseFlags(["-v", "value"], options), Error, @@ -53,7 +54,7 @@ Deno.test("flags optionRequire videoType", () => { ); }); -Deno.test("flags optionRequire audioType", () => { +test("flags optionRequire audioType", () => { assertThrows( () => parseFlags(["-a", "value"], options), Error, @@ -61,7 +62,7 @@ Deno.test("flags optionRequire audioType", () => { ); }); -Deno.test("flags optionRequire imageType", () => { +test("flags optionRequire imageType", () => { assertThrows( () => parseFlags(["-i", "value"], options), Error, @@ -69,7 +70,7 @@ Deno.test("flags optionRequire imageType", () => { ); }); -Deno.test("flags optionRequire videoAudio", () => { +test("flags optionRequire videoAudio", () => { assertThrows( () => parseFlags(["-v", "value", "-a", "value"], options), Error, @@ -77,7 +78,7 @@ Deno.test("flags optionRequire videoAudio", () => { ); }); -Deno.test("flags optionRequire audioVideo", () => { +test("flags optionRequire audioVideo", () => { assertThrows( () => parseFlags(["-a", "value", "-v", "value"], options), Error, @@ -85,7 +86,7 @@ Deno.test("flags optionRequire audioVideo", () => { ); }); -Deno.test("flags optionRequire imageVideo", () => { +test("flags optionRequire imageVideo", () => { assertThrows( () => parseFlags(["-i", "value", "-v", "value"], options), Error, diff --git a/flags/test/option/standalone_test.ts b/flags/test/option/standalone_test.ts index 5c9142ac..929d4c8f 100644 --- a/flags/test/option/standalone_test.ts +++ b/flags/test/option/standalone_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -19,7 +20,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags optionStandalone flag", () => { +test("flags optionStandalone flag", () => { const { flags, unknown, literal } = parseFlags(["-f"], options); assertEquals(flags, { flag: true, fooBar: 3 }); @@ -27,7 +28,7 @@ Deno.test("flags optionStandalone flag", () => { assertEquals(literal, []); }); -Deno.test("flags optionStandalone flagCombine", () => { +test("flags optionStandalone flagCombine", () => { assertThrows( () => parseFlags(["-f", "-a"], options), Error, @@ -35,7 +36,7 @@ Deno.test("flags optionStandalone flagCombine", () => { ); }); -Deno.test("flags optionStandalone flagCombineLong", () => { +test("flags optionStandalone flagCombineLong", () => { assertThrows( () => parseFlags(["--flag", "--all"], options), Error, diff --git a/flags/test/option/unknown_test.ts b/flags/test/option/unknown_test.ts index c0aa73cc..8255e39e 100644 --- a/flags/test/option/unknown_test.ts +++ b/flags/test/option/unknown_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { parseFlags } from "../../flags.ts"; import type { ParseFlagsOptions } from "../../types.ts"; @@ -9,7 +10,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("unknown flags", () => { +test("unknown flags", () => { const { flags, unknown, literal } = parseFlags( ["-f", "foo", "-", "--", "bar"], options, diff --git a/flags/test/option/value_test.ts b/flags/test/option/value_test.ts index 106b79f7..babf545e 100644 --- a/flags/test/option/value_test.ts +++ b/flags/test/option/value_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -38,7 +39,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags - option - value - collect boolean", () => { +test("flags - option - value - collect boolean", () => { const { flags, unknown, literal } = parseFlags(["-bbb"], options); assertEquals(flags, { boolean: [true, true, true], default: "bar" }); @@ -46,7 +47,7 @@ Deno.test("flags - option - value - collect boolean", () => { assertEquals(literal, []); }); -Deno.test("flags - option - value - function validator with no value", () => { +test("flags - option - value - function validator with no value", () => { const { flags, unknown, literal } = parseFlags(["-f", "-d"], options); assertEquals(flags, { function: true, default: "bar" }); @@ -54,7 +55,7 @@ Deno.test("flags - option - value - function validator with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - option - value - function validator with valid value", () => { +test("flags - option - value - function validator with valid value", () => { const { flags, unknown, literal } = parseFlags(["-f", "foo", "-d"], options); assertEquals(flags, { function: ["foo"], default: "bar" }); @@ -62,7 +63,7 @@ Deno.test("flags - option - value - function validator with valid value", () => assertEquals(literal, []); }); -Deno.test("flags - option - value - function validator with collected values", () => { +test("flags - option - value - function validator with collected values", () => { const { flags, unknown, literal } = parseFlags([ "-f", "foo", @@ -78,7 +79,7 @@ Deno.test("flags - option - value - function validator with collected values", ( assertEquals(literal, []); }); -Deno.test("flags - option - value - function validator with invalid value", () => { +test("flags - option - value - function validator with invalid value", () => { assertThrows( () => parseFlags(["-f", "fo", "-d"], options), Error, @@ -86,7 +87,7 @@ Deno.test("flags - option - value - function validator with invalid value", () = ); }); -Deno.test("flags - option - value - function validator with incremental value", () => { +test("flags - option - value - function validator with incremental value", () => { const { flags } = parseFlags(["-iii"], options); assertEquals(flags, { incremental: 3, default: "bar" }); }); diff --git a/flags/test/option/variadic_test.ts b/flags/test/option/variadic_test.ts index e8bed0a2..d5f6b787 100644 --- a/flags/test/option/variadic_test.ts +++ b/flags/test/option/variadic_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -47,7 +48,7 @@ const options: ParseFlagsOptions = { // Optional: -Deno.test("flags optionVariadic optional", () => { +test("flags optionVariadic optional", () => { const { flags, unknown, literal } = parseFlags(["-o"], options); assertEquals(flags, { optional: true }); @@ -57,7 +58,7 @@ Deno.test("flags optionVariadic optional", () => { // Boolean: -Deno.test("flags optionVariadic boolean", () => { +test("flags optionVariadic boolean", () => { const { flags, unknown, literal } = parseFlags( ["-b", "1", "0", "true", "false"], options, @@ -68,7 +69,7 @@ Deno.test("flags optionVariadic boolean", () => { assertEquals(literal, []); }); -Deno.test("flags optionVariadic booleanInvalidValue", () => { +test("flags optionVariadic booleanInvalidValue", () => { assertThrows( () => parseFlags(["-b", "1", "0", "true", "false", "2"], options), Error, @@ -78,7 +79,7 @@ Deno.test("flags optionVariadic booleanInvalidValue", () => { // String: -Deno.test("flags optionVariadic string", () => { +test("flags optionVariadic string", () => { const { flags, unknown, literal } = parseFlags( ["-s", "1", "0", "true", "false"], options, @@ -91,7 +92,7 @@ Deno.test("flags optionVariadic string", () => { // Number: -Deno.test("flags optionVariadic number", () => { +test("flags optionVariadic number", () => { const { flags, unknown, literal } = parseFlags( ["-n", "1", "0", "654", "1.2"], options, @@ -102,7 +103,7 @@ Deno.test("flags optionVariadic number", () => { assertEquals(literal, []); }); -Deno.test("flags optionVariadic numberInvalidValue", () => { +test("flags optionVariadic numberInvalidValue", () => { assertThrows( () => parseFlags(["-n", "1", "0", "654", "abc", "1,2"], options), Error, @@ -112,7 +113,7 @@ Deno.test("flags optionVariadic numberInvalidValue", () => { // Exact: -Deno.test("flags optionVariadic arg1 + arg2", () => { +test("flags optionVariadic arg1 + arg2", () => { const { flags, unknown, literal } = parseFlags(["-e", "1", "abc"], options); assertEquals(flags, { variadicOption: [1, "abc"] }); @@ -120,7 +121,7 @@ Deno.test("flags optionVariadic arg1 + arg2", () => { assertEquals(literal, []); }); -Deno.test("flags optionVariadic arg1 + arg2 + arg3", () => { +test("flags optionVariadic arg1 + arg2 + arg3", () => { const { flags, unknown, literal } = parseFlags( ["-e", "1", "abc", "def", "1", "true"], options, @@ -131,7 +132,7 @@ Deno.test("flags optionVariadic arg1 + arg2 + arg3", () => { assertEquals(literal, []); }); -Deno.test("flags optionVariadic exactInvalidValue", () => { +test("flags optionVariadic exactInvalidValue", () => { assertThrows( () => parseFlags(["-e", "abc", "def", "ghi", "1"], options), Error, @@ -139,7 +140,7 @@ Deno.test("flags optionVariadic exactInvalidValue", () => { ); }); -Deno.test("flags optionVariadic exactMissingValue", () => { +test("flags optionVariadic exactMissingValue", () => { assertThrows( () => parseFlags(["-e", "1"], options), Error, @@ -147,7 +148,7 @@ Deno.test("flags optionVariadic exactMissingValue", () => { ); }); -Deno.test("flags optionVariadic exactLastOptional", () => { +test("flags optionVariadic exactLastOptional", () => { const { flags, unknown, literal } = parseFlags(["-e", "1", "abc"], options); assertEquals(flags, { variadicOption: [1, "abc"] }); @@ -155,7 +156,7 @@ Deno.test("flags optionVariadic exactLastOptional", () => { assertEquals(literal, []); }); -Deno.test("flags optionVariadic exactLastOptionalVariadic", () => { +test("flags optionVariadic exactLastOptionalVariadic", () => { const { flags, unknown, literal } = parseFlags( ["-e", "1", "abc", "def", "1", "0", "true", "false"], options, diff --git a/flags/test/setting/allow_empty_test.ts b/flags/test/setting/allow_empty_test.ts index b994ad11..03eec4fb 100644 --- a/flags/test/setting/allow_empty_test.ts +++ b/flags/test/setting/allow_empty_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { parseFlags } from "../../flags.ts"; -Deno.test("[flags] should not allow empty by default", () => { +test("[flags] should not allow empty by default", () => { assertThrows( () => parseFlags([], { @@ -15,7 +16,7 @@ Deno.test("[flags] should not allow empty by default", () => { ); }); -Deno.test("[flags] should not allow empty if disabled", () => { +test("[flags] should not allow empty if disabled", () => { assertThrows( () => parseFlags([], { @@ -30,7 +31,7 @@ Deno.test("[flags] should not allow empty if disabled", () => { ); }); -Deno.test("[flags] should allow empty if enabled", () => { +test("[flags] should allow empty if enabled", () => { const { flags, unknown } = parseFlags([], { allowEmpty: true, flags: [{ diff --git a/flags/test/setting/option_test.ts b/flags/test/setting/option_test.ts index 6058520c..d4ca5e90 100644 --- a/flags/test/setting/option_test.ts +++ b/flags/test/setting/option_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; import type { FlagOptions } from "../../types.ts"; -Deno.test("flags option callback", () => { +test("flags option callback", () => { const options: Array<{ option: FlagOptions; value: unknown }> = []; parseFlags([ "--foo", diff --git a/flags/test/setting/stop_early_test.ts b/flags/test/setting/stop_early_test.ts index 1ea8c56c..1e6c3e71 100644 --- a/flags/test/setting/stop_early_test.ts +++ b/flags/test/setting/stop_early_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; -Deno.test("flags stopEarly disable", () => { +test("flags stopEarly disable", () => { const { flags, unknown, literal } = parseFlags([ "-f", "true", @@ -38,7 +39,7 @@ Deno.test("flags stopEarly disable", () => { assertEquals(literal, ["--literal-arg1", "--literal-arg2"]); }); -Deno.test("flags stopEarly enabled", () => { +test("flags stopEarly enabled", () => { const { flags, unknown, literal } = parseFlags([ "-f", "true", @@ -78,7 +79,7 @@ Deno.test("flags stopEarly enabled", () => { assertEquals(literal, ["--literal-arg1", "--literal-arg2"]); }); -Deno.test("flags stopEarly unknown option", () => { +test("flags stopEarly unknown option", () => { assertThrows( () => parseFlags([ diff --git a/flags/test/setting/stop_on_unknown_test.ts b/flags/test/setting/stop_on_unknown_test.ts index c638ff75..aad720e0 100644 --- a/flags/test/setting/stop_on_unknown_test.ts +++ b/flags/test/setting/stop_on_unknown_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; -Deno.test("[flags] should stop on unknown option with stopOnUnknown enabled", () => { +test("[flags] should stop on unknown option with stopOnUnknown enabled", () => { const { flags, unknown, literal } = parseFlags([ "-f", "true", diff --git a/flags/test/type/boolean_test.ts b/flags/test/type/boolean_test.ts index 59642461..7cd064f8 100644 --- a/flags/test/type/boolean_test.ts +++ b/flags/test/type/boolean_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -16,7 +17,7 @@ const options = { }], }; -Deno.test("flags - type - boolean - with no value", () => { +test("flags - type - boolean - with no value", () => { const { flags, unknown, literal } = parseFlags(["-f"], options); assertEquals(flags, { flag: true }); @@ -24,7 +25,7 @@ Deno.test("flags - type - boolean - with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - long flag with no value", () => { +test("flags - type - boolean - long flag with no value", () => { const { flags, unknown, literal } = parseFlags(["--flag"], options); assertEquals(flags, { flag: true }); @@ -32,7 +33,7 @@ Deno.test("flags - type - boolean - long flag with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - with true value", () => { +test("flags - type - boolean - with true value", () => { const { flags, unknown, literal } = parseFlags(["-f", "true"], options); assertEquals(flags, { flag: true }); @@ -40,7 +41,7 @@ Deno.test("flags - type - boolean - with true value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - long flag with true value", () => { +test("flags - type - boolean - long flag with true value", () => { const { flags, unknown, literal } = parseFlags(["--flag", "true"], options); assertEquals(flags, { flag: true }); @@ -48,7 +49,7 @@ Deno.test("flags - type - boolean - long flag with true value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - with false value", () => { +test("flags - type - boolean - with false value", () => { const { flags, unknown, literal } = parseFlags(["-f", "false"], options); assertEquals(flags, { flag: false }); @@ -56,7 +57,7 @@ Deno.test("flags - type - boolean - with false value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - long flag with false value and argument", () => { +test("flags - type - boolean - long flag with false value and argument", () => { const { flags, unknown, literal } = parseFlags( ["--flag", "false", "unknown"], options, @@ -67,7 +68,7 @@ Deno.test("flags - type - boolean - long flag with false value and argument", () assertEquals(literal, []); }); -Deno.test("flags - type - boolean - with 1 value", () => { +test("flags - type - boolean - with 1 value", () => { const { flags, unknown, literal } = parseFlags(["-f", "1"], options); assertEquals(flags, { flag: true }); @@ -75,7 +76,7 @@ Deno.test("flags - type - boolean - with 1 value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - long flag with 1 value", () => { +test("flags - type - boolean - long flag with 1 value", () => { const { flags, unknown, literal } = parseFlags(["--flag", "1"], options); assertEquals(flags, { flag: true }); @@ -83,7 +84,7 @@ Deno.test("flags - type - boolean - long flag with 1 value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - with 0 value", () => { +test("flags - type - boolean - with 0 value", () => { const { flags, unknown, literal } = parseFlags(["-f", "0"], options); assertEquals(flags, { flag: false }); @@ -91,7 +92,7 @@ Deno.test("flags - type - boolean - with 0 value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - long flag with 0 value and argument", () => { +test("flags - type - boolean - long flag with 0 value and argument", () => { const { flags, unknown, literal } = parseFlags( ["--flag", "0", "unknown"], options, @@ -102,7 +103,7 @@ Deno.test("flags - type - boolean - long flag with 0 value and argument", () => assertEquals(literal, []); }); -Deno.test("flags - type - boolean - negatable option with argument", () => { +test("flags - type - boolean - negatable option with argument", () => { const { flags, unknown, literal } = parseFlags( ["--no-flag", "unknown"], options, @@ -113,7 +114,7 @@ Deno.test("flags - type - boolean - negatable option with argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - boolean - no value option with default value", () => { +test("flags - type - boolean - no value option with default value", () => { const parseOptions = { flags: [{ name: "foo", @@ -128,7 +129,7 @@ Deno.test("flags - type - boolean - no value option with default value", () => { assertEquals(result2.flags, { foo: true }); }); -Deno.test("flags - type - boolean - with invalid value", () => { +test("flags - type - boolean - with invalid value", () => { assertThrows( () => parseFlags(["-f", "unknown"], options), Error, diff --git a/flags/test/type/integer_test.ts b/flags/test/type/integer_test.ts index 694781c9..92593819 100644 --- a/flags/test/type/integer_test.ts +++ b/flags/test/type/integer_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -24,7 +25,7 @@ const requiredValueOptions: ParseFlagsOptions = { }], }; -Deno.test("flags - type - integer - with no value", () => { +test("flags - type - integer - with no value", () => { const { flags, unknown, literal } = parseFlags(["-f"], optionalValueOptions); assertEquals(flags, { flag: true }); @@ -32,7 +33,7 @@ Deno.test("flags - type - integer - with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - integer - with valid value", () => { +test("flags - type - integer - with valid value", () => { const { flags, unknown, literal } = parseFlags( ["--flag", "123"], optionalValueOptions, @@ -43,7 +44,7 @@ Deno.test("flags - type - integer - with valid value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - integer - with argument", () => { +test("flags - type - integer - with argument", () => { const { flags, unknown, literal } = parseFlags( ["-f", "456", "unknown"], optionalValueOptions, @@ -54,7 +55,7 @@ Deno.test("flags - type - integer - with argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - integer - with missing value", () => { +test("flags - type - integer - with missing value", () => { assertThrows( () => parseFlags(["-f"], requiredValueOptions), Error, @@ -62,7 +63,7 @@ Deno.test("flags - type - integer - with missing value", () => { ); }); -Deno.test("flags - type - integer - with invalid string value", () => { +test("flags - type - integer - with invalid string value", () => { assertThrows( () => parseFlags(["-f", "abc"], requiredValueOptions), Error, @@ -70,7 +71,7 @@ Deno.test("flags - type - integer - with invalid string value", () => { ); }); -Deno.test("flags - type - integer - with invalid float value", () => { +test("flags - type - integer - with invalid float value", () => { assertThrows( () => parseFlags(["-f", "1.23"], requiredValueOptions), Error, diff --git a/flags/test/type/no_value_test.ts b/flags/test/type/no_value_test.ts index 0268a9aa..13a57193 100644 --- a/flags/test/type/no_value_test.ts +++ b/flags/test/type/no_value_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { parseFlags } from "../../flags.ts"; import type { ParseFlagsOptions } from "../../types.ts"; @@ -9,7 +10,7 @@ const options: ParseFlagsOptions = { }], }; -Deno.test("flags - type - no value - short flag without argument", () => { +test("flags - type - no value - short flag without argument", () => { const { flags, unknown, literal } = parseFlags(["-f"], options); assertEquals(flags, { flag: true }); @@ -17,7 +18,7 @@ Deno.test("flags - type - no value - short flag without argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - no value - long flag without argument", () => { +test("flags - type - no value - long flag without argument", () => { const { flags, unknown, literal } = parseFlags(["--flag"], options); assertEquals(flags, { flag: true }); @@ -25,7 +26,7 @@ Deno.test("flags - type - no value - long flag without argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - no value - short flag with argument", () => { +test("flags - type - no value - short flag with argument", () => { const { flags, unknown, literal } = parseFlags(["-f", "true"], options); assertEquals(flags, { flag: true }); @@ -33,7 +34,7 @@ Deno.test("flags - type - no value - short flag with argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - no value - long flag with argument", () => { +test("flags - type - no value - long flag with argument", () => { const { flags, unknown, literal } = parseFlags(["--flag", "true"], options); assertEquals(flags, { flag: true }); @@ -41,7 +42,7 @@ Deno.test("flags - type - no value - long flag with argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - no value - should throw if a no value flag has a value", () => { +test("flags - type - no value - should throw if a no value flag has a value", () => { assertThrows( () => parseFlags(["-f=123"], options), Error, @@ -49,7 +50,7 @@ Deno.test("flags - type - no value - should throw if a no value flag has a value ); }); -Deno.test("flags - type - no value - should not throw unexpected error value with no options", () => { +test("flags - type - no value - should not throw unexpected error value with no options", () => { const result = parseFlags(["-f=123"]); assertEquals(result, { unknown: [], diff --git a/flags/test/type/number_test.ts b/flags/test/type/number_test.ts index 311645a2..536f9e35 100644 --- a/flags/test/type/number_test.ts +++ b/flags/test/type/number_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -24,7 +25,7 @@ const requiredValueOptions: ParseFlagsOptions = { }], }; -Deno.test("flags - type - number - with no value", () => { +test("flags - type - number - with no value", () => { const { flags, unknown, literal } = parseFlags(["-f"], optionalValueOptions); assertEquals(flags, { flag: true }); @@ -32,7 +33,7 @@ Deno.test("flags - type - number - with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - number - with valid value", () => { +test("flags - type - number - with valid value", () => { const { flags, unknown, literal } = parseFlags( ["--flag", "123"], optionalValueOptions, @@ -43,7 +44,7 @@ Deno.test("flags - type - number - with valid value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - number - with argument", () => { +test("flags - type - number - with argument", () => { const { flags, unknown, literal } = parseFlags( ["-f", "456", "unknown"], optionalValueOptions, @@ -54,7 +55,7 @@ Deno.test("flags - type - number - with argument", () => { assertEquals(literal, []); }); -Deno.test("flags - type - number - with missing value", () => { +test("flags - type - number - with missing value", () => { assertThrows( () => parseFlags(["-f"], requiredValueOptions), Error, @@ -62,7 +63,7 @@ Deno.test("flags - type - number - with missing value", () => { ); }); -Deno.test("flags - type - number - with invalid string value", () => { +test("flags - type - number - with invalid string value", () => { assertThrows( () => parseFlags(["-f", "abc"], requiredValueOptions), Error, diff --git a/flags/test/type/string_test.ts b/flags/test/type/string_test.ts index 7f027b99..6a84d47b 100644 --- a/flags/test/type/string_test.ts +++ b/flags/test/type/string_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertThrows } from "@std/assert"; import { OptionType } from "../../deprecated.ts"; import { parseFlags } from "../../flags.ts"; @@ -34,7 +35,7 @@ const requiredNumberValueOptions: ParseFlagsOptions = { }], }; -Deno.test("flags - type - string - with no value", () => { +test("flags - type - string - with no value", () => { const { flags, unknown, literal } = parseFlags(["-f"], optionalValueOptions); assertEquals(flags, { flag: true }); @@ -42,7 +43,7 @@ Deno.test("flags - type - string - with no value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with valid value", () => { +test("flags - type - string - with valid value", () => { const { flags, unknown, literal } = parseFlags( ["--flag", "value"], optionalValueOptions, @@ -53,7 +54,7 @@ Deno.test("flags - type - string - with valid value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with special chars", () => { +test("flags - type - string - with special chars", () => { const { flags, unknown, literal } = parseFlags( ["-f", '!"§$%&/()=?*+#=\\/@*-+,<😎>,.;:_-abc123€√', "unknown"], optionalValueOptions, @@ -64,7 +65,7 @@ Deno.test("flags - type - string - with special chars", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with missing value", () => { +test("flags - type - string - with missing value", () => { assertThrows( () => parseFlags(["-f"], requiredStringValueOptions), Error, @@ -72,7 +73,7 @@ Deno.test("flags - type - string - with missing value", () => { ); }); -Deno.test("flags - type - string - value starting with '-'", () => { +test("flags - type - string - value starting with '-'", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-a", "unknown"], requiredStringValueOptions, @@ -83,7 +84,7 @@ Deno.test("flags - type - string - value starting with '-'", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with negative numeric value", () => { +test("flags - type - string - with negative numeric value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-1", "unknown"], requiredNumberValueOptions, @@ -94,7 +95,7 @@ Deno.test("flags - type - string - with negative numeric value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with negative numeric value 2", () => { +test("flags - type - string - with negative numeric value 2", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-123", "unknown"], requiredNumberValueOptions, @@ -105,7 +106,7 @@ Deno.test("flags - type - string - with negative numeric value 2", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with negative decimal value", () => { +test("flags - type - string - with negative decimal value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-12.2", "unknown"], requiredNumberValueOptions, @@ -116,7 +117,7 @@ Deno.test("flags - type - string - with negative decimal value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with negative numeric string value", () => { +test("flags - type - string - with negative numeric string value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-1", "unknown"], requiredStringValueOptions, @@ -127,7 +128,7 @@ Deno.test("flags - type - string - with negative numeric string value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - value starting with hyphen", () => { +test("flags - type - string - value starting with hyphen", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-foo", "unknown"], requiredStringValueOptions, @@ -138,7 +139,7 @@ Deno.test("flags - type - string - value starting with hyphen", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with long flag as value", () => { +test("flags - type - string - with long flag as value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "--foo", "unknown"], requiredStringValueOptions, @@ -149,7 +150,7 @@ Deno.test("flags - type - string - with long flag as value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with long flag and value as value", () => { +test("flags - type - string - with long flag and value as value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "--foo=bar", "unknown"], requiredStringValueOptions, @@ -160,7 +161,7 @@ Deno.test("flags - type - string - with long flag and value as value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with short flag and value as value", () => { +test("flags - type - string - with short flag and value as value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-a=b", "unknown"], requiredStringValueOptions, @@ -171,7 +172,7 @@ Deno.test("flags - type - string - with short flag and value as value", () => { assertEquals(literal, []); }); -Deno.test("flags - type - string - with only hyphens as value", () => { +test("flags - type - string - with only hyphens as value", () => { const { flags, unknown, literal } = parseFlags( ["-f", "-------------", "unknown"], requiredStringValueOptions, diff --git a/internal/runtime/delete_env.ts b/internal/runtime/delete_env.ts new file mode 100644 index 00000000..b5165154 --- /dev/null +++ b/internal/runtime/delete_env.ts @@ -0,0 +1,18 @@ +/** + * Delete environment variable. + * + * @internal + * @param name The name of the environment variable. + */ +export function deleteEnv(name: string): string | undefined { + // deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + if (Deno) { + return Deno.env.delete(name); + } else if (process) { + delete process.env[name]; + } else { + throw new Error("unsupported runtime"); + } +} diff --git a/internal/runtime/read.ts b/internal/runtime/read.ts index a6bb7277..14bd4b15 100644 --- a/internal/runtime/read.ts +++ b/internal/runtime/read.ts @@ -4,20 +4,28 @@ * @internal * @param data Uint8Array to store the data. */ -export function read(data: Uint8Array): Promise { - // dnt-shim-ignore deno-lint-ignore no-explicit-any - const { Deno, process } = globalThis as any; +export async function read(data: Uint8Array): Promise { + // deno-lint-ignore no-explicit-any + const { Deno, Bun, process } = globalThis as any; if (Deno) { - return Deno.stdin.read(data); + return await Deno.stdin.read(data); + } else if (Bun) { + const reader = Bun.stdin.stream().getReader(); + const { value: buffer } = await reader.read(); + await reader.cancel(); + for (let i = 0; i < buffer.length; i++) { + data[i] = buffer[i]; + } + return buffer.length; } else if (process) { - return new Promise((resolve, reject) => { + return await new Promise((resolve, reject) => { process.stdin.once("readable", () => { try { const buffer = process.stdin.read(); if (buffer === null) { - return null; + return resolve(null); } for (let i = 0; i < buffer.length; i++) { diff --git a/internal/runtime/read_sync.ts b/internal/runtime/read_sync.ts index c409a4b5..82aeb92f 100644 --- a/internal/runtime/read_sync.ts +++ b/internal/runtime/read_sync.ts @@ -11,7 +11,7 @@ const { readSync: readSyncNode } = process */ export function readSync(data: Uint8Array): number { if (Deno) { - return Deno.stdout.readSync(data); + return Deno.stdin.readSync(data); } else if (readSyncNode) { const buffer = Buffer.alloc(data.byteLength); const bytesRead = readSyncNode( diff --git a/internal/runtime/runtime_name.ts b/internal/runtime/runtime_name.ts new file mode 100644 index 00000000..a2f565e3 --- /dev/null +++ b/internal/runtime/runtime_name.ts @@ -0,0 +1,15 @@ +/** Names of supported runtimes. */ +export type RuntimeName = "deno" | "node" | "bun"; + +export function getRuntimeName(): RuntimeName { + switch (true) { + case "Deno" in globalThis: + return "deno"; + case "Bun" in globalThis: + return "bun"; + case "process" in globalThis: + return "node"; + default: + throw new Error("unsupported runtime"); + } +} diff --git a/internal/runtime/set_env.ts b/internal/runtime/set_env.ts new file mode 100644 index 00000000..1b672aad --- /dev/null +++ b/internal/runtime/set_env.ts @@ -0,0 +1,19 @@ +/** + * Set environment variable. + * + * @internal + * @param name The name of the environment variable. + * @param value The value of the environment variable. + */ +export function setEnv(name: string, value: string): void { + // deno-lint-ignore no-explicit-any + const { Deno, process } = globalThis as any; + + if (Deno) { + Deno.env.set(name, value); + } else if (process) { + process.env[name] = value; + } else { + throw new Error("unsupported runtime"); + } +} diff --git a/internal/testing/test/create_test.ts b/internal/testing/test/create_test.ts new file mode 100644 index 00000000..b76174c5 --- /dev/null +++ b/internal/testing/test/create_test.ts @@ -0,0 +1,21 @@ +import type { TestFn, TestOptions } from "./test_options.ts"; + +export interface TestFunction { + (testOptions: TestOptions): void; + (name: string, fn: TestFn): void; +} + +export async function createTest(): Promise { + if ("Deno" in globalThis) { + const { createDenoTestFunction } = await import("./runtime/deno.ts"); + return createDenoTestFunction(); + } else if ("Bun" in globalThis) { + const { createBunTestFunction } = await import("./runtime/bun.ts"); + return createBunTestFunction(); + } else if ("process" in globalThis) { + const { createNodeTestFunction } = await import("./runtime/node.ts"); + return createNodeTestFunction(); + } else { + throw new Error("unsupported runtime"); + } +} diff --git a/internal/testing/test/create_test_function.ts b/internal/testing/test/create_test_function.ts new file mode 100644 index 00000000..2fe30f04 --- /dev/null +++ b/internal/testing/test/create_test_function.ts @@ -0,0 +1,23 @@ +import { yellow } from "@std/fmt/colors"; +import type { TestFn, TestOptions } from "./test_options.ts"; + +export interface GenericTestFunction { + (testOptions: TestOptions): T; + (name: string, fn: TestFn): T; +} + +export function createTestFunction( + runTest: (options: TestOptions) => T, +): GenericTestFunction { + return (nameOrOptions: string | TestOptions, fn?: TestFn): T => { + if (typeof nameOrOptions === "string") { + return runTest({ name: nameOrOptions, fn: fn as TestFn }); + } + + if (nameOrOptions.ignore) { + console.warn(yellow("skip: %s"), nameOrOptions.name); + } + + return runTest(nameOrOptions); + }; +} diff --git a/internal/testing/test/mod.ts b/internal/testing/test/mod.ts new file mode 100644 index 00000000..792cb0c4 --- /dev/null +++ b/internal/testing/test/mod.ts @@ -0,0 +1,11 @@ +import { createTest, type TestFunction } from "./create_test.ts"; + +export type { + StepFunction, + StepOptions, + TestContext, + TestFn, + TestOptions, +} from "./test_options.ts"; + +export const test: TestFunction = await createTest(); diff --git a/internal/testing/test/runtime/bun.ts b/internal/testing/test/runtime/bun.ts new file mode 100644 index 00000000..b5f545bb --- /dev/null +++ b/internal/testing/test/runtime/bun.ts @@ -0,0 +1,94 @@ +import { + createTestFunction, + type GenericTestFunction, +} from "../create_test_function.ts"; +import type { TestFn, TestOptions } from "../test_options.ts"; + +type BunTestMod = { test: BunTest } | { default: { test: BunTest } }; +const bunTestMod: BunTestMod = await import("bun:test" + ""); + +const bunTest: BunTest = "default" in bunTestMod + ? bunTestMod.default.test + : bunTestMod.test; + +export function createBunTestFunction(): GenericTestFunction { + return createTestFunction( + (opts: TestOptions): void => { + createBunTestInnerFunction(opts); + }, + ); +} + +function createBunTestInnerFunction( + { name, fn, only, ignore }: TestOptions, +): boolean { + const skip = Array.isArray(ignore) ? ignore.includes("bun") : ignore; + if (only) { + bunTest.only(name, createBunTestFn(fn)); + } else if (skip) { + bunTest.skip(name, createBunTestFn(fn)); + return true; + } else { + bunTest(name, createBunTestFn(fn)); + } + + return false; +} + +function createBunTestFn(fn: TestFn): BunTestFn { + return () => { + fn({ + step: createTestFunction((opts: TestOptions): Promise => + Promise.resolve(createBunTestInnerFunction(opts)) + ), + }); + }; +} + +interface BunTest { + ( + label: string, + fn: BunTestFn, + options?: number | BunTestOptions, + ): void; + only( + label: string, + fn: BunTestFn, + options?: number | BunTestOptions, + ): void; + skip( + label: string, + fn: BunTestFn, + options?: number | BunTestOptions, + ): void; +} + +type BunTestFn = + | (() => void | Promise) + | ((done: (err?: unknown) => void) => void); + +interface BunTestOptions { + /** + * Sets the timeout for the test in milliseconds. + * + * If the test does not complete within this time, the test will fail with: + * ```ts + * 'Timeout: test {name} timed out after 5000ms' + * ``` + * + * @default 5000 // 5 seconds + */ + timeout?: number; + /** + * Sets the number of times to retry the test if it fails. + * + * @default 0 + */ + retry?: number; + /** + * Sets the number of times to repeat the test, regardless of whether it passed or failed. + * + * @default 0 + */ + repeats?: number; +} diff --git a/internal/testing/test/runtime/deno.ts b/internal/testing/test/runtime/deno.ts new file mode 100644 index 00000000..05d0dca9 --- /dev/null +++ b/internal/testing/test/runtime/deno.ts @@ -0,0 +1,30 @@ +import { + createTestFunction, + type GenericTestFunction, +} from "../create_test_function.ts"; +import type { TestFn, TestOptions } from "../test_options.ts"; + +export function createDenoTestFunction(): GenericTestFunction { + return createTestFunction(({ name, fn, only, ignore }: TestOptions) => + Deno.test({ + name, + fn: createDenoTestFn(fn), + only, + ignore: Array.isArray(ignore) ? ignore.includes("deno") : ignore, + }) + ); +} + +function createDenoTestFn(fn: TestFn): Deno.TestDefinition["fn"] { + return (ctx: Deno.TestContext) => + fn({ + ...ctx, + step: createTestFunction(({ name, ignore, fn }) => + ctx.step({ + name, + fn: createDenoTestFn(fn), + ignore: Array.isArray(ignore) ? ignore.includes("deno") : ignore, + }) + ), + }); +} diff --git a/internal/testing/test/runtime/node.ts b/internal/testing/test/runtime/node.ts new file mode 100644 index 00000000..a796fdfa --- /dev/null +++ b/internal/testing/test/runtime/node.ts @@ -0,0 +1,40 @@ +// import type { TestContext as NodeTestContext } from "node:test"; +import { test as nodeTest } from "node:test"; +import { + createTestFunction, + type GenericTestFunction, +} from "../create_test_function.ts"; +import type { TestFn, TestOptions } from "../test_options.ts"; + +export function createNodeTestFunction(): GenericTestFunction { + return createTestFunction( + ({ name, fn, only, ignore }: TestOptions) => + nodeTest(name, { + only, + skip: Array.isArray(ignore) ? ignore.includes("node") : ignore, + }, createNodeTestFn(fn)), + ); +} + +function createNodeTestFn(fn: TestFn): NodeTestFn { + return (ctx: NodeTestContext) => + fn({ + ...ctx, + step: createTestFunction(async ({ name, ignore, fn: stepFn }) => { + const skip = Array.isArray(ignore) + ? ignore.includes("deno") + : ignore === true; + + await ctx.test(name, { skip }, createNodeTestFn(stepFn)); + + return skip; + }), + }); +} + +// deno-lint-ignore no-explicit-any +type NodeTestFn = (t: NodeTestContext, done: (result?: any) => void) => any; + +interface NodeTestContext { + test: typeof nodeTest; +} diff --git a/internal/testing/test/test_options.ts b/internal/testing/test/test_options.ts new file mode 100644 index 00000000..9451c8ef --- /dev/null +++ b/internal/testing/test/test_options.ts @@ -0,0 +1,28 @@ +import type { RuntimeName } from "../../runtime/runtime_name.ts"; + +export interface TestOptions { + name: string; + fn: TestFn; + ignore?: boolean | Array; + only?: boolean; +} + +export interface TestFn { + (t: TestContext): void | Promise; +} + +export interface TestContext { + step: StepFunction; +} + +export interface StepFunction { + (stepOptions: StepOptions): Promise; + (name: string, fn: TestFn): Promise; +} + +export interface StepOptions { + name: string; + fn: TestFn; + ignore?: boolean | Array; + only?: boolean; +} diff --git a/keycode/test/key_code_test.ts b/keycode/test/key_code_test.ts index 4b2feb1e..eff81ea3 100644 --- a/keycode/test/key_code_test.ts +++ b/keycode/test/key_code_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { type KeyCode, parse } from "../key_code.ts"; import { @@ -20,7 +21,7 @@ const defaults: KeyCode = { }; for (const char of "abcdefghijklmnopqrstuvwxyz123456789") { - Deno.test(`keycode - parse key - ${char}`, function () { + test(`keycode - parse key - ${char}`, function () { const keys: KeyCode[] = parse(char); assertEquals( @@ -36,7 +37,7 @@ for (const char of "abcdefghijklmnopqrstuvwxyz123456789") { } for (const char of "ABCDEFGHIJKLMNOPQRSTUVWXYZ") { - Deno.test(`keycode - parse key - shift + ${char}`, function () { + test(`keycode - parse key - shift + ${char}`, function () { const keys: KeyCode[] = parse(char); assertEquals( @@ -53,7 +54,7 @@ for (const char of "ABCDEFGHIJKLMNOPQRSTUVWXYZ") { } for (const char of '!"§$%&/()=?,;.:-_¬”#£fi^^˜·¯˙»„‰') { - Deno.test(`keycode - parse special key - ${char}`, function () { + test(`keycode - parse special key - ${char}`, function () { const keys: KeyCode[] = parse(char); assertEquals( @@ -71,7 +72,8 @@ for (const char of '!"§$%&/()=?,;.:-_¬”#£fi^^˜·¯˙»„‰') { for (const code of Object.keys(SpecialKeyMap)) { const name = SpecialKeyMap[code]; - Deno.test(`keycode - parse key - SpecialKeyMap - ${name} (${code})`, function () { + // test(`keycode - parse key - SpecialKeyMap - ${name} (${code})`, function () { + test(`keycode - parse key - SpecialKeyMap - ${name}`, function () { // const keys: KeyEvent[] = parse( ESC + code ); const keys: KeyCode[] = parse(code); @@ -90,7 +92,7 @@ for (const code of Object.keys(SpecialKeyMap)) { for (const code of Object.keys(KeyMap)) { const name = KeyMap[code]; - Deno.test(`keycode - parse key - KeyMap - ${name} (${code})`, function () { + test(`keycode - parse key - KeyMap - ${name} (${code})`, function () { const keys: KeyCode[] = parse(ESC + code); assertEquals( @@ -108,7 +110,7 @@ for (const code of Object.keys(KeyMap)) { for (const code of Object.keys(KeyMapShift)) { const name = KeyMapShift[code]; - Deno.test(`keycode - parse key - KeyMapShift - shift + ${name} (${code})`, function () { + test(`keycode - parse key - KeyMapShift - shift + ${name} (${code})`, function () { const keys: KeyCode[] = parse(ESC + code); assertEquals( @@ -127,7 +129,7 @@ for (const code of Object.keys(KeyMapShift)) { for (const code of Object.keys(KeyMapCtrl)) { const name = KeyMapCtrl[code]; - Deno.test(`keycode - parse key - KeyMapCtrl - ctrl + ${name} (${code})`, function () { + test(`keycode - parse key - KeyMapCtrl - ctrl + ${name} (${code})`, function () { const keys: KeyCode[] = parse(ESC + code); assertEquals( @@ -143,7 +145,7 @@ for (const code of Object.keys(KeyMapCtrl)) { }); } -Deno.test(`keycode - parse string - abc`, function () { +test(`keycode - parse string - abc`, function () { const keys: KeyCode[] = parse("abc"); assertEquals( @@ -167,7 +169,7 @@ Deno.test(`keycode - parse string - abc`, function () { ); }); -Deno.test("keycode - xterm/gnome ESC [ letter (with modifiers)", function () { +test("keycode - xterm/gnome ESC [ letter (with modifiers)", function () { const keys = parse( "\x1b[2P\x1b[3P\x1b[4P\x1b[5P\x1b[6P\x1b[7P\x1b[8P\x1b[3Q\x1b[8Q\x1b[3R\x1b[8R\x1b[3S\x1b[8S", ); diff --git a/keypress/mod.ts b/keypress/mod.ts index ca4ede79..8f3be010 100644 --- a/keypress/mod.ts +++ b/keypress/mod.ts @@ -125,12 +125,12 @@ export class Keypress extends EventTarget * @param listener Event listener. * @param options Event listener options. */ - addEventListener( + override addEventListener( type: "keydown", listener: KeyPressEventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions, ): void; - addEventListener( + override addEventListener( type: KeyPressEventType, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions, @@ -149,12 +149,12 @@ export class Keypress extends EventTarget * @param listener Event listener. * @param options Event listener options. */ - removeEventListener( + override removeEventListener( type: "keydown", listener: KeyPressEventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean, ): void; - removeEventListener( + override removeEventListener( type: KeyPressEventType, listener: EventListenerOrEventListenerObject | null, options?: EventListenerOptions | boolean, diff --git a/keypress/test.ts b/keypress/test.ts index b637b1d0..0a0206a7 100644 --- a/keypress/test.ts +++ b/keypress/test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { KeyPressEvent } from "./mod.ts"; -Deno.test({ +test({ name: "[keypress] should create KeyPressEvent", fn() { const event = new KeyPressEvent("keydown", {}); diff --git a/prompt/_generic_input.ts b/prompt/_generic_input.ts index 27552880..63abf5e3 100644 --- a/prompt/_generic_input.ts +++ b/prompt/_generic_input.ts @@ -37,14 +37,15 @@ export abstract class GenericInput< TValue, TRawValue, > extends GenericPrompt { - protected abstract readonly settings: GenericInputPromptSettings< + // @ts-ignore ignore jsr publish error + protected abstract override readonly settings: GenericInputPromptSettings< TValue, TRawValue >; protected inputValue = ""; protected inputIndex = 0; - public getDefaultSettings( + public override getDefaultSettings( options: GenericInputPromptOptions, ): GenericInputPromptSettings { const settings = super.getDefaultSettings(options); @@ -64,7 +65,7 @@ export abstract class GenericInput< return this.inputValue; } - protected message(): string { + protected override message(): string { const message: string = super.message() + " " + this.settings.pointer + " "; this.cursor.x = stripAnsiCode(message).length + this.inputIndex + 1; return message + this.input(); @@ -94,7 +95,7 @@ export abstract class GenericInput< * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { switch (true) { case this.isKey(this.settings.keys, "moveCursorLeft", event): this.moveCursorLeft(); diff --git a/prompt/_generic_list.ts b/prompt/_generic_list.ts index 49f8e464..549ca680 100644 --- a/prompt/_generic_list.ts +++ b/prompt/_generic_list.ts @@ -165,7 +165,8 @@ export abstract class GenericList< TOption extends GenericListOptionSettings, TGroup extends GenericListOptionGroupSettings, > extends GenericInput { - protected abstract readonly settings: GenericListSettings< + // @ts-ignore ignore jsr publish error + protected abstract override readonly settings: GenericListSettings< TValue, TReturnValue, TRawValue, @@ -190,7 +191,7 @@ export abstract class GenericList< return { name: label }; } - public getDefaultSettings( + public override getDefaultSettings( { groupIcon = true, groupOpenIcon = groupIcon, @@ -350,7 +351,7 @@ export abstract class GenericList< return this.getCurrentInputValue() !== ""; } - protected message(): string { + protected override message(): string { let message = `${this.settings.indent}${this.settings.prefix}` + bold(this.settings.message) + this.defaults(); @@ -366,7 +367,7 @@ export abstract class GenericList< } /** Render options. */ - protected body(): string | Promise { + protected override body(): string | Promise { return this.getList() + this.getInfo(); } @@ -561,7 +562,7 @@ export abstract class GenericList< } /** Read user input. */ - protected read(): Promise { + protected override read(): Promise { if (!this.settings.search) { this.settings.tty.cursorHide(); } @@ -580,7 +581,7 @@ export abstract class GenericList< * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { if ( this.isKey(this.settings.keys, "open", event) && isOptionGroup(this.selectedOption) && @@ -616,7 +617,7 @@ export abstract class GenericList< } } - protected async submit(): Promise { + protected override async submit(): Promise { if (this.isSearchSelected()) { this.selectNext(); return; @@ -624,32 +625,32 @@ export abstract class GenericList< await super.submit(); } - protected moveCursorLeft(): void { + protected override moveCursorLeft(): void { if (this.settings.search) { super.moveCursorLeft(); } } - protected moveCursorRight(): void { + protected override moveCursorRight(): void { if (this.settings.search) { super.moveCursorRight(); } } - protected deleteChar(): void { + protected override deleteChar(): void { if (this.settings.search) { super.deleteChar(); } } - protected deleteCharRight(): void { + protected override deleteCharRight(): void { if (this.settings.search) { super.deleteCharRight(); this.match(); } } - protected addChar(char: string): void { + protected override addChar(char: string): void { if (this.settings.search) { super.addChar(char); this.match(); diff --git a/prompt/_generic_prompt.ts b/prompt/_generic_prompt.ts index 1bfb3a1a..7804f535 100644 --- a/prompt/_generic_prompt.ts +++ b/prompt/_generic_prompt.ts @@ -1,5 +1,6 @@ import type { Cursor } from "@cliffy/ansi/cursor-position"; import { type Tty, tty } from "@cliffy/ansi/tty"; +import { getRuntimeName } from "@cliffy/internal/runtime/runtime-name"; import { type KeyCode, parse } from "@cliffy/keycode"; import { bold, @@ -361,7 +362,7 @@ export abstract class GenericPrompt { /** Read user input from stdin. */ #readChar = async (): Promise => { - const buffer = new Uint8Array(256); + const buffer = new Uint8Array(getRuntimeName() === "deno" ? 8 : 4096); const isTty = this.settings.reader.isTerminal(); if (isTty) { diff --git a/prompt/_generic_suggestions.ts b/prompt/_generic_suggestions.ts index 7b80b0b3..b3dae0f9 100644 --- a/prompt/_generic_suggestions.ts +++ b/prompt/_generic_suggestions.ts @@ -102,7 +102,8 @@ const sep = getOs() === "windows" ? "\\" : "/"; /** Generic input prompt representation. */ export abstract class GenericSuggestions extends GenericInput { - protected abstract readonly settings: GenericSuggestionsSettings< + // @ts-ignore ignore jsr publish error + protected abstract override readonly settings: GenericSuggestionsSettings< TValue, TRawValue >; @@ -112,7 +113,7 @@ export abstract class GenericSuggestions #envPermissions: Record = {}; #hasReadPermissions?: boolean; - public getDefaultSettings( + public override getDefaultSettings( options: GenericSuggestionsOptions, ): GenericSuggestionsSettings { const settings = super.getDefaultSettings(options); @@ -168,7 +169,7 @@ export abstract class GenericSuggestions } } - protected async render(): Promise { + protected override async render(): Promise { if (this.settings.files && this.#hasReadPermissions === undefined) { // deno-lint-ignore no-explicit-any const status = await (globalThis as any).Deno?.permissions.request({ @@ -199,7 +200,7 @@ export abstract class GenericSuggestions ); } - protected input(): string { + protected override input(): string { return super.input() + dim(this.getSuggestion()); } @@ -260,7 +261,7 @@ export abstract class GenericSuggestions ); } - protected body(): string | Promise { + protected override body(): string | Promise { return this.getList() + this.getInfo(); } @@ -365,7 +366,7 @@ export abstract class GenericSuggestions * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { switch (true) { case this.isKey(this.settings.keys, "next", event): if (this.settings.list) { @@ -411,7 +412,7 @@ export abstract class GenericSuggestions } /** Delete char right. */ - protected deleteCharRight(): void { + protected override deleteCharRight(): void { if (this.inputIndex < this.inputValue.length) { super.deleteCharRight(); if (!this.getCurrentInputValue().length) { diff --git a/prompt/checkbox.ts b/prompt/checkbox.ts index 8f9d8533..90ed0c27 100644 --- a/prompt/checkbox.ts +++ b/prompt/checkbox.ts @@ -205,7 +205,7 @@ export class Checkbox extends GenericList< * * @param value Input value. */ - public static inject(value: Array): void { + public static override inject(value: Array): void { GenericPrompt.inject(value); } @@ -217,7 +217,7 @@ export class Checkbox extends GenericList< this.listOffset = this.getPageOffset(this.listIndex); } - public getDefaultSettings( + public override getDefaultSettings( options: CheckboxOptions, ): CheckboxSettings { const settings = super.getDefaultSettings(options); @@ -265,7 +265,7 @@ export class Checkbox extends GenericList< ); } - protected mapOption( + protected override mapOption( options: CheckboxOptions, option: CheckboxOption | GenericListSeparatorOption, ): CheckboxOptionSettings { @@ -287,7 +287,7 @@ export class Checkbox extends GenericList< } } - protected mapOptionGroup( + protected override mapOptionGroup( promptOptions: CheckboxOptions, option: CheckboxOptionGroup, ): CheckboxOptionGroupSettings { @@ -302,14 +302,14 @@ export class Checkbox extends GenericList< }; } - protected match(): void { + protected override match(): void { super.match(); if (this.isSearching()) { this.selectSearch(); } } - protected getListItemIcon( + protected override getListItemIcon( option: | CheckboxOptionSettings | CheckboxOptionGroupSettings, @@ -351,7 +351,7 @@ export class Checkbox extends GenericList< * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { const hasConfirmed: boolean = this.confirmSubmit; this.confirmSubmit = false; @@ -372,7 +372,7 @@ export class Checkbox extends GenericList< } } - protected hint(): string | undefined { + protected override hint(): string | undefined { if (this.confirmSubmit) { const info = this.isBackButton(this.selectedOption) ? ` To leave the current group press ${ @@ -397,7 +397,7 @@ export class Checkbox extends GenericList< return super.hint(); } - protected async submit(hasConfirmed?: boolean): Promise { + protected override async submit(hasConfirmed?: boolean): Promise { if ( !hasConfirmed && this.settings.confirmSubmit && diff --git a/prompt/confirm.ts b/prompt/confirm.ts index 9b264133..bf7d3d96 100644 --- a/prompt/confirm.ts +++ b/prompt/confirm.ts @@ -61,7 +61,7 @@ export class Confirm extends GenericSuggestions { * * @param value Input value. */ - public static inject(value: string): void { + public static override inject(value: string): void { GenericPrompt.inject(value); } @@ -73,7 +73,7 @@ export class Confirm extends GenericSuggestions { this.settings = this.getDefaultSettings(options); } - public getDefaultSettings(options: ConfirmOptions): ConfirmSettings { + public override getDefaultSettings(options: ConfirmOptions): ConfirmSettings { return { ...super.getDefaultSettings(options), active: options.active || "Yes", @@ -89,7 +89,7 @@ export class Confirm extends GenericSuggestions { }; } - protected defaults(): string { + protected override defaults(): string { let defaultMessage = ""; if (this.settings.default === true) { @@ -106,7 +106,7 @@ export class Confirm extends GenericSuggestions { return defaultMessage ? dim(` (${defaultMessage})`) : ""; } - protected success(value: boolean): string | undefined { + protected override success(value: boolean): string | undefined { this.saveSuggestions(this.format(value)); return super.success(value); } diff --git a/prompt/input.ts b/prompt/input.ts index 144bada0..61eba79d 100644 --- a/prompt/input.ts +++ b/prompt/input.ts @@ -52,7 +52,7 @@ export class Input extends GenericSuggestions { * * @param value Input value. */ - public static inject(value: string): void { + public static override inject(value: string): void { GenericPrompt.inject(value); } @@ -64,7 +64,7 @@ export class Input extends GenericSuggestions { this.settings = this.getDefaultSettings(options); } - public getDefaultSettings(options: InputOptions): InputSettings { + public override getDefaultSettings(options: InputOptions): InputSettings { return { ...super.getDefaultSettings(options), minLength: options.minLength ?? 0, @@ -72,7 +72,7 @@ export class Input extends GenericSuggestions { }; } - protected success(value: string): string | undefined { + protected override success(value: string): string | undefined { this.saveSuggestions(value); return super.success(value); } diff --git a/prompt/list.ts b/prompt/list.ts index 7aca2f99..4469d208 100644 --- a/prompt/list.ts +++ b/prompt/list.ts @@ -62,7 +62,7 @@ export class List extends GenericSuggestions { * * @param value Input value. */ - public static inject(value: string): void { + public static override inject(value: string): void { GenericPrompt.inject(value); } @@ -74,7 +74,7 @@ export class List extends GenericSuggestions { this.settings = this.getDefaultSettings(options); } - public getDefaultSettings(options: ListOptions): ListSettings { + public override getDefaultSettings(options: ListOptions): ListSettings { return { ...super.getDefaultSettings(options), separator: options.separator ?? ",", @@ -85,7 +85,7 @@ export class List extends GenericSuggestions { }; } - protected input(): string { + protected override input(): string { const oldInput: string = this.inputValue; const tags: string[] = this.getTags(oldInput); const separator: string = this.settings.separator + " "; @@ -117,7 +117,7 @@ export class List extends GenericSuggestions { ); } - protected success(value: string[]): string | undefined { + protected override success(value: string[]): string | undefined { this.saveSuggestions(...value); return super.success(value); } @@ -136,12 +136,12 @@ export class List extends GenericSuggestions { .join(this.settings.separator + " "); } - protected getCurrentInputValue(): string { + protected override getCurrentInputValue(): string { return this.getTags().pop() ?? ""; } /** Add char. */ - protected addChar(char: string): void { + protected override addChar(char: string): void { switch (char) { case this.settings.separator: if ( @@ -159,14 +159,14 @@ export class List extends GenericSuggestions { } /** Delete char left. */ - protected deleteChar(): void { + protected override deleteChar(): void { if (this.inputValue[this.inputIndex - 1] === " ") { super.deleteChar(); } super.deleteChar(); } - protected async complete(): Promise { + protected override async complete(): Promise { const tags = this.getTags().slice(0, -1); tags.push(await super.complete()); return tags.join(this.settings.separator + " "); diff --git a/prompt/number.ts b/prompt/number.ts index 8d773700..fbd5a431 100644 --- a/prompt/number.ts +++ b/prompt/number.ts @@ -66,7 +66,7 @@ export class Number extends GenericSuggestions { * * @param value Input value. */ - public static inject(value: string): void { + public static override inject(value: string): void { GenericPrompt.inject(value); } @@ -78,7 +78,7 @@ export class Number extends GenericSuggestions { this.settings = this.getDefaultSettings(options); } - public getDefaultSettings(options: NumberOptions): NumberSettings { + public override getDefaultSettings(options: NumberOptions): NumberSettings { const settings = super.getDefaultSettings(options); return { ...settings, @@ -95,7 +95,7 @@ export class Number extends GenericSuggestions { }; } - protected success(value: number): string | undefined { + protected override success(value: number): string | undefined { this.saveSuggestions(value); return super.success(value); } @@ -104,7 +104,7 @@ export class Number extends GenericSuggestions { * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { switch (true) { case this.settings.suggestions && this.isKey(this.settings.keys, "next", event): @@ -199,7 +199,7 @@ export class Number extends GenericSuggestions { * Add char to input. * @param char Char. */ - protected addChar(char: string): void { + protected override addChar(char: string): void { if (isNumeric(char)) { super.addChar(char); } else if ( diff --git a/prompt/secret.ts b/prompt/secret.ts index 380c8b61..3db600b7 100644 --- a/prompt/secret.ts +++ b/prompt/secret.ts @@ -60,7 +60,7 @@ export class Secret extends GenericInput { * * @param value Input value. */ - public static inject(value: string): void { + public static override inject(value: string): void { GenericPrompt.inject(value); } @@ -72,7 +72,7 @@ export class Secret extends GenericInput { this.settings = this.getDefaultSettings(options); } - public getDefaultSettings(options: SecretOptions): SecretSettings { + public override getDefaultSettings(options: SecretOptions): SecretSettings { return { ...super.getDefaultSettings(options), label: options.label ?? "Secret", @@ -82,14 +82,14 @@ export class Secret extends GenericInput { }; } - protected input(): string { + protected override input(): string { return underline( this.settings.hidden ? "" : "*".repeat(this.inputValue.length), ); } /** Read user input. */ - protected read(): Promise { + protected override read(): Promise { if (this.settings.hidden) { this.settings.tty.cursorHide(); } diff --git a/prompt/select.ts b/prompt/select.ts index fb7bedd1..52b2543b 100644 --- a/prompt/select.ts +++ b/prompt/select.ts @@ -159,7 +159,7 @@ export class Select extends GenericList< * * @param value Input value. */ - public static inject(value: TValue): void { + public static override inject(value: TValue): void { GenericPrompt.inject(value); } @@ -171,7 +171,7 @@ export class Select extends GenericList< this.listOffset = this.getPageOffset(this.listIndex); } - public getDefaultSettings( + public override getDefaultSettings( options: SelectOptions, ): SelectSettings { return { @@ -203,11 +203,11 @@ export class Select extends GenericList< ); } - protected input(): string { + protected override input(): string { return underline(brightBlue(this.inputValue)); } - protected async submit(): Promise { + protected override async submit(): Promise { if ( this.isBackButton(this.selectedOption) || isOptionGroup(this.selectedOption) diff --git a/prompt/test/checkbox_test.ts b/prompt/test/checkbox_test.ts index 9bbd53bb..7d8a6e17 100644 --- a/prompt/test/checkbox_test.ts +++ b/prompt/test/checkbox_test.ts @@ -1,9 +1,11 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { assertType, type IsExact } from "@std/testing/types"; import { Checkbox } from "../checkbox.ts"; -Deno.test("prompt checkbox: valid value", async () => { +test("prompt checkbox: valid value", async () => { Checkbox.inject(["value1", "value3"]); const result: string[] | undefined = await Checkbox.prompt({ message: "message", @@ -12,7 +14,7 @@ Deno.test("prompt checkbox: valid value", async () => { assertEquals(result, ["value1", "value3"]); }); -Deno.test("prompt checkbox: empty value", async () => { +test("prompt checkbox: empty value", async () => { Checkbox.inject([]); const result: string[] | undefined = await Checkbox.prompt({ message: "message", @@ -22,7 +24,7 @@ Deno.test("prompt checkbox: empty value", async () => { assertEquals(result, []); }); -Deno.test("prompt checkbox: object value", async () => { +test("prompt checkbox: object value", async () => { Checkbox.inject([{ id: 1, name: "foo" }]); const books = [ @@ -39,7 +41,7 @@ Deno.test("prompt checkbox: object value", async () => { assertType>>(true); }); -Deno.test("prompt checkbox: invalid value", async () => { +test("prompt checkbox: invalid value", async () => { await assertRejects( async () => { Checkbox.inject(["value3", "value4"]); @@ -50,12 +52,12 @@ Deno.test("prompt checkbox: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt checkbox: null value", async () => { +test("prompt checkbox: null value", async () => { await assertRejects( async () => { // deno-lint-ignore no-explicit-any @@ -67,12 +69,12 @@ Deno.test("prompt checkbox: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt checkbox: min options", async () => { +test("prompt checkbox: min options", async () => { await assertRejects( async () => { Checkbox.inject(["value1", "value2"]); @@ -85,13 +87,13 @@ Deno.test("prompt checkbox: min options", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }The minimum number of options is 3 but got 2.`, ), ); }); -Deno.test("prompt checkbox: max options", async () => { +test("prompt checkbox: max options", async () => { await assertRejects( async () => { Checkbox.inject(["value1", "value2"]); @@ -104,7 +106,7 @@ Deno.test("prompt checkbox: max options", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }The maximum number of options is 1 but got 2.`, ), ); diff --git a/prompt/test/confirm_test.ts b/prompt/test/confirm_test.ts index 732dcfdb..a2c4c996 100644 --- a/prompt/test/confirm_test.ts +++ b/prompt/test/confirm_test.ts @@ -1,36 +1,38 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { Confirm } from "../confirm.ts"; -Deno.test("prompt confirm: y", async () => { +test("prompt confirm: y", async () => { console.log(); Confirm.inject("y"); const result: boolean | undefined = await Confirm.prompt("message"); assertEquals(result, true); }); -Deno.test("prompt confirm: yes", async () => { +test("prompt confirm: yes", async () => { console.log(); Confirm.inject("Yes"); const result: boolean | undefined = await Confirm.prompt("message"); assertEquals(result, true); }); -Deno.test("prompt confirm: n", async () => { +test("prompt confirm: n", async () => { console.log(); Confirm.inject("n"); const result: boolean | undefined = await Confirm.prompt("message"); assertEquals(result, false); }); -Deno.test("prompt confirm: no", async () => { +test("prompt confirm: no", async () => { console.log(); Confirm.inject("No"); const result: boolean | undefined = await Confirm.prompt("message"); assertEquals(result, false); }); -Deno.test("prompt confirm: empty value", async () => { +test("prompt confirm: empty value", async () => { console.log(); await assertRejects( async () => { @@ -39,12 +41,12 @@ Deno.test("prompt confirm: empty value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt confirm: invalid value", async () => { +test("prompt confirm: invalid value", async () => { console.log(); await assertRejects( async () => { @@ -53,12 +55,12 @@ Deno.test("prompt confirm: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt confirm: null value", async () => { +test("prompt confirm: null value", async () => { console.log(); await assertRejects( async () => { @@ -68,7 +70,7 @@ Deno.test("prompt confirm: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/input_test.ts b/prompt/test/input_test.ts index 2b415813..5b4d6d7e 100644 --- a/prompt/test/input_test.ts +++ b/prompt/test/input_test.ts @@ -1,15 +1,17 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { Input } from "../input.ts"; -Deno.test("prompt input: value", async () => { +test("prompt input: value", async () => { console.log(); Input.inject("hallo"); const result: string | undefined = await Input.prompt("message"); assertEquals(result, "hallo"); }); -Deno.test("prompt input: validate option", async () => { +test("prompt input: validate option", async () => { console.log(); Input.inject("foo"); const result: string | undefined = await Input.prompt({ @@ -19,7 +21,7 @@ Deno.test("prompt input: validate option", async () => { assertEquals(result, "foo"); }); -Deno.test("prompt input: default value", async () => { +test("prompt input: default value", async () => { console.log(); Input.inject(""); const result: string | undefined = await Input.prompt({ @@ -30,7 +32,7 @@ Deno.test("prompt input: default value", async () => { assertEquals(result, "default"); }); -Deno.test("prompt input: empty value", async () => { +test("prompt input: empty value", async () => { console.log(); await assertRejects( async () => { @@ -43,13 +45,13 @@ Deno.test("prompt input: empty value", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }Value must be longer than 8 but has a length of 0.`, ), ); }); -Deno.test("prompt input: invalid value", async () => { +test("prompt input: invalid value", async () => { console.log(); await assertRejects( async () => { @@ -61,12 +63,12 @@ Deno.test("prompt input: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt input: null value", async () => { +test("prompt input: null value", async () => { console.log(); await assertRejects( async () => { @@ -76,7 +78,7 @@ Deno.test("prompt input: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/list_test.ts b/prompt/test/list_test.ts index 4382ffa1..8a3fbe30 100644 --- a/prompt/test/list_test.ts +++ b/prompt/test/list_test.ts @@ -1,15 +1,17 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { List } from "../list.ts"; -Deno.test('prompt list: , separator option: ","', async () => { +test('prompt list: , separator option: ","', async () => { console.log(); List.inject("tag1, tag2, tag3"); const result: string[] | undefined = await List.prompt("message"); assertEquals(result, ["tag1", "tag2", "tag3"]); }); -Deno.test('prompt list: separator option: " "', async () => { +test('prompt list: separator option: " "', async () => { console.log(); List.inject("tag1 tag2 tag3"); const result: string[] | undefined = await List.prompt({ @@ -19,7 +21,7 @@ Deno.test('prompt list: separator option: " "', async () => { assertEquals(result, ["tag1", "tag2", "tag3"]); }); -Deno.test('prompt list: separator option: ";"', async () => { +test('prompt list: separator option: ";"', async () => { console.log(); List.inject(" tag tag1 ; tag2 ; tag3 "); const result: string[] | undefined = await List.prompt({ @@ -29,7 +31,7 @@ Deno.test('prompt list: separator option: ";"', async () => { assertEquals(result, ["tag tag1", "tag2", "tag3"]); }); -Deno.test('prompt list: separator option: "-"', async () => { +test('prompt list: separator option: "-"', async () => { console.log(); List.inject(" tag tag1 -tag2-tag3 "); const result: string[] | undefined = await List.prompt({ @@ -39,7 +41,7 @@ Deno.test('prompt list: separator option: "-"', async () => { assertEquals(result, ["tag tag1", "tag2", "tag3"]); }); -Deno.test("prompt list: empty value", async () => { +test("prompt list: empty value", async () => { console.log(); await assertRejects( async () => { @@ -52,12 +54,12 @@ Deno.test("prompt list: empty value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt list: min length", async () => { +test("prompt list: min length", async () => { console.log(); await assertRejects( async () => { @@ -70,13 +72,13 @@ Deno.test("prompt list: min length", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }Value must be longer than 3 but has a length of 2.`, ), ); }); -Deno.test("prompt list: max length", async () => { +test("prompt list: max length", async () => { console.log(); await assertRejects( async () => { @@ -89,13 +91,13 @@ Deno.test("prompt list: max length", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }Value can't be longer than 2 but has a length of 3.`, ), ); }); -Deno.test("prompt list: min tags", async () => { +test("prompt list: min tags", async () => { console.log(); await assertRejects( async () => { @@ -108,13 +110,13 @@ Deno.test("prompt list: min tags", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }The minimum number of tags is 3 but got 0.`, ), ); }); -Deno.test("prompt list: max tags", async () => { +test("prompt list: max tags", async () => { console.log(); await assertRejects( async () => { @@ -127,14 +129,14 @@ Deno.test("prompt list: max tags", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }The maximum number of tags is 2 but got 3.`, ), ); }); // @TODO: add maxLength option to list pormpt -Deno.test("prompt list: null value", async () => { +test("prompt list: null value", async () => { console.log(); await assertRejects( async () => { @@ -144,7 +146,7 @@ Deno.test("prompt list: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/number_test.ts b/prompt/test/number_test.ts index d8e8e179..ec523005 100644 --- a/prompt/test/number_test.ts +++ b/prompt/test/number_test.ts @@ -1,29 +1,31 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { Number } from "../number.ts"; -Deno.test("prompt number: value", async () => { +test("prompt number: value", async () => { console.log(); Number.inject("1"); const result: number | undefined = await Number.prompt("message"); assertEquals(result, 1); }); -Deno.test("prompt number: negative value", async () => { +test("prompt number: negative value", async () => { console.log(); Number.inject("-1"); const result: number | undefined = await Number.prompt("message"); assertEquals(result, -1); }); -Deno.test("prompt number: number value", async () => { +test("prompt number: number value", async () => { console.log(); Number.inject("0"); const result: number | undefined = await Number.prompt("message"); assertEquals(result, 0); }); -Deno.test("prompt number: empty value", async () => { +test("prompt number: empty value", async () => { await assertRejects( async () => { Number.inject(""); @@ -31,12 +33,12 @@ Deno.test("prompt number: empty value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt number: invalid value", async () => { +test("prompt number: invalid value", async () => { await assertRejects( async () => { Number.inject("abc"); @@ -44,12 +46,12 @@ Deno.test("prompt number: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt number: null value", async () => { +test("prompt number: null value", async () => { await assertRejects( async () => { // deno-lint-ignore no-explicit-any @@ -58,7 +60,7 @@ Deno.test("prompt number: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/prompt_list_test.ts b/prompt/test/prompt_list_test.ts index cffc1d5c..69e11fbf 100644 --- a/prompt/test/prompt_list_test.ts +++ b/prompt/test/prompt_list_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertType, type IsExact } from "@std/testing/types"; import { assertEquals, assertRejects } from "@std/assert"; import { inject, prompt } from "../prompt.ts"; @@ -6,7 +7,7 @@ import { Confirm } from "../confirm.ts"; import { Number } from "../number.ts"; import { Input } from "../input.ts"; -Deno.test("prompt - prompt list", async () => { +test("prompt - prompt list", async () => { let beforeCalled = 0; let afterCalled = 0; const expectedResult = { @@ -122,7 +123,7 @@ Deno.test("prompt - prompt list", async () => { assertEquals(afterCalled, 1); }); -Deno.test("prompt - prompt list - before next callback", async () => { +test("prompt - prompt list - before next callback", async () => { await assertRejects( async () => { inject({ @@ -151,7 +152,7 @@ Deno.test("prompt - prompt list - before next callback", async () => { ); }); -Deno.test("prompt - prompt list - after next callback", async () => { +test("prompt - prompt list - after next callback", async () => { await assertRejects( async () => { inject({ diff --git a/prompt/test/secret_test.ts b/prompt/test/secret_test.ts index c6714ae2..345b1f02 100644 --- a/prompt/test/secret_test.ts +++ b/prompt/test/secret_test.ts @@ -1,15 +1,17 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { Secret } from "../secret.ts"; -Deno.test("prompt secret: value", async () => { +test("prompt secret: value", async () => { console.log(); Secret.inject("hallo"); const result: string | undefined = await Secret.prompt("message"); assertEquals(result, "hallo"); }); -Deno.test("prompt secret: validate option", async () => { +test("prompt secret: validate option", async () => { console.log(); Secret.inject("a".repeat(9)); const result: string | undefined = await Secret.prompt({ @@ -19,7 +21,7 @@ Deno.test("prompt secret: validate option", async () => { assertEquals(result, "a".repeat(9)); }); -Deno.test("prompt secret: empty value", async () => { +test("prompt secret: empty value", async () => { console.log(); await assertRejects( async () => { @@ -32,13 +34,13 @@ Deno.test("prompt secret: empty value", async () => { Error, red( `${ - Deno.build.os === "windows" ? bold("× ") : bold("✘ ") + getOs() === "windows" ? bold("× ") : bold("✘ ") }Secret must be longer than 8 but has a length of 0.`, ), ); }); -Deno.test("prompt secret: invalid value", async () => { +test("prompt secret: invalid value", async () => { console.log(); await assertRejects( async () => { @@ -50,12 +52,12 @@ Deno.test("prompt secret: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt secret: null value", async () => { +test("prompt secret: null value", async () => { console.log(); await assertRejects( async () => { @@ -65,7 +67,7 @@ Deno.test("prompt secret: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/select_test.ts b/prompt/test/select_test.ts index 90472d00..92829876 100644 --- a/prompt/test/select_test.ts +++ b/prompt/test/select_test.ts @@ -1,9 +1,11 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { assertType, type IsExact } from "@std/testing/types"; import { Select } from "../select.ts"; -Deno.test("prompt select: value", async () => { +test("prompt select: value", async () => { console.log(); Select.inject("value2"); const result: string | undefined = await Select.prompt({ @@ -13,7 +15,7 @@ Deno.test("prompt select: value", async () => { assertEquals(result, "value2"); }); -Deno.test("prompt select: object value", async () => { +test("prompt select: object value", async () => { Select.inject({ id: 1, name: "foo" }); const books = [ @@ -30,7 +32,7 @@ Deno.test("prompt select: object value", async () => { assertType>(true); }); -Deno.test("prompt select: empty value", async () => { +test("prompt select: empty value", async () => { await assertRejects( async () => { Select.inject(""); @@ -41,12 +43,12 @@ Deno.test("prompt select: empty value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt select: invalid value", async () => { +test("prompt select: invalid value", async () => { await assertRejects( async () => { Select.inject("value4"); @@ -57,12 +59,12 @@ Deno.test("prompt select: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt select: null value", async () => { +test("prompt select: null value", async () => { await assertRejects( async () => { // deno-lint-ignore no-explicit-any @@ -74,7 +76,7 @@ Deno.test("prompt select: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/test/toggle_test.ts b/prompt/test/toggle_test.ts index 81d2aed1..df1309a9 100644 --- a/prompt/test/toggle_test.ts +++ b/prompt/test/toggle_test.ts @@ -1,22 +1,24 @@ +import { getOs } from "@cliffy/internal/runtime/get-os"; +import { test } from "@cliffy/internal/testing/test"; import { assertEquals, assertRejects } from "@std/assert"; import { bold, red } from "@std/fmt/colors"; import { Toggle } from "../toggle.ts"; -Deno.test("prompt toggle: yes", async () => { +test("prompt toggle: yes", async () => { console.log(); Toggle.inject("Yes"); const result: boolean | undefined = await Toggle.prompt("message"); assertEquals(result, true); }); -Deno.test("prompt toggle: no", async () => { +test("prompt toggle: no", async () => { console.log(); Toggle.inject("No"); const result: boolean | undefined = await Toggle.prompt("message"); assertEquals(result, false); }); -Deno.test("prompt toggle: empty value", async () => { +test("prompt toggle: empty value", async () => { console.log(); await assertRejects( async () => { @@ -25,12 +27,12 @@ Deno.test("prompt toggle: empty value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt toggle: invalid value", async () => { +test("prompt toggle: invalid value", async () => { console.log(); await assertRejects( async () => { @@ -39,12 +41,12 @@ Deno.test("prompt toggle: invalid value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); -Deno.test("prompt toggle: null value", async () => { +test("prompt toggle: null value", async () => { console.log(); await assertRejects( async () => { @@ -54,7 +56,7 @@ Deno.test("prompt toggle: null value", async () => { }, Error, red( - `${Deno.build.os === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, + `${getOs() === "windows" ? bold("× ") : bold("✘ ")}Invalid answer.`, ), ); }); diff --git a/prompt/toggle.ts b/prompt/toggle.ts index 317087dd..b97d4fb0 100644 --- a/prompt/toggle.ts +++ b/prompt/toggle.ts @@ -63,7 +63,7 @@ export class Toggle extends GenericPrompt { : ""; } - public getDefaultSettings(options: ToggleOptions): ToggleSettings { + public override getDefaultSettings(options: ToggleOptions): ToggleSettings { const settings = super.getDefaultSettings(options); return { ...settings, @@ -77,7 +77,7 @@ export class Toggle extends GenericPrompt { }; } - protected message(): string { + protected override message(): string { let message = super.message() + " " + this.settings.pointer + " "; if (this.status === this.settings.active) { @@ -94,7 +94,7 @@ export class Toggle extends GenericPrompt { } /** Read user input from stdin, handle events and validate user input. */ - protected read(): Promise { + protected override read(): Promise { this.settings.tty.cursorHide(); return super.read(); } @@ -103,7 +103,7 @@ export class Toggle extends GenericPrompt { * Handle user input event. * @param event Key event. */ - protected async handleEvent(event: KeyCode): Promise { + protected override async handleEvent(event: KeyCode): Promise { switch (true) { case event.sequence === this.settings.inactive[0].toLowerCase(): case this.isKey(this.settings.keys, "inactive", event): diff --git a/table/_utils.ts b/table/_utils.ts index 87231de6..00f780e0 100644 --- a/table/_utils.ts +++ b/table/_utils.ts @@ -7,7 +7,8 @@ import { Cell, type CellType } from "./cell.ts"; import { consumeWords } from "./consume_words.ts"; import { stripAnsiCode } from "@std/fmt/colors"; -import { unicodeWidth } from "@std/cli/unicode-width"; +import { unicodeWidth } from "./unicode_width.ts"; +// import { unicodeWidth } from "@std/cli/unicode-width"; /** * Get longest cell from given row index. diff --git a/table/row.ts b/table/row.ts index aad1c6a4..591079f0 100644 --- a/table/row.ts +++ b/table/row.ts @@ -44,7 +44,7 @@ export class Row< * * @param cells Cells or row. */ - public static from( + public static override from( cells: RowType, ): Row { const row = new this(...cells); diff --git a/table/table.ts b/table/table.ts index cd9f3d71..52d6781a 100644 --- a/table/table.ts +++ b/table/table.ts @@ -68,7 +68,9 @@ export class Table extends Array { * * @param rows An array of rows or a table instance. */ - public static from(rows: TableType): Table { + public static override from( + rows: TableType, + ): Table { const table = new this(...rows); if (rows instanceof Table) { table.options = { ...(rows as Table).options }; @@ -184,7 +186,7 @@ export class Table extends Array { } /** Generate table string. */ - public toString(): string { + public override toString(): string { return new TableLayout(this, this.options).toString(); } diff --git a/table/test/align_test.ts b/table/test/align_test.ts index 2b093523..30f0fffc 100644 --- a/table/test/align_test.ts +++ b/table/test/align_test.ts @@ -1,9 +1,10 @@ +import { test } from "@cliffy/internal/testing/test"; import { Table } from "../table.ts"; import { assertEquals } from "@std/assert"; import { Row } from "../row.ts"; import { Cell } from "../cell.ts"; -Deno.test("table - align - align table", () => { +test("table - align - align table", () => { assertEquals( new Table() .header(["Foo", "Bar", "Baz"]) @@ -28,7 +29,7 @@ Deno.test("table - align - align table", () => { ); }); -Deno.test("table - align - align row and cell", () => { +test("table - align - align row and cell", () => { assertEquals( new Table() .header(Row.from(["Foo", "Bar", "Baz"]).align("center")) @@ -52,7 +53,7 @@ Deno.test("table - align - align row and cell", () => { ); }); -Deno.test("table - align - default direction", () => { +test("table - align - default direction", () => { const cell = new Cell("foo"); const row = new Row(cell); const table = new Table(row); @@ -63,7 +64,7 @@ Deno.test("table - align - default direction", () => { assertEquals(table[0].getAlign(), "left"); }); -Deno.test("table - align - override direction", () => { +test("table - align - override direction", () => { const cell = new Cell("foo").align("center"); const row = new Row(cell).align("center"); const table = new Table(row).align("center"); @@ -74,7 +75,7 @@ Deno.test("table - align - override direction", () => { assertEquals(table[0].getAlign(), "center"); }); -Deno.test("table - align - inherit direction", () => { +test("table - align - inherit direction", () => { const cell = new Cell("foo"); const row = new Row(cell); const table = new Table(row).align("right"); diff --git a/table/test/ansi_regex_source_test.ts b/table/test/ansi_regex_source_test.ts index eab09efc..6a907eb8 100644 --- a/table/test/ansi_regex_source_test.ts +++ b/table/test/ansi_regex_source_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { ansiRegexSource } from "../_utils.ts"; import { assertEquals } from "@std/assert"; -Deno.test(`table - ansiRegexSource`, () => { +test(`table - ansiRegexSource`, () => { const DIGITS = String.raw`\d+`; // All open and close ANSI codes taken from calls to `code(...)` in // https://deno.land/std@0.221.0/fmt/colors.ts diff --git a/table/test/ansi_wrapping_within_cell_test.ts b/table/test/ansi_wrapping_within_cell_test.ts index 776c5b2e..20aab6c2 100644 --- a/table/test/ansi_wrapping_within_cell_test.ts +++ b/table/test/ansi_wrapping_within_cell_test.ts @@ -1,3 +1,4 @@ +import { test } from "@cliffy/internal/testing/test"; import { Table } from "../table.ts"; import { assertEquals } from "@std/assert"; @@ -84,7 +85,7 @@ for (const { description, content, width, expect } of tests) { // console.log(`expect\n${expect}`); // console.log(JSON.stringify({ actual, expect }, null, '\t')); - Deno.test(`table - ${description}`, () => { + test(`table - ${description}`, () => { assertEquals(actual, expect); }); } diff --git a/table/test/border_test.ts b/table/test/border_test.ts index 14152c11..52aaf9c8 100644 --- a/table/test/border_test.ts +++ b/table/test/border_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { border } from "../border.ts"; import { Table } from "../table.ts"; import { assertEquals } from "@std/assert"; -Deno.test("default table chars", () => { +test("default table chars", () => { assertEquals( Table .from([ @@ -23,7 +24,7 @@ Deno.test("default table chars", () => { ); }); -Deno.test("custom global table chars", () => { +test("custom global table chars", () => { assertEquals( Table .chars({ @@ -63,7 +64,7 @@ geeeeeeeeeeeefeeeeeeeeeeeeeeeefeeeeeeeeeeeeeeeeeeeh`.slice(1), Table.chars(border); }); -Deno.test("custom table chars", () => { +test("custom table chars", () => { assertEquals( Table .from([ diff --git a/table/test/span_test.ts b/table/test/span_test.ts index 6769bdbc..45a7fb18 100644 --- a/table/test/span_test.ts +++ b/table/test/span_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { Cell } from "../cell.ts"; import { Table } from "../table.ts"; import { assertEquals } from "@std/assert"; -Deno.test("should allow undefined cell values", () => { +test("should allow undefined cell values", () => { assertEquals( Table.from([ ["foo", undefined, "bar"], @@ -20,7 +21,7 @@ Deno.test("should allow undefined cell values", () => { ); }); -Deno.test("should override undefined cell values with col & row span", () => { +test("should override undefined cell values with col & row span", () => { assertEquals( Table.from([ [new Cell("foo").colSpan(2), undefined, "bar"], @@ -41,7 +42,7 @@ Deno.test("should override undefined cell values with col & row span", () => { ); }); -Deno.test("colspan + rowspan 1", () => { +test("colspan + rowspan 1", () => { const expected = ` ┌────────────────────┬────────────────┬────────────────┐ │ Row 1 & 2 Column 1 │ Row 1 Column 2 │ Row 1 Column 3 │ @@ -83,7 +84,7 @@ Deno.test("colspan + rowspan 1", () => { ); }); -Deno.test("colspan + rowspan 2", () => { +test("colspan + rowspan 2", () => { const expected = ` ┌────────────────────┬────────────────┬────────────────┐ │ Row 1 & 2 Column 1 │ Row 1 Column 2 │ Row 1 Column 3 │ @@ -124,7 +125,7 @@ Deno.test("colspan + rowspan 2", () => { ); }); -Deno.test("colspan + rowspan 3", () => { +test("colspan + rowspan 3", () => { const expected = ` ┌────────────────┬─────┐ │ Row 5 Column 1 │ Row │ @@ -149,7 +150,7 @@ Deno.test("colspan + rowspan 3", () => { ); }); -Deno.test("colspan + rowspan 4", () => { +test("colspan + rowspan 4", () => { const expected = ` ┌─────┐ │ Row │ @@ -171,7 +172,7 @@ Deno.test("colspan + rowspan 4", () => { ); }); -Deno.test("colspan + rowspan 5", () => { +test("colspan + rowspan 5", () => { const expected = ` ┌────────────────┬────────────────┬────────────────┬────────────────┐ │ Row 1 Column 1 │ Row 1 Column 2 │ Row 1 Column 3 │ Row 1 Column 4 │ @@ -200,7 +201,7 @@ Deno.test("colspan + rowspan 5", () => { ); }); -Deno.test("colspan + rowspan 6", () => { +test("colspan + rowspan 6", () => { const expected = ` ┌────────────────┬────────────────┬─────────────────────────────────┐ │ Row 1 Column 1 │ Row 1 Column 2 │ Row 1 & 2 Column 3 & 4 │ @@ -229,7 +230,7 @@ Deno.test("colspan + rowspan 6", () => { ); }); -Deno.test("colspan + rowspan 7", () => { +test("colspan + rowspan 7", () => { const expected = ` ┌────────────────┬────────────────┬──┬──┐ │ Row 1 Column 1 │ Row 1 Column 2 │ │ │ @@ -265,7 +266,7 @@ Deno.test("colspan + rowspan 7", () => { ); }); -Deno.test("colspan + rowspan 8", () => { +test("colspan + rowspan 8", () => { const expected = ` ┌────────────────┬────────────────────┬──┬──┐ │ Row 1 Column 1 │ Row 1 & 2 Column 2 │ │ │ @@ -300,7 +301,7 @@ Deno.test("colspan + rowspan 8", () => { ); }); -Deno.test("should allow an empty array as first row", () => { +test("should allow an empty array as first row", () => { assertEquals( Table.from([ [], diff --git a/table/test/special_chars.ts b/table/test/special_chars_test.ts similarity index 79% rename from table/test/special_chars.ts rename to table/test/special_chars_test.ts index 05505546..382a3683 100644 --- a/table/test/special_chars.ts +++ b/table/test/special_chars_test.ts @@ -1,7 +1,8 @@ +import { test } from "@cliffy/internal/testing/test"; import { Table } from "../table.ts"; import { assertEquals } from "@std/assert"; -Deno.test("table - special chars - chinese characters", () => { +test("table - special chars - chinese characters", () => { assertEquals( Table.from([ ["名字为 豆贝 尔维了", "cell2", "cell3"], @@ -17,7 +18,7 @@ cell1 豆 贝 cell3`.slice(1), ); }); -Deno.test("table - special chars - japanese characters", () => { +test("table - special chars - japanese characters", () => { assertEquals( Table.from([ ["私は ふわっち クン", "cell2", "cell3"], @@ -33,7 +34,7 @@ cell1 ふわ ふわ cell3 `.slice(1), ); }); -Deno.test("table - special chars - full width & cjk sybmol characters", () => { +test("table - special chars - full width & cjk sybmol characters", () => { assertEquals( Table.from([ ["!、¥", "cell2", "cell3"], @@ -49,7 +50,7 @@ cell1 〜 〜 cell3`.slice(1), ); }); -Deno.test("table - special chars - Korean", () => { +test("table - special chars - Korean", () => { assertEquals( Table.from([["한"]]) .border(true) @@ -61,7 +62,7 @@ Deno.test("table - special chars - Korean", () => { ); }); -Deno.test("table - emoji (within BMP)", () => { +test("table - emoji (within BMP)", () => { assertEquals( Table.from([["✅"]]) .border(true) @@ -73,7 +74,7 @@ Deno.test("table - emoji (within BMP)", () => { ); }); -Deno.test("table - emoji (outside BMP)", () => { +test("table - emoji (outside BMP)", () => { assertEquals( Table.from([["💩"]]) .border(true) @@ -85,7 +86,7 @@ Deno.test("table - emoji (outside BMP)", () => { ); }); -Deno.test("table - zero-width non-joiner", () => { +test("table - zero-width non-joiner", () => { assertEquals( Table.from([["a\u200cb"]]) .border(true) @@ -97,7 +98,7 @@ Deno.test("table - zero-width non-joiner", () => { ); }); -Deno.test("table - single-width char (outside BMP)", () => { +test("table - single-width char (outside BMP)", () => { assertEquals( Table.from([["𐌰𐌱"]]) .border(true) diff --git a/table/test/table_test.ts b/table/test/table_test.ts index c2008416..01d53ff1 100644 --- a/table/test/table_test.ts +++ b/table/test/table_test.ts @@ -1,8 +1,9 @@ +import { test } from "@cliffy/internal/testing/test"; import { Table } from "../table.ts"; import { assertEquals, assertStrictEquals, assertThrows } from "@std/assert"; import { Row } from "../row.ts"; -Deno.test("simple table", () => { +test("simple table", () => { assertEquals( Table.from([ ["cell1", "cell2", "cell3"], @@ -18,7 +19,7 @@ cell1 cell2 cell3`.slice(1), ); }); -Deno.test("simple table from table", () => { +test("simple table from table", () => { assertEquals( Table.from( new Table() @@ -39,7 +40,7 @@ cell1 cell2 cell3`.slice(1), ); }); -Deno.test("simple table from json", () => { +test("simple table from json", () => { assertEquals( Table.fromJson([{ firstName: "foo", @@ -64,7 +65,7 @@ foo bar 132`.slice(1), ); }); -Deno.test("clone simple table", () => { +test("clone simple table", () => { const table1 = Table.from([ ["cell1", "cell2", "cell3"], ["cell1", "cell2", "cell3"], @@ -76,7 +77,7 @@ Deno.test("clone simple table", () => { assertThrows(() => assertStrictEquals(table2, table3), Error); }); -Deno.test("table getter", () => { +test("table getter", () => { const header = Row.from(["1", "2", "3"]).border(false); const table = new Table() .header(header) @@ -105,7 +106,7 @@ Deno.test("table getter", () => { assertEquals(table.hasHeaderBorder(), false); }); -Deno.test("simple table with min col with", () => { +test("simple table with min col with", () => { assertEquals( Table.from([ ["cell1", "cell2", "cell3"], @@ -126,7 +127,7 @@ Deno.test("simple table with min col with", () => { ); }); -Deno.test("simple table with word break", () => { +test("simple table with word break", () => { assertEquals( Table.from([ ["cell1", "cell2 cell2", "cell3"], @@ -151,7 +152,7 @@ cell cell cell ); }); -Deno.test("simple border table", () => { +test("simple border table", () => { assertEquals( Table.from([ ["cell1", "cell2", "cell3"], @@ -172,7 +173,7 @@ Deno.test("simple border table", () => { ); }); -Deno.test("simple nested table", () => { +test("simple nested table", () => { assertEquals( Table.from([[ Table.from([ @@ -256,7 +257,7 @@ cell1 cell2 cell3 cell1 cell2 cell3 cell1 cell2 cell3`.slice(1), ); }); -Deno.test("simple nested border table", () => { +test("simple nested border table", () => { assertEquals( Table.from([[ Table.from([ @@ -361,7 +362,7 @@ Deno.test("simple nested border table", () => { ); }); -Deno.test("multiline table", () => { +test("multiline table", () => { assertEquals( Table.from([ [ @@ -416,7 +417,7 @@ cell1 cell2 At vero eos et ); }); -Deno.test("multiline border table", () => { +test("multiline border table", () => { assertEquals( Table.from([ [ @@ -476,7 +477,7 @@ Deno.test("multiline border table", () => { ); }); -Deno.test("nested multiline border table", () => { +test("nested multiline border table", () => { assertEquals( Table.from([[ Table.from([ @@ -582,7 +583,7 @@ cell1 cell2 cell3 ); }); -Deno.test("nested multiline border table", () => { +test("nested multiline border table", () => { assertEquals( Table.from([[ Table.from([ @@ -709,7 +710,7 @@ Deno.test("nested multiline border table", () => { ); }); -Deno.test("table with padding", () => { +test("table with padding", () => { assertEquals( Table.from([ [ diff --git a/table/test/utils_test.ts b/table/test/utils_test.ts index c2ea94a9..32bdec21 100644 --- a/table/test/utils_test.ts +++ b/table/test/utils_test.ts @@ -1,53 +1,54 @@ +import { test } from "@cliffy/internal/testing/test"; import { assertEquals } from "@std/assert"; import { consumeWords } from "../consume_words.ts"; const str = "│cell1│cell2 cell2 cell2 cell2 cell2 cell2 cell2 cell2 cell2 cell2│cell3│"; -Deno.test("consume words 01", () => { +test("consume words 01", () => { assertEquals(consumeWords(str.length, str), str); }); -Deno.test("consume words 02", () => { +test("consume words 02", () => { assertEquals( consumeWords(str.length - 1, str), "│cell1│cell2 cell2 cell2 cell2 cell2 cell2 cell2 cell2 cell2", ); }); -Deno.test("consume words 03", () => { +test("consume words 03", () => { assertEquals(consumeWords(5, str), "│cell1│cell2"); }); -Deno.test("consume words 04", () => { +test("consume words 04", () => { assertEquals(consumeWords(12, str), "│cell1│cell2"); }); -Deno.test("consume words 05", () => { +test("consume words 05", () => { assertEquals(consumeWords(17, str), "│cell1│cell2"); }); -Deno.test("consume words 06", () => { +test("consume words 06", () => { assertEquals(consumeWords(18, str), "│cell1│cell2 cell2"); }); -Deno.test("consume words 07", () => { +test("consume words 07", () => { assertEquals(consumeWords(19, str), "│cell1│cell2 cell2"); }); -Deno.test("consume words 08", () => { +test("consume words 08", () => { assertEquals(consumeWords(19, ` ${str} `), " │cell1│cell2"); }); -Deno.test("consume words 09", () => { +test("consume words 09", () => { assertEquals(consumeWords(20, ` ${str} `), " │cell1│cell2 cell2"); }); -Deno.test("consume words 10", () => { +test("consume words 10", () => { assertEquals(consumeWords(21, ` ${str} `), " │cell1│cell2 cell2"); }); -Deno.test("consume words 11", () => { +test("consume words 11", () => { assertEquals(consumeWords(22, ` ${str} `), " │cell1│cell2 cell2"); }); @@ -60,7 +61,7 @@ const multilineStr = ` │cell1│cell2 │cell3│ └─────┴───────────────────────────────────────────────────────────┴─────┘`; -Deno.test("consume words 12", () => { +test("consume words 12", () => { assertEquals( consumeWords(74, multilineStr.slice(1)), " ┌─────┬───────────────────────────────────────────────────────────┬─────┐", diff --git a/table/unicode_width.ts b/table/unicode_width.ts new file mode 100644 index 00000000..b67cccc7 --- /dev/null +++ b/table/unicode_width.ts @@ -0,0 +1,107 @@ +let tables: Uint8Array[] | null = null; + +const data = { + "UNICODE_VERSION": "15.0.0", + "tables": [ + { + "d": "AAECAwQFBgcICQoLDA0OAw8DDwkQCRESERIA", + "r": "AQEBAgEBAQEBAQEBAQEBBwEHAVABBwcBBwF4", + }, + { + "d": + "AAECAwQFBgcGCAYJCgsMDQ4PEAYREhMUBhUWFxgZGhscHR4fICEiIyIkJSYnKCkqJSssLS4vMDEyMzQ1Njc4OToGOzwKBj0GPj9AQUIGQwZEBkVGR0hJSktMTQZOBgoGT1BRUlNUVVZXWFkGWgZbBlxdXl1fYGFiY2RlZmdoBmlqBmsGAQZsBm1uO29wcXI7czt0dXZ3OwY7eHkGent8Bn0Gfn+AgYKDhIWGBoc7iAZdO4kGiosGAXGMBo0GjgaPBpAGkQaSBpMGlJUGlpcGmJmam5ydnp+gLgahLKIGo6SlpganqKmqqwasBq0Grq8GsLGyswa0BrUGtre4Brm6uwZHvAa9vga/wME7wjvDxAbFO8bHO8gGyQbKywbMzQbOBs/Q0QbSBr8GvgbT1AbUBtUG1gbXBtjZ2tsG3N0G3t/g4eLjO+Tl5ufoO+k76gbrBuztOwbu7/AGO+XxCgYKCwZd8g==", + "r": + "AQEBAQEBAQEBAQEBAQEBAQEBAQMBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQECBQEOAQEBAQEBAQEBAwEBAQEBAQEBAQIBAwEIAQEBAQEBAQEBAQEBAQIBAQEBAQEBAQEBAQEBAQEBDQEBBQEBAQEBAgEBAwEBAQEBAQEBAQEBbQHaAQEFAQEBBAECAQEBAQEBAQEBAwGuASFkCAELAQEBAQEBAQEHAQMBAQEaAQIBCAEFAQEBAQEBAQEBAQEBAQEBAQEBAQECAQEBAQIBAQEBAQEBAwEDAQEBAQEBAQUBAQEBAQEBBAEBAVIBAdkBARABAQFfARMBAYoBBAEBBQEmAUkBAQcBAQIBHgEBARUBAQEBAQUBAQcBDwEBARoBAgEBAQEBAQECAQEBAQEBAQEBAQEBAQEBAQMBBAEBAgEBAQEUfwEBAQIDAXj/AQ==", + }, + { + "d": + "AFUVAF3Xd3X/93//VXVVV9VX9V91f1/31X93XVXdVdVV9dVV/VVX1X9X/131VfXVVXV3V1VdVV1V1/1dV1X/3VUAVf3/3/9fVf3/3/9fVV1V/11VFQBQVQEAEEEQVQBQVQBAVFUVAFVUVQUAEAAUBFBVFVFVAEBVBQBUVRUAVVFVBRAAAVBVAVVQVQBVBQBAVUVUAQBUUQEAVQVVUVVUAVRVUVUFVUVBVVRBFRRQUVVQUVUBEFRRVQVVBQBRVRQBVFVRVUFVBVVFVVRVUVVUVQRUBQRQVUFVBVVFVVBVBVVQVRVUAVRVUVUFVVFVRVUFRFVRAEBVFQBAVVEAVFUAQFVQVRFRVQEAQAAEVQEAAQBUVUVVAQQAQVVQBVRVAVRVRUFVUVVRVaoAVQFVBVRVBVUFVQVVEABQVUUBAFVRVRUAVUFVUVVAFVRVRVUBVRUUVUUAQEQBAFQVABRVAEBVAFUEQFRFVRUAVVBVBVAQUFVFUBFQVQAFVUAABABUUVVUUFUVANd/X3//BUD3XdV1VQAEAFVXVdX9V1VXVQBUVdVdVdV1VX111VXVV9V//1X/X1VdVf9fVV9VdVdV1VX31dfVXXX9193/d1X/VV9VV3VVX//1VfVVXVVdVdVVdVWlVWlVqVaWVf/f/1X/Vf/1X1Xf/19V9VVf9df1X1X1X1XVVWlVfV31VVpVd1V3VapV33/fVZVVlVX1WVWlVelV+v/v//7/31Xv/6/77/tVWaVVVlVdVWaVmlX1/1WpVVZVlVWVVlVW+V9VFVBVAKqaqlWqWlWqVaoKoKpqqapqgapVqaqpqmqqVapqqv+qVqpqVRVAAFBVBVVQVUUVVUFVVFVQVQBQVRVVBQBQVRUAUFWqVkBVFQVQVVFVAUBBVRVVVFVUVQQUVAVRVVBVRVVRVFFVqlVFVQCqWlUAqmqqaqpVqlZVqmpVAV1VUVVUVQVAVQFBVQBVQBVVQVUAVRVUVQFVBQBUVQVQVVFVAEBVFFRVFVBVFUBBUUVVUVVAVRUAAQBUVRVVUFUFAEBVARRVFVAEVUVVFQBAVVRVBQBUAFRVAAVEVUVVFQBEFQRVBVBVEFRVUFUVAEARVFUVUQAQVQEFEABVFQBBVRVEFVUABVVUVQEAQFUVABRAVRVVAUABVQUAQFBVAEAAEFUFAAUABEFVAUBFEAAQVVARVRVUVVBVBUBVRFVUFQBQVQBUVQBAVRVVFUBVqlRVWlWqVapaVapWVaqpqmmqalVlVWpZVapVqlVBAFUAUABAVRVQVRUAQAEAVQVQVQVUVQBAFQBUVVFVVFUVAAEAVQBAABQAEARAVUVVAFUAQFUAQFVWVZVV/39V/1//X1X/76uq6v9XVWpVqlWqVlVaVapaVapWVamqmqqmqlWqapWqVapWqmqmqpaqWlWVaqpVZVVpVVZVlapVqlpVVmqpVapVlVZVqlZVqlVWVapqqpqqVapWqlZVqpqqWlWlqlWqVlWqVlVRVQD/Xw==", + "r": + "CBcBCAEBAQEBAQEBAQECAQEBAQEBAQEBAQEBAQMBAQECAQEBAQEBAQEBAQEBBAEBGAEDAQwBAwEIAQEBAQEBAQgcCAEDAQEBAQEDAQEBDQEDEAELAQEBEQEKAQEBDgEBAgIBAQoBBQQBCAEBAQEBAQEHAQEHBgEWAQIBDQECAgEFAQECAgEKAQ0BAQIKAQ0BDQEBAQEBAQEBAgEHAQ4BAQEBAQQBBgEBDgEBAQEBAQcBAQIBAQEBBAEFAQEBDgEBAQEBAQECAQcBDwECAQwCDQEBAQEBAQECAQgBAQEEAQcBDQEBAQEBAQQBBwERAQEBARYBAQECAQEBGAECAQIBARIBBgEBDQECAQEBAQECAQgBAQEZAQEBAgYBAQEDAQECAQEBAQMBCBgIBwEMAQEGAQcBBwEQAQEBAQEBAgIBCgEBDQEIAQ0BAQEBAQEBBgEBDgEBAQEBAQEBAgEMBwEMAQwBAQEBCQECAwEHAQEBAQ0BAQEBDgIBBgEDAQEBAQEBAQMBAQEBAgEBAQEBAQEBCAEBAgEBAQEBAQkBCAgBAwECAQEBAgEBAQkBAQEBAwECAQMBAQIBBwEFAQEDAQYBAQEBAgEBAQEBAQEBAQECAgEDAQECBAIDAgIBBQEEAQEBAwEPAQEBCyIBCAEJAwQBAQIBAQEBAgECAQEBAQMBAQEBAwEBAQEBAQEBAQgBAQMDAgEBAwEEAQIBAQEBBAEBAQEBAQECAQEBAQEBAQEBAQEHAQQBAwEBAQcBAgUBBgECAQYBAQwBAQEUAQELCAYBFgMFAQYDAQoBAQMBARQBAQkBAQoBBgEVAwsBCgIPAQ0BGQEBAgEHARQBAwIBBgEBAQUBBgQBAgEJAQEBBQECAQMHAQELAQECCQEQAQECAgECAQsBDAEBAQEBCgEBAQsBAQEECQ4BCAQCAQEECAEEAQEFCAEPAQEEAQEPAQgBFAEBAQEBAQEKAQEJAQ8BEAEBEwEBAQIBCwEBDgENAwEKAQEBAQELAQEBAQECAQwBCAEBAQEBDgEDAQwBAQECAQEXAQEBAQEHAgEBBQEIAQEBAQEQAgEBBQEUAQEBAQEbAQEBAQEGARQBAQEBARkBAQEBCQEBAQEQAQIBDwEBARQBAQEBBwEBAQkBAQEBAQECAQEBCwECAQEVAQEBAQQBBQEBAQEOAQEBAQEBEgEBFgEBAgEMAQEBAQ8BAQMBFgEBDgEBBQEPAQETAQECAQMOAgUBCgIBGQEBAQEIAQMBBwEBAwECEwgBAQcLAQUBFwEBAQEDAQEBBwEBBAEBDg0BAQwBAQEDAQQBAQEDBAEBBAEBAQEBEAEPAQgBAQsBAQ4BEQEMAgEBBwEOAQEHAQEBAQQBBAEDCwECAQEBAwEBBggBAgEBAREBBQMKAQEBAwQCEQEBHgEPAQIBAQYEAQYBAwEUAQUMAQEBAQEBAQECAQEBAgEIAwEBBgsBAgEODAMBAgEBCwEBAQEBAwECAQECAQEBBwgPAQ==", + }, + ], +} as const; + +function lookupWidth(cp: number) { + if (!tables) tables = data.tables.map(runLengthDecode); + const t1Offset = tables[0]![(cp >> 13) & 0xff]!; + const t2Offset = tables[1]![128 * t1Offset + ((cp >> 6) & 0x7f)]!; + const packedWidths = tables[2]![16 * t2Offset + ((cp >> 2) & 0xf)]!; + + const width = (packedWidths >> (2 * (cp & 0b11))) & 0b11; + + return width === 3 ? 1 : width; +} + +const cache = new Map(); +function charWidth(char: string) { + if (cache.has(char)) return cache.get(char)!; + + const codePoint = char.codePointAt(0)!; + let width: number | null = null; + + if (codePoint < 0x7f) { + width = codePoint >= 0x20 ? 1 : codePoint === 0 ? 0 : null; + } else if (codePoint >= 0xa0) { + width = lookupWidth(codePoint); + } else { + width = null; + } + + cache.set(char, width); + return width; +} + +/** + * Calculate the physical width of a string in a TTY-like environment. This is + * useful for cases such as calculating where a line-wrap will occur and + * underlining strings. + * + * The physical width is given by the number of columns required to display + * the string. The number of columns a given unicode character occupies can + * vary depending on the character itself. + * + * @param str The string to measure. + * @returns The unicode width of the string. + * + * @example Calculating the unicode width of a string + * ```ts + * import { unicodeWidth } from "@std/cli/unicode-width"; + * import { assertEquals } from "@std/assert"; + * + * assertEquals(unicodeWidth("hello world"), 11); + * assertEquals(unicodeWidth("天地玄黃宇宙洪荒"), 16); + * assertEquals(unicodeWidth("fullwidth"), 18); + * ``` + * + * @example Calculating the unicode width of a color-encoded string + * ```ts + * import { unicodeWidth } from "@std/cli/unicode-width"; + * import { stripAnsiCode } from "@std/fmt/colors"; + * import { assertEquals } from "@std/assert"; + * + * assertEquals(unicodeWidth(stripAnsiCode("\x1b[36mголубой\x1b[39m")), 7); + * assertEquals(unicodeWidth(stripAnsiCode("\x1b[31m紅色\x1b[39m")), 4); + * assertEquals(unicodeWidth(stripAnsiCode("\x1B]8;;https://deno.land\x07🦕\x1B]8;;\x07")), 2); + * ``` + * + * Use + * {@linkcode https://jsr.io/@std/fmt/doc/colors/~/stripAnsiCode | stripAnsiCode} + * to remove ANSI escape codes from a string before passing it to + * {@linkcode unicodeWidth}. + */ +export function unicodeWidth(str: string): number { + return [...str].map((ch) => charWidth(ch) ?? 0).reduce((a, b) => a + b, 0); +} + +function runLengthDecode({ d, r }: { d: string; r: string }) { + const data = atob(d); + const runLengths = atob(r); + let out = ""; + + for (const [i, ch] of [...runLengths].entries()) { + out += data[i]!.repeat(ch.codePointAt(0)!); + } + + return Uint8Array.from([...out].map((x) => x.codePointAt(0)!)); +} diff --git a/tasks/setup_node.ts b/tasks/setup_node.ts new file mode 100755 index 00000000..1505deb9 --- /dev/null +++ b/tasks/setup_node.ts @@ -0,0 +1,108 @@ +#! /usr/bin/env -S deno run -A + +import { walk } from "@std/fs/walk"; +import denoConfig from "../deno.json" with { type: "json" }; +import { join } from "@std/path/posix"; + +const projects = await getProjects(); +const paths: Record> = {}; + +await Promise.all(projects.map(async (project) => { + let { default: { exports } }: { + default: { exports: Record | string }; + } = await import(`../${project}/deno.json`, { with: { type: "json" } }); + + if (typeof exports === "string") { + exports = { ".": exports }; + } + + for (const [specifier, path] of Object.entries(exports)) { + paths[join("@cliffy", project, specifier)] = [`./${join(project, path)}`]; + } +})); + +await Deno.writeTextFile( + "./tsconfig.json", + JSON.stringify({ + compilerOptions: { + allowJs: true, + esModuleInterop: true, + experimentalDecorators: false, + inlineSourceMap: true, + isolatedModules: true, + module: "esnext", + moduleDetection: "force", + strict: true, + target: "esnext", + useDefineForClassFields: true, + paths, + }, + }), +); + +const dependencies: Record = {}; +for (const [specifier, version] of Object.entries(denoConfig.imports)) { + if (specifier.includes("cliffy")) { + continue; + } + dependencies[specifier] = version.startsWith("jsr:") + ? `npm:@jsr/${version.replace("/", "__").replace("jsr:@", "")}` + : version; +} + +console.log("PATH:", Deno.env.get("PATH")); +console.log("PNPM_HOME:", Deno.env.get("PNPM_HOME")); + +await Deno.writeTextFile( + "./package.json", + JSON.stringify({ + type: "module", + packageManager: "pnpm@9.7.1", + dependencies: { + ...dependencies, + tsx: "4.17.0", + }, + }), +); + +await Deno.writeTextFile("./.npmrc", "@jsr:registry=https://npm.jsr.io\n"); + +await new Deno.Command("deno", { + args: ["fmt", "tsconfig.json", "package.json"], +}).spawn().output(); + +if (!Deno.args.includes("--no-install")) { + if (Deno.args.includes("--bun")) { + await new Deno.Command("bun", { + args: ["install"], + }).spawn().output(); + } else { + await new Deno.Command("pnpm", { + args: ["install"], + }).spawn().output(); + } +} + +async function getProjects(): Promise> { + const projects: Array = []; + + for await ( + const entry of walk(".", { includeDirs: true, followSymlinks: false }) + ) { + if ( + entry.isDirectory && !entry.path.startsWith(".") && + [".", "node_modules"].every((path) => !entry.path.startsWith(path)) + ) { + try { + const files = [...Deno.readDirSync(entry.path)]; + if (files.some((file) => file.name === "deno.json")) { + projects.push(entry.path); + } + } catch (error) { + console.error(`Error reading directory ${entry.path}:`, error); + } + } + } + + return projects; +} diff --git a/testing/snapshot.ts b/testing/snapshot.ts index 532c4192..c23312fd 100644 --- a/testing/snapshot.ts +++ b/testing/snapshot.ts @@ -1,6 +1,8 @@ import { eraseDown } from "@cliffy/ansi/ansi-escapes"; +import { getRuntimeName } from "@cliffy/internal/runtime/runtime-name"; +import { test } from "@cliffy/internal/testing/test"; + import { quoteString } from "./_quote_string.ts"; -import { basename } from "@std/path"; import { red } from "@std/fmt/colors"; import { assertSnapshot } from "@std/testing/snapshot"; import { AssertionError } from "@std/assert/assertion-error"; @@ -114,26 +116,34 @@ export async function snapshotTest( } function registerTest(options: SnapshotTestOptions) { - const fileName = basename(options.meta.url); + const fileName = options.meta.url.split("/").at(-1) ?? ""; - Deno.test({ - name: options.name, - ignore: options.ignore ?? false, - only: options.only ?? false, - async fn(ctx) { - const steps = Object.entries(options.steps ?? {}); - if (steps.length) { - for (const [name, step] of steps) { - await ctx.step({ - name, - fn: (ctx) => fn(ctx, step), - }); + if (["node", "bun"].includes(getRuntimeName())) { + test({ + name: options.name, + ignore: true, + fn() {}, + }); + } else { + Deno.test({ + name: options.name, + ignore: options.ignore ?? false, + only: options.only ?? false, + async fn(ctx) { + const steps = Object.entries(options.steps ?? {}); + if (steps.length) { + for (const [name, step] of steps) { + await ctx.step({ + name, + fn: (ctx) => fn(ctx, step), + }); + } + } else { + await fn(ctx); } - } else { - await fn(ctx); - } - }, - }); + }, + }); + } async function fn( ctx: Deno.TestContext,