diff --git a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js index 2aed389bace..2fd141bebd5 100644 --- a/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js +++ b/packages/@ember/-internals/glimmer/tests/integration/helpers/tracked-test.js @@ -1,9 +1,16 @@ import EmberObject from '@ember/object'; import { A } from '@ember/array'; +import MutableArray from '@ember/array/mutable'; import { tracked, notifyPropertyChange } from '@ember/-internals/metal'; -import { InternalMutableArray as MutableArray } from '@ember/array/index-internal'; import Service, { service } from '@ember/service'; -import { moduleFor, RenderingTestCase, runTask } from 'internal-test-helpers'; +import { + expectDeprecation, + moduleFor, + RenderingTestCase, + runTask, + testUnless, +} from 'internal-test-helpers'; +import { DEPRECATIONS } from '@ember/-internals/deprecations'; import { precompileTemplate } from '@ember/template-compilation'; import { setComponentTemplate } from '@glimmer/manager'; @@ -172,7 +179,14 @@ moduleFor( this.assertText('1, 2, 3, 4'); } - '@test custom ember array properties rerender when updated'() { + [`${testUnless( + DEPRECATIONS.DEPRECATE_MUTABLE_ARRAY_MIXIN.isRemoved + )} @test custom ember array properties rerender when updated`]() { + expectDeprecation( + /The `MutableArray` mixin is deprecated/, + DEPRECATIONS.DEPRECATE_MUTABLE_ARRAY_MIXIN.isEnabled + ); + let CustomArray = class extends EmberObject.extend(MutableArray) { init() { super.init(...arguments); diff --git a/packages/@ember/-internals/runtime/tests/mixins/array_test.js b/packages/@ember/-internals/runtime/tests/mixins/array_test.js index 3ec1baed666..8e47fdd49a5 100644 --- a/packages/@ember/-internals/runtime/tests/mixins/array_test.js +++ b/packages/@ember/-internals/runtime/tests/mixins/array_test.js @@ -7,9 +7,21 @@ import { arrayContentWillChange, } from '@ember/-internals/metal'; import EmberObject, { get, set, computed, observer as emberObserver } from '@ember/object'; -import { A as emberA } from '@ember/array'; -import { InternalEmberArray as EmberArray } from '@ember/array/index-internal'; -import { moduleFor, AbstractTestCase, runLoopSettled } from 'internal-test-helpers'; +import EmberArray, { A as emberA } from '@ember/array'; +import { + expectDeprecation, + moduleFor, + AbstractTestCase, + runLoopSettled, + testUnless, +} from 'internal-test-helpers'; +import { DEPRECATIONS } from '../../../deprecations'; + +const MIXIN = DEPRECATIONS.DEPRECATE_EMBER_ARRAY_MIXIN; + +function expectMixinDeprecation() { + expectDeprecation(/The `EmberArray` mixin is deprecated/, MIXIN.isEnabled); +} /* Implement a basic fake mutable array. This validates that any non-native @@ -19,6 +31,7 @@ const TestArray = class extends EmberObject.extend(EmberArray) { _content = null; init() { + super.init(...arguments); this._content = this._content || []; } @@ -50,7 +63,11 @@ const TestArray = class extends EmberObject.extend(EmberArray) { moduleFor( 'Ember.Array', class extends AbstractTestCase { - ['@test the return value of slice has Ember.Array applied'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test the return value of slice has Ember.Array applied`]( + assert + ) { + expectMixinDeprecation(); + let x = EmberObject.extend(EmberArray).create({ length: 0, }); @@ -58,7 +75,9 @@ moduleFor( assert.equal(EmberArray.detect(y), true, 'mixin should be applied'); } - ['@test slice supports negative index arguments'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test slice supports negative index arguments`](assert) { + expectMixinDeprecation(); + let testArray = TestArray.create({ _content: [1, 2, 3, 4] }); assert.deepEqual(testArray.slice(-2), [3, 4], 'slice(-2)'); @@ -97,7 +116,9 @@ let obj, observer; moduleFor( 'mixins/array/arrayContent[Will|Did]Change', class extends AbstractTestCase { - async ['@test should notify observers of []'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test should notify observers of []`](assert) { + expectMixinDeprecation(); + obj = DummyArray.extend({ enumerablePropertyDidChange: emberObserver('[]', function () { this._count++; @@ -130,6 +151,8 @@ moduleFor( 'notify observers of length', class extends AbstractTestCase { beforeEach(assert) { + expectMixinDeprecation(); + obj = DummyArray.extend({ lengthDidChange: emberObserver('length', function () { this._after++; @@ -146,7 +169,9 @@ moduleFor( obj = undefined; } - async ['@test should notify observers when call with no params'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test should notify observers when call with no params`]( + assert + ) { arrayContentWillChange(obj); await runLoopSettled(); @@ -159,7 +184,9 @@ moduleFor( } // API variation that included items only - async ['@test should not notify when passed lengths are same'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test should not notify when passed lengths are same`]( + assert + ) { arrayContentWillChange(obj, 0, 1, 1); await runLoopSettled(); @@ -171,7 +198,9 @@ moduleFor( assert.equal(obj._after, 0); } - async ['@test should notify when passed lengths are different'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test should notify when passed lengths are different`]( + assert + ) { arrayContentWillChange(obj, 0, 1, 2); await runLoopSettled(); @@ -193,6 +222,8 @@ moduleFor( 'notify array observers (internal)', class extends AbstractTestCase { beforeEach(assert) { + expectMixinDeprecation(); + obj = DummyArray.create(); observer = class extends EmberObject { @@ -220,7 +251,9 @@ moduleFor( obj = observer = null; } - ['@test should notify array observers when called with no params'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test should notify array observers when called with no params`]( + assert + ) { arrayContentWillChange(obj); assert.deepEqual(observer._before, [obj, 0, -1, -1]); @@ -229,7 +262,9 @@ moduleFor( } // API variation that included items only - ['@test should notify when called with same length items'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test should notify when called with same length items`]( + assert + ) { arrayContentWillChange(obj, 0, 1, 1); assert.deepEqual(observer._before, [obj, 0, 1, 1]); @@ -237,7 +272,9 @@ moduleFor( assert.deepEqual(observer._after, [obj, 0, 1, 1]); } - ['@test should notify when called with diff length items'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test should notify when called with diff length items`]( + assert + ) { arrayContentWillChange(obj, 0, 2, 1); assert.deepEqual(observer._before, [obj, 0, 2, 1]); @@ -245,7 +282,7 @@ moduleFor( assert.deepEqual(observer._after, [obj, 0, 2, 1]); } - ['@test removing array observer should disable'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test removing array observer should disable`](assert) { removeArrayObserver(obj, observer, { willChange: 'arrayWillChange', didChange: 'arrayDidChange', @@ -269,6 +306,8 @@ moduleFor( 'EmberArray.@each support', class extends AbstractTestCase { beforeEach() { + expectMixinDeprecation(); + ary = TestArray.create({ _content: [ { isDone: true, desc: 'Todo 1' }, @@ -284,7 +323,9 @@ moduleFor( ary = null; } - async ['@test adding an object should notify (@each.isDone)'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test adding an object should notify (@each.isDone)`]( + assert + ) { let called = 0; let observerObject = EmberObject.create({ @@ -306,7 +347,9 @@ moduleFor( assert.equal(called, 1, 'calls observer when object is pushed'); } - async ['@test using @each to observe arrays that does not return objects raise error'](assert) { + async [`${testUnless(MIXIN.isRemoved)} @test using @each to observe arrays that does not return objects raise error`]( + assert + ) { let called = 0; let observerObject = EmberObject.create({ @@ -333,7 +376,12 @@ moduleFor( await runLoopSettled(); assert.equal(called, 0, 'not calls observer when object is pushed'); } + } +); +moduleFor( + '@each support', + class extends AbstractTestCase { ['@test `objectAt` returns correct object'](assert) { let arr = ['first', 'second', 'third', 'fourth']; assert.equal(objectAt(arr, 2), 'third'); diff --git a/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js b/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js index 445e4eceedc..a8f3b97eec9 100644 --- a/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js +++ b/packages/@ember/-internals/runtime/tests/mixins/container_proxy_test.js @@ -1,15 +1,20 @@ import { getOwner } from '@ember/-internals/owner'; import { Container, Registry } from '@ember/-internals/container'; -import ContainerProxy from '../../lib/mixins/container_proxy-internal'; +import ContainerProxy from '../../lib/mixins/container_proxy'; import EmberObject from '@ember/object'; import { run, schedule } from '@ember/runloop'; -import { moduleFor, AbstractTestCase } from 'internal-test-helpers'; +import { expectDeprecation, moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers'; +import { DEPRECATIONS } from '../../../deprecations'; import { destroy } from '@glimmer/destroyable'; +const MIXIN = DEPRECATIONS.DEPRECATE_CONTAINER_PROXY_MIXIN; + moduleFor( '@ember/-internals/runtime/mixins/container_proxy', class extends AbstractTestCase { beforeEach() { + expectDeprecation(/The `ContainerProxyMixin` mixin is deprecated/, MIXIN.isEnabled); + this.Owner = EmberObject.extend(ContainerProxy); this.instance = this.Owner.create(); @@ -20,14 +25,14 @@ moduleFor( }); } - ['@test provides ownerInjection helper method'](assert) { + [`${testUnless(MIXIN.isRemoved)} @test provides ownerInjection helper method`](assert) { let result = this.instance.ownerInjection(); assert.equal(getOwner(result), this.instance, 'returns an object with an associated owner'); } - ['@test actions queue completes before destruction'](assert) { - assert.expect(1); + [`${testUnless(MIXIN.isRemoved)} @test actions queue completes before destruction`](assert) { + assert.expect(2); this.registry.register( 'service:auth', @@ -46,10 +51,12 @@ moduleFor( }); } - '@test being destroyed by @ember/destroyable properly destroys the container and created instances'( + [`${testUnless( + MIXIN.isRemoved + )} @test being destroyed by @ember/destroyable properly destroys the container and created instances`]( assert ) { - assert.expect(1); + assert.expect(2); this.registry.register( 'service:foo', diff --git a/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js b/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js index e2b205a93db..d1ea1cf96a0 100644 --- a/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js +++ b/packages/@ember/-internals/runtime/tests/mixins/target_action_support_test.js @@ -1,9 +1,13 @@ import { context } from '@ember/-internals/environment'; import EmberObject from '@ember/object'; -import TargetActionSupport from '../../lib/mixins/target_action_support-internal'; +import TargetActionSupport from '../../lib/mixins/target_action_support'; import { expectDeprecation, moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers'; import { DEPRECATIONS } from '../../../deprecations'; +// A production build runs one assertion for all deprecation expectations. +// One pattern keeps the assertion count equal in both builds. +const DEPRECATION = /The `TargetActionSupport` mixin is deprecated|Calling `triggerAction` on/; + let originalLookup = context.lookup; let lookup; @@ -23,10 +27,7 @@ moduleFor( )} @test it should return false if no target or action are specified`](assert) { assert.expect(2); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create(); @@ -38,10 +39,7 @@ moduleFor( )} @test it should support actions specified as strings`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ @@ -61,10 +59,7 @@ moduleFor( )} @test it should invoke the send() method on objects that implement it`](assert) { assert.expect(4); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ @@ -85,10 +80,7 @@ moduleFor( )} @test it should find targets specified using a property path`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let Test = {}; lookup.Test = Test; @@ -112,10 +104,7 @@ moduleFor( )} @test it should use an actionContext object specified as a property on the object`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create({ action: 'anEvent', @@ -138,10 +127,7 @@ moduleFor( )} @test it should find an actionContext specified as a property path`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let Test = {}; lookup.Test = Test; @@ -165,10 +151,7 @@ moduleFor( )} @test it should use the target specified in the argument`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let targetObj = EmberObject.create({ anEvent() { @@ -190,10 +173,7 @@ moduleFor( )} @test it should use the action specified in the argument`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ @@ -214,10 +194,7 @@ moduleFor( )} @test it should use the actionContext specified in the argument`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let context = {}; let obj = EmberObject.extend(TargetActionSupport).create({ @@ -240,10 +217,7 @@ moduleFor( )} @test it should allow multiple arguments from actionContext`](assert) { assert.expect(4); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let param1 = 'someParam'; let param2 = 'someOtherParam'; @@ -274,10 +248,7 @@ moduleFor( )} @test it should use a null value specified in the actionContext argument`](assert) { assert.expect(3); - expectDeprecation( - /Calling `triggerAction` on/, - DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled - ); + expectDeprecation(DEPRECATION, DEPRECATIONS.DEPRECATE_TARGET_ACTION_SUPPORT.isEnabled); let obj = EmberObject.extend(TargetActionSupport).create({ target: EmberObject.create({ diff --git a/packages/ember/tests/service_injection_test.js b/packages/ember/tests/service_injection_test.js index abcd39580fd..f30de7e8507 100644 --- a/packages/ember/tests/service_injection_test.js +++ b/packages/ember/tests/service_injection_test.js @@ -1,8 +1,14 @@ import { getOwner } from '@ember/-internals/owner'; import Controller from '@ember/controller'; import Service, { service } from '@ember/service'; -import _ProxyMixin from '@ember/-internals/runtime/lib/mixins/-proxy-internal'; -import { moduleFor, ApplicationTestCase } from 'internal-test-helpers'; +import { _ProxyMixin } from '@ember/-internals/runtime'; +import { + expectDeprecation, + moduleFor, + ApplicationTestCase, + testUnless, +} from 'internal-test-helpers'; +import { DEPRECATIONS } from '@ember/-internals/deprecations'; import { computed } from '@ember/object'; import { precompileTemplate } from '@ember/template-compilation'; @@ -27,7 +33,14 @@ moduleFor( assert.ok(controller.get('myService') instanceof MyService); } - async ['@test Service can be an object proxy and access owner in init GH#16484'](assert) { + async [`${testUnless( + DEPRECATIONS.DEPRECATE_PROXY_MIXIN.isRemoved + )} @test Service can be an object proxy and access owner in init GH#16484`](assert) { + expectDeprecation( + /The `ProxyMixin` mixin is deprecated/, + DEPRECATIONS.DEPRECATE_PROXY_MIXIN.isEnabled + ); + let serviceOwner; this.add(