Cleaning up tests. (#34)

This commit is contained in:
Sergio Díaz 2018-06-02 23:47:03 -06:00 committed by GitHub
parent 8e961211a5
commit cc7245b501
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 1442 additions and 1401 deletions

View File

@ -12,7 +12,7 @@ const config = {
endpoint: 'https://example.org',
version: 1,
'GET /anything': {
alias: 'anything',
alias: 'alias',
payload: {
name: '$env.params.name'
}

View File

@ -1,19 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`List Command with flags: --no-format 1`] = `
Array [
"GET anything https://example.org/anything
",
"GET teapot https://example.org/status/418
",
]
`;
exports[`List Command with flags: 1`] = `
Array [
" HTTP Verb Alias Endpoint
",
" GET anything https://example.org/anything
" GET alias https://example.org/anything
",
" GET teapot https://example.org/status/418
",
@ -21,3 +12,12 @@ Array [
",
]
`;
exports[`List Command with flags: 2`] = `
Array [
"GET alias https://example.org/anything
",
"GET teapot https://example.org/status/418
",
]
`;

View File

@ -1,20 +1,34 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Request Command with flags: anything --as-json --verbose 1`] = `
exports[`Request Command with flags: alias %s %s 1`] = `
Array [
"{\\"request\\":{\\"body\\":{\\"name\\":\\"David\\"},\\"endpoint\\":\\"https://example.org/anything\\"},\\"response\\":{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"},\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
"",
" Status Endpoint
",
" 200 https://example.org/anything
",
"
",
"\\"{\\"hello\\": \\"world\\"}\\"
",
]
`;
exports[`Request Command with flags: anything --as-json 1`] = `
exports[`Request Command with flags: alias --as-json %s 1`] = `
Array [
"{\\"status\\":200,\\"headers\\":[],\\"body\\":\\"{\\\\\\"hello\\\\\\": \\\\\\"world\\\\\\"}\\"}
",
]
`;
exports[`Request Command with flags: anything --no-format 1`] = `
exports[`Request Command with flags: alias --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: alias --no-format %s 1`] = `
Array [
"200
",
@ -27,9 +41,9 @@ Array [
]
`;
exports[`Request Command with flags: anything --quiet 1`] = `Array []`;
exports[`Request Command with flags: alias --quiet %s 1`] = `Array []`;
exports[`Request Command with flags: anything --verbose 1`] = `
exports[`Request Command with flags: alias --verbose %s 1`] = `
Array [
"",
" Status Endpoint
@ -55,17 +69,3 @@ Array [
",
]
`;
exports[`Request Command with flags: anything 1`] = `
Array [
"",
" Status Endpoint
",
" 200 https://example.org/anything
",
"
",
"\\"{\\"hello\\": \\"world\\"}\\"
",
]
`;

View File

@ -19,18 +19,18 @@ describe('Request Command', () => {
afterEach(() => jest.restoreAllMocks());
test.each([
['anything'],
['anything', '--verbose'],
['anything', '--as-json'],
['anything', '--as-json', '--verbose'],
['anything', '--no-format'],
['anything', '--quiet']
])('with flags:', async (...args) => {
['alias'],
['alias', '--verbose'],
['alias', '--as-json'],
['alias', '--as-json', '--verbose'],
['alias', '--no-format'],
['alias', '--quiet']
])('with flags: %s %s %s', async (...args) => {
await RequestCommand.run(args);
expect(result).toMatchSnapshot();
});
it('should thrown an error when the request fails', async () => {
it('should throw an error when the request fails', async () => {
requestPromiseNativeMock.fail = true;
await expect(RequestCommand.run(['anything'])).rejects.toThrow(Error);
});

View File

@ -8,7 +8,7 @@ describe('utils', () => {
expect(utils.openConfigFile('beau.yml')).toMatchSnapshot();
});
it('should thrown if given not given a file', () => {
it('should throw if given not given a file', () => {
expect(() => utils.openConfigFile('not-a-file.yml')).toThrow();
});
});

2574
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,26 +13,27 @@
"./src/*"
],
"dependencies": {
"@oclif/command": "^1.4.30",
"@oclif/config": "^1.6.21",
"@oclif/plugin-help": "^2.0.0",
"@oclif/command": "^1.4.32",
"@oclif/config": "^1.6.27",
"@oclif/plugin-help": "^2.0.4",
"@oclif/plugin-warn-if-update-available": "^1.3.9",
"cli-color": "^1.1.0",
"clui": "^0.3.1",
"deepmerge": "^2.1.1",
"dotenv": "^5.0.1",
"dotenv": "^6.0.0",
"globby": "^8.0.1",
"is-plain-object": "^2.0.4",
"joi": "^13.3.0",
"js-yaml": "^3.11.0",
"js-yaml": "^3.12.0",
"jsome": "^2.5.0",
"request": "^2.87.0",
"request-promise-native": "^1.0.5",
"requireg": "^0.1.6"
"requireg": "^0.1.8"
},
"repository": "git@github.com:Seich/Beau.git",
"devDependencies": {
"jest": "^23.0.0",
"jest": "^23.1.0",
"jest-watch-typeahead": "^0.1.0",
"strip-ansi": "^4.0.0"
},
"oclif": {
@ -45,12 +46,16 @@
},
"jest": {
"testEnvironment": "node",
"notify": true
"notify": true,
"watchPlugins": [
"jest-watch-typeahead/filename",
"jest-watch-typeahead/testname"
]
},
"bin": {
"beau": "./bin/beau"
},
"engines": {
"node": ">=8.9.3"
"node": ">=8.10.0"
}
}

View File

@ -96,7 +96,6 @@ class Request {
this.originalRequest
);
try {
const response = await request(settings);
let results = {
@ -122,9 +121,6 @@ class Request {
cache.add(this.ALIAS, results);
return results;
} catch ({ error }) {
throw new Error(`Request Error: ` + error);
}
}
}

View File

@ -28,7 +28,7 @@ class RequestList {
return await request.exec(this.cache);
} catch (reason) {
throw new Error(
`Request: ${request.VERB} ${
`Request ${request.VERB} ${
request.ENDPOINT
} FAILED. \n${reason}`
);