Skip to content

Commit

Permalink
test: Make axe-core version test more robust (#767)
Browse files Browse the repository at this point in the history
- Test every package (under `packages/*`)
- Use the battle-tested [`semver`](https://www.npmjs.com/package/semver) library rather than a regex
  • Loading branch information
stephenmathieson authored Aug 7, 2023
1 parent 6be181b commit 6824caf
Show file tree
Hide file tree
Showing 3 changed files with 887 additions and 200 deletions.
64 changes: 18 additions & 46 deletions axe_core_test/axe-core-version.test.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
const { assert } = require('chai');
const cli = require('../packages/cli/package.json');
const puppeteer = require('../packages/puppeteer/package.json');
const reporterEarl = require('../packages/reporter-earl/package.json');
const webdriverjs = require('../packages/webdriverjs/package.json');

describe('verify axe-core version', () => {
const versioning = /([1-9].[0-9]*)/;

it('cli', () => {
const cliVersion = cli.version;
const cliAxeCoreVersion = cli.dependencies['axe-core'];

const [packageAxeCoreVersion] = cliAxeCoreVersion.match(versioning);
const [axeCoreCliVersion] = cliVersion.match(versioning);
assert.strictEqual(axeCoreCliVersion, packageAxeCoreVersion);
});

it('puppeteer', () => {
const puppeteerVersion = puppeteer.version;
const puppeteerAxeCoreVersion = puppeteer.dependencies['axe-core'];

const [packageAxeCoreVersion] = puppeteerAxeCoreVersion.match(versioning);
const [axeCorePuppeteerVersion] = puppeteerVersion.match(versioning);
assert.strictEqual(axeCorePuppeteerVersion, packageAxeCoreVersion);
});

it('reporter-earl', () => {
const reporterEarlVersion = reporterEarl.version;
const reporterEarlAxeCoreVersion = reporterEarl.devDependencies['axe-core'];

const [packageAxeCoreVersion] =
reporterEarlAxeCoreVersion.match(versioning);
const [axeCoreReporterEarlVersion] = reporterEarlVersion.match(versioning);
assert.strictEqual(axeCoreReporterEarlVersion, packageAxeCoreVersion);
});

it('webdriverjs', () => {
const webdriverjsVersion = webdriverjs.version;
const webdriverjsAxeCoreVersion = webdriverjs.dependencies['axe-core'];

const [packageAxeCoreVersion] = webdriverjsAxeCoreVersion.match(versioning);
const [axeCoreWebdriverjsVersion] = webdriverjsVersion.match(versioning);

assert.strictEqual(axeCoreWebdriverjsVersion, packageAxeCoreVersion);
const assert = require('assert');
const glob = require('glob');
const semver = require('semver');

for (const pkgFile of glob.sync('../packages/*/package.json')) {
const pkg = require(pkgFile);
const axeDependency =
pkg.dependencies?.['axe-core'] || pkg.devDependencies?.['axe-core'];

describe(pkg.name, () => {
it('should have the same semver major/minor as its axe-core dependency', () => {
const axeVersion = semver.parse(semver.coerce(axeDependency));
const pkgVersion = semver.parse(pkg.version);

assert.equal(axeVersion.major, pkgVersion.major);
assert.equal(axeVersion.minor, pkgVersion.minor);
});
});
});
}
Loading

0 comments on commit 6824caf

Please sign in to comment.