1
0
Fork 0

fix(tests): cover rule failures through main

This commit is contained in:
ssube 2019-11-15 18:43:46 -06:00 committed by Sean Sube
parent b818aa66d4
commit c053da9051
1 changed files with 53 additions and 19 deletions

View File

@ -1,9 +1,22 @@
import { expect } from 'chai'; import { expect } from 'chai';
import mockFs from 'mock-fs'; import mockFs from 'mock-fs';
import { main, STATUS_SUCCESS } from '../src/app'; import { main, STATUS_ERROR, STATUS_SUCCESS } from '../src/app';
import { describeLeaks, itLeaks } from './helpers/async'; import { describeLeaks, itLeaks } from './helpers/async';
const TEST_ARGS_PRE = ['node', 'test'];
const TEST_ARGS_CONFIG = ['--config-path', 'docs', '--config-name', 'config.yml'];
const TEST_ARGS_RULES = ['--rule-file', 'rules.yml', '--tag', 'test'];
const TEST_ARGS_SOURCE = ['--source', 'test.yml'];
const TEST_FILES = {
'docs': {
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
},
'rules.yml': '{name: test, rules: [{name: test, desc: test, level: info, tags: [test], check: {type: number}}]}',
'test.yml': 'hello world',
};
describeLeaks('main app', async () => { describeLeaks('main app', async () => {
itLeaks('completion should succeed', async () => { itLeaks('completion should succeed', async () => {
const status = await main(['node', 'test', 'complete']); const status = await main(['node', 'test', 'complete']);
@ -11,16 +24,12 @@ describeLeaks('main app', async () => {
}); });
itLeaks('should list rules and exit', async () => { itLeaks('should list rules and exit', async () => {
mockFs({ mockFs(TEST_FILES);
docs: {
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
},
});
const status = await main([ const status = await main([
'node', 'test', 'list', ...TEST_ARGS_PRE,
'--config-path', 'docs', 'list',
'--config-name', 'config.yml', ...TEST_ARGS_CONFIG,
]); ]);
mockFs.restore(); mockFs.restore();
@ -29,22 +38,47 @@ describeLeaks('main app', async () => {
}); });
itLeaks('should load the source', async () => { itLeaks('should load the source', async () => {
mockFs({ mockFs(TEST_FILES);
'docs': {
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
},
'test.yml': 'hello world',
});
const status = await main([ const status = await main([
'node', 'test', ...TEST_ARGS_PRE,
'--config-path', 'docs', ...TEST_ARGS_CONFIG,
'--config-name', 'config.yml', ...TEST_ARGS_SOURCE,
'--source', 'test.yml',
]); ]);
mockFs.restore(); mockFs.restore();
expect(status).to.equal(STATUS_SUCCESS); expect(status).to.equal(STATUS_SUCCESS);
}); });
itLeaks('should exit with rule errors', async () => {
mockFs(TEST_FILES);
const status = await main([
...TEST_ARGS_PRE,
...TEST_ARGS_CONFIG,
...TEST_ARGS_SOURCE,
...TEST_ARGS_RULES,
]);
mockFs.restore();
expect(status).to.equal(STATUS_ERROR);
});
itLeaks('should exit with error count', async () => {
mockFs(TEST_FILES);
const status = await main([
...TEST_ARGS_PRE,
...TEST_ARGS_CONFIG,
...TEST_ARGS_SOURCE,
...TEST_ARGS_RULES,
'--count',
]);
mockFs.restore();
expect(status).to.equal(STATUS_ERROR);
});
}); });