1
0
Fork 0

cover rule file and module validation

This commit is contained in:
ssube 2019-11-17 16:56:59 -06:00 committed by Sean Sube
parent 197b6119a8
commit 089725ef60
2 changed files with 61 additions and 1 deletions

View File

@ -13,6 +13,7 @@ const TEST_ARGS_SOURCE = ['--source', 'test.yml'];
const TEST_FILES = {
'docs': {
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
'partial.yml': 'data: {logger: {name: test}}',
},
'rules.yml': `{
name: test,
@ -122,4 +123,20 @@ describeLeaks('main app', async () => {
expect(status).to.equal(STATUS_SUCCESS);
expect(result).to.equal('foo: 4\n');
});
it('should validate config before running', async () => {
mockFs(TEST_FILES);
const status = await main([
...TEST_ARGS_PRE,
...TEST_ARGS_CONFIG.slice(0, 3),
'partial.yml',
...TEST_ARGS_RULES,
...TEST_ARGS_SOURCE,
]);
mockFs.restore();
expect(status).to.equal(STATUS_ERROR);
});
});

View File

@ -68,6 +68,33 @@ describeLeaks('load rule file helper', async () => {
expect(rules.length).to.equal(1);
});
itLeaks('should validate rule files', async () => {
mockFS({
test: `{
name: foo,
definitions: [],
rules: {}
}`
});
const ctx = new VisitorContext({
logger: NullLogger.global,
schemaOptions: {
coerce: false,
defaults: false,
mutate: false,
},
});
const rules = await loadRuleFiles([
'test',
], ctx);
mockFS.restore();
expect(rules.length).to.equal(0);
});
});
describeLeaks('load rule path helper', async () => {
@ -174,5 +201,21 @@ describeLeaks('load rule module helper', async () => {
return expect(loadRuleModules(['test'], ctx, requireStub)).to.eventually.deep.equal([]);
});
itLeaks('should validate rule module exports');
itLeaks('should validate rule module exports', async () => {
const requireStub = stub().returns({
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,
},
});
return expect(loadRuleModules(['test'], ctx, requireStub)).to.eventually.deep.equal([]);
});
});