From 84cd48f3a14134df5ce4a75ff6ea2726a8a9ade7 Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Tue, 22 Oct 2019 17:24:28 +0200 Subject: [PATCH 1/2] [CHORE] configure the ability to filter deprecations from assertNoDeprecations --- .../tests/helpers/deprecated-test.js | 13 +++++- .../qunit-asserts/assert-deprecation.ts | 30 ++++++++---- .../tests/helpers/test-in-debug.js | 6 +-- packages/-ember-data/tests/test-helper.js | 46 +++++++++++++------ 4 files changed, 68 insertions(+), 27 deletions(-) diff --git a/packages/-ember-data/tests/helpers/deprecated-test.js b/packages/-ember-data/tests/helpers/deprecated-test.js index d486a3293c9..7ac5237676a 100644 --- a/packages/-ember-data/tests/helpers/deprecated-test.js +++ b/packages/-ember-data/tests/helpers/deprecated-test.js @@ -1,5 +1,6 @@ import { test } from 'qunit'; import VERSION from 'ember-data/version'; +import { DEBUG } from '@glimmer/env'; // small comparison function for major and minor semver values function gte(EDVersion, DeprecationVersion) { @@ -22,8 +23,18 @@ 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 (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..16cfbb482e9 100644 --- a/packages/-ember-data/tests/test-helper.js +++ b/packages/-ember-data/tests/test-helper.js @@ -3,9 +3,9 @@ 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'; @@ -14,30 +14,46 @@ 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) { + 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; From f32459618e5adfa95debfda3aaabe167ad09073c Mon Sep 17 00:00:00 2001 From: Chris Thoburn Date: Wed, 23 Oct 2019 16:52:31 +0200 Subject: [PATCH 2/2] turn off helpers until tests are fixed --- .../-ember-data/tests/helpers/deprecated-test.js | 13 ++++++++++--- packages/-ember-data/tests/test-helper.js | 5 ++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/-ember-data/tests/helpers/deprecated-test.js b/packages/-ember-data/tests/helpers/deprecated-test.js index 7ac5237676a..25bf20ccd67 100644 --- a/packages/-ember-data/tests/helpers/deprecated-test.js +++ b/packages/-ember-data/tests/helpers/deprecated-test.js @@ -2,6 +2,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) { let _edv = EDVersion.split('.'); @@ -26,10 +31,12 @@ export function deprecatedTest(testName, deprecation, testCallback) { async function interceptor(assert) { await testCallback.call(this, assert); if (DEBUG) { - if (typeof assert.test.expected === 'number') { - assert.test.expected += 1; + if (SHOULD_ASSERT_ALL) { + if (typeof assert.test.expected === 'number') { + assert.test.expected += 1; + } + assert.expectDeprecation(deprecation); } - assert.expectDeprecation(deprecation); } } diff --git a/packages/-ember-data/tests/test-helper.js b/packages/-ember-data/tests/test-helper.js index 16cfbb482e9..baefbda919a 100644 --- a/packages/-ember-data/tests/test-helper.js +++ b/packages/-ember-data/tests/test-helper.js @@ -8,6 +8,7 @@ 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(); @@ -40,7 +41,9 @@ QUnit.begin(() => { const hooks = (mod.hooks.afterEach = mod.hooks.afterEach || []); if (mod.tests.length !== 0) { - hooks.unshift(assertAllDeprecations); + if (SHOULD_ASSERT_ALL) { + hooks.unshift(assertAllDeprecations); + } } }); }