From 1faf25daacc5533401c6daa3a482e9fc2ea6aa73 Mon Sep 17 00:00:00 2001 From: Gant Date: Fri, 2 Feb 2018 00:09:41 -0600 Subject: [PATCH] add tests for findPluginInfo --- .../__snapshots__/findPluginInfo.ts.snap | 12 ++++++ __tests__/command_helpers/findPluginInfo.ts | 37 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 __tests__/command_helpers/__snapshots__/findPluginInfo.ts.snap create mode 100644 __tests__/command_helpers/findPluginInfo.ts diff --git a/__tests__/command_helpers/__snapshots__/findPluginInfo.ts.snap b/__tests__/command_helpers/__snapshots__/findPluginInfo.ts.snap new file mode 100644 index 0000000..5caf6b3 --- /dev/null +++ b/__tests__/command_helpers/__snapshots__/findPluginInfo.ts.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`findPluginInfo Function can find plugins 1`] = ` +Object { + "plugin": Object { + "check": [Function], + "report": [Function], + "snapshot": [Function], + }, + "success": true, +} +`; diff --git a/__tests__/command_helpers/findPluginInfo.ts b/__tests__/command_helpers/findPluginInfo.ts new file mode 100644 index 0000000..83e7273 --- /dev/null +++ b/__tests__/command_helpers/findPluginInfo.ts @@ -0,0 +1,37 @@ +const findPluginInfo = require('../../src/extensions/functions/findPluginInfo') +const examplePlugin = require('examplePlugin') +const mockContext = examplePlugin(require('mockContext')) + +describe('findPluginInfo Function', () => { + test('can fail to find plugins', () => { + const rule = { + rule: 'custom', + plugin: 'FAKE', + name: 'checkThing' + } + const customPluginRule = findPluginInfo(rule, mockContext) + expect(customPluginRule).toEqual({ message: "Plugin not found 'FAKE'", success: false }) + } + + test('can fail to find plugins', () => { + const rule = { + rule: 'custom', + plugin: 'Example Plugin', + name: 'FAKE' + } + const customPluginRule = findPluginInfo(rule, mockContext) + expect(customPluginRule.message).toEqual("NOT FOUND: Custom rule from 'Example Plugin' plugin with check function 'FAKE'") + expect(customPluginRule.success).toBeFalsy() + } + + test('can find plugins', () => { + const rule = { + rule: 'custom', + plugin: 'Example Plugin', + name: 'checkThing' + } + const customPluginRule = findPluginInfo(rule, mockContext) + expect(customPluginRule.success).toBeTruthy() + expect(customPluginRule).toMatchSnapshot() + } +})