Skip to content

Commit 782a075

Browse files
committed
allow cli-table to determine optimal column width
1 parent ef642ff commit 782a075

1 file changed

Lines changed: 19 additions & 18 deletions

File tree

lib/log.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ print.assertions = function() {
9090
currentTest, test;
9191

9292
table = new Table({
93-
head: ['Module', 'Test', 'Assertion', 'Result'],
94-
colWidths: [40, 40, 40, 8]
93+
head: ['Module', 'Test', 'Assertion', 'Result']
9594
});
9695

9796
data.assertions.forEach(function(data) {
@@ -109,7 +108,7 @@ print.assertions = function() {
109108
test = currentTest = data.test;
110109
}
111110

112-
table.push([module, test, data.message, data.result ? 'ok' : 'fail']);
111+
table.push([module, test, data.message || '', data.result ? 'ok' : 'fail']);
113112
});
114113

115114
log('\nAssertions:\n' + table.toString());
@@ -154,8 +153,7 @@ print.tests = function() {
154153
currentModule, module;
155154

156155
table = new Table({
157-
head: ['Module', 'Test', 'Failed', 'Passed', 'Total'],
158-
colWidths: [40, 40, 8, 8, 8]
156+
head: ['Module', 'Test', 'Failed', 'Passed', 'Total']
159157
});
160158

161159
data.tests.forEach(function(data) {
@@ -173,21 +171,22 @@ print.tests = function() {
173171
};
174172

175173
// truncate file name
176-
function truncfile(code) {
174+
function truncFile(code) {
177175
if (code && code.length > fileColWidth) {
178176
code = '...' + code.slice(code.length - fileColWidth + 3);
179177
}
180178
return code;
181179
}
182180

183181
print.summary = function() {
184-
var table = new Table({
185-
head: ['File', 'Failed', 'Passed', 'Total', 'Runtime'],
186-
colWidths: [fileColWidth + 2, 10, 10, 10, 10]
182+
var table;
183+
184+
table = new Table({
185+
head: ['File', 'Failed', 'Passed', 'Total', 'Runtime']
187186
});
188187

189188
data.summaries.forEach(function(data) {
190-
table.push([truncfile(data.code), data.failed, data.passed, data.total, data.runtime]);
189+
table.push([truncFile(data.code), data.failed, data.passed, data.total, data.runtime]);
191190
});
192191

193192
log('\nSummary:\n' + table.toString());
@@ -198,8 +197,7 @@ print.globalSummary = function() {
198197
data = exports.stats();
199198

200199
table = new Table({
201-
head: ['Files', 'Tests', 'Assertions', 'Failed', 'Passed', 'Runtime'],
202-
colWidths: [12, 12, 12, 12, 12, 12]
200+
head: ['Files', 'Tests', 'Assertions', 'Failed', 'Passed', 'Runtime']
203201
});
204202

205203
table.push([data.files, data.tests, data.assertions, data.failed,
@@ -228,12 +226,16 @@ print.coverage = function() {
228226
if (!data.coverages.length) return;
229227

230228
table = new Table({
231-
head: ['File', 'Statements', 'Branches', 'Functions', 'Lines'],
232-
colWidths: [fileColWidth + 2, 14, 14, 14, 14]
229+
head: ['File', 'Statements', 'Branches', 'Functions', 'Lines']
233230
});
234231

235-
data.coverages.forEach(function(data) {
236-
table.push([truncfile(data.code), getMet(data.statements), getMet(data.branches), getMet(data.functions), getMet(data.lines)]);
232+
data.coverages.forEach(function(coverage) {
233+
table.push([
234+
truncFile(coverage.code),
235+
getMet(coverage.statements),
236+
getMet(coverage.branches),
237+
getMet(coverage.functions),
238+
getMet(coverage.lines)]);
237239
});
238240

239241
log('\nCoverage:\n' + table.toString());
@@ -246,8 +248,7 @@ print.globalCoverage = function() {
246248

247249
coverage = exports.stats().coverage;
248250
table = new Table({
249-
head: ['Files', 'Statements', 'Branches', 'Functions', 'Lines'],
250-
colWidths: [8, 14, 14, 14, 14]
251+
head: ['Files', 'Statements', 'Branches', 'Functions', 'Lines']
251252
});
252253

253254
table.push([

0 commit comments

Comments
 (0)