Skip to content

Commit

Permalink
Should not stop while async report methods are executing (closes DevE…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKamaev committed Jun 3, 2019
1 parent 1a603cd commit 683f7f0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export default class Reporter {
this.stopOnFirstFail = task.opts.stopOnFirstFail;
this.outStream = outStream;

this.pendingTaskDonePromise = Reporter._createPendingPromise();

this._assignTaskEventHandlers();
}

Expand Down Expand Up @@ -186,6 +188,8 @@ export default class Reporter {
};

await this.plugin.reportTaskDone(endTime, this.passed, task.warningLog.messages, result);

this.pendingTaskDonePromise.resolve();
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/runner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ export default class Runner extends EventEmitter {
const browserSetErrorPromise = promisifyEvent(browserSet, 'error');

const taskDonePromise = task.once('done')
.then(() => browserSetErrorPromise.cancel());
.then(() => browserSetErrorPromise.cancel())
.then(() => {
return Promise.all(reporters.map(reporter => reporter.pendingTaskDonePromise));
});


const promises = [
Expand Down
9 changes: 9 additions & 0 deletions test/functional/fixtures/regression/gh-3835/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
</html>
51 changes: 51 additions & 0 deletions test/functional/fixtures/regression/gh-3835/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const expect = require('chai').expect;

function timeout (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}

let startedReportTaskCount = 0;
let finishedReportTaskCount = 0;


const getReporter = function (delay) {
return {
name: () => {
return {
reportTestDone () {
},
reportFixtureStart: () => {
},
reportTaskStart: () => {
},
reportTaskDone: async () => {
startedReportTaskCount++;

await timeout(delay);

finishedReportTaskCount++;
}
};
},
output: {
write: () => {
},
end: () => {
}
}
};
};

describe('[Regression](GH-3835) - Should not stop while async report methods are executiing', function () {
const reporters = [ getReporter(1), getReporter(500), getReporter(1000) ];

it('Click on hidden element recreated on timeout', function () {
return runTests('testcafe-fixtures/index.js', null, { reporter: reporters })
.then(() => {
expect(finishedReportTaskCount).eql(startedReportTaskCount);
expect(finishedReportTaskCount).eql(reporters.length);
});
});
});


Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fixture `Should not stop while async report methods are executing (GH-3835)`
.page `http://localhost:3000/fixtures/regression/gh-3835/pages/index.html`;

test(`Custom async reporters with delay`, async () => {
});

0 comments on commit 683f7f0

Please sign in to comment.