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 37b6646 commit 2a0a8d4
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 136 deletions.
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "testcafe-reporter-minimal",
"version": "1.0.2",
"version": "2.0.0",
"description": "Minimal TestCafe reporter plugin.",
"repository": "https://github.com/DevExpress/testcafe-reporter-minimal",
"author": {
Expand Down Expand Up @@ -35,6 +35,6 @@
"os-family": "^1.0.0",
"publish-please": "^2.1.4",
"read-file-relative": "^1.2.0",
"testcafe": "0.0.21"
"testcafe": "0.2.0-alpha"
}
}
85 changes: 55 additions & 30 deletions src/index.js
@@ -1,4 +1,4 @@
var NEW_LINE = '\n ';
var NEW_LINE = '\n ';

export default function () {
return {
Expand All @@ -9,25 +9,25 @@ export default function () {
testCount: 0,

reportTaskStart (startTime, userAgents, testCount) {
var uaList = userAgents
.map(ua => this.chalk.blue(ua))
.join(', ');

this.testCount = testCount;

this.setIndent(0)
this.setIndent(1)
.useWordWrap(true)
.write(this.chalk.bold(`Running tests in: ${uaList}`))
.newline()
.write(this.chalk.bold('Running tests in:'))
.newline();

userAgents.forEach(ua => {
this.write(`- ${this.chalk.blue(ua)}`)
.newline();
});
},

reportFixtureStart (name) {
this.currentFixtureName = name;
},

reportTestDone (name, errs) {
var hasErr = !!errs.length;
reportTestDone (name, testRunInfo) {
var hasErr = !!testRunInfo.errs.length;
var dot = hasErr ? this.chalk.red('.') : '.';

if (this.spaceLeft - 1 < 0) {
Expand All @@ -40,7 +40,7 @@ export default function () {
this.write(dot);

if (hasErr) {
this.errDescriptors = this.errDescriptors.concat(errs.map(err => {
this.errDescriptors = this.errDescriptors.concat(testRunInfo.errs.map(err => {
return {
err: err,
testName: name,
Expand All @@ -50,34 +50,59 @@ export default function () {
}
},

reportTaskDone (endTime, passed) {
_renderErrors () {
this.newline();

this.errDescriptors.forEach((errDescriptor) => {
var title = `${this.chalk.bold.red(this.symbols.err)} ${errDescriptor.fixtureName} - ${errDescriptor.testName}`;

this.setIndent(1)
.useWordWrap(true)
.newline()
.write(title)
.newline()
.newline()
.setIndent(3)
.write(this.formatError(errDescriptor.err))
.newline()
.newline();
});
},

_renderWarnings (warnings) {
this.newline()
.setIndent(1)
.write(this.chalk.bold.yellow(`Warnings (${warnings.length}):`))
.newline();

warnings.forEach(msg => {
this.setIndent(1)
.write(this.chalk.bold.yellow(`--`))
.newline()
.setIndent(2)
.write(msg)
.newline();
});
},

reportTaskDone (endTime, passed, warnings) {
var allPassed = !this.errDescriptors.length;
var footer = allPassed ?
this.chalk.bold.green(`${this.testCount} passed`) :
this.chalk.bold.red(`${this.testCount - passed}/${this.testCount} failed`);

this.setIndent(2)
.newline()
if (!allPassed)
this._renderErrors();
else
this.newline();

this.setIndent(1)
.newline()
.write(footer)
.newline();

if (!allPassed) {
this.errDescriptors.forEach((errDescriptor, idx) => {
var prefix = `${idx + 1}) `;
var title = this.chalk.bold.red(`${prefix}${errDescriptor.fixtureName} - ${errDescriptor.testName}`);

this.setIndent(2)
.useWordWrap(true)
.newline()
.write(title)
.newline()
.setIndent(2 + prefix.length)
.write(this.formatError(errDescriptor.err))
.newline()
.newline();
});
}
if (warnings.length)
this._renderWarnings(warnings);
}
};
}
2 changes: 1 addition & 1 deletion test/data/report-with-colors-win.json
@@ -1 +1 @@
"\u001b[1mRunning tests in: \u001b[94mChrome 41.0.2227 / Mac OS X 10.10.1\u001b[39m, \u001b[94mFirefox 47 / Mac OS X\n10.10.1\u001b[39m\u001b[22m\n\n\n .\u001b[31m.\u001b[39m...\u001b[31m.\u001b[39m\n\n \u001b[1m\u001b[31m2/6 failed\u001b[39m\u001b[22m\n\n \u001b[1m\u001b[31m1) First fixture - Second test in first fixture\u001b[39m\u001b[22m\n Chrome 41.0.2227 / Mac OS X 10.10.1\n Error on page \"http://example.org\":\n\n Some error\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n Screenshot: /screenshots/1445437598847/errors\n\n\n \u001b[1m\u001b[31m2) First fixture - Second test in first fixture\u001b[39m\u001b[22m\n Firefox 47 / Mac OS X 10.10.1\n The specified selector does not match any element in the DOM tree.\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m3) Third fixture - First test in third fixture\u001b[39m\u001b[22m\n Firefox 47 / Mac OS X 10.10.1\n - Error in beforeEach hook -\n The specified selector does not match any element in the DOM tree.\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n"
" \u001b[1mRunning tests in:\u001b[22m\n - \u001b[94mChrome 41.0.2227 / Mac OS X 10.10.1\u001b[39m\n - \u001b[94mFirefox 47 / Mac OS X 10.10.1\u001b[39m\n\n . \u001b[31m.\u001b[39m . . . \u001b[31m.\u001b[39m\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m First fixture - Second test in first fixture\n\n Error on page \"http://example.org\":\n\n Some error\n\n Browser: Chrome 41.0.2227 / Mac OS X 10.10.1\n Screenshot: /screenshots/1445437598847/errors\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m First fixture - Second test in first fixture\n\n The specified selector does not match any element in the DOM tree.\n\n Browser: Firefox 47 / Mac OS X 10.10.1\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m Third fixture - First test in third fixture\n\n - Error in beforeEach hook -\n The specified selector does not match any element in the DOM tree.\n\n Browser: Firefox 47 / Mac OS X 10.10.1\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m2/6 failed\u001b[39m\u001b[22m\n\n \u001b[1m\u001b[33mWarnings (3):\u001b[39m\u001b[22m\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take a screenshot due to an error.\n\n ReferenceError: someVar is not defined\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take a screenshot due to an error.\n\n ReferenceError: someOtherVar is not defined\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take screenshots because the screenshot directory is not\n specified. To specify it, use the \"-s\" or \"--screenshots\" command line\n option or the \"screenshots\" method of the test runner in case you are using\n API.\n"
2 changes: 1 addition & 1 deletion test/data/report-with-colors.json
@@ -1 +1 @@
"\u001b[1mRunning tests in: \u001b[34mChrome 41.0.2227 / Mac OS X 10.10.1\u001b[39m, \u001b[34mFirefox 47 / Mac OS X\n10.10.1\u001b[39m\u001b[22m\n\n\n .\u001b[31m.\u001b[39m...\u001b[31m.\u001b[39m\n\n \u001b[1m\u001b[31m2/6 failed\u001b[39m\u001b[22m\n\n \u001b[1m\u001b[31m1) First fixture - Second test in first fixture\u001b[39m\u001b[22m\n Chrome 41.0.2227 / Mac OS X 10.10.1\n Error on page \"http://example.org\":\n\n Some error\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n Screenshot: /screenshots/1445437598847/errors\n\n\n \u001b[1m\u001b[31m2) First fixture - Second test in first fixture\u001b[39m\u001b[22m\n Firefox 47 / Mac OS X 10.10.1\n The specified selector does not match any element in the DOM tree.\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m3) Third fixture - First test in third fixture\u001b[39m\u001b[22m\n Firefox 47 / Mac OS X 10.10.1\n - Error in beforeEach hook -\n The specified selector does not match any element in the DOM tree.\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n"
" \u001b[1mRunning tests in:\u001b[22m\n - \u001b[34mChrome 41.0.2227 / Mac OS X 10.10.1\u001b[39m\n - \u001b[34mFirefox 47 / Mac OS X 10.10.1\u001b[39m\n\n . \u001b[31m.\u001b[39m . . . \u001b[31m.\u001b[39m\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m First fixture - Second test in first fixture\n\n Error on page \"http://example.org\":\n\n Some error\n\n Browser: Chrome 41.0.2227 / Mac OS X 10.10.1\n Screenshot: /screenshots/1445437598847/errors\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m First fixture - Second test in first fixture\n\n The specified selector does not match any element in the DOM tree.\n\n Browser: Firefox 47 / Mac OS X 10.10.1\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m✖\u001b[39m\u001b[22m Third fixture - First test in third fixture\n\n - Error in beforeEach hook -\n The specified selector does not match any element in the DOM tree.\n\n Browser: Firefox 47 / Mac OS X 10.10.1\n\n 1 |var createCallsiteRecord = require('callsite-record');\n 2 |\n 3 |function someFunc () {\n > 4 | throw new Error('Hey ya!');\n 5 |}\n 6 |\n 7 |try {\n 8 | someFunc();\n 9 |}\n\n at someFunc (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n at Object.<anonymous> (some-file:1:1)\n\n\n \u001b[1m\u001b[31m2/6 failed\u001b[39m\u001b[22m\n\n \u001b[1m\u001b[33mWarnings (3):\u001b[39m\u001b[22m\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take a screenshot due to an error.\n\n ReferenceError: someVar is not defined\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take a screenshot due to an error.\n\n ReferenceError: someOtherVar is not defined\n \u001b[1m\u001b[33m--\u001b[39m\u001b[22m\n Was unable to take screenshots because the screenshot directory is not\n specified. To specify it, use the \"-s\" or \"--screenshots\" command line\n option or the \"screenshots\" method of the test runner in case you are using\n API.\n"
124 changes: 72 additions & 52 deletions test/data/report-without-colors
@@ -1,69 +1,89 @@
Running tests in: Chrome 41.0.2227 / Mac OS X 10.10.1, Firefox 47 / Mac OS X
10.10.1
Running tests in:
- Chrome 41.0.2227 / Mac OS X 10.10.1
- Firefox 47 / Mac OS X 10.10.1

. . . . . .

......
✖ First fixture - Second test in first fixture

2/6 failed
Error on page "http://example.org":

1) First fixture - Second test in first fixture
Chrome 41.0.2227 / Mac OS X 10.10.1
Error on page "http://example.org":
Some error

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 () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}

at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)

Screenshot: /screenshots/1445437598847/errors

✖ First fixture - Second test in first fixture

2) First fixture - Second test in first fixture
Firefox 47 / Mac OS X 10.10.1
The specified selector does not match any element in the DOM tree.
The specified selector does not match any element in the DOM tree.

1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}
Browser: Firefox 47 / Mac OS X 10.10.1

at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}

at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)

3) Third fixture - First test in third fixture
Firefox 47 / Mac OS X 10.10.1
- Error in beforeEach hook -
The specified selector does not match any element in the DOM tree.

1 |var createCallsiteRecord = require('callsite-record');
2 |
3 |function someFunc () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}
✖ Third fixture - First test in third fixture

at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1: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 () {
> 4 | throw new Error('Hey ya!');
5 |}
6 |
7 |try {
8 | someFunc();
9 |}

at someFunc (some-file:1:1)
at Object.<anonymous> (some-file:1:1)
at Object.<anonymous> (some-file:1:1)


2/6 failed

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.

0 comments on commit 2a0a8d4

Please sign in to comment.