Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d1f8d19
pass failing metadata to results
cgcgbcbc May 16, 2016
732e1c0
modify mini reporter for failing test output
cgcgbcbc May 16, 2016
269007a
rename variable && reorder output
cgcgbcbc May 17, 2016
cb01bd3
do not output description
cgcgbcbc May 17, 2016
452cb41
add knownFailure to run-status
cgcgbcbc May 17, 2016
05a6c99
fix mistake in run-status
cgcgbcbc May 17, 2016
d0e5dc2
add failing output in verbose reporter
cgcgbcbc May 19, 2016
bdb5333
push a test to known failure only when it marked as failing and it fails
cgcgbcbc May 20, 2016
1d02fa5
integrate runStatus.knownFailure for output
cgcgbcbc May 20, 2016
97b9918
and some test
cgcgbcbc May 20, 2016
53b9302
fix verbose reporter
cgcgbcbc May 20, 2016
7969dca
add test for verbose reporter
cgcgbcbc May 20, 2016
7f7160d
fix tests after remove reason for known failure
cgcgbcbc May 20, 2016
1352138
enhance coverage for reporters/mini
cgcgbcbc May 20, 2016
d618a6a
enhance coverage for reporter/verbose
cgcgbcbc May 20, 2016
4be62ef
remove unnecessary empty line output in verbose reporter for known fa…
cgcgbcbc May 20, 2016
0624cf3
verify no reason for known failure.
cgcgbcbc May 20, 2016
dd92262
delete unused commented code
cgcgbcbc May 22, 2016
bb7867d
remove time
cgcgbcbc May 22, 2016
5f67b2a
plur failure
cgcgbcbc May 23, 2016
7066b2a
add a tick
cgcgbcbc May 23, 2016
6da3cf7
2 known failures instead of 2 tests known failure
cgcgbcbc May 23, 2016
da4c00f
fix indent
cgcgbcbc May 23, 2016
6e3a568
add knownFailure count to blank result
cgcgbcbc May 23, 2016
0142cea
add knownFailureCount to runstatus
cgcgbcbc May 23, 2016
acd0fda
fix npm test
cgcgbcbc May 23, 2016
c2a7b42
fix test
cgcgbcbc May 23, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function getBlankResults() {
stats: {
testCount: 0,
passCount: 0,
knownFailureCount: 0,
skipCount: 0,
todoCount: 0,
failCount: 0
Expand Down
19 changes: 18 additions & 1 deletion lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ MiniReporter.prototype.start = function () {
MiniReporter.prototype.reset = function () {
this.clearInterval();
this.passCount = 0;
this.knownFailureCount = 0;
this.failCount = 0;
this.skipCount = 0;
this.todoCount = 0;
Expand Down Expand Up @@ -80,6 +81,9 @@ MiniReporter.prototype.test = function (test) {
this.failCount++;
} else {
this.passCount++;
if (test.failing) {
this.knownFailureCount++;
}
}

if (test.todo || test.skip) {
Expand All @@ -102,7 +106,7 @@ MiniReporter.prototype._test = function (test) {
var PADDING = 1;
var title = cliTruncate(test.title, process.stdout.columns - SPINNER_WIDTH - PADDING);

if (test.error) {
if (test.error || test.failing) {
title = colors.error(test.title);
}

Expand All @@ -120,6 +124,7 @@ MiniReporter.prototype.unhandledError = function (err) {
MiniReporter.prototype.reportCounts = function (time) {
var lines = [
this.passCount > 0 ? '\n ' + colors.pass(this.passCount, 'passed') : '',
this.knownFailureCount > 0 ? '\n ' + colors.error(this.knownFailureCount, plur('known failure', this.knownFailureCount)) : '',
this.failCount > 0 ? '\n ' + colors.error(this.failCount, 'failed') : '',
this.skipCount > 0 ? '\n ' + colors.skip(this.skipCount, 'skipped') : '',
this.todoCount > 0 ? '\n ' + colors.todo(this.todoCount, 'todo') : ''
Expand Down Expand Up @@ -156,6 +161,18 @@ MiniReporter.prototype.finish = function (runStatus) {

var i = 0;

if (this.knownFailureCount > 0) {
runStatus.knownFailures.forEach(function (test) {
i++;

var title = test.title;

status += '\n\n\n ' + colors.error(i + '.', title);
// TODO output description with link
// status += colors.stack(description);
});
}

if (this.failCount > 0) {
runStatus.errors.forEach(function (test) {
if (!test.error || !test.error.message) {
Expand Down
16 changes: 14 additions & 2 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ VerboseReporter.prototype.test = function (test, runStatus) {
return ' ' + colors.skip('- ' + test.title);
}

if (test.failing) {
return ' ' + colors.error(figures.tick) + ' ' + colors.error(test.title);
}

if (runStatus.fileCount === 1 && runStatus.testCount === 1 && test.title === '[anonymous]') {
return undefined;
}
Expand Down Expand Up @@ -74,6 +78,7 @@ VerboseReporter.prototype.finish = function (runStatus) {
runStatus.failCount > 0 ?
' ' + colors.error(runStatus.failCount, plur('test', runStatus.failCount), 'failed') :
' ' + colors.pass(runStatus.passCount, plur('test', runStatus.passCount), 'passed'),
runStatus.knownFailureCount > 0 ? ' ' + colors.error(runStatus.knownFailureCount, plur('known failure', runStatus.knownFailureCount)) : '',
runStatus.skipCount > 0 ? ' ' + colors.skip(runStatus.skipCount, plur('test', runStatus.skipCount), 'skipped') : '',
runStatus.todoCount > 0 ? ' ' + colors.todo(runStatus.todoCount, plur('test', runStatus.todoCount), 'todo') : '',
runStatus.rejectionCount > 0 ? ' ' + colors.error(runStatus.rejectionCount, 'unhandled', plur('rejection', runStatus.rejectionCount)) : '',
Expand All @@ -86,9 +91,16 @@ VerboseReporter.prototype.finish = function (runStatus) {
output += lines.join('\n');
}

if (runStatus.failCount > 0) {
var i = 0;
var i = 0;

if (runStatus.knownFailureCount > 0) {
runStatus.knownFailures.forEach(function (test) {
i++;
output += '\n\n\n ' + colors.error(i + '.', test.title);
});
}

if (runStatus.failCount > 0) {
runStatus.tests.forEach(function (test) {
if (!(test.error && test.error.message)) {
return;
Expand Down
7 changes: 7 additions & 0 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ function RunStatus(opts) {
this.rejectionCount = 0;
this.exceptionCount = 0;
this.passCount = 0;
this.knownFailureCount = 0;
this.skipCount = 0;
this.todoCount = 0;
this.failCount = 0;
this.fileCount = 0;
this.testCount = 0;
this.previousFailCount = 0;
this.knownFailures = [];
this.errors = [];
this.stats = [];
this.tests = [];
Expand Down Expand Up @@ -123,6 +125,10 @@ RunStatus.prototype.handleTest = function (test) {
this.errors.push(test);
}

if (test.failing && !test.error) {
this.knownFailures.push(test);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where should I write tests for this line? Seems that there is no test/run-status.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgcgbcbc, @nfcampos is running into that as well: #844 (comment).

Maybe leave that for now, focus on the reporter tests (which use stubbed data anyway).

}

this.emit('test', test, this);
};

Expand Down Expand Up @@ -172,6 +178,7 @@ RunStatus.prototype.processResults = function (results) {
this.tests = flatten(this.tests);

this.passCount = sum(this.stats, 'passCount');
this.knownFailureCount = sum(this.stats, 'knownFailureCount');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to work for me when I run your code against a test file (will post the code in a PR comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that the results does not have that count, I grep processResults in directory but find nothing, can you tell me where it is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems it is called in api.js, but since it has knownFailures, should I just use its length?

this.skipCount = sum(this.stats, 'skipCount');
this.todoCount = sum(this.stats, 'todoCount');
this.failCount = sum(this.stats, 'failCount');
Expand Down
9 changes: 8 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ Runner.prototype._addTestResult = function (result) {
error: result.reason,
type: test.metadata.type,
skip: test.metadata.skipped,
todo: test.metadata.todo
todo: test.metadata.todo,
failing: test.metadata.failing
};

this.results.push(result);
Expand Down Expand Up @@ -177,6 +178,12 @@ Runner.prototype._buildStats = function () {
})
.length;

stats.knownFailureCount = this.results
.filter(function (result) {
return result.passed === true && result.result.metadata.failing;
})
.length;

stats.passCount = stats.testCount - stats.failCount - stats.skipCount - stats.todoCount;

return stats;
Expand Down
4 changes: 3 additions & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ Test.prototype._result = function () {
var passed = reason === undefined;
if (this.metadata.failing) {
passed = !passed;
if (!passed) {
if (passed) {
reason = undefined;
} else {
reason = new Error('Test was expected to fail, but succeeded, you should stop marking the test as failing');
}
}
Expand Down
65 changes: 65 additions & 0 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ test('passing test', function (t) {
t.end();
});

test('known failure test', function (t) {
var reporter = miniReporter();

var actualOutput = reporter.test({
title: 'known failure',
failing: true
});

var expectedOutput = [
' ',
' ' + graySpinner + ' ' + chalk.red('known failure'),
'',
' ' + chalk.green('1 passed'),
' ' + chalk.red('1 known failure')
].join('\n');

t.is(actualOutput, expectedOutput);
t.end();
});

test('failing test', function (t) {
var reporter = miniReporter();

Expand All @@ -76,6 +96,28 @@ test('failing test', function (t) {
t.end();
});

test('failed known failure test', function (t) {
var reporter = miniReporter();

var actualOutput = reporter.test({
title: 'known failure',
failing: true,
error: {
message: 'Test was expected to fail, but succeeded, you should stop marking the test as failing'
}
});

var expectedOutput = [
' ',
' ' + graySpinner + ' ' + chalk.red('known failure'),
'',
' ' + chalk.red('1 failed')
].join('\n');

t.is(actualOutput, expectedOutput);
t.end();
});

test('passing test after failing', function (t) {
var reporter = miniReporter();

Expand Down Expand Up @@ -164,6 +206,29 @@ test('results with passing tests', function (t) {
t.end();
});

test('results with passing known failure tests', function (t) {
var reporter = miniReporter();
reporter.passCount = 1;
reporter.knownFailureCount = 1;
reporter.failCount = 0;

var runStatus = {
knownFailures: [{title: 'known failure', failing: true}]
};
var actualOutput = reporter.finish(runStatus);
var expectedOutput = [
'\n ' + chalk.green('1 passed'),
' ' + chalk.red('1 known failure'),
'',
'',
' ' + chalk.red('1. known failure'),
''
].join('\n');

t.is(actualOutput, expectedOutput);
t.end();
});

test('results with skipped tests', function (t) {
var reporter = miniReporter();
reporter.passCount = 0;
Expand Down
36 changes: 36 additions & 0 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ test('don\'t display test title if there is only one anonymous test', function (
t.end();
});

test('known failure test', function (t) {
var reporter = createReporter();

var actualOutput = reporter.test({
title: 'known failure',
failing: true
}, createRunStatus());

var expectedOutput = ' ' + chalk.red(figures.tick) + ' ' + chalk.red('known failure');

t.is(actualOutput, expectedOutput);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this assertion failed..
screen shot 2016-05-23 at 15 49 48 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the assertion to

t.is(JSON.stringify(actual), JSON.stringify(expected)

Copy link
Contributor

@vadimdemedes vadimdemedes May 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think colors are the issue here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. My suggestion above will make the color chars visible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not see your comment when I posted mine ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, fixed now

t.end();
});

test('failing test', function (t) {
var reporter = createReporter();

Expand Down Expand Up @@ -214,6 +228,28 @@ test('results with passing tests', function (t) {
t.end();
});

test('results with passing known failure tests', function (t) {
var reporter = createReporter();
var runStatus = createRunStatus();
runStatus.passCount = 1;
runStatus.knownFailureCount = 1;
runStatus.knownFailures = [{title: 'known failure', failing: true}];

var actualOutput = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.green('1 test passed') + time,
' ' + chalk.red('1 known failure'),
'',
'',
' ' + chalk.red('1. known failure'),
''
].join('\n');

t.is(actualOutput, expectedOutput);
t.end();
});

test('results with skipped tests', function (t) {
var reporter = createReporter();
var runStatus = createRunStatus();
Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,13 +622,13 @@ test('failing tests should fail', function (t) {
t.end();
});

test('failing callback tests should end with an error', function (t) {
test('failing callback tests should end without error', function (t) {
var err = new Error('failed');
ava.cb.failing(function (a) {
a.end(err);
}).run().then(function (result) {
t.is(result.passed, true);
t.is(result.reason, err);
t.is(result.reason, undefined);
t.end();
});
});
Expand Down