mirror of https://github.com/Seich/Beau.git
Added a spec file for the ListCommand.
This commit is contained in:
parent
aa0b937582
commit
6e4a77527a
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
",
|
||||
"
|
||||
",
|
||||
]
|
||||
`;
|
||||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in New Issue