diff --git a/__tests__/command_helpers/__snapshots__/reviewRule.ts.snap b/__tests__/command_helpers/__snapshots__/reviewRule.ts.snap new file mode 100644 index 0000000..c9148c8 --- /dev/null +++ b/__tests__/command_helpers/__snapshots__/reviewRule.ts.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reviewRule when rule: custom Errors when plugin doesn not exist 1`] = `[Error: Plugin not found 'FAKE']`; + +exports[`reviewRule when rule: unknown rule gets added 1`] = `[Error: Encountered unknown rule]`; diff --git a/__tests__/command_helpers/reviewRule.ts b/__tests__/command_helpers/reviewRule.ts index d7f60e3..510588f 100644 --- a/__tests__/command_helpers/reviewRule.ts +++ b/__tests__/command_helpers/reviewRule.ts @@ -80,15 +80,32 @@ describe('reviewRule', () => { // should not change rules expect(reportResults.cliRules.length).toBe(1) }) + + test('Errors when plugin doesn not exist', async () => { + const rule = ['CUSTOM', [{ rule: 'custom', plugin: 'FAKE', name: 'checkSecondThing' }]] + + // Async error snapshots (not simple) + try { + await reviewRule(rule, reportResults, mockContext) + fail('Unknown rule should have errored') + } catch (e) { + expect(e).toMatchSnapshot() + } + }) }) describe('when rule: unknown', () => { test('rule gets added', async () => { const rule = ['UNKNOWN', [{ rule: 'UNKNOWN', command: 'ls', match: '.+' }]] - const numErrors = mockContext.print.error.mock.calls.length - const result = await reviewRule(rule, reportResults, mockContext) - // Failure in a specific rule - expect(mockContext.print.error.mock.calls.length).toBe(numErrors + 1) + + // Async error snapshots (not simple) + try { + await reviewRule(rule, reportResults, mockContext) + fail('Unknown rule should have errored') + } catch (e) { + expect(e).toMatchSnapshot() + } + }) }) }) diff --git a/src/extensions/functions/reviewRule.ts b/src/extensions/functions/reviewRule.ts index cf3eedb..0f813b0 100644 --- a/src/extensions/functions/reviewRule.ts +++ b/src/extensions/functions/reviewRule.ts @@ -65,9 +65,9 @@ module.exports = async ( break case 'custom': const customPluginRule = findPluginInfo(rule, context) - if (customPluginRule.success && customPluginRule.plugin.report) { + if (customPluginRule.success) { // let plugin update the report - customPluginRule.plugin.report(rule, context, report) + if (customPluginRule.plugin.report) customPluginRule.plugin.report(rule, context, report) } else { throw new Error(customPluginRule.message) } @@ -82,5 +82,4 @@ module.exports = async ( .then(results => { return results }) - .catch(err => print.error(err)) }