diff --git a/packages/-ember-data/tests/helpers/deprecated-test.js b/packages/-ember-data/tests/helpers/deprecated-test.js index d486a3293c9..25bf20ccd67 100644 --- a/packages/-ember-data/tests/helpers/deprecated-test.js +++ b/packages/-ember-data/tests/helpers/deprecated-test.js @@ -1,5 +1,11 @@ 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) { @@ -22,8 +28,20 @@ export function deprecatedTest(testName, deprecation, testCallback) { throw new Error(`deprecatedTest expects { id } to be a meaningful string`); } + 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 (gte(VERSION, deprecation.until)) { - test(`DEPRECATION ${deprecation.id} until ${deprecation.until} | ${testName}`, testCallback); + test(`DEPRECATION ${deprecation.id} until ${deprecation.until} | ${testName}`, interceptor); } else { test(`DEPRECATION ${deprecation.id} until ${deprecation.until} | ${testName}`, function(assert) { if (deprecation.refactor === true) { diff --git a/packages/-ember-data/tests/helpers/qunit-asserts/assert-deprecation.ts b/packages/-ember-data/tests/helpers/qunit-asserts/assert-deprecation.ts index a695067a0bc..5f64ae46878 100644 --- a/packages/-ember-data/tests/helpers/qunit-asserts/assert-deprecation.ts +++ b/packages/-ember-data/tests/helpers/qunit-asserts/assert-deprecation.ts @@ -56,7 +56,7 @@ function verifyDeprecation(config: DeprecationConfig, label?: string): AssertSom return isMatched; }); DEPRECATIONS_FOR_TEST = DEPRECATIONS_FOR_TEST.filter(deprecation => { - matchedDeprecations.indexOf(deprecation) === -1; + return matchedDeprecations.indexOf(deprecation) === -1; }); HANDLED_DEPRECATIONS_FOR_TEST.push(...matchedDeprecations); @@ -75,9 +75,18 @@ function verifyDeprecation(config: DeprecationConfig, label?: string): AssertSom }; } -function verifyNoDeprecation(label?: string): AssertNoneResult { - const UNHANDLED_DEPRECATIONS = DEPRECATIONS_FOR_TEST; - DEPRECATIONS_FOR_TEST = []; +function verifyNoDeprecation(filter?: (deprecation: FoundDeprecation) => boolean, label?: string): AssertNoneResult { + let UNHANDLED_DEPRECATIONS; + + if (filter) { + UNHANDLED_DEPRECATIONS = DEPRECATIONS_FOR_TEST.filter(filter); + DEPRECATIONS_FOR_TEST = DEPRECATIONS_FOR_TEST.filter(deprecation => { + return UNHANDLED_DEPRECATIONS.indexOf(deprecation) === -1; + }); + } else { + UNHANDLED_DEPRECATIONS = DEPRECATIONS_FOR_TEST; + DEPRECATIONS_FOR_TEST = []; + } let deprecationStr = UNHANDLED_DEPRECATIONS.reduce((a, b) => { return `${a}${b.message}\n`; @@ -149,10 +158,15 @@ export function configureDeprecationHandler() { let result = verifyDeprecation(config, label); this.pushResult(result); - DEPRECATIONS_FOR_TEST = origDeprecations.concat(DEPRECATIONS_FOR_TEST); + if (callback) { + DEPRECATIONS_FOR_TEST = origDeprecations.concat(DEPRECATIONS_FOR_TEST); + } }; - - QUnit.assert.expectNoDeprecation = async function(cb, label?: string) { + QUnit.assert.expectNoDeprecation = async function( + cb?: () => unknown, + label?: string, + filter?: (deprecation: FoundDeprecation) => boolean + ) { let origDeprecations = DEPRECATIONS_FOR_TEST; if (cb) { @@ -163,7 +177,7 @@ export function configureDeprecationHandler() { } } - let result = verifyNoDeprecation(label); + let result = verifyNoDeprecation(filter, label); this.pushResult(result); DEPRECATIONS_FOR_TEST = origDeprecations.concat(DEPRECATIONS_FOR_TEST); }; diff --git a/packages/-ember-data/tests/helpers/test-in-debug.js b/packages/-ember-data/tests/helpers/test-in-debug.js index 949b64daac2..fbdfb345688 100644 --- a/packages/-ember-data/tests/helpers/test-in-debug.js +++ b/packages/-ember-data/tests/helpers/test-in-debug.js @@ -1,10 +1,10 @@ import { DEBUG } from '@glimmer/env'; import { test, skip } from 'qunit'; -export default function testInDebug() { +export default function testInDebug(label, callback) { if (DEBUG) { - test(...arguments); + test(`[DEBUG-ONLY] ${label}`, callback); } else { - skip(...arguments); + skip(`[DEBUG-ONLY] ${label}`, callback); } } diff --git a/packages/-ember-data/tests/test-helper.js b/packages/-ember-data/tests/test-helper.js index b87f4f8f0df..baefbda919a 100644 --- a/packages/-ember-data/tests/test-helper.js +++ b/packages/-ember-data/tests/test-helper.js @@ -3,41 +3,60 @@ import config from '../config/environment'; import RSVP from 'rsvp'; import { setApplication } from '@ember/test-helpers'; import { start } from 'ember-qunit'; +import { DEBUG } from '@glimmer/env'; import QUnit from 'qunit'; -import DS from 'ember-data'; 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(); setApplication(Application.create(config.APP)); const { assert } = QUnit; -const transforms = { - boolean: DS.BooleanTransform.create(), - date: DS.DateTransform.create(), - number: DS.NumberTransform.create(), - string: DS.StringTransform.create(), -}; QUnit.begin(() => { + function assertAllDeprecations(assert) { + if (typeof assert.test.expected === 'number') { + assert.test.expected += 1; + } + assert.expectNoDeprecation(undefined, undefined, deprecation => { + // only assert EmberData deprecations + const id = deprecation.options.id; + const isEmberDataDeprecation = id.includes('DS') || id.includes('EmberData') || id.includes('ember-data'); + + if (!isEmberDataDeprecation) { + // eslint-disable-next-line no-console + console.log('Detected Non-Ember-Data Deprecation', deprecation); + } + + return isEmberDataDeprecation; + }); + } + // ensure we don't regress quietly + // this plays nicely with `expectDeprecation` + if (DEBUG) { + QUnit.config.modules.forEach(mod => { + const hooks = (mod.hooks.afterEach = mod.hooks.afterEach || []); + + if (mod.tests.length !== 0) { + if (SHOULD_ASSERT_ALL) { + hooks.unshift(assertAllDeprecations); + } + } + }); + } + RSVP.configure('onerror', reason => { // only print error messages if they're exceptions; // otherwise, let a future turn of the event loop // handle the error. + // TODO kill this off if (reason && reason instanceof Error) { throw reason; } }); - - // Prevent all tests involving serialization to require a container - // TODO kill the need for this - DS.JSONSerializer.reopen({ - transformFor(attributeType) { - return this._super(attributeType, true) || transforms[attributeType]; - }, - }); }); assert.wait = wait;