-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(modules): don't log errors when {validateResult:false} (#16)
If { validateResult: false } we already don't throw from earlier fix. However, we still logged the errors, which doesn't really make sense. Although the user could turn off error logging in general for all requests, this fix will turn off error logging "automatically" just for the specific request where { validateResult: false }.
- Loading branch information
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import search from '../modules/search'; | ||
const { InvalidOptionsError } = require('./errors'); | ||
import moduleExec from './moduleExec'; | ||
|
||
import _env from '../env-node'; | ||
import _fetch from './yahooFinanceFetch'; | ||
import _moduleExec from './moduleExec'; | ||
|
||
const yf = { | ||
_env, | ||
_fetch, | ||
_opts: { validation: { logErrors: true }}, | ||
_moduleExec, | ||
search | ||
}; | ||
|
||
describe('moduleExec', () => { | ||
|
||
describe('result validation', () => { | ||
|
||
it('throws on unexpected input', async () => { | ||
yf._opts.validation.logErrors = false; | ||
await expect(yf.search('AAPL', {}, { devel: 'search-fakeBadResult.json' })) | ||
.rejects.toThrow(/Failed Yahoo Schema/) | ||
yf._opts.validation.logErrors = true; | ||
}); | ||
|
||
it('dont throw or log on unexpected input with {validateResult: false}', async () => { | ||
yf._opts.validation.logErrors = true; | ||
const realConsole = console; | ||
const fakeConsole = { error: jest.fn(), log: jest.fn(), dir: jest.fn() }; | ||
|
||
/* @ts-ignore */ | ||
console = fakeConsole; | ||
await expect(yf.search('AAPL', {}, { | ||
devel: 'search-fakeBadResult.json', | ||
validateResult: false | ||
})).resolves.toBeDefined(); | ||
console = realConsole; | ||
|
||
expect(fakeConsole.log).not.toHaveBeenCalled(); | ||
expect(fakeConsole.error).not.toHaveBeenCalled(); | ||
expect(fakeConsole.dir).not.toHaveBeenCalled(); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters