1
0
Fork 0
salty-dog/test/TestApp.ts

85 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-11-10 03:56:49 +00:00
import { expect } from 'chai';
2019-11-14 05:07:54 +00:00
import mockFs from 'mock-fs';
2019-11-10 03:56:49 +00:00
import { main, STATUS_ERROR, STATUS_SUCCESS } from '../src/app';
2019-11-14 05:07:54 +00:00
import { describeLeaks, itLeaks } from './helpers/async';
2019-11-10 03:56:49 +00:00
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',
};
2019-11-10 03:56:49 +00:00
describeLeaks('main app', async () => {
2019-11-14 05:07:54 +00:00
itLeaks('completion should succeed', async () => {
2019-11-10 03:56:49 +00:00
const status = await main(['node', 'test', 'complete']);
expect(status).to.equal(STATUS_SUCCESS);
});
2019-11-14 05:07:54 +00:00
itLeaks('should list rules and exit', async () => {
mockFs(TEST_FILES);
const status = await main([
...TEST_ARGS_PRE,
'list',
...TEST_ARGS_CONFIG,
]);
mockFs.restore();
2019-11-14 05:07:54 +00:00
expect(status).to.equal(STATUS_SUCCESS);
});
itLeaks('should load the source', async () => {
mockFs(TEST_FILES);
2019-11-14 05:07:54 +00:00
const status = await main([
...TEST_ARGS_PRE,
...TEST_ARGS_CONFIG,
...TEST_ARGS_SOURCE,
2019-11-14 05:07:54 +00:00
]);
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);
});
2019-11-10 03:56:49 +00:00
});