From 61498e7fabc20db6b7635ad8bfbd43a5cb300c4a Mon Sep 17 00:00:00 2001 From: ssube Date: Sun, 17 Nov 2019 17:45:12 -0600 Subject: [PATCH] cover rule module defs directly --- test/rule/TestLoadRule.ts | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/test/rule/TestLoadRule.ts b/test/rule/TestLoadRule.ts index b25c471..4fc4a09 100644 --- a/test/rule/TestLoadRule.ts +++ b/test/rule/TestLoadRule.ts @@ -167,11 +167,6 @@ describeLeaks('load rule module helper', async () => { }, }); const requireStub = stub().withArgs('test').returns({ - definitions: { - foo: { - type: 'string', - }, - }, name: 'test', rules: [{ check: {}, @@ -218,4 +213,33 @@ describeLeaks('load rule module helper', async () => { return expect(loadRuleModules(['test'], ctx, requireStub)).to.eventually.deep.equal([]); }); + + itLeaks('should load module definitions', async () => { + const requireStub = stub().returns({ + definitions: { + foo: { + type: 'string', + }, + }, + name: 'test-rules', + rules: [], + /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + }) as any; + const ctx = new VisitorContext({ + logger: NullLogger.global, + schemaOptions: { + coerce: false, + defaults: false, + mutate: false, + }, + }); + + await loadRuleModules(['test'], ctx, requireStub); + const schema = ctx.compile({ + $ref: 'test-rules#/definitions/foo', + }); + + expect(schema(2)).to.equal(false); + expect(schema('foo')).to.equal(true); + }); });