From b3fa9dd9be9898edb686c63770b4ed614bdebaac Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 16 Nov 2019 18:27:39 -0600 Subject: [PATCH] fix(tests): cover rule module error handling, exclude by level --- test/rule/TestLoadRule.ts | 15 +++++++++++++++ test/rule/TestRule.ts | 12 ++++++++++++ 2 files changed, 27 insertions(+) diff --git a/test/rule/TestLoadRule.ts b/test/rule/TestLoadRule.ts index 6b07923..773cbb5 100644 --- a/test/rule/TestLoadRule.ts +++ b/test/rule/TestLoadRule.ts @@ -157,5 +157,20 @@ describeLeaks('load rule module helper', async () => { expect(rules.length).to.equal(1); }); + itLeaks('should handle errors loading rule modules', async () => { + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + const requireStub = stub().throws(new Error('could not load this module')) as any; + const ctx = new VisitorContext({ + logger: NullLogger.global, + schemaOptions: { + coerce: false, + defaults: false, + mutate: false, + }, + }); + + return expect(loadRuleModules(['test'], ctx, requireStub)).to.eventually.deep.equal([]); + }); + itLeaks('should validate rule module exports'); }); diff --git a/test/rule/TestRule.ts b/test/rule/TestRule.ts index 335bb60..238f66a 100644 --- a/test/rule/TestRule.ts +++ b/test/rule/TestRule.ts @@ -97,6 +97,18 @@ describeLeaks('rule resolver', async () => { expect(rules[0]).to.equal(TEST_RULES[0]); }); }); + + describeLeaks('exclude by level', async () => { + itLeaks('should exclude warn rules', async () => { + const rules = await resolveRules(TEST_RULES, createRuleSelector({ + excludeLevel: [LogLevel.Warn], + includeTag: ['all'], + })); + + expect(rules.length).to.equal(1); + expect(rules[0]).to.equal(TEST_RULES[0]); + }); + }); }); describe('create rule sources helper', () => {