diff --git a/bin/__tests__/list.spec.js b/bin/__tests__/list.spec.js deleted file mode 100644 index 96d059e..0000000 --- a/bin/__tests__/list.spec.js +++ /dev/null @@ -1,11 +0,0 @@ -const { test, expect } = require('@oclif/test'); -const Nock = require('@fancy-test/nock'); - -const Test = test.register('nock', Nock); - -describe('List Command', () => { - let a = Test.stdout().command(['list', '-c', 'hello.yml']); - a.it('tst', ctx => { - console.log(ctx); - }); -}); diff --git a/bin/cli/__mocks__/utils.js b/bin/cli/__mocks__/utils.js new file mode 100644 index 0000000..ebfc5fd --- /dev/null +++ b/bin/cli/__mocks__/utils.js @@ -0,0 +1,31 @@ +const Beau = require('../../../src/beau'); +const original = require.requireActual('../utils'); + +const utils = {}; + +const config = { + environment: { + params: { + name: 'David' + } + }, + endpoint: 'https://httpbin.org/', + version: 1, + 'GET /anything': { + alias: 'anything', + payload: { + name: '$env.params.name' + } + }, + 'GET /status/418': { + alias: 'teapot' + } +}; + +utils.loadConfig = function() { + return new Beau(config, {}); +}; + +utils.baseFlags = original.baseFlags; + +module.exports = utils; diff --git a/bin/cli/__tests__/__snapshots__/list.spec.js.snap b/bin/cli/__tests__/__snapshots__/list.spec.js.snap new file mode 100644 index 0000000..8a25510 --- /dev/null +++ b/bin/cli/__tests__/__snapshots__/list.spec.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`List Command Should disable formatting when the flag is active. 1`] = ` +Array [ + "GET anything https://httpbin.org/anything +", + "GET teapot https://httpbin.org/status/418 +", +] +`; + +exports[`List Command Should list available requests for a given file. 1`] = ` +Array [ + " HTTP Verb Alias Endpoint +", + " GET anything https://httpbin.org/anything +", + " GET teapot https://httpbin.org/status/418 +", + " +", +] +`; diff --git a/bin/cli/__tests__/list.spec.js b/bin/cli/__tests__/list.spec.js new file mode 100644 index 0000000..0d10426 --- /dev/null +++ b/bin/cli/__tests__/list.spec.js @@ -0,0 +1,29 @@ +const ListCommand = require('../commands/list'); +const stripAnsi = require('strip-ansi'); + +jest.mock('../utils'); + +describe('List Command', () => { + let result; + + beforeEach(() => { + result = []; + jest + .spyOn(process.stdout, 'write') + .mockImplementation(val => + result.push(stripAnsi(val.toString('utf8'))) + ); + }); + + afterEach(() => jest.restoreAllMocks()); + + it('Should list available requests for a given file.', async () => { + await ListCommand.run([]); + expect(result).toMatchSnapshot(); + }); + + it('Should disable formatting when the flag is active.', async () => { + await ListCommand.run(['--no-format']); + expect(result).toMatchSnapshot(); + }); +}); diff --git a/package-lock.json b/package-lock.json index 7d1eced..9cc37fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1178,6 +1178,17 @@ "has-ansi": "^2.0.0", "strip-ansi": "^3.0.0", "supports-color": "^2.0.0" + }, + "dependencies": { + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + } } }, "ci-info": { @@ -6822,6 +6833,16 @@ "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", "strip-ansi": "^3.0.0" + }, + "dependencies": { + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + } } }, "string_decoder": { @@ -6839,11 +6860,20 @@ "integrity": "sha1-TkhM1N5aC7vuGORjB3EKioFiGHg=" }, "strip-ansi": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=", + "dev": true, "requires": { - "ansi-regex": "^2.0.0" + "ansi-regex": "^3.0.0" + }, + "dependencies": { + "ansi-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", + "integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=", + "dev": true + } } }, "strip-bom": { @@ -7593,6 +7623,16 @@ "requires": { "string-width": "^1.0.1", "strip-ansi": "^3.0.1" + }, + "dependencies": { + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "requires": { + "ansi-regex": "^2.0.0" + } + } } }, "wrappy": { diff --git a/package.json b/package.json index a4a6e1e..8c312d9 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "license": "MIT", "scripts": { "test": "jest", - "test:coverage": "jest --coverage" + "test:coverage": "jest --coverage ./src" }, "dependencies": { "@oclif/command": "^1.4.16", @@ -29,7 +29,8 @@ }, "repository": "git@github.com:Seich/Beau.git", "devDependencies": { - "jest": "^22.4.0" + "jest": "^22.4.0", + "strip-ansi": "^4.0.0" }, "oclif": { "commands": "./bin/cli/commands",