From 260a81f978b2e36c020e1bfe6990c23e4bcb6adb Mon Sep 17 00:00:00 2001 From: Stefan Penner Date: Sun, 26 Jul 2015 09:43:55 -0700 Subject: [PATCH] [BUGFIX release] upgrade rsvp + backburner + add more tests --- bower.json | 4 +- packages/ember-runtime/lib/ext/rsvp.js | 9 +- packages/ember-runtime/tests/ext/rsvp_test.js | 126 +++++++++++++++++- 3 files changed, 133 insertions(+), 6 deletions(-) diff --git a/bower.json b/bower.json index 8f1ff1edcca..c3add2f16b7 100644 --- a/bower.json +++ b/bower.json @@ -10,8 +10,8 @@ "qunit-phantom-runner": "jonkemp/qunit-phantomjs-runner#1.2.0" }, "devDependencies": { - "backburner": "https://github.com/ebryn/backburner.js.git#4a0105a4a0bc4cf73bdf3e554aea14f3f438876c", - "rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.14", + "backburner": "https://github.com/ebryn/backburner.js.git#ea82b6d703a7b65b4c4c65671843edb8d67f2a6c", + "rsvp": "https://github.com/tildeio/rsvp.js.git#3.0.20", "router.js": "https://github.com/tildeio/router.js.git#ed45bc5c5e055af0ab875ef2c52feda792ee23e4", "dag-map": "https://github.com/krisselden/dag-map.git#e307363256fe918f426e5a646cb5f5062d3245be", "ember-dev": "https://github.com/emberjs/ember-dev.git#a064f0cd2f4c225ffd023b63d4cb31a79db04aaf" diff --git a/packages/ember-runtime/lib/ext/rsvp.js b/packages/ember-runtime/lib/ext/rsvp.js index 6373fdda590..979abfe020a 100644 --- a/packages/ember-runtime/lib/ext/rsvp.js +++ b/packages/ember-runtime/lib/ext/rsvp.js @@ -61,9 +61,7 @@ export function onerrorDefault(e) { Test.adapter.exception(error); Logger.error(error.stack); } else { - Ember.run.schedule(Ember.run.queues[Ember.run.queues.length-1], function() { - throw error; - }); + throw error; } } else if (Ember.onerror) { Ember.onerror(error); @@ -73,6 +71,11 @@ export function onerrorDefault(e) { } } +export function after (cb) { + Ember.run.schedule(Ember.run.queues[Ember.run.queues.length - 1], cb); +} + RSVP.on('error', onerrorDefault); +RSVP.configure('after', after); export default RSVP; diff --git a/packages/ember-runtime/tests/ext/rsvp_test.js b/packages/ember-runtime/tests/ext/rsvp_test.js index 6722bcf1274..9ecd4648ee7 100644 --- a/packages/ember-runtime/tests/ext/rsvp_test.js +++ b/packages/ember-runtime/tests/ext/rsvp_test.js @@ -142,7 +142,6 @@ QUnit.test('rejections like jqXHR which have errorThrown property work', functio } }); - QUnit.test('rejections where the errorThrown is a string should wrap the sting in an error object', function() { expect(2); @@ -167,3 +166,128 @@ QUnit.test('rejections where the errorThrown is a string should wrap the sting i Ember.testing = wasEmberTesting; } }); + +var wasTesting; +var reason = 'i failed'; +QUnit.module('Ember.test: rejection assertions', { + before() { + wasTesting = Ember.testing; + Ember.testing = true; + }, + after() { + Ember.testing = wasTesting; + } +}); + +function ajax(something) { + return RSVP.Promise(function(resolve) { + QUnit.stop(); + setTimeout(function() { + QUnit.start(); + resolve(); + }, 0); // fake true / foreign async + }); +} + +QUnit.test('unambigiously unhandled rejection', function() { + QUnit.throws(function() { + Ember.run(function() { + RSVP.Promise.reject(reason); + }); // something is funky, we should likely assert + }, reason); +}); + +QUnit.test('sync handled', function() { + Ember.run(function() { + RSVP.Promise.reject(reason).catch(function() { }); + }); // handled, we shouldn't need to assert. + ok(true, 'reached end of test'); +}); + +QUnit.test('handled within the same micro-task (via Ember.RVP.Promise)', function() { + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + RSVP.Promise.resolve(1).then(() => rejection.catch(function() { })); + }); // handled, we shouldn't need to assert. + ok(true, 'reached end of test'); +}); + +QUnit.test('handled within the same micro-task (via direct run-loop)', function() { + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + + Ember.run.schedule('afterRender', () => rejection.catch(function() { })); + }); // handled, we shouldn't need to assert. + ok(true, 'reached end of test'); +}); + +QUnit.test('handled in the next microTask queue flush (Ember.run.next)', function() { + expect(2); + + QUnit.throws(function() { + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + + QUnit.stop(); + Ember.run.next(() => { + QUnit.start(); + rejection.catch(function() { }); + ok(true, 'reached end of test'); + }); + }); + }, reason); + + // a promise rejection survived a full flush of the run-loop without being handled + // this is very likely an issue. +}); + +QUnit.test('handled in the same microTask Queue flush do to data locality', function() { + // an ambiguous scenario, this may or may not assert + // it depends on the locality of `user#1` + var store = { + find() { + return Promise.resolve(1); + } + }; + + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + + store.find('user', 1).then(() => rejection.catch(function() { })); + }); + + ok(true, 'reached end of test'); +}); + +QUnit.test('handled in a different microTask Queue flush do to data locality', function() { + // an ambiguous scenario, this may or may not assert + // it depends on the locality of `user#1` + var store = { + find() { + return ajax(); + } + }; + + QUnit.throws(function() { + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + + store.find('user', 1).then(() => { + rejection.catch(function() { }); + ok(true, 'reached end of test'); + }); + }); + }, reason); +}); + +QUnit.test('handled in the next microTask queue flush (ajax example)', function() { + QUnit.throws(function() { + Ember.run(function() { + var rejection = RSVP.Promise.reject(reason); + ajax('/something/').then(() => { + rejection.catch(function() { }); + ok(true, 'reached end of test'); + }); + }); + }, reason); +});