Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

921 firefox scheduler test fix #922

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules/
dist/
tmp/
coverage/
lib/**/*.d.ts
.idea/
Expand Down
16 changes: 16 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

var path = require('path');

var fs = require('fs');

var coverage = process.env.COVERAGE;

// configures browsers to run test against
Expand All @@ -11,6 +13,12 @@ var browsers = (process.env.TEST_BROWSERS || 'ChromeHeadless').split(',');
// use puppeteer provided Chrome for testing
process.env.CHROME_BIN = require('puppeteer').executablePath();

var tmpDir = path.join(__dirname, 'tmp');

fs.mkdirSync(tmpDir, { recursive: true });

var firefoxProfile = fs.mkdtempSync(path.join(tmpDir, 'firefox-profile'));

var absoluteBasePath = path.resolve(__dirname);

var suite = coverage ? 'test/coverageBundle.js' : 'test/testBundle.js';
Expand All @@ -35,6 +43,14 @@ module.exports = function(karma) {

reporters: [ 'progress' ].concat(coverage ? 'coverage' : []),

customLaunchers: {
'FirefoxHeadless': {
base: 'Firefox',
flags: [ '-headless' ],
profile: firefoxProfile
}
},

browsers,

browserNoActivityTimeout: 30000,
Expand Down
57 changes: 38 additions & 19 deletions lib/features/scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,49 @@ Scheduler.prototype.schedule = function(taskFn, id = Ids.next()) {

const newScheduled = this._schedule(taskFn, id);

if (this.DEBUG) {
console.log('Scheduler.schedule', { id, ...newScheduled });
}

this._scheduled[id] = newScheduled;

return newScheduled.promise;
};

Scheduler.prototype._schedule = function(taskFn, id) {

const {
promise,
resolve,
reject
} = defer();
const deferred = defer();

const executionId = requestAnimationFrame(() => {

try {
resolve(taskFn());
} catch (error) {
reject(error);
this._scheduled[id] = null;

if (this.DEBUG) {
console.log('Scheduler.exec', { id, executionId });
}

try {
deferred.resolve(taskFn());

if (this.DEBUG) {
console.log('Scheduler.executed', { id, executionId });
}
} catch (error) {
deferred.reject(error);
}
} catch (err) {
console.log(err);
}
});

if (this.DEBUG) {
console.log('Scheduler._schedule', { id, executionId });
}

return {
executionId,
promise
promise: deferred.promise
};
};

Expand All @@ -89,6 +108,11 @@ Scheduler.prototype.cancel = function(id) {
const scheduled = this._scheduled[id];

if (scheduled) {

if (this.DEBUG) {
console.log('Scheduler.cancel', { id, executionId: scheduled.executionId });
}

this._cancel(scheduled);

this._scheduled[id] = null;
Expand All @@ -108,17 +132,12 @@ Scheduler.prototype._cancel = function(scheduled) {
*/
function defer() {

let resolve;
let reject;
const deferred = {};

const promise = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
deferred.promise = new Promise((resolve, reject) => {
deferred.resolve = resolve;
deferred.reject = reject;
});

return {
promise,
resolve,
reject
};
return deferred;
}
Loading
Loading