Skip to content

Commit

Permalink
[CHORE] test fixes for deprecations, enables asserting all deprecatio…
Browse files Browse the repository at this point in the history
…ns (#6628)

* [CHORE] test fixes for deprecations, enables asserting all deprecations

* fix lint

* dont run in prod

* make prod happy

* fix lint

* fix deprecations in ff code
  • Loading branch information
runspired authored Nov 6, 2019
1 parent 1a8f716 commit a8d70a3
Show file tree
Hide file tree
Showing 21 changed files with 830 additions and 684 deletions.
13 changes: 3 additions & 10 deletions packages/-ember-data/tests/helpers/deprecated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { test } from 'qunit';
import VERSION from 'ember-data/version';
import { DEBUG } from '@glimmer/env';

// temporary so that we can split out test fixes
// from landing this. If working locally turn this
// on to have tests fail that require being fixed.
export const SHOULD_ASSERT_ALL = false;

// small comparison function for major and minor semver values
function gte(EDVersion, DeprecationVersion) {
let _edv = EDVersion.split('.');
Expand All @@ -31,12 +26,10 @@ export function deprecatedTest(testName, deprecation, testCallback) {
async function interceptor(assert) {
await testCallback.call(this, assert);
if (DEBUG) {
if (SHOULD_ASSERT_ALL) {
if (typeof assert.test.expected === 'number') {
assert.test.expected += 1;
}
assert.expectDeprecation(deprecation);
if (typeof assert.test.expected === 'number') {
assert.test.expected += 1;
}
assert.expectDeprecation(deprecation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,18 @@ export function configureAssertionHandler() {
label?: string
): Promise<void> {
let outcome;
if (DEBUG) {
try {
let result = cb();
if (isThenable(result)) {
await result;
}
outcome = verifyAssertion('', matcher, label);
} catch (e) {
outcome = verifyAssertion(e.message, matcher, label);

try {
let result = cb();
if (isThenable(result)) {
await result;
}
} else {
outcome = verifyAssertion('', matcher, label);
} catch (e) {
outcome = verifyAssertion(e.message, matcher, label);
}

if (!DEBUG) {
outcome = {
result: true,
actual: '',
Expand All @@ -85,6 +86,15 @@ export function configureAssertionHandler() {
outcome = verifyNoAssertion(e.message, label);
}

if (!DEBUG) {
outcome = {
result: true,
actual: '',
expected: '',
message: `Assertions do not run in production environments`,
};
}

this.pushResult(outcome);
};
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QUnit from 'qunit';
import { registerDeprecationHandler } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { checkMatcher } from './check-matcher';
import isThenable from './utils/is-thenable';

Expand Down Expand Up @@ -157,6 +158,16 @@ export function configureDeprecationHandler() {
}

let result = verifyDeprecation(config, label);

if (!DEBUG) {
result = {
result: true,
actual: { id: config.id, count: 0 },
expected: { id: config.id, count: 0 },
message: `Deprecations do not trigger in production environments`,
};
}

this.pushResult(result);
if (callback) {
DEPRECATIONS_FOR_TEST = origDeprecations.concat(DEPRECATIONS_FOR_TEST);
Expand All @@ -178,6 +189,16 @@ export function configureDeprecationHandler() {
}

let result = verifyNoDeprecation(filter, label);

if (!DEBUG) {
result = {
result: true,
actual: [],
expected: [],
message: `Deprecations do not trigger in production environments`,
};
}

this.pushResult(result);
DEPRECATIONS_FOR_TEST = origDeprecations.concat(DEPRECATIONS_FOR_TEST);
};
Expand Down
21 changes: 21 additions & 0 deletions packages/-ember-data/tests/helpers/qunit-asserts/assert-warning.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import QUnit from 'qunit';
import { registerWarnHandler } from '@ember/debug';
import { DEBUG } from '@glimmer/env';
import { checkMatcher } from './check-matcher';
import isThenable from './utils/is-thenable';

Expand Down Expand Up @@ -148,6 +149,16 @@ export function configureWarningHandler() {
}

let result = verifyWarning(config, label);

if (!DEBUG) {
result = {
result: true,
actual: { id: config.id, count: 0 },
expected: { id: config.id, count: 0 },
message: `Warnings do not trigger in production environments`,
};
}

this.pushResult(result);
WARNINGS_FOR_TEST = origWarnings.concat(WARNINGS_FOR_TEST);
};
Expand All @@ -164,6 +175,16 @@ export function configureWarningHandler() {
}

let result = verifyNoWarning(label);

if (!DEBUG) {
result = {
result: true,
actual: [],
expected: [],
message: `Warnings do not trigger in production environments`,
};
}

this.pushResult(result);
WARNINGS_FOR_TEST = origWarnings.concat(WARNINGS_FOR_TEST);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/-ember-data/tests/integration/application-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ module('integration/application - Attaching initializer', function(hooks) {
this.owner = this.application.buildInstance();

let store = this.owner.lookup('service:store');
assert.expectDeprecation({
id: 'ember-data:-legacy-test-registrations',
});
assert.ok(
store && store.get('isCustomStore'),
'ember-data initializer does not overwrite the previous registered service store'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module('integration/lifecycle_hooks - Lifecycle Hooks', function(hooks) {
'When the adapter acknowledges that a record has been created without a new data payload, a `didCreate` event is triggered.',
{
id: 'ember-data:evented-api-usage',
count: 1,
until: '4.0',
},
async function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { JsonApiValidationError } from '@ember-data/store/-private/ts-interfaces
import RecordData from '@ember-data/store/-private/ts-interfaces/record-data';
import { RecordIdentifier } from '@ember-data/store/-private/ts-interfaces/identifier';
import { RECORD_DATA_ERRORS } from '@ember-data/canary-features';
import JSONAPISerializer from '@ember-data/serializer/json-api';

class Person extends Model {
// TODO fix the typing for naked attrs
Expand Down Expand Up @@ -109,6 +110,7 @@ module('integration/record-data - Custom RecordData Errors', function(hooks) {
owner.register('model:person', Person);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
owner.register('serializer:application', JSONAPISerializer);
});

test('Record Data invalid errors', async function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { attr } from '@ember-data/model';
import Ember from 'ember';
import RecordData from '@ember-data/store/-private/ts-interfaces/record-data';
import { RECORD_DATA_STATE } from '@ember-data/canary-features';
import JSONAPISerializer from '@ember-data/serializer/json-api';

class Person extends Model {
// TODO fix the typing for naked attrs
Expand Down Expand Up @@ -105,6 +106,7 @@ module('integration/record-data - Record Data State', function(hooks) {
owner.register('model:person', Person);
owner.unregister('service:store');
owner.register('service:store', CustomStore);
owner.register('serializer:application', JSONAPISerializer);
});

test('Record Data state saving', async function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ module('integration/relationships/has_many - Has-Many Relationships', function(h
'PromiseArray proxies evented methods to its ManyArray',
{
id: 'ember-data:evented-api-usage',
count: 3,
until: '4.0',
},
function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EmberObject from '@ember/object';
import { attr } from '@ember-data/model';
import { REQUEST_SERVICE } from '@ember-data/canary-features';
import { RequestStateEnum } from '@ember-data/store/-private/ts-interfaces/fetch-manager';
import JSONSerializer from '@ember-data/serializer/json';

class Person extends Model {
// TODO fix the typing for naked attrs
Expand All @@ -26,6 +27,7 @@ if (REQUEST_SERVICE) {
hooks.beforeEach(function() {
let { owner } = this;
owner.register('model:person', Person);
owner.register('serializer:application', JSONSerializer);
store = owner.lookup('service:store');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module('integration/store - adapterFor', function(hooks) {
assert.expectAssertion(() => {
store.adapterFor('person');
}, /Assertion Failed: No adapter was found for 'person' and no 'application' adapter was found as a fallback/);
assert.expectDeprecation({
id: 'ember-data:-legacy-test-registrations',
});
});

test('we find and instantiate the application adapter', async function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ module('integration/store - serializerFor', function(hooks) {
deprecatedTest(
'we can specify a fallback serializer on the adapter when there is no application serializer',
{
id: 'ember-data:default-serializers',
id: 'ember-data:default-serializer',
count: 1,
until: '4.0',
},
async function(assert) {
Expand Down Expand Up @@ -233,7 +234,7 @@ module('integration/store - serializerFor', function(hooks) {
deprecatedTest(
'specifying defaultSerializer on the application adapter when there is a per-type serializer does not work',
{
id: 'ember-data:default-serializers',
id: 'ember-data:default-serializer',
until: '4.0',
},
async function(assert) {
Expand Down Expand Up @@ -309,7 +310,7 @@ module('integration/store - serializerFor', function(hooks) {
deprecatedTest(
'specifying defaultSerializer on a fallback adapter when there is no per-type serializer does work',
{
id: 'ember-data:default-serializers',
id: 'ember-data:default-serializer',
until: '4.0',
},
async function(assert) {
Expand Down Expand Up @@ -374,7 +375,8 @@ module('integration/store - serializerFor', function(hooks) {
deprecatedTest(
'When the per-type, application and adapter specified fallback serializer do not exist, we fallback to the -default serializer',
{
id: 'ember-data:default-serializers',
id: 'ember-data:default-serializer',
count: 4,
until: '4.0',
},
async function(assert) {
Expand Down
5 changes: 1 addition & 4 deletions packages/-ember-data/tests/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { DEBUG } from '@glimmer/env';
import QUnit from 'qunit';
import { wait, asyncEqual, invokeAsync } from 'dummy/tests/helpers/async';
import configureAsserts from 'dummy/tests/helpers/qunit-asserts';
import { SHOULD_ASSERT_ALL } from './helpers/deprecated-test';

configureAsserts();

Expand Down Expand Up @@ -41,9 +40,7 @@ QUnit.begin(() => {
const hooks = (mod.hooks.afterEach = mod.hooks.afterEach || []);

if (mod.tests.length !== 0) {
if (SHOULD_ASSERT_ALL) {
hooks.unshift(assertAllDeprecations);
}
hooks.unshift(assertAllDeprecations);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (CUSTOM_MODEL_CLASS) {
createRecord: () => RSVP.reject(),
})
);
owner.register('serializer:-default', JSONAPISerializer);
owner.register('serializer:application', JSONAPISerializer);
owner.unregister('service:store');
});

Expand Down
Loading

0 comments on commit a8d70a3

Please sign in to comment.