ember-source 4.5.0-beta.1 → 4.6.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/blueprints-js/-addon-import.js +48 -0
  2. package/blueprints-js/acceptance-test/mocha-files/tests/acceptance/__name__-test.js +24 -0
  3. package/blueprints-js/acceptance-test/mocha-rfc-232-files/tests/acceptance/__name__-test.js +13 -0
  4. package/blueprints-js/acceptance-test/qunit-files/tests/acceptance/__name__-test.js +12 -0
  5. package/blueprints-js/acceptance-test/qunit-rfc-232-files/tests/acceptance/__name__-test.js +13 -0
  6. package/blueprints-js/component/files/__root__/__path__/__name__.js +3 -0
  7. package/blueprints-js/component/files/__root__/__templatepath__/__templatename__.hbs +1 -0
  8. package/blueprints-js/component-addon/files/__root__/__path__/__name__.js +1 -0
  9. package/blueprints-js/component-class/files/__root__/__path__/__name__.js +3 -0
  10. package/blueprints-js/component-class-addon/files/__root__/__path__/__name__.js +1 -0
  11. package/blueprints-js/component-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +34 -0
  12. package/blueprints-js/component-test/mocha-files/__root__/__testType__/__path__/__test__.js +36 -0
  13. package/blueprints-js/component-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +38 -0
  14. package/blueprints-js/component-test/qunit-files/__root__/__testType__/__path__/__test__.js +31 -0
  15. package/blueprints-js/component-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +36 -0
  16. package/blueprints-js/controller/files/__root__/__path__/__name__.js +3 -0
  17. package/blueprints-js/controller-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +16 -0
  18. package/blueprints-js/controller-test/mocha-files/__root__/__testType__/__path__/__test__.js +18 -0
  19. package/blueprints-js/controller-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +13 -0
  20. package/blueprints-js/controller-test/qunit-files/__root__/__testType__/__path__/__test__.js +12 -0
  21. package/blueprints-js/controller-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  22. package/blueprints-js/helper/files/__root__/__collection__/__name__.js +5 -0
  23. package/blueprints-js/helper/mu-files/__root__/__collection__/__name__.js +7 -0
  24. package/blueprints-js/helper-addon/files/__root__/__path__/__name__.js +1 -0
  25. package/blueprints-js/helper-test/mocha-0.12-files/__root__/__testType__/__collection__/__name__-test.js +26 -0
  26. package/blueprints-js/helper-test/mocha-files/__root__/__testType__/__collection__/__name__-test.js +28 -0
  27. package/blueprints-js/helper-test/mocha-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +18 -0
  28. package/blueprints-js/helper-test/qunit-files/__root__/__testType__/__collection__/__name__-test.js +15 -0
  29. package/blueprints-js/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js +17 -0
  30. package/blueprints-js/initializer/files/__root__/initializers/__name__.js +5 -0
  31. package/blueprints-js/initializer-addon/files/__root__/__path__/__name__.js +1 -0
  32. package/blueprints-js/initializer-test/mocha-files/__root__/__testType__/__path__/__name__-test.js +28 -0
  33. package/blueprints-js/initializer-test/mocha-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +31 -0
  34. package/blueprints-js/initializer-test/qunit-files/__root__/__testType__/__path__/__name__-test.js +25 -0
  35. package/blueprints-js/initializer-test/qunit-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +37 -0
  36. package/blueprints-js/instance-initializer/files/__root__/instance-initializers/__name__.js +5 -0
  37. package/blueprints-js/instance-initializer-addon/files/__root__/__path__/__name__.js +1 -0
  38. package/blueprints-js/instance-initializer-test/mocha-files/__root__/__testType__/__path__/__name__-test.js +30 -0
  39. package/blueprints-js/instance-initializer-test/mocha-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +32 -0
  40. package/blueprints-js/instance-initializer-test/qunit-files/__root__/__testType__/__path__/__name__-test.js +26 -0
  41. package/blueprints-js/instance-initializer-test/qunit-rfc-232-files/__root__/__testType__/__path__/__name__-test.js +39 -0
  42. package/blueprints-js/mixin/files/__root__/mixins/__name__.js +3 -0
  43. package/blueprints-js/mixin-test/mocha-files/__root__/__testType__/__name__-test.js +13 -0
  44. package/blueprints-js/mixin-test/mocha-rfc-232-files/__root__/__testType__/__name__-test.js +13 -0
  45. package/blueprints-js/mixin-test/qunit-files/__root__/__testType__/__name__-test.js +12 -0
  46. package/blueprints-js/mixin-test/qunit-rfc-232-files/__root__/__testType__/__name__-test.js +12 -0
  47. package/blueprints-js/route/files/__root__/__path__/__name__.js +9 -0
  48. package/blueprints-js/route/files/__root__/__templatepath__/__templatename__.hbs +2 -0
  49. package/blueprints-js/route-addon/files/__root__/__path__/__name__.js +1 -0
  50. package/blueprints-js/route-addon/files/__root__/__templatepath__/__templatename__.js +1 -0
  51. package/blueprints-js/route-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +15 -0
  52. package/blueprints-js/route-test/mocha-files/__root__/__testType__/__path__/__test__.js +17 -0
  53. package/blueprints-js/route-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  54. package/blueprints-js/route-test/qunit-files/__root__/__testType__/__path__/__test__.js +11 -0
  55. package/blueprints-js/route-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +11 -0
  56. package/blueprints-js/service/files/__root__/__path__/__name__.js +3 -0
  57. package/blueprints-js/service-test/mocha-0.12-files/__root__/__testType__/__path__/__test__.js +16 -0
  58. package/blueprints-js/service-test/mocha-files/__root__/__testType__/__path__/__test__.js +18 -0
  59. package/blueprints-js/service-test/mocha-rfc-232-files/__root__/__testType__/__path__/__test__.js +13 -0
  60. package/blueprints-js/service-test/qunit-files/__root__/__testType__/__path__/__test__.js +12 -0
  61. package/blueprints-js/service-test/qunit-rfc-232-files/__root__/__testType__/__path__/__test__.js +12 -0
  62. package/blueprints-js/template/files/__root__/__path__/__name__.hbs +0 -0
  63. package/blueprints-js/test-framework-detector.js +60 -0
  64. package/blueprints-js/util/files/__root__/utils/__name__.js +3 -0
  65. package/blueprints-js/util-test/mocha-files/__root__/__testType__/__name__-test.js +11 -0
  66. package/blueprints-js/util-test/mocha-rfc-232-files/__root__/__testType__/__name__-test.js +11 -0
  67. package/blueprints-js/util-test/qunit-files/__root__/__testType__/__name__-test.js +10 -0
  68. package/blueprints-js/util-test/qunit-rfc-232-files/__root__/__testType__/__name__-test.js +10 -0
  69. package/build-metadata.json +3 -3
  70. package/dist/ember-template-compiler.js +4 -4
  71. package/dist/ember-template-compiler.map +1 -1
  72. package/dist/ember-testing.js +112 -136
  73. package/dist/ember-testing.map +1 -1
  74. package/dist/ember.debug.js +584 -944
  75. package/dist/ember.debug.map +1 -1
  76. package/dist/header/license.js +1 -1
  77. package/dist/packages/@ember/-internals/error-handling/index.js +1 -1
  78. package/dist/packages/@ember/-internals/glimmer/index.js +21 -11
  79. package/dist/packages/@ember/-internals/metal/index.js +16 -9
  80. package/dist/packages/@ember/-internals/routing/lib/system/router.js +0 -4
  81. package/dist/packages/@ember/-internals/runtime/lib/compare.js +4 -3
  82. package/dist/packages/@ember/-internals/runtime/lib/mixins/array.js +281 -368
  83. package/dist/packages/@ember/-internals/runtime/lib/system/array_proxy.js +8 -5
  84. package/dist/packages/@ember/application/lib/application.js +4 -1
  85. package/dist/packages/@ember/canary-features/index.js +2 -2
  86. package/dist/packages/@ember/controller/lib/controller_mixin.js +8 -18
  87. package/dist/packages/@ember/engine/index.js +3 -1
  88. package/dist/packages/@ember/object/index.js +16 -8
  89. package/dist/packages/@ember/object/lib/computed/computed_macros.js +6 -4
  90. package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +74 -365
  91. package/dist/packages/@ember/test/adapter.js +2 -2
  92. package/dist/packages/ember/version.js +1 -1
  93. package/dist/packages/ember-testing/lib/adapters/adapter.js +11 -27
  94. package/dist/packages/ember-testing/lib/adapters/qunit.js +8 -16
  95. package/dist/packages/ember-testing/lib/ext/application.js +28 -19
  96. package/dist/packages/ember-testing/lib/helpers/and_then.js +4 -1
  97. package/dist/packages/ember-testing/lib/helpers/current_path.js +5 -0
  98. package/dist/packages/ember-testing/lib/helpers/current_route_name.js +5 -0
  99. package/dist/packages/ember-testing/lib/helpers/current_url.js +8 -1
  100. package/dist/packages/ember-testing/lib/helpers/visit.js +12 -2
  101. package/dist/packages/ember-testing/lib/helpers/wait.js +6 -1
  102. package/dist/packages/ember-testing/lib/initializers.js +3 -3
  103. package/dist/packages/ember-testing/lib/test/adapter.js +2 -1
  104. package/dist/packages/ember-testing/lib/test/helpers.js +3 -1
  105. package/dist/packages/ember-testing/lib/test/on_inject_helpers.js +2 -2
  106. package/dist/packages/ember-testing/lib/test/promise.js +8 -8
  107. package/dist/packages/ember-testing/lib/test/waiters.js +14 -45
  108. package/dist/packages/ember-testing/lib/test.js +1 -1
  109. package/docs/data.json +745 -729
  110. package/package.json +7 -6
@@ -1,27 +1,18 @@
1
1
  /* globals QUnit */
2
2
  import { inspect } from '@ember/-internals/utils';
3
3
  import Adapter from './adapter';
4
- /**
5
- @module ember
6
- */
7
4
 
8
- /**
9
- This class implements the methods defined by TestAdapter for the
10
- QUnit testing framework.
5
+ function isVeryOldQunit(obj) {
6
+ return obj != null && typeof obj.stop === 'function';
7
+ }
11
8
 
12
- @class QUnitAdapter
13
- @namespace Ember.Test
14
- @extends TestAdapter
15
- @public
16
- */
17
-
18
- export default Adapter.extend({
9
+ const QUnitAdapter = Adapter.extend({
19
10
  init() {
20
11
  this.doneCallbacks = [];
21
12
  },
22
13
 
23
14
  asyncStart() {
24
- if (typeof QUnit.stop === 'function') {
15
+ if (isVeryOldQunit(QUnit)) {
25
16
  // very old QUnit version
26
17
  // eslint-disable-next-line qunit/no-qunit-stop
27
18
  QUnit.stop();
@@ -34,7 +25,7 @@ export default Adapter.extend({
34
25
  // checking for QUnit.stop here (even though we _need_ QUnit.start) because
35
26
  // QUnit.start() still exists in QUnit 2.x (it just throws an error when calling
36
27
  // inside a test context)
37
- if (typeof QUnit.stop === 'function') {
28
+ if (isVeryOldQunit(QUnit)) {
38
29
  QUnit.start();
39
30
  } else {
40
31
  let done = this.doneCallbacks.pop(); // This can be null if asyncStart() was called outside of a test
@@ -49,4 +40,5 @@ export default Adapter.extend({
49
40
  QUnit.config.current.assert.ok(false, inspect(error));
50
41
  }
51
42
 
52
- });
43
+ });
44
+ export default QUnitAdapter;
@@ -5,13 +5,14 @@ import TestPromise, { resolve, getLastPromise } from '../test/promise';
5
5
  import run from '../test/run';
6
6
  import { invokeInjectHelpersCallbacks } from '../test/on_inject_helpers';
7
7
  import { asyncStart, asyncEnd } from '../test/adapter';
8
+ import { assert } from '@ember/debug';
8
9
  EmberApplication.reopen({
9
10
  /**
10
11
  This property contains the testing helpers for the current application. These
11
12
  are created once you call `injectTestHelpers` on your `Application`
12
13
  instance. The included helpers are also available on the `window` object by
13
14
  default, but can be used from this object on the individual application also.
14
- @property testHelpers
15
+ @property testHelpers
15
16
  @type {Object}
16
17
  @default {}
17
18
  @public
@@ -21,9 +22,9 @@ EmberApplication.reopen({
21
22
  /**
22
23
  This property will contain the original methods that were registered
23
24
  on the `helperContainer` before `injectTestHelpers` is called.
24
- When `removeTestHelpers` is called, these methods are restored to the
25
+ When `removeTestHelpers` is called, these methods are restored to the
25
26
  `helperContainer`.
26
- @property originalMethods
27
+ @property originalMethods
27
28
  @type {Object}
28
29
  @default {}
29
30
  @private
@@ -35,7 +36,7 @@ EmberApplication.reopen({
35
36
  This property indicates whether or not this application is currently in
36
37
  testing mode. This is set when `setupForTesting` is called on the current
37
38
  application.
38
- @property testing
39
+ @property testing
39
40
  @type {Boolean}
40
41
  @default false
41
42
  @since 1.3.0
@@ -50,11 +51,11 @@ EmberApplication.reopen({
50
51
  (preventing both accidental leaking of state between tests and interference
51
52
  with your testing framework). `setupForTesting` should only be called after
52
53
  setting a custom `router` class (for example `App.Router = Router.extend(`).
53
- Example:
54
- ```
54
+ Example:
55
+ ```
55
56
  App.setupForTesting();
56
57
  ```
57
- @method setupForTesting
58
+ @method setupForTesting
58
59
  @public
59
60
  */
60
61
  setupForTesting() {
@@ -68,7 +69,7 @@ EmberApplication.reopen({
68
69
  /**
69
70
  This will be used as the container to inject the test helpers into. By
70
71
  default the helpers are injected into `window`.
71
- @property helperContainer
72
+ @property helperContainer
72
73
  @type {Object} The object to be used for test helpers.
73
74
  @default window
74
75
  @since 1.2.0
@@ -82,13 +83,13 @@ EmberApplication.reopen({
82
83
  to `window`. If a function of the same name has already been defined it will be cached
83
84
  (so that it can be reset if the helper is removed with `unregisterHelper` or
84
85
  `removeTestHelpers`).
85
- Any callbacks registered with `onInjectHelpers` will be called once the
86
+ Any callbacks registered with `onInjectHelpers` will be called once the
86
87
  helpers have been injected.
87
- Example:
88
+ Example:
88
89
  ```
89
90
  App.injectTestHelpers();
90
91
  ```
91
- @method injectTestHelpers
92
+ @method injectTestHelpers
92
93
  @public
93
94
  */
94
95
  injectTestHelpers(helperContainer) {
@@ -109,8 +110,11 @@ EmberApplication.reopen({
109
110
  this.testHelpers = {};
110
111
 
111
112
  for (let name in helpers) {
112
- this.originalMethods[name] = this.helperContainer[name];
113
- this.testHelpers[name] = this.helperContainer[name] = helper(this, name);
113
+ // SAFETY: It is safe to access a property on an object
114
+ this.originalMethods[name] = this.helperContainer[name]; // SAFETY: It is not quite as safe to do this, but it _seems_ to be ok.
115
+
116
+ this.testHelpers[name] = this.helperContainer[name] = helper(this, name); // SAFETY: We checked that it exists
117
+
114
118
  protoWrap(TestPromise.prototype, name, helper(this, name), helpers[name].meta.wait);
115
119
  }
116
120
 
@@ -120,11 +124,11 @@ EmberApplication.reopen({
120
124
  /**
121
125
  This removes all helpers that have been registered, and resets and functions
122
126
  that were overridden by the helpers.
123
- Example:
124
- ```javascript
127
+ Example:
128
+ ```javascript
125
129
  App.removeTestHelpers();
126
130
  ```
127
- @public
131
+ @public
128
132
  @method removeTestHelpers
129
133
  */
130
134
  removeTestHelpers() {
@@ -133,7 +137,8 @@ EmberApplication.reopen({
133
137
  }
134
138
 
135
139
  for (let name in helpers) {
136
- this.helperContainer[name] = this.originalMethods[name];
140
+ this.helperContainer[name] = this.originalMethods[name]; // SAFETY: This is a weird thing, but it's not technically unsafe here.
141
+
137
142
  delete TestPromise.prototype[name];
138
143
  delete this.testHelpers[name];
139
144
  delete this.originalMethods[name];
@@ -145,10 +150,12 @@ EmberApplication.reopen({
145
150
  // of helper chaining
146
151
 
147
152
  function protoWrap(proto, name, callback, isAsync) {
153
+ // SAFETY: This isn't entirely safe, but it _seems_ to be ok.
148
154
  proto[name] = function (...args) {
149
155
  if (isAsync) {
150
156
  return callback.apply(this, args);
151
157
  } else {
158
+ // SAFETY: This is not actually safe.
152
159
  return this.then(function () {
153
160
  return callback.apply(this, args);
154
161
  });
@@ -157,8 +164,10 @@ function protoWrap(proto, name, callback, isAsync) {
157
164
  }
158
165
 
159
166
  function helper(app, name) {
160
- let fn = helpers[name].method;
161
- let meta = helpers[name].meta;
167
+ let helper = helpers[name];
168
+ assert(`[BUG] Missing helper: ${name}`, helper);
169
+ let fn = helper.method;
170
+ let meta = helper.meta;
162
171
 
163
172
  if (!meta.wait) {
164
173
  return (...args) => fn.apply(app, [app, ...args]);
@@ -1,3 +1,6 @@
1
+ import { assert } from '@ember/debug';
1
2
  export default function andThen(app, callback) {
2
- return app.testHelpers.wait(callback(app));
3
+ let wait = app.testHelpers['wait'];
4
+ assert('[BUG] Missing wait helper', wait);
5
+ return wait(callback(app));
3
6
  }
@@ -2,6 +2,8 @@
2
2
  @module ember
3
3
  */
4
4
  import { get } from '@ember/-internals/metal';
5
+ import { RoutingService } from '@ember/-internals/routing';
6
+ import { assert } from '@ember/debug';
5
7
  /**
6
8
  Returns the current path.
7
9
 
@@ -22,7 +24,10 @@ click('#some-link-id').then(validateURL);
22
24
  */
23
25
 
24
26
  export default function currentPath(app) {
27
+ assert('[BUG] app.__container__ is not set', app.__container__);
28
+
25
29
  let routingService = app.__container__.lookup('service:-routing');
26
30
 
31
+ assert('[BUG] service:-routing is not a RoutingService', routingService instanceof RoutingService);
27
32
  return get(routingService, 'currentPath');
28
33
  }
@@ -2,6 +2,8 @@
2
2
  @module ember
3
3
  */
4
4
  import { get } from '@ember/-internals/metal';
5
+ import { RoutingService } from '@ember/-internals/routing';
6
+ import { assert } from '@ember/debug';
5
7
  /**
6
8
  Returns the currently active route name.
7
9
 
@@ -21,7 +23,10 @@ visit('/some/path').then(validateRouteName)
21
23
  */
22
24
 
23
25
  export default function currentRouteName(app) {
26
+ assert('[BUG] app.__container__ is not set', app.__container__);
27
+
24
28
  let routingService = app.__container__.lookup('service:-routing');
25
29
 
30
+ assert('[BUG] service:-routing is not a RoutingService', routingService instanceof RoutingService);
26
31
  return get(routingService, 'currentRouteName');
27
32
  }
@@ -2,6 +2,8 @@
2
2
  @module ember
3
3
  */
4
4
  import { get } from '@ember/-internals/metal';
5
+ import { assert } from '@ember/debug';
6
+ import Router from '@ember/routing/router';
5
7
  /**
6
8
  Returns the current URL.
7
9
 
@@ -22,7 +24,12 @@ click('#some-link-id').then(validateURL);
22
24
  */
23
25
 
24
26
  export default function currentURL(app) {
27
+ assert('[BUG] app.__container__ is not set', app.__container__);
28
+
25
29
  let router = app.__container__.lookup('router:main');
26
30
 
27
- return get(router, 'location').getURL();
31
+ assert('[BUG] router:main is not a Router', router instanceof Router);
32
+ let location = get(router, 'location');
33
+ assert('[BUG] location is still a string', typeof location !== 'string');
34
+ return location.getURL();
28
35
  }
@@ -1,3 +1,5 @@
1
+ import { assert } from '@ember/debug';
2
+ import Router from '@ember/routing/router';
1
3
  import { run } from '@ember/runloop';
2
4
  /**
3
5
  Loads a route, sets up any controllers, and renders any templates associated
@@ -19,18 +21,24 @@ import { run } from '@ember/runloop';
19
21
  */
20
22
 
21
23
  export default function visit(app, url) {
22
- let router = app.__container__.lookup('router:main');
24
+ assert('[BUG] Missing container', app.__container__);
23
25
 
26
+ const router = app.__container__.lookup('router:main');
27
+
28
+ assert('[BUG] router:main is not a Router', router instanceof Router);
24
29
  let shouldHandleURL = false;
25
30
  app.boot().then(() => {
31
+ assert('[BUG] router.location is still a string', typeof router.location !== 'string');
26
32
  router.location.setURL(url);
27
33
 
28
34
  if (shouldHandleURL) {
35
+ assert("[BUG] __deprecatedInstance__ isn't set", app.__deprecatedInstance__);
29
36
  run(app.__deprecatedInstance__, 'handleURL', url);
30
37
  }
31
38
  });
32
39
 
33
40
  if (app._readinessDeferrals > 0) {
41
+ // SAFETY: This should be safe, though it is odd.
34
42
  router.initialURL = url;
35
43
  run(app, 'advanceReadiness');
36
44
  delete router.initialURL;
@@ -38,5 +46,7 @@ export default function visit(app, url) {
38
46
  shouldHandleURL = true;
39
47
  }
40
48
 
41
- return app.testHelpers.wait();
49
+ let wait = app.testHelpers['wait'];
50
+ assert('[BUG] missing wait helper', wait);
51
+ return wait();
42
52
  }
@@ -5,6 +5,8 @@ import { checkWaiters } from '../test/waiters';
5
5
  import { RSVP } from '@ember/-internals/runtime';
6
6
  import { _getCurrentRunLoop, _hasScheduledTimers, run } from '@ember/runloop';
7
7
  import { pendingRequests } from '../test/pending_requests';
8
+ import { assert } from '@ember/debug';
9
+ import Router from '@ember/routing/router';
8
10
  /**
9
11
  Causes the run loop to process any pending events. This is used to ensure that
10
12
  any async operations from other helpers (or your assertions) have been processed.
@@ -38,8 +40,11 @@ import { pendingRequests } from '../test/pending_requests';
38
40
 
39
41
  export default function wait(app, value) {
40
42
  return new RSVP.Promise(function (resolve) {
41
- let router = app.__container__.lookup('router:main'); // Every 10ms, poll for the async thing to have finished
43
+ assert('[BUG] Missing container', app.__container__);
42
44
 
45
+ const router = app.__container__.lookup('router:main');
46
+
47
+ assert('[BUG] Expected router:main to be a subclass of Ember Router', router instanceof Router); // Every 10ms, poll for the async thing to have finished
43
48
 
44
49
  let watcher = setInterval(() => {
45
50
  // 1. If the router is loading, keep polling
@@ -1,8 +1,8 @@
1
1
  import { onLoad } from '@ember/application';
2
2
  let name = 'deferReadiness in `testing` mode';
3
- onLoad('Ember.Application', function (Application) {
4
- if (!Application.initializers[name]) {
5
- Application.initializer({
3
+ onLoad('Ember.Application', function (ApplicationClass) {
4
+ if (!ApplicationClass.initializers[name]) {
5
+ ApplicationClass.initializer({
6
6
  name: name,
7
7
 
8
8
  initialize(application) {
@@ -24,6 +24,7 @@ export function asyncEnd() {
24
24
  }
25
25
 
26
26
  function adapterDispatch(error) {
27
- adapter.exception(error);
27
+ adapter.exception(error); // @ts-expect-error Normally unreachable
28
+
28
29
  console.error(error.stack); // eslint-disable-line no-console
29
30
  }
@@ -124,6 +124,8 @@ export function registerAsyncHelper(name, helperMethod) {
124
124
  */
125
125
 
126
126
  export function unregisterHelper(name) {
127
- delete helpers[name];
127
+ delete helpers[name]; // SAFETY: This isn't necessarily a safe thing to do, but in terms of the immediate types here
128
+ // it won't error.
129
+
128
130
  delete TestPromise.prototype[name];
129
131
  }
@@ -31,7 +31,7 @@ export function onInjectHelpers(callback) {
31
31
  callbacks.push(callback);
32
32
  }
33
33
  export function invokeInjectHelpersCallbacks(app) {
34
- for (let i = 0; i < callbacks.length; i++) {
35
- callbacks[i](app);
34
+ for (let callback of callbacks) {
35
+ callback(app);
36
36
  }
37
37
  }
@@ -1,15 +1,15 @@
1
1
  import { RSVP } from '@ember/-internals/runtime';
2
2
  import run from './run';
3
- let lastPromise;
3
+ let lastPromise = null;
4
4
  export default class TestPromise extends RSVP.Promise {
5
- constructor() {
6
- super(...arguments);
5
+ constructor(executor, label) {
6
+ super(executor, label);
7
7
  lastPromise = this;
8
8
  }
9
9
 
10
- then(_onFulfillment, ...args) {
11
- let onFulfillment = typeof _onFulfillment === 'function' ? result => isolate(_onFulfillment, result) : undefined;
12
- return super.then(onFulfillment, ...args);
10
+ then(onFulfilled, onRejected, label) {
11
+ let normalizedOnFulfilled = typeof onFulfilled === 'function' ? result => isolate(onFulfilled, result) : undefined;
12
+ return super.then(normalizedOnFulfilled, onRejected, label);
13
13
  }
14
14
 
15
15
  }
@@ -55,10 +55,10 @@ export function getLastPromise() {
55
55
  // 2. Invoke method
56
56
  // 3. Return the last promise created during method
57
57
 
58
- function isolate(onFulfillment, result) {
58
+ function isolate(onFulfilled, result) {
59
59
  // Reset lastPromise for nested helpers
60
60
  lastPromise = null;
61
- let value = onFulfillment(result);
61
+ let value = onFulfilled(result);
62
62
  let promise = lastPromise;
63
63
  lastPromise = null; // If the method returned a promise
64
64
  // return that promise. If not,
@@ -3,55 +3,24 @@
3
3
  */
4
4
  const contexts = [];
5
5
  const callbacks = [];
6
- /**
7
- This allows ember-testing to play nicely with other asynchronous
8
- events, such as an application that is waiting for a CSS3
9
- transition or an IndexDB transaction. The waiter runs periodically
10
- after each async helper (i.e. `click`, `andThen`, `visit`, etc) has executed,
11
- until the returning result is truthy. After the waiters finish, the next async helper
12
- is executed and the process repeats.
13
-
14
- For example:
15
-
16
- ```javascript
17
- import { registerWaiter } from '@ember/test';
18
-
19
- registerWaiter(function() {
20
- return myPendingTransactions() === 0;
21
- });
22
- ```
23
- The `context` argument allows you to optionally specify the `this`
24
- with which your callback will be invoked.
25
-
26
- For example:
27
-
28
- ```javascript
29
- import { registerWaiter } from '@ember/test';
30
-
31
- registerWaiter(MyDB, MyDB.hasPendingTransactions);
32
- ```
33
-
34
- @public
35
- @for @ember/test
36
- @static
37
- @method registerWaiter
38
- @param {Object} context (optional)
39
- @param {Function} callback
40
- @since 1.2.0
41
- */
42
-
43
- export function registerWaiter(context, callback) {
44
- if (arguments.length === 1) {
45
- callback = context;
46
- context = null;
6
+ export function registerWaiter(...args) {
7
+ let checkedCallback;
8
+ let checkedContext;
9
+
10
+ if (args.length === 1) {
11
+ checkedContext = null;
12
+ checkedCallback = args[0];
13
+ } else {
14
+ checkedContext = args[0];
15
+ checkedCallback = args[1];
47
16
  }
48
17
 
49
- if (indexOf(context, callback) > -1) {
18
+ if (indexOf(checkedContext, checkedCallback) > -1) {
50
19
  return;
51
20
  }
52
21
 
53
- contexts.push(context);
54
- callbacks.push(callback);
22
+ contexts.push(checkedContext);
23
+ callbacks.push(checkedCallback);
55
24
  }
56
25
  /**
57
26
  `unregisterWaiter` is used to unregister a callback that was
@@ -106,7 +75,7 @@ export function checkWaiters() {
106
75
 
107
76
  for (let i = 0; i < callbacks.length; i++) {
108
77
  let context = contexts[i];
109
- let callback = callbacks[i];
78
+ let callback = callbacks[i]; // SAFETY: The loop ensures that this exists
110
79
 
111
80
  if (!callback.call(context)) {
112
81
  return true;
@@ -22,7 +22,7 @@ import { getAdapter, setAdapter } from './test/adapter';
22
22
  const Test = {
23
23
  /**
24
24
  Hash containing all known test helpers.
25
- @property _helpers
25
+ @property _helpers
26
26
  @private
27
27
  @since 1.7.0
28
28
  */