Skip to content

Commit

Permalink
test(cli): remove bats and use cli-testing-library (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
plasticrake authored Jan 14, 2023
1 parent 0588373 commit c6bb459
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 49 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"adamsandle",
"baust",
"georgovassilis",
"gmrchk",
"plasticrake",
"wzaatar",

Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"tplink-smarthome-crypto": "^4.0.0"
},
"devDependencies": {
"@gmrchk/cli-testing-library": "^0.1.2",
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "^4.3.4",
"@types/chai-as-promised": "^7.1.5",
Expand Down
49 changes: 0 additions & 49 deletions test/cli.bats

This file was deleted.

99 changes: 99 additions & 0 deletions test/cli.ts
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');
});
});
});

0 comments on commit c6bb459

Please sign in to comment.