1
0
Fork 0
salty-dog/test/reporter/TestTableReporter.ts

48 lines
1.4 KiB
TypeScript

import { expect } from 'chai';
import { ERROR_EMPTY_RESULT, TableReporter } from '../../src/reporter/TableReporter.js';
import { makeResults } from '../helpers.js';
describe('table reporter', () => {
it('should handle empty results', async () => {
const reporter = new TableReporter();
const report = await reporter.report([]);
expect(report).to.equal(ERROR_EMPTY_RESULT);
});
it('should group results by rule', async () => {
const ruleNames = ['test', 'foo', 'bar'];
const { results } = makeResults(ruleNames);
const reporter = new TableReporter();
const report = await reporter.report(results);
for (const name of ruleNames) {
expect(report).to.include(` ${name} `); // wrap with margin to avoid partial words
}
});
it('should print results in a table', async () => {
const ruleNames = ['test', 'foo', 'bar'];
const { results } = makeResults(ruleNames);
const reporter = new TableReporter();
const report = await reporter.report(results);
const lines = report.split('\n');
const lastLine = lines.pop();
for (const line of lines) {
expect(line).to.match(/^[|]/);
}
expect(lastLine).to.equal('');
});
});
describe('print table helper', () => {
it('should include column names in the first row');
it('should have a second row with delimiters');
it('should show data starting from the third row');
it('should pad and right-align short fields');
});