tests: Disable deprecation warnings when testing deprecated functions

This commit is contained in:
Richard Hansen 2021-11-30 23:17:35 -05:00
parent c4f18a9b3a
commit 6beb5dcaf5
2 changed files with 21 additions and 10 deletions

View file

@ -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 = '';

View file

@ -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,6 +86,8 @@ describe('easysync-other', function () {
const stringOp = (str) => Changeset.deserializeOps(str).next().value;
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('');
@ -89,6 +96,9 @@ describe('easysync-other', function () {
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 () {