cover rule file and module validation
This commit is contained in:
parent
197b6119a8
commit
089725ef60
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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([]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue