import Ember from 'ember';
import QUnit from 'qunit';

function unhandledRejectionAssertion(current, error) {
  let message, source;

  if (typeof error === 'object' && error !== null) {
    message = error.message;
    source = error.stack;
  } else if (typeof error === 'string') {
    message = error;
    source = 'unknown source';
  } else {
    message = 'unhandledRejection occured, but it had no message';
    source = 'unknown source';
  }

  current.pushResult({
    result: false,
    actual: false,
    expected: true,
    message: message,
    source: source,
  });
}

export default Ember.Test.Adapter.extend({
  init() {
    this.doneCallbacks = [];
  },

  asyncStart() {
    this.doneCallbacks.push(QUnit.config.current ? QUnit.config.current.assert.async() : null);
  },

  asyncEnd() {
    let done = this.doneCallbacks.pop();
    // This can be null if asyncStart() was called outside of a test
    if (done) {
      done();
    }
  },

  exception(error) {
    unhandledRejectionAssertion(QUnit.config.current, error);
  },
});

@@ -46,16 +46,85 @@
 'qunit';
+%0Aimport hasEmberVersion from '@ember/test-helpers/has-ember-version';
 %0A%0Afuncti
@@ -648,22 +648,21 @@
 %0A%7D%0A%0A
-export default
+let Adapter =
  Emb
@@ -1021,30 +1021,381 @@
  %7D,%0A
-%0A  exception(error) %7B%0A
+%7D);%0A%0A// Ember 2.17 and higher do not require the test adapter to have an %60exception%60%0A// method When %60exception%60 is not present, the unhandled rejection is%0A// automatically re-thrown and will therefore hit QUnit's own global error%0A// handler (therefore appropriately causing test failure)%0Aif (!hasEmberVersion(2, 17)) %7B%0A  Adapter = Adapter.extend(%7B%0A    exception(error) %7B%0A  
     
@@ -1452,17 +1452,48 @@
 error);%0A
+  
   %7D,%0A
+  
 %7D);%0A
+%7D%0A%0Aexport default Adapter;%0A

Remove `exception` method from QUnit test adapter.