Skip to content

Commit

Permalink
chore: add axe-config-generator package (#6395)
Browse files Browse the repository at this point in the history
#### Details

Add a `axe-config-generator` package, which generates an
`axe-config.json` file containing the current
[ScanOptions](https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter)
we provide to axe.run for fastpass scans.

##### Motivation

Keep tool in centralized location

##### Context

We have been noticing confusion from users about how/ why the set of
rules that the web extension uses differs from the set of rules that
axe-core provides. This tool is the first step in increasing clarity
about which rules the extension is running.

#### Pull request checklist
<!-- If a checklist item is not applicable to this change, write "n/a"
in the checkbox -->
- [n/a] Addresses an existing issue: #0000
- [x] Ran `yarn fastpass`
- [n/a] Added/updated relevant unit test(s) (and ran `yarn test`)
- [n/a] Verified code coverage for the changes made. Check coverage
report at: `<rootDir>/test-results/unit/coverage`
- [x] PR title *AND* final merge commit title both start with a semantic
tag (`fix:`, `chore:`, `feat(feature-name):`, `refactor:`). See
`CONTRIBUTING.md`.
- [n/a] (UI changes only) Added screenshots/GIFs to description above
- [n/a] (UI changes only) Verified usability with NVDA/JAWS
  • Loading branch information
sfoslund authored Feb 13, 2023
1 parent 10eba28 commit 0c6a9e4
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ module.exports = function (grunt) {
const packageValidatorBundlePath = path.join(packageValidatorPath, 'bundle');
const packageValidatorDropPath = path.join(packageValidatorPath, 'drop');

const packageAxeConfigPath = path.join('packages', 'axe-config');
const packageAxeConfigBundlePath = path.join(packageAxeConfigPath, 'bundle');
const packageAxeConfigDropPath = path.join(packageAxeConfigPath, 'drop');

const mockAdbObjPath = path.join('packages', 'mock-adb', 'obj');
const mockAdbBinPath = path.join('packages', 'mock-adb', 'bin');
const mockAdbDropPath = path.join('drop', 'mock-adb');
Expand All @@ -50,6 +54,7 @@ module.exports = function (grunt) {
'package-report': packageReportDropPath,
'package-ui': packageUIDropPath,
'package-validator': packageValidatorDropPath,
'package-axe-config': packageAxeConfigDropPath,
scss: path.join('src', '**/*.scss.d.ts'),
},
concurrent: {
Expand Down Expand Up @@ -171,6 +176,15 @@ module.exports = function (grunt) {
},
],
},
'package-axe-config': {
files: [
{
cwd: '.',
src: path.join(packageAxeConfigPath, 'index.js'),
dest: path.join(packageAxeConfigDropPath, 'index.js'),
},
],
},
},
exec: {
'esbuild-dev': `node esbuild.js`,
Expand All @@ -180,6 +194,11 @@ module.exports = function (grunt) {
'webpack-package-ui': `"${webpackPath}" --config-name package-ui`,
'esbuild-package-validator': `node esbuild.js --env validator`,
'generate-validator': `node ${packageValidatorDropPath}`,
'esbuild-package-axe-config': `node esbuild.js --env axe-config`,
'generate-axe-config': `node ${path.join(
packageAxeConfigBundlePath,
'axe-config-generator.bundle.js',
)} ${path.join(packageAxeConfigDropPath, 'axe-config.json')}`,
'generate-scss-typings': `"${typedScssModulesPath}" src --exportType default`,
'dotnet-publish-mock-adb': {
command: `dotnet publish -c Release -o "${path.resolve(mockAdbDropPath)}"`,
Expand Down Expand Up @@ -710,6 +729,19 @@ module.exports = function (grunt) {
console.log(`package is in ${packageValidatorDropPath}`);
});

grunt.registerTask('package-axe-config', function () {
const mustExistPath = path.join(
packageAxeConfigBundlePath,
'axe-config-generator.bundle.js',
);

mustExist(mustExistPath, 'Have you run esbuild?');

grunt.task.run('clean:package-axe-config');
grunt.task.run('copy:package-axe-config');
console.log(`package is in ${packageAxeConfigDropPath}`);
});

grunt.registerTask('build-mock-adb', function () {
grunt.task.run('exec:dotnet-publish-mock-adb');
});
Expand Down Expand Up @@ -799,6 +831,11 @@ module.exports = function (grunt) {
'exec:esbuild-package-validator',
'package-validator',
]);
grunt.registerTask('generate-axe-config', [
'exec:esbuild-package-axe-config',
'package-axe-config',
'exec:generate-axe-config',
]);
grunt.registerTask('build-all', [
'clean:intermediates',
'exec:generate-scss-typings',
Expand Down
11 changes: 11 additions & 0 deletions esbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ switch (argsObj.env) {

break;

case 'axe-config':
entryFiles = {
'axe-config-generator': `${src}/packages/axe-config/generate-config-json.ts`,
};
outdir = path.join(__dirname, 'packages/axe-config/bundle');
platform = 'node';

ignoreNodeModules(plugins);

break;

// dev web extension
default:
define = {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"build:package:report": "lerna --scope accessibility-insights-report run build",
"build:package:ui": "lerna --scope accessibility-insights-ui run build",
"build:prod": "grunt build-prod",
"build:package:axe-config": "grunt generate-axe-config",
"change-log": "node ./tools/get-change-log-for-release.js",
"clean": "grunt clean:*",
"clean:mock-adb": "grunt clean:mock-adb",
Expand Down
18 changes: 18 additions & 0 deletions packages/axe-config/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the MIT License.
-->

# @accessibility-insights/axe-config

This library provides the [axe core run options](https://www.deque.com/axe/core-documentation/api-documentation/#options-parameter) currently used by default in Accessibility Insights for Web extension FastPass scans.

## Contributing

To contribute, please visit [accessibility-insights-web](https://github.com/microsoft/accessibility-insights-web/blob/main/README.md) for more information.

### Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
5 changes: 5 additions & 0 deletions packages/axe-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const axeScanOptions = require('./axe-config.json');
exports.axeScanOptions = axeScanOptions;
20 changes: 20 additions & 0 deletions packages/axe-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@accessibility-insights/axe-config",
"version": "1.0.0",
"description": "Provides the current axe-core run options used by Accessibility Insights for Web for FastPass scans.",
"license": "MIT",
"files": [
"../../LICENSE",
"drop",
"README.md"
],
"main": "drop/index.js",
"scripts": {
"build": "grunt build-axe-config"
},
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/accessibility-insights-web"
},
"dependencies": {}
}
7 changes: 7 additions & 0 deletions packages/axe-config/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
const baseConfig = require('../../prettier.config');

module.exports = {
...baseConfig,
};
30 changes: 30 additions & 0 deletions src/packages/axe-config/generate-config-json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as axe from 'axe-core';
import * as fs from 'fs';
import * as path from 'path';
import { explicitRuleOverrides, getRuleInclusions } from 'scanner/get-rule-inclusions';
import { ScanParameterGenerator } from 'scanner/scan-parameter-generator';

const defaultConfigFilePath = path.join(__dirname, '../../../drop/axe-config.json');
const configFilePath = process.argv[2] || defaultConfigFilePath;

const generateAxeConfig = () => {
console.log('Generating axe config file...');

const ruleIncludedStatus = getRuleInclusions(axe._audit.rules, explicitRuleOverrides);
const scanParameterGenerator = new ScanParameterGenerator(ruleIncludedStatus);
const scanOptions = scanParameterGenerator.getAxeEngineOptions({});
const config = JSON.stringify(scanOptions, null, '\t');

console.log(`Writing config to ${configFilePath}...`);
if (!fs.existsSync(path.dirname(configFilePath))) {
fs.mkdirSync(path.dirname(configFilePath));
}
fs.writeFileSync(configFilePath, config);

console.log('Finished generating axe config file.');
};

generateAxeConfig();

0 comments on commit 0c6a9e4

Please sign in to comment.