From af9d179e799ced01adf3b24cec392416ad07bb52 Mon Sep 17 00:00:00 2001 From: Adam Jones Date: Fri, 17 Feb 2023 13:39:14 +0000 Subject: [PATCH] Add tests --- examples/default-command-inverted.js | 11 +++++++++++ examples/default-command.js | 11 +++++++++++ src/__test__/index.test.ts | 23 +++++++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 examples/default-command-inverted.js create mode 100644 examples/default-command.js diff --git a/examples/default-command-inverted.js b/examples/default-command-inverted.js new file mode 100644 index 0000000..e335c21 --- /dev/null +++ b/examples/default-command-inverted.js @@ -0,0 +1,11 @@ +require('ts-node/register') +const cli = require('../src/index').cac() + +const command = cli + .command("something", "Do something") + .alias("!") + .action(async () => { + console.log("Did something!"); + }); + +cli.parse() diff --git a/examples/default-command.js b/examples/default-command.js new file mode 100644 index 0000000..1275c61 --- /dev/null +++ b/examples/default-command.js @@ -0,0 +1,11 @@ +require('ts-node/register') +const cli = require('../src/index').cac() + +const command = cli + .command("", "Do something") + .alias("something") + .action(async () => { + console.log("Did something!"); + }); + +cli.parse() diff --git a/src/__test__/index.test.ts b/src/__test__/index.test.ts index 6cb8406..f134021 100644 --- a/src/__test__/index.test.ts +++ b/src/__test__/index.test.ts @@ -176,3 +176,26 @@ describe('--version in help message', () => { expect(output).toContain(`--version`) }) }) + +describe("default commands", () => { + test("simple: empty call", async () => { + const output = await getOutput('default-command.js', []) + expect(output).toContain("Did something!") + }) + + test("simple: name alias call", async () => { + const output = await getOutput('default-command.js', ["something"]) + expect(output).toContain("Did something!") + }) + + // See https://github.com/cacjs/cac/issues/151 + test("inverted: empty call", async () => { + const output = await getOutput('default-command-inverted.js', []) + expect(output).toContain("Did something!") + }) + + test("inverted: name alias call", async () => { + const output = await getOutput('default-command-inverted.js', ["something"]) + expect(output).toContain("Did something!") + }) +})