From 4ebcde88eb08296abff310f9ae554d0898542793 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 23 Sep 2019 10:45:16 -0400 Subject: [PATCH] feat(configure): accept ver property as axeVersion fallback (#1812) * fix(configure): accept ver property as fallback * fix test --- lib/core/public/configure.js | 14 ++++++++------ test/core/public/configure.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/lib/core/public/configure.js b/lib/core/public/configure.js index 47b5de6654..52d8cd280f 100644 --- a/lib/core/public/configure.js +++ b/lib/core/public/configure.js @@ -8,12 +8,13 @@ function configureChecksRulesAndBranding(spec) { throw new Error('No audit configured'); } - if (spec.axeVersion) { - if (!/^\d+\.\d+\.\d+(-canary)?/.test(spec.axeVersion)) { - throw new Error(`Invalid configured version ${spec.axeVersion}`); + if (spec.axeVersion || spec.ver) { + let specVersion = spec.axeVersion || spec.ver; + if (!/^\d+\.\d+\.\d+(-canary)?/.test(specVersion)) { + throw new Error(`Invalid configured version ${specVersion}`); } - let [version, canary] = spec.axeVersion.split('-'); + let [version, canary] = specVersion.split('-'); let [major, minor, patch] = version.split('.').map(Number); let [axeVersion, axeCanary] = axe.version.split('-'); @@ -26,10 +27,11 @@ function configureChecksRulesAndBranding(spec) { (major === axeMajor && minor === axeMinor && patch === axePatch && - ((canary && axeCanary) || (canary && !axeCanary))) + canary && + canary !== axeCanary) ) { throw new Error( - `Configured version ${spec.axeVersion} is not compatible with current axe version ${axe.version}` + `Configured version ${specVersion} is not compatible with current axe version ${axe.version}` ); } } diff --git a/test/core/public/configure.js b/test/core/public/configure.js index ce3c10846a..6cbf39d01b 100644 --- a/test/core/public/configure.js +++ b/test/core/public/configure.js @@ -585,6 +585,11 @@ describe('axe.configure', function() { axe.configure({ axeVersion: '1.2.3' }); + + axe.version = '1.2.3-canary.2664bae'; + axe.configure({ + axeVersion: '1.2.3-canary.2664bae' + }); }); }); @@ -690,5 +695,28 @@ describe('axe.configure', function() { ); }); }); + + it('should accept ver property as fallback', function() { + assert.throws(function fn() { + axe.configure( + { + ver: '1.3.0' + }, + /^Configured version/ + ); + }); + }); + + it('should accept axeVersion over ver property', function() { + assert.throws(function fn() { + axe.configure( + { + ver: '0.1.2', + axeVersion: '1.3.0' + }, + /^Configured version 1\.3\.0/ + ); + }); + }); }); });