Skip to content

Commit

Permalink
test: adds simple tests for github-release CLI and --debug flag (addi…
Browse files Browse the repository at this point in the history
…tional command.ts coverage)
  • Loading branch information
Joe Bottigliero committed Jan 6, 2021
1 parent 8500cda commit 9d40c3a
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion test/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@

import {resolve} from 'path';

import {describe, it} from 'mocha';
import {describe, it, afterEach} from 'mocha';
import {expect, assert} from 'chai';
import * as sinon from 'sinon';

import command from '../src/bin/command';

function getExampleConfigurationPath() {
return resolve('./test/fixtures/config', 'simple.json');
}

const sandbox = sinon.createSandbox();

describe('CLI', () => {
afterEach(() => {
sandbox.restore();
});
describe('release-pr', () => {
it('can be configured using flags', () => {
const argv = command.parse(
Expand Down Expand Up @@ -63,5 +69,43 @@ describe('CLI', () => {
argv.changelogSections as []
);
});

it('supports --debug', async () => {
const messages: string[] = [];
sandbox.replace(console, 'error', (...args: string[]) => {
messages.push(...args);
});
await new Promise(resolve => {
command
/**
* This could/should eventually be replaced with async handling in `yargs.parse`
* @see https://github.com/yargs/yargs/issues/1069
*/
.onFinishCommand(() => {
resolve(22);
})
.parse(
'release-pr --debug --repo-url=googleapis/release-please-cli --package-name=cli-package'
);
});
expect(messages[0]).to.match(/command release-pr failed with status 500/);
// we know it's the verbose logging if it has the stack seperator
expect(messages[1]).to.eq('---------');
// includes the stack
expect(messages[2]).to.match(/HttpError/);
});
});

describe('github-release', () => {
it('can be configured using flags', () => {
const argv = command.parse(
'github-release --repo-url=googleapis/release-please-cli --package-name=cli-package'
);
expect(argv).includes({
repoUrl: 'googleapis/release-please-cli',
releaseType: 'node',
packageName: 'cli-package',
});
});
});
});

0 comments on commit 9d40c3a

Please sign in to comment.