Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests when deprecations are enabled #20695

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
ApplicationTestCase,
ModuleBasedTestResolver,
expectDeprecation,
moduleFor,
strip,
testUnless,
} from 'internal-test-helpers';

import { ENV } from '@ember/-internals/environment';
Expand All @@ -24,7 +22,6 @@ import type { SimpleElement, SimpleNode } from '@simple-dom/interface';
import type { EmberPrecompileOptions } from 'ember-template-compiler';
import { compile } from 'ember-template-compiler';
import { runTask } from 'internal-test-helpers/lib/run';
import { DEPRECATIONS } from '@ember/-internals/deprecations';
import templateOnly from '@ember/component/template-only';

interface CapturedBounds {
Expand Down Expand Up @@ -788,13 +785,7 @@ if (ENV._DEBUG_RENDER_TREE) {
]);
}

async [`${testUnless(
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isRemoved
)} template-only components`]() {
expectDeprecation(
/resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);
async [`@test template-only components`]() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, no? What made you put that there in the first place?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a couple things:

  • I originally was not updating these tests to use setComponenttemplate
  • I changed (per Ed's suggestion) the timing of when the deprecation is thrown to only occur if there is a found resolved template, rather than anytime layoutFor is called (this ended up simplifying the implementation in resolver.ts)

this.addTemplate(
'application',
strip`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { moduleFor, RenderingTestCase, strip, runTask, testUnless } from 'internal-test-helpers';
import {
moduleFor,
RenderingTestCase,
strip,
runTask,
testUnless,
expectDeprecation,
} from 'internal-test-helpers';

import { set } from '@ember/object';

Expand Down Expand Up @@ -284,6 +291,11 @@ class AbstractAppendTest extends RenderingTestCase {
)} lifecycle hooks during component append`](assert) {
let hooks = [];

expectDeprecation(
/resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);

let oldRegisterComponent = this.registerComponent;
let componentsByName = {};

Expand Down Expand Up @@ -532,6 +544,11 @@ class AbstractAppendTest extends RenderingTestCase {
)} appending, updating and destroying a single component`](assert) {
let willDestroyCalled = 0;

expectDeprecation(
/separately resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);

this.registerComponent('x-parent', {
ComponentClass: Component.extend({
layoutName: 'components/x-parent',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { DEBUG } from '@glimmer/env';
import {
expectDeprecation,
moduleFor,
RenderingTestCase,
runTask,
testUnless,
} from 'internal-test-helpers';
import { moduleFor, RenderingTestCase, runTask, testUnless } from 'internal-test-helpers';

import { setComponentTemplate, getComponentTemplate } from '@glimmer/manager';
import { Component, compile } from '../../utils/helpers';
Expand All @@ -31,8 +25,6 @@ moduleFor(
[`${testUnless(
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isRemoved
)} it takes precedence over resolver`]() {
kategengler marked this conversation as resolved.
Show resolved Hide resolved
expectDeprecation('', DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled);

this.registerComponent('foo-bar', {
ComponentClass: setComponentTemplate(compile('hello'), Component.extend()),
resolveableTemplate: 'noooooo!',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
defineSimpleHelper,
defineSimpleModifier,
testUnless,
expectDeprecation,
} from 'internal-test-helpers';

import { Input, Textarea } from '@ember/component';
Expand Down Expand Up @@ -268,6 +269,11 @@ moduleFor(
[`${testUnless(DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isRemoved)} Can use action helper`](
assert
) {
expectDeprecation(
/Migrate to native functions/,
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isEnabled
);

let called = 0;

let Foo = defineComponent(
Expand All @@ -294,6 +300,11 @@ moduleFor(
[`${testUnless(DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isRemoved)} Can use action modifier`](
assert
) {
expectDeprecation(
/Migrate to native functions/,
DEPRECATIONS.DEPRECATE_TEMPLATE_ACTION.isEnabled
);

let called = 0;

let Foo = defineComponent(
Expand Down
19 changes: 12 additions & 7 deletions packages/@ember/-internals/glimmer/tests/integration/mount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Engine, { getEngineParent } from '@ember/engine';

import { backtrackingMessageFor } from '../utils/debug-stack';
import { compile, Component } from '../utils/helpers';
import { setComponentTemplate } from '@glimmer/manager';

moduleFor(
'{{mount}} single param assertion',
Expand Down Expand Up @@ -142,19 +143,23 @@ moduleFor(
},
});

this.engineRegistrations['template:components/component-with-backtracking-set'] = compile(
'[component {{this.person.name}}]',
{
moduleName: 'my-app/templates/components/component-with-backtracking-set.hbs',
}
);
this.engineRegistrations['component:component-with-backtracking-set'] = Component.extend({
let ComponentWithBacktrackingSet = Component.extend({
init() {
this._super(...arguments);
this.set('person.name', 'Ben');
},
});

setComponentTemplate(
compile('[component {{this.person.name}}]', {
moduleName: 'my-app/templates/components/component-with-backtracking-set.hbs',
}),
ComponentWithBacktrackingSet
);

this.engineRegistrations['component:component-with-backtracking-set'] =
ComponentWithBacktrackingSet;

let expectedBacktrackingMessage = backtrackingMessageFor('name', 'Person \\(Ben\\)', {
renderTree: ['application', 'route-with-mount', 'chat', 'this.person.name'],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ moduleFor(
[`${testUnless(
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isRemoved
)} each template is only compiled once`]() {
expectDeprecation(/msg here/, DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled);
expectDeprecation(
/resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);
// static layout
this.registerComponent('component-one', { resolveableTemplate: 'One' });

Expand Down
17 changes: 16 additions & 1 deletion packages/ember/tests/component_registration_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import Application from '@ember/application';
import Controller from '@ember/controller';
import { Component } from '@ember/-internals/glimmer';
import { compile } from 'ember-template-compiler';
import { moduleFor, testUnless, ApplicationTestCase, defineComponent } from 'internal-test-helpers';
import {
moduleFor,
testUnless,
ApplicationTestCase,
defineComponent,
expectDeprecation,
} from 'internal-test-helpers';
import { DEBUG } from '@glimmer/env';
import { DEPRECATIONS } from '@ember/-internals/deprecations';
import templateOnly from '@ember/component/template-only';
Expand Down Expand Up @@ -83,6 +89,10 @@ moduleFor(
)} Late-registered components can be rendered with template registered on the container`](
assert
) {
expectDeprecation(
/resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);
this.addTemplate(
'application',
`<div id='wrapper'>hello world {{sally-rutherford}}-{{#sally-rutherford}}!!!{{/sally-rutherford}}</div>`
Expand Down Expand Up @@ -119,6 +129,11 @@ moduleFor(
)} Late-registered components can be rendered with ONLY the template registered on the container`](
assert
) {
expectDeprecation(
/resolved templates/,
DEPRECATIONS.DEPRECATE_COMPONENT_TEMPLATE_RESOLVING.isEnabled
);

this.addTemplate(
'application',
`<div id='wrapper'>hello world {{borf-snorlax}}-{{#borf-snorlax}}!!!{{/borf-snorlax}}</div>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,22 @@ moduleFor(

this.addTemplate('parent.index', '{{foo-bar}}');

this.addComponent('foo-bar', {
ComponentClass: Component.extend({
routerService: service('router'),
init() {
this._super(...arguments);
componentInstance = this;
},
actions: {
transitionToSister() {
get(this, 'routerService').transitionTo('parent.sister');
},
let FooBar = Component.extend({
routerService: service('router'),
layout: this.compile('foo-bar'),
init() {
this._super(...arguments);
componentInstance = this;
},
actions: {
transitionToSister() {
get(this, 'routerService').transitionTo('parent.sister');
},
}),
template: `foo-bar`,
},
});

this.addComponent('foo-bar', {
ComponentClass: FooBar,
});

this.render('{{foo-bar}}');
Expand Down
5 changes: 5 additions & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
label: 'Deprecation Version',
});

QUnit.config.urlConfig.push({
id: 'ALL_DEPRECATIONS_ENABLED',
label: 'Enable All Deprecations',
});


if (QUnit.config.seed) {
QUnit.config.reorder = false;
Expand Down