Skip to content

Commit

Permalink
feat(configure): accept ver property as axeVersion fallback (#1812)
Browse files Browse the repository at this point in the history
* fix(configure): accept ver property as fallback

* fix test
  • Loading branch information
straker committed Sep 23, 2019
1 parent 1aa567c commit 4ebcde8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/core/public/configure.js
Expand Up @@ -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('-');
Expand All @@ -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}`
);
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/core/public/configure.js
Expand Up @@ -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'
});
});
});

Expand Down Expand Up @@ -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/
);
});
});
});
});

0 comments on commit 4ebcde8

Please sign in to comment.