Skip to content

Commit

Permalink
test(cli): use snapshots to match list of commands in help
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
bajtos committed Sep 23, 2019
1 parent 32e8643 commit a6863e5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// IMPORTANT
// This snapshot file is auto-generated, but designed for humans.
// It should be checked into source control and tracked carefully.
// Re-generate by setting UPDATE_SNAPSHOTS=1 and running tests.
// Make sure to inspect the changes in the snapshots below.
// Do not ignore changes!

'use strict';

exports[`cli lists available commands 1`] = `
Available commands:
lb4 app
lb4 extension
lb4 controller
lb4 datasource
lb4 model
lb4 repository
lb4 service
lb4 example
lb4 openapi
lb4 observer
lb4 interceptor
lb4 discover
lb4 relation
`;


exports[`cli prints commands with --help 1`] = `
Available commands:
lb4 app
lb4 extension
lb4 controller
lb4 datasource
lb4 model
lb4 repository
lb4 service
lb4 example
lb4 openapi
lb4 observer
lb4 interceptor
lb4 discover
lb4 relation
`;
17 changes: 3 additions & 14 deletions packages/cli/test/integration/cli/cli.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
const expect = require('@loopback/testlab').expect;
const util = require('util');
const main = require('../../../lib/cli');
const {expectToMatchSnapshot} = require('../../snapshots');

function getLog(buffer) {
buffer = buffer || [];
Expand All @@ -21,13 +22,7 @@ describe('cli', () => {
it('lists available commands', () => {
const entries = [];
main({commands: true}, getLog(entries));
expect(entries).to.eql([
'Available commands: ',
' lb4 app\n lb4 extension\n lb4 controller\n lb4 datasource\n ' +
'lb4 model\n lb4 repository\n lb4 service\n lb4 example\n ' +
'lb4 openapi\n lb4 observer\n lb4 interceptor\n lb4 discover\n ' +
'lb4 relation',
]);
expectToMatchSnapshot(entries.join('\n'));
});

it('lists versions', () => {
Expand All @@ -41,13 +36,7 @@ describe('cli', () => {
it('prints commands with --help', () => {
const entries = [];
main({help: true, _: []}, getLog(entries), true);
expect(entries).to.containEql('Available commands: ');
expect(entries).to.containEql(
' lb4 app\n lb4 extension\n lb4 controller\n lb4 datasource\n ' +
'lb4 model\n lb4 repository\n lb4 service\n lb4 example\n ' +
'lb4 openapi\n lb4 observer\n lb4 interceptor\n lb4 discover\n ' +
'lb4 relation',
);
expectToMatchSnapshot(entries.join('\n'));
});

it('does not print commands with --help for a given command', () => {
Expand Down

0 comments on commit a6863e5

Please sign in to comment.