Updated tests. (#30)

With the introduction of data-driven tests in Jest 23 CLI tests could be made significantly smaller and easier to keep updated.
This commit is contained in:
Sergio Díaz 2018-05-29 15:23:58 -06:00 committed by GitHub
parent 8fcd8b9fd3
commit c8ff4945d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1893 additions and 3314 deletions

View File

@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`List Command Should disable formatting when the flag is active. 1`] = ` exports[`List Command with flags: --no-format 1`] = `
Array [ Array [
"GET anything https://example.org/anything "GET anything https://example.org/anything
", ",
@ -9,7 +9,7 @@ Array [
] ]
`; `;
exports[`List Command Should list available requests for a given file. 1`] = ` exports[`List Command with flags: 1`] = `
Array [ Array [
" HTTP Verb Alias Endpoint " HTTP Verb Alias Endpoint
", ",

View File

@ -1,6 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Request Command Should output an unformatted version 1`] = ` exports[`Request Command with flags: anything --as-json --verbose 1`] = `
Array [
"{\\"request\\":{\\"body\\":{\\"name\\":\\"David\\"},\\"endpoint\\":\\"https://example.org/anything\\"},\\"response\\":{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"},\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
",
]
`;
exports[`Request Command with flags: anything --as-json 1`] = `
Array [
"{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
",
]
`;
exports[`Request Command with flags: anything --no-format 1`] = `
Array [ Array [
"200 "200
", ",
@ -13,37 +27,9 @@ Array [
] ]
`; `;
exports[`Request Command Should output nothing 1`] = `Array []`; exports[`Request Command with flags: anything --quiet 1`] = `Array []`;
exports[`Request Command Should output the response as json 1`] = ` exports[`Request Command with flags: anything --verbose 1`] = `
Array [
"{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
",
]
`;
exports[`Request Command Should output the response as json verboselly 1`] = `
Array [
"{\\"request\\":{\\"body\\":{\\"name\\":\\"David\\"},\\"endpoint\\":\\"https://example.org/anything\\"},\\"response\\":{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"},\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
",
]
`;
exports[`Request Command Should request the given alias 1`] = `
Array [
"",
" Status Endpoint
",
" 200 https://example.org/anything
",
"
",
"\\"{\\"hello\\": \\"world\\"}\\"
",
]
`;
exports[`Request Command Should show all information available when being verbose 1`] = `
Array [ Array [
"", "",
" Status Endpoint " Status Endpoint
@ -69,3 +55,17 @@ Array [
", ",
] ]
`; `;
exports[`Request Command with flags: anything 1`] = `
Array [
"",
" Status Endpoint
",
" 200 https://example.org/anything
",
"
",
"\\"{\\"hello\\": \\"world\\"}\\"
",
]
`;

View File

@ -16,13 +16,8 @@ describe('List Command', () => {
afterEach(() => jest.restoreAllMocks()); afterEach(() => jest.restoreAllMocks());
it('Should list available requests for a given file.', async () => { test.each([[], ['--no-format']])('with flags:', async (...args) => {
await ListCommand.run([]); await ListCommand.run(args);
expect(result).toMatchSnapshot();
});
it('Should disable formatting when the flag is active.', async () => {
await ListCommand.run(['--no-format']);
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });
}); });

View File

@ -18,33 +18,15 @@ describe('Request Command', () => {
afterEach(() => jest.restoreAllMocks()); afterEach(() => jest.restoreAllMocks());
it('Should request the given alias', async () => { test.each([
await RequestCommand.run(['anything']); ['anything'],
expect(result).toMatchSnapshot(); ['anything', '--verbose'],
}); ['anything', '--as-json'],
['anything', '--as-json', '--verbose'],
it('Should show all information available when being verbose', async () => { ['anything', '--no-format'],
await RequestCommand.run(['anything', '--verbose']); ['anything', '--quiet']
expect(result).toMatchSnapshot(); ])('with flags:', async (...args) => {
}); await RequestCommand.run(args);
it('Should output the response as json', async () => {
await RequestCommand.run(['anything', '--as-json']);
expect(result).toMatchSnapshot();
});
it('Should output the response as json verboselly', async () => {
await RequestCommand.run(['anything', '--as-json', '--verbose']);
expect(result).toMatchSnapshot();
});
it('Should output an unformatted version', async () => {
await RequestCommand.run(['anything', '--no-format']);
expect(result).toMatchSnapshot();
});
it('Should output nothing', async () => {
await RequestCommand.run(['anything', '--quiet']);
expect(result).toMatchSnapshot(); expect(result).toMatchSnapshot();
}); });

5094
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@
}, },
"repository": "git@github.com:Seich/Beau.git", "repository": "git@github.com:Seich/Beau.git",
"devDependencies": { "devDependencies": {
"jest": "^22.4.0", "jest": "^23.0.0",
"strip-ansi": "^4.0.0" "strip-ansi": "^4.0.0"
}, },
"oclif": { "oclif": {