Skip to content

Commit

Permalink
Implement warnings. New error format. Bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Jul 27, 2016
1 parent a2b5429 commit ced1ffc
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 92 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-reporter-xunit",
"version": "1.0.0",
"version": "2.0.0",
"description": "xUnit TestCafe reporter plugin.",
"repository": "https://github.com/DevExpress/testcafe-reporter-xunit",
"author": {
Expand Down Expand Up @@ -36,6 +36,6 @@
"normalize-newline": "^1.0.2",
"publish-please": "^2.1.4",
"read-file-relative": "^1.2.0",
"testcafe": "0.0.21"
"testcafe": "0.2.0-alpha"
}
}
83 changes: 59 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,73 @@ export default function () {
this.currentFixtureName = this.escapeHtml(name);
},

reportTestDone (name, errs, durationMs, unstable, screenshotPath) {
var hasErr = !!errs.length;
_renderErrors (errs) {
this.report += ' >\n';
this.report += this.indentString('<failure>\n', 4);
this.report += this.indentString('<![CDATA[', 4);

if (unstable)
errs.forEach((err, idx) => {
err = this.formatError(err, `${idx + 1}) `);

this.report += '\n';
this.report += this.wordWrap(err, 6, LINE_WIDTH);
this.report += '\n';
});

this.report += this.indentString(']]>\n', 4);
this.report += this.indentString('</failure>\n', 4);
this.report += this.indentString('</testcase>\n', 2);
},

reportTestDone (name, testRunInfo) {
var hasErr = !!testRunInfo.errs.length;

if (testRunInfo.unstable)
name += ' (unstable)';

if (screenshotPath)
name += ` (screenshots: ${screenshotPath})`;
if (testRunInfo.screenshotPath)
name += ` (screenshots: ${testRunInfo.screenshotPath})`;

name = this.escapeHtml(name);

var openTag = `<testcase classname="${this.currentFixtureName}" name="${name}" time="${durationMs / 1000}"`;
var openTag = `<testcase classname="${this.currentFixtureName}" name="${name}" time="${testRunInfo.durationMs /
1000}"`;

this.report += this.indentString(openTag, 2);

if (hasErr) {
this.report += ' >\n';
this.report += this.indentString('<failure>\n', 4);
this.report += this.indentString('<![CDATA[', 4);
if (hasErr)
this._renderErrors(testRunInfo.errs);
else
this.report += ' />\n';
},

errs.forEach((err, idx) => {
err = this.formatError(err, `${idx + 1}) `);
_renderWarnings (warnings) {
this.setIndent(2)
.write('<system-out>')
.newline()
.write('<![CDATA[')
.newline()
.setIndent(4)
.write(`Warnings (${warnings.length}):`)
.newline();

this.report += '\n';
this.report += this.wordWrap(err, 6, LINE_WIDTH);
this.report += '\n';
});
warnings.forEach(msg => {
this.setIndent(4)
.write('--')
.newline()
.setIndent(0)
.write(this.wordWrap(msg, 6, LINE_WIDTH))
.newline();
});

this.report += this.indentString(']]>\n', 4);
this.report += this.indentString('</failure>\n', 4);
this.report += this.indentString('</testcase>\n', 2);
}
else
this.report += ' />\n';
this.setIndent(2)
.write(']]>')
.newline()
.write('</system-out>')
.newline();
},

reportTaskDone (endTime, passed) {
reportTaskDone (endTime, passed, warnings) {
var name = `TestCafe Tests: ${this.escapeHtml(this.uaList)}`;
var failures = this.testCount - passed;
var time = (endTime - this.startTime) / 1000;
Expand All @@ -65,7 +95,12 @@ export default function () {
.write(`<testsuite name="${name}" tests="${this.testCount}" failures="${failures}" ` +
`errors="${failures}" time="${time}" timestamp="${endTime.toUTCString()}" >`)
.newline()
.write(this.report)
.write(this.report);

if (warnings.length)
this._renderWarnings(warnings);

this.setIndent(0)
.write('</testsuite>');
}
};
Expand Down
33 changes: 26 additions & 7 deletions test/data/report-with-colors → test/data/report-with-colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<testcase classname="First fixture" name="Second test in first fixture (screenshots: /screenshots/1445437598847)" time="74" >
<failure>
<![CDATA[
1) Chrome 41.0.2227 / Mac OS X 10.10.1
Error on page "http://example.org":
1) Error on page "http://example.org":
Some error
Browser: Chrome 41.0.2227 / Mac OS X 10.10.1
Screenshot: /screenshots/1445437598847/errors
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
Expand All @@ -23,10 +25,9 @@
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
Screenshot: /screenshots/1445437598847/errors
2) The specified selector does not match any element in the DOM tree.
2) Firefox 47 / Mac OS X 10.10.1
The specified selector does not match any element in the DOM tree.
Browser: Firefox 47 / Mac OS X 10.10.1
1 |var createCallsiteRecord = require('callsite-record');
2 |
Expand All @@ -50,10 +51,11 @@
<testcase classname="Third fixture" name="First test in third fixture (unstable)" time="74" >
<failure>
<![CDATA[
1) Firefox 47 / Mac OS X 10.10.1
- Error in beforeEach hook -
1) - Error in beforeEach hook -
The specified selector does not match any element in the DOM tree.
Browser: Firefox 47 / Mac OS X 10.10.1
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
Expand All @@ -70,4 +72,21 @@
]]>
</failure>
</testcase>
<system-out>
<![CDATA[
Warnings (3):
--
Was unable to take a screenshot due to an error.
ReferenceError: someVar is not defined
--
Was unable to take a screenshot due to an error.
ReferenceError: someOtherVar is not defined
--
Was unable to take screenshots because the screenshot directory is not specified. To specify
it, use the "-s" or "--screenshots" command line option or the "screenshots" method of the
test runner in case you are using API.
]]>
</system-out>
</testsuite>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
<testcase classname="First fixture" name="Second test in first fixture (screenshots: /screenshots/1445437598847)" time="74" >
<failure>
<![CDATA[
1) Chrome 41.0.2227 / Mac OS X 10.10.1
Error on page "http://example.org":
1) Error on page "http://example.org":
Some error
Browser: Chrome 41.0.2227 / Mac OS X 10.10.1
Screenshot: /screenshots/1445437598847/errors
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
Expand All @@ -23,10 +25,9 @@
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
Screenshot: /screenshots/1445437598847/errors
2) The specified selector does not match any element in the DOM tree.
2) Firefox 47 / Mac OS X 10.10.1
The specified selector does not match any element in the DOM tree.
Browser: Firefox 47 / Mac OS X 10.10.1
1 |var createCallsiteRecord = require('callsite-record');
2 |
Expand All @@ -50,10 +51,11 @@
<testcase classname="Third fixture" name="First test in third fixture (unstable)" time="74" >
<failure>
<![CDATA[
1) Firefox 47 / Mac OS X 10.10.1
- Error in beforeEach hook -
1) - Error in beforeEach hook -
The specified selector does not match any element in the DOM tree.
Browser: Firefox 47 / Mac OS X 10.10.1
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
Expand All @@ -70,4 +72,21 @@
]]>
</failure>
</testcase>
<system-out>
<![CDATA[
Warnings (3):
--
Was unable to take a screenshot due to an error.
ReferenceError: someVar is not defined
--
Was unable to take a screenshot due to an error.
ReferenceError: someOtherVar is not defined
--
Was unable to take screenshots because the screenshot directory is not specified. To specify
it, use the "-s" or "--screenshots" command line option or the "screenshots" method of the
test runner in case you are using API.
]]>
</system-out>
</testsuite>
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var createReport = require('./utils/create-report');

it('Should produce report with colors', function () {
var report = createReport(true);
var expected = read('./data/report-with-colors');
var expected = read('./data/report-with-colors.xml');

report = normalizeNewline(report).trim();
expected = normalizeNewline(expected).trim();
Expand All @@ -15,7 +15,7 @@ it('Should produce report with colors', function () {

it('Should produce report without colors', function () {
var report = createReport(false);
var expected = read('./data/report-without-colors');
var expected = read('./data/report-without-colors.xml');

report = normalizeNewline(report).trim();
expected = normalizeNewline(expected).trim();
Expand Down
Loading

0 comments on commit ced1ffc

Please sign in to comment.