Skip to content

Commit

Permalink
chore: add CLI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed Nov 1, 2024
1 parent 09aab73 commit 26689b8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
- run: bun run tsc
- run: bun run lint
- run: bun run build-cli
# - run: bun test
- run: bun run copy-html
- run: bun run sanity-check
- uses: actions/setup-node@v4
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"type": "module",
"scripts": {
"tsc": "bun x tsc",
"test": "bun run build-cli && bun test",
"lint": "bun x eslint src/**/*.ts",
"lint-staged": "lint-staged",
"build": "bun x rimraf tsm-cli/bin/tsm && bun run build-cli && bun run copy-html && bun run sanity-check",
Expand Down Expand Up @@ -34,6 +35,7 @@
"@typescript-eslint/eslint-plugin": "^8.12.2",
"eslint": "^8.54.0",
"husky": "^9.1.6",
"interactive-cli-tester": "^0.3.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
Expand Down
33 changes: 33 additions & 0 deletions tests/tsmx.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test, expect } from 'bun:test'
import { CLITest, ANSI } from 'interactive-cli-tester'

test('tsmx should provide team and cluster options and set accordingly', async () => {
const cli = new CLITest('./tsm-cli/bin/tsm', ['--tsmx'])

await cli.run()

await cli.waitForOutput('Change team context to')
expect(cli.getOutput()).toInclude('❯ teamsykmelding')
expect(cli.getOutput()).toInclude('tsm')

await cli.write(ANSI.CURSOR_DOWN + ANSI.CR)
await cli.getNextOutput()
expect(cli.getOutput()).toInclude('teamsykmelding')
expect(cli.getOutput()).toInclude('❯ tsm')

await cli.waitForOutput('Which cluster?')
expect(cli.getOutput()).toInclude('❯ dev-gcp')
expect(cli.getOutput()).toInclude('prod-gcp')

await cli.write(ANSI.CURSOR_DOWN + ANSI.CR)
await cli.getNextOutput()
expect(cli.getOutput()).toInclude('dev-gcp')
expect(cli.getOutput()).toInclude('❯ prod-gcp')

expect(await cli.waitForExit()).toBe(0)

const output = cli.getOutput()
expect(output).toInclude('→ Cluster set to prod-gcp')
expect(output).toInclude('→ Namespace set to tsm')
expect(output).toInclude('→ tsm team switched to tsm')
})

0 comments on commit 26689b8

Please sign in to comment.