87 lines
2.1 KiB
TypeScript
87 lines
2.1 KiB
TypeScript
import { expect } from 'chai';
|
|
import mockFs from 'mock-fs';
|
|
|
|
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']);
|
|
expect(status).to.equal(STATUS_SUCCESS);
|
|
});
|
|
|
|
itLeaks('should list rules and exit', async () => {
|
|
mockFs(TEST_FILES);
|
|
|
|
const status = await main([
|
|
...TEST_ARGS_PRE,
|
|
'list',
|
|
...TEST_ARGS_CONFIG,
|
|
]);
|
|
|
|
mockFs.restore();
|
|
|
|
expect(status).to.equal(STATUS_SUCCESS);
|
|
});
|
|
|
|
itLeaks('should load the source', async () => {
|
|
mockFs(TEST_FILES);
|
|
|
|
const status = await main([
|
|
...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);
|
|
});
|
|
|
|
it('should fix up partial documents'); // TODO: test fix mode
|
|
});
|