ember-source 4.6.0-alpha.2 → 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.
- package/build-metadata.json +3 -3
- package/dist/ember-template-compiler.js +2 -2
- package/dist/ember-template-compiler.map +1 -1
- package/dist/ember-testing.js +110 -129
- package/dist/ember-testing.map +1 -1
- package/dist/ember.debug.js +465 -525
- package/dist/ember.debug.map +1 -1
- package/dist/header/license.js +1 -1
- package/dist/packages/@ember/-internals/error-handling/index.js +1 -1
- package/dist/packages/@ember/-internals/metal/index.js +16 -6
- package/dist/packages/@ember/-internals/runtime/lib/compare.js +4 -3
- package/dist/packages/@ember/-internals/runtime/lib/mixins/array.js +281 -368
- package/dist/packages/@ember/-internals/runtime/lib/system/array_proxy.js +8 -5
- package/dist/packages/@ember/application/lib/application.js +4 -1
- package/dist/packages/@ember/engine/index.js +3 -1
- package/dist/packages/@ember/object/index.js +16 -8
- package/dist/packages/@ember/object/lib/computed/reduce_computed_macros.js +1 -1
- package/dist/packages/@ember/test/adapter.js +2 -2
- package/dist/packages/ember/version.js +1 -1
- package/dist/packages/ember-testing/lib/adapters/adapter.js +9 -20
- package/dist/packages/ember-testing/lib/adapters/qunit.js +8 -16
- package/dist/packages/ember-testing/lib/ext/application.js +28 -19
- package/dist/packages/ember-testing/lib/helpers/and_then.js +4 -1
- package/dist/packages/ember-testing/lib/helpers/current_path.js +5 -0
- package/dist/packages/ember-testing/lib/helpers/current_route_name.js +5 -0
- package/dist/packages/ember-testing/lib/helpers/current_url.js +8 -1
- package/dist/packages/ember-testing/lib/helpers/visit.js +12 -2
- package/dist/packages/ember-testing/lib/helpers/wait.js +6 -1
- package/dist/packages/ember-testing/lib/initializers.js +3 -3
- package/dist/packages/ember-testing/lib/test/adapter.js +2 -1
- package/dist/packages/ember-testing/lib/test/helpers.js +3 -1
- package/dist/packages/ember-testing/lib/test/on_inject_helpers.js +2 -2
- package/dist/packages/ember-testing/lib/test/promise.js +8 -8
- package/dist/packages/ember-testing/lib/test/waiters.js +14 -45
- package/dist/packages/ember-testing/lib/test.js +1 -1
- package/docs/data.json +268 -258
- package/package.json +3 -3
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { get, objectAt, alias, PROPERTY_DID_CHANGE, addArrayObserver, removeArrayObserver, replace, arrayContentDidChange, arrayContentWillChange, tagForProperty } from '@ember/-internals/metal';
|
|
5
5
|
import { isObject } from '@ember/-internals/utils';
|
|
6
6
|
import EmberObject from './object';
|
|
7
|
-
import {
|
|
7
|
+
import EmberArray, { MutableArray } from '../mixins/array';
|
|
8
8
|
import { assert } from '@ember/debug';
|
|
9
9
|
import { setCustomTagFor } from '@glimmer/manager';
|
|
10
10
|
import { combine, consumeTag, validateTag, valueForTag, tagFor } from '@glimmer/validator';
|
|
@@ -122,7 +122,7 @@ class ArrayProxy extends EmberObject {
|
|
|
122
122
|
@method replaceContent
|
|
123
123
|
@param {Number} idx The starting index
|
|
124
124
|
@param {Number} amt The number of items to remove from the content.
|
|
125
|
-
@param {
|
|
125
|
+
@param {Array} objects Optional array of objects to insert.
|
|
126
126
|
@return {void}
|
|
127
127
|
@public
|
|
128
128
|
*/
|
|
@@ -130,9 +130,9 @@ class ArrayProxy extends EmberObject {
|
|
|
130
130
|
|
|
131
131
|
replaceContent(idx, amt, objects) {
|
|
132
132
|
let content = get(this, 'content');
|
|
133
|
-
assert('[BUG] Called
|
|
133
|
+
assert('[BUG] Called replaceContent without content', content);
|
|
134
134
|
assert('Mutating a non-mutable array is not allowed', isMutable(content));
|
|
135
|
-
|
|
135
|
+
replace(content, idx, amt, objects);
|
|
136
136
|
} // Overriding objectAt is not supported.
|
|
137
137
|
|
|
138
138
|
|
|
@@ -221,7 +221,10 @@ class ArrayProxy extends EmberObject {
|
|
|
221
221
|
if (arrangedContent && !arrangedContent.isDestroyed) {
|
|
222
222
|
// @ts-expect-error This check is still good for ensuring correctness
|
|
223
223
|
assert("Can't set ArrayProxy's content to itself", arrangedContent !== this);
|
|
224
|
-
assert(`ArrayProxy expects
|
|
224
|
+
assert(`ArrayProxy expects a native Array, EmberArray, or ArrayProxy, but you passed ${typeof arrangedContent}`, function (arr) {
|
|
225
|
+
return Array.isArray(arr) || EmberArray.detect(arr);
|
|
226
|
+
}(arrangedContent));
|
|
227
|
+
assert('ArrayProxy expected its contents to not be destroyed', !arrangedContent.isDestroyed);
|
|
225
228
|
addArrayObserver(arrangedContent, this, ARRAY_OBSERVER_MAPPING);
|
|
226
229
|
this._arrangedContent = arrangedContent;
|
|
227
230
|
}
|
|
@@ -13,7 +13,7 @@ import { RSVP } from '@ember/-internals/runtime';
|
|
|
13
13
|
import { EventDispatcher } from '@ember/-internals/views';
|
|
14
14
|
import { Route, Router, HashLocation, HistoryLocation, AutoLocation, NoneLocation, BucketCache } from '@ember/-internals/routing';
|
|
15
15
|
import ApplicationInstance from '../instance';
|
|
16
|
-
import Engine from '@ember/engine';
|
|
16
|
+
import Engine, { buildInitializerMethod } from '@ember/engine';
|
|
17
17
|
import { privatize as P } from '@ember/-internals/container';
|
|
18
18
|
import { setupApplicationRegistry } from '@ember/-internals/glimmer';
|
|
19
19
|
import { RouterService } from '@ember/-internals/routing';
|
|
@@ -841,6 +841,9 @@ class Application extends Engine {
|
|
|
841
841
|
|
|
842
842
|
}
|
|
843
843
|
|
|
844
|
+
Application.initializer = buildInitializerMethod('initializers', 'initializer');
|
|
845
|
+
Application.instanceInitializer = buildInitializerMethod('instanceInitializers', 'instance initializer');
|
|
846
|
+
|
|
844
847
|
function commonSetupRegistry(registry) {
|
|
845
848
|
registry.register('router:main', Router);
|
|
846
849
|
registry.register('-view-registry:main', {
|
|
@@ -420,8 +420,10 @@ function resolverFor(namespace) {
|
|
|
420
420
|
};
|
|
421
421
|
return ResolverClass.create(props);
|
|
422
422
|
}
|
|
423
|
+
/** @internal */
|
|
423
424
|
|
|
424
|
-
|
|
425
|
+
|
|
426
|
+
export function buildInitializerMethod(bucketName, humanName) {
|
|
425
427
|
return function (initializer) {
|
|
426
428
|
// If this is the first initializer being added to a subclass, we are going to reopen the class
|
|
427
429
|
// to make sure we have a new `initializers` object, which extends from the parent class' using
|
|
@@ -117,8 +117,12 @@ export { notifyPropertyChange, defineProperty, get, set, getProperties, setPrope
|
|
|
117
117
|
|
|
118
118
|
const BINDINGS_MAP = new WeakMap();
|
|
119
119
|
|
|
120
|
+
function hasProto(obj) {
|
|
121
|
+
return obj != null && obj.constructor !== undefined && typeof obj.constructor.proto === 'function';
|
|
122
|
+
}
|
|
123
|
+
|
|
120
124
|
function setupAction(target, key, actionFn) {
|
|
121
|
-
if (target
|
|
125
|
+
if (hasProto(target)) {
|
|
122
126
|
target.constructor.proto();
|
|
123
127
|
}
|
|
124
128
|
|
|
@@ -128,6 +132,7 @@ function setupAction(target, key, actionFn) {
|
|
|
128
132
|
target.actions = parentActions ? Object.assign({}, parentActions) : {};
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
assert("[BUG] Somehow the target doesn't have actions!", target.actions != null);
|
|
131
136
|
target.actions[key] = actionFn;
|
|
132
137
|
return {
|
|
133
138
|
get() {
|
|
@@ -151,13 +156,13 @@ function setupAction(target, key, actionFn) {
|
|
|
151
156
|
};
|
|
152
157
|
}
|
|
153
158
|
|
|
154
|
-
export function action(
|
|
159
|
+
export function action(...args) {
|
|
155
160
|
let actionFn;
|
|
156
161
|
|
|
157
|
-
if (!isElementDescriptor(
|
|
158
|
-
actionFn =
|
|
162
|
+
if (!isElementDescriptor(args)) {
|
|
163
|
+
actionFn = args[0];
|
|
159
164
|
|
|
160
|
-
let decorator = function (target, key,
|
|
165
|
+
let decorator = function (target, key, _desc, _meta, isClassicDecorator) {
|
|
161
166
|
assert('The @action decorator may only be passed a method when used in classic classes. You should decorate methods directly in native classes', isClassicDecorator);
|
|
162
167
|
assert('The action() decorator must be passed a method when used in classic classes', typeof actionFn === 'function');
|
|
163
168
|
return setupAction(target, key, actionFn);
|
|
@@ -167,8 +172,11 @@ export function action(target, key, desc) {
|
|
|
167
172
|
return decorator;
|
|
168
173
|
}
|
|
169
174
|
|
|
170
|
-
|
|
171
|
-
|
|
175
|
+
let [target, key, desc] = args;
|
|
176
|
+
actionFn = desc === null || desc === void 0 ? void 0 : desc.value;
|
|
177
|
+
assert('The @action decorator must be applied to methods when used in native classes', typeof actionFn === 'function'); // SAFETY: TS types are weird with decorators. This should work.
|
|
178
|
+
|
|
172
179
|
return setupAction(target, key, actionFn);
|
|
173
|
-
}
|
|
180
|
+
} // SAFETY: TS types are weird with decorators. This should work.
|
|
181
|
+
|
|
174
182
|
setClassicDecorator(action);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export default
|
|
1
|
+
import { Adapter } from 'ember-testing';
|
|
2
|
+
export default Adapter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export default "4.6.0-alpha.
|
|
1
|
+
export default "4.6.0-alpha.3";
|
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import { Object as EmberObject } from '@ember/-internals/runtime';
|
|
2
|
-
|
|
3
|
-
@module @ember/test
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
The primary purpose of this class is to create hooks that can be implemented
|
|
8
|
-
by an adapter for various test frameworks.
|
|
9
|
-
|
|
10
|
-
@class TestAdapter
|
|
11
|
-
@public
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default EmberObject.extend({
|
|
2
|
+
const Adapter = EmberObject.extend({
|
|
15
3
|
/**
|
|
16
4
|
This callback will be called whenever an async operation is about to start.
|
|
17
|
-
|
|
5
|
+
Override this to call your framework's methods that handle async
|
|
18
6
|
operations.
|
|
19
|
-
|
|
7
|
+
@public
|
|
20
8
|
@method asyncStart
|
|
21
9
|
*/
|
|
22
10
|
asyncStart() {},
|
|
23
11
|
|
|
24
12
|
/**
|
|
25
13
|
This callback will be called whenever an async operation has completed.
|
|
26
|
-
|
|
14
|
+
@public
|
|
27
15
|
@method asyncEnd
|
|
28
16
|
*/
|
|
29
17
|
asyncEnd() {},
|
|
@@ -32,13 +20,13 @@ export default EmberObject.extend({
|
|
|
32
20
|
Override this method with your testing framework's false assertion.
|
|
33
21
|
This function is called whenever an exception occurs causing the testing
|
|
34
22
|
promise to fail.
|
|
35
|
-
|
|
36
|
-
|
|
23
|
+
QUnit example:
|
|
24
|
+
```javascript
|
|
37
25
|
exception: function(error) {
|
|
38
26
|
ok(false, error);
|
|
39
27
|
};
|
|
40
28
|
```
|
|
41
|
-
|
|
29
|
+
@public
|
|
42
30
|
@method exception
|
|
43
31
|
@param {String} error The exception to be raised.
|
|
44
32
|
*/
|
|
@@ -46,4 +34,5 @@ export default EmberObject.extend({
|
|
|
46
34
|
throw error;
|
|
47
35
|
}
|
|
48
36
|
|
|
49
|
-
});
|
|
37
|
+
});
|
|
38
|
+
export default Adapter;
|
|
@@ -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
|
-
|
|
10
|
-
|
|
5
|
+
function isVeryOldQunit(obj) {
|
|
6
|
+
return obj != null && typeof obj.stop === 'function';
|
|
7
|
+
}
|
|
11
8
|
|
|
12
|
-
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
When `removeTestHelpers` is called, these methods are restored to the
|
|
25
26
|
`helperContainer`.
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
54
|
+
Example:
|
|
55
|
+
```
|
|
55
56
|
App.setupForTesting();
|
|
56
57
|
```
|
|
57
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
+
Any callbacks registered with `onInjectHelpers` will be called once the
|
|
86
87
|
helpers have been injected.
|
|
87
|
-
|
|
88
|
+
Example:
|
|
88
89
|
```
|
|
89
90
|
App.injectTestHelpers();
|
|
90
91
|
```
|
|
91
|
-
|
|
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
|
-
|
|
113
|
-
this.
|
|
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
|
-
|
|
124
|
-
|
|
127
|
+
Example:
|
|
128
|
+
```javascript
|
|
125
129
|
App.removeTestHelpers();
|
|
126
130
|
```
|
|
127
|
-
|
|
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
|
|
161
|
-
|
|
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]);
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
4
|
-
if (!
|
|
5
|
-
|
|
3
|
+
onLoad('Ember.Application', function (ApplicationClass) {
|
|
4
|
+
if (!ApplicationClass.initializers[name]) {
|
|
5
|
+
ApplicationClass.initializer({
|
|
6
6
|
name: name,
|
|
7
7
|
|
|
8
8
|
initialize(application) {
|
|
@@ -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
|
|
35
|
-
|
|
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(
|
|
5
|
+
constructor(executor, label) {
|
|
6
|
+
super(executor, label);
|
|
7
7
|
lastPromise = this;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
then(
|
|
11
|
-
let
|
|
12
|
-
return super.then(
|
|
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(
|
|
58
|
+
function isolate(onFulfilled, result) {
|
|
59
59
|
// Reset lastPromise for nested helpers
|
|
60
60
|
lastPromise = null;
|
|
61
|
-
let value =
|
|
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,
|