fix(tests): cover rule failures through main
This commit is contained in:
parent
b818aa66d4
commit
c053da9051
|
@ -1,9 +1,22 @@
|
|||
import { expect } from 'chai';
|
||||
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';
|
||||
|
||||
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 () => {
|
||||
itLeaks('completion should succeed', async () => {
|
||||
const status = await main(['node', 'test', 'complete']);
|
||||
|
@ -11,16 +24,12 @@ describeLeaks('main app', async () => {
|
|||
});
|
||||
|
||||
itLeaks('should list rules and exit', async () => {
|
||||
mockFs({
|
||||
docs: {
|
||||
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
|
||||
},
|
||||
});
|
||||
mockFs(TEST_FILES);
|
||||
|
||||
const status = await main([
|
||||
'node', 'test', 'list',
|
||||
'--config-path', 'docs',
|
||||
'--config-name', 'config.yml',
|
||||
...TEST_ARGS_PRE,
|
||||
'list',
|
||||
...TEST_ARGS_CONFIG,
|
||||
]);
|
||||
|
||||
mockFs.restore();
|
||||
|
@ -29,22 +38,47 @@ describeLeaks('main app', async () => {
|
|||
});
|
||||
|
||||
itLeaks('should load the source', async () => {
|
||||
mockFs({
|
||||
'docs': {
|
||||
'config.yml': 'data: {logger: {level: debug, name: test, stream: !stream stderr}}',
|
||||
},
|
||||
'test.yml': 'hello world',
|
||||
});
|
||||
mockFs(TEST_FILES);
|
||||
|
||||
const status = await main([
|
||||
'node', 'test',
|
||||
'--config-path', 'docs',
|
||||
'--config-name', 'config.yml',
|
||||
'--source', 'test.yml',
|
||||
...TEST_ARGS_PRE,
|
||||
...TEST_ARGS_CONFIG,
|
||||
...TEST_ARGS_SOURCE,
|
||||
]);
|
||||
|
||||
mockFs.restore();
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue