Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
domdomegg committed Feb 17, 2023
1 parent 8342919 commit af9d179
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/default-command-inverted.js
Original file line number Diff line number Diff line change
@@ -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()
11 changes: 11 additions & 0 deletions examples/default-command.js
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
})
})

0 comments on commit af9d179

Please sign in to comment.