-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cli): remove bats and use cli-testing-library (#149)
- Loading branch information
1 parent
0588373
commit c6bb459
Showing
5 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
"adamsandle", | ||
"baust", | ||
"georgovassilis", | ||
"gmrchk", | ||
"plasticrake", | ||
"wzaatar", | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import { prepareEnvironment } from '@gmrchk/cli-testing-library'; | ||
|
||
import { expect } from './setup'; | ||
|
||
const runner = 'ts-node'; | ||
const cli = './src/cli.ts'; | ||
|
||
describe('cli', function () { | ||
this.slow(5000); | ||
this.timeout(10000); | ||
|
||
// @ts-expect-error: buildable | ||
let { execute, cleanup }: Awaited<ReturnType<typeof prepareEnvironment>> = {}; | ||
|
||
beforeEach(async () => { | ||
({ execute, cleanup } = await prepareEnvironment()); | ||
}); | ||
|
||
afterEach(async () => { | ||
await cleanup(); | ||
}); | ||
|
||
describe('when run without arguments', function () { | ||
it('returns non-zero code & outputs help', async function () { | ||
const { code, stderr } = await execute(runner, cli); | ||
expect(code).to.not.equal(0); | ||
expect(stderr[0]).to.include('Usage:'); | ||
expect( | ||
stderr.some((x) => x.includes('Commands:')), | ||
'outputs Commands' | ||
).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('--help', function () { | ||
it('returns zero code & outputs help', async function () { | ||
const { code, stdout } = await execute(runner, `${cli} --help`); | ||
expect(code).to.equal(0); | ||
expect(stdout[0]).to.include('Usage:'); | ||
expect( | ||
stdout.some((x) => x.includes('Commands:')), | ||
'outputs Commands' | ||
).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('search', function () { | ||
it('returns zero code & outputs Searching...', async function () { | ||
this.timeout(20000); | ||
const { code, stdout } = await execute(runner, `${cli} search`); | ||
expect(code).to.equal(0); | ||
expect(stdout[0]).to.include('Searching...'); | ||
}); | ||
}); | ||
|
||
describe('encrypt', function () { | ||
it('returns zero code & outputs encrypted result', async function () { | ||
const { code, stdout } = await execute( | ||
runner, | ||
`${cli} encrypt base64 test` | ||
); | ||
expect(code).to.equal(0); | ||
expect(stdout.join()).to.equal('37rJvQ=='); | ||
}); | ||
}); | ||
|
||
describe('encryptWithHeader', function () { | ||
it('returns zero code & outputs encrypted result', async function () { | ||
const { code, stdout } = await execute( | ||
runner, | ||
`${cli} encryptWithHeader base64 test` | ||
); | ||
expect(code).to.equal(0); | ||
expect(stdout.join()).to.equal('AAAABN+6yb0='); | ||
}); | ||
}); | ||
|
||
describe('decrypt', function () { | ||
it('returns zero code & outputs decrypted result', async function () { | ||
const { code, stdout } = await execute( | ||
runner, | ||
`${cli} decrypt base64 37rJvQ==` | ||
); | ||
expect(code).to.equal(0); | ||
expect(stdout.join()).to.equal('test'); | ||
}); | ||
}); | ||
|
||
describe('decryptWithHeader', function () { | ||
it('returns zero code & outputs decrypted result', async function () { | ||
const { code, stdout } = await execute( | ||
runner, | ||
`${cli} decryptWithHeader base64 AAAABN+6yb0=` | ||
); | ||
expect(code).to.equal(0); | ||
expect(stdout.join()).to.equal('test'); | ||
}); | ||
}); | ||
}); |