From 6beb5dcaf534281b87d87933e2e231d627df108d Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 30 Nov 2021 23:17:35 -0500 Subject: [PATCH] tests: Disable deprecation warnings when testing deprecated functions --- src/static/js/pad_utils.js | 1 + src/tests/frontend/specs/easysync-other.js | 30 ++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index 27190c3d1..9d5367023 100644 --- a/src/static/js/pad_utils.js +++ b/src/static/js/pad_utils.js @@ -101,6 +101,7 @@ const padutils = { * @param {...*} args - Passed to `console.warn`, with a stack trace appended. */ warnDeprecated: (...args) => { + if (padutils.warnDeprecated.disabledForTestingOnly) return; const err = new Error(); if (Error.captureStackTrace) Error.captureStackTrace(err, padutils.warnDeprecated); err.name = ''; diff --git a/src/tests/frontend/specs/easysync-other.js b/src/tests/frontend/specs/easysync-other.js index 26376713a..856b7df62 100644 --- a/src/tests/frontend/specs/easysync-other.js +++ b/src/tests/frontend/specs/easysync-other.js @@ -3,6 +3,7 @@ const Changeset = require('../../../static/js/Changeset'); const AttributePool = require('../../../static/js/AttributePool'); const {randomMultiline, poolOrArray} = require('../easysync-helper.js'); +const {padutils} = require('../../../static/js/pad_utils'); describe('easysync-other', function () { describe('filter attribute numbers', function () { @@ -23,8 +24,12 @@ describe('easysync-other', function () { const testMakeAttribsString = (testId, pool, opcode, attribs, correctString) => { it(`testMakeAttribsString#${testId}`, async function () { const p = poolOrArray(pool); - const str = Changeset.makeAttribsString(opcode, attribs, p); - expect(str).to.equal(correctString); + padutils.warnDeprecated.disabledForTestingOnly = true; + try { + expect(Changeset.makeAttribsString(opcode, attribs, p)).to.equal(correctString); + } finally { + delete padutils.warnDeprecated.disabledForTestingOnly; + } }); }; @@ -81,14 +86,19 @@ describe('easysync-other', function () { const stringOp = (str) => Changeset.deserializeOps(str).next().value; - expect(Changeset.opAttributeValue(stringOp('*0*1+1'), 'name', p)).to.equal('david'); - expect(Changeset.opAttributeValue(stringOp('*0+1'), 'name', p)).to.equal('david'); - expect(Changeset.opAttributeValue(stringOp('*1+1'), 'name', p)).to.equal(''); - expect(Changeset.opAttributeValue(stringOp('+1'), 'name', p)).to.equal(''); - expect(Changeset.opAttributeValue(stringOp('*0*1+1'), 'color', p)).to.equal('green'); - expect(Changeset.opAttributeValue(stringOp('*1+1'), 'color', p)).to.equal('green'); - expect(Changeset.opAttributeValue(stringOp('*0+1'), 'color', p)).to.equal(''); - expect(Changeset.opAttributeValue(stringOp('+1'), 'color', p)).to.equal(''); + padutils.warnDeprecated.disabledForTestingOnly = true; + try { + expect(Changeset.opAttributeValue(stringOp('*0*1+1'), 'name', p)).to.equal('david'); + expect(Changeset.opAttributeValue(stringOp('*0+1'), 'name', p)).to.equal('david'); + expect(Changeset.opAttributeValue(stringOp('*1+1'), 'name', p)).to.equal(''); + expect(Changeset.opAttributeValue(stringOp('+1'), 'name', p)).to.equal(''); + expect(Changeset.opAttributeValue(stringOp('*0*1+1'), 'color', p)).to.equal('green'); + expect(Changeset.opAttributeValue(stringOp('*1+1'), 'color', p)).to.equal('green'); + expect(Changeset.opAttributeValue(stringOp('*0+1'), 'color', p)).to.equal(''); + expect(Changeset.opAttributeValue(stringOp('+1'), 'color', p)).to.equal(''); + } finally { + delete padutils.warnDeprecated.disabledForTestingOnly; + } }); describe('applyToAttribution', function () {