[axe-config] extract module to it's own package (#128815)

This commit is contained in:
Spencer 2022-03-29 16:12:14 -06:00 committed by GitHub
parent f782f8bf33
commit 40ba9bf53b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 176 additions and 15 deletions

View file

@ -464,6 +464,7 @@
"@istanbuljs/schema": "^0.1.2",
"@jest/console": "^26.6.2",
"@jest/reporters": "^26.6.2",
"@kbn/axe-config": "link:bazel-bin/packages/kbn-axe-config",
"@kbn/babel-code-parser": "link:bazel-bin/packages/kbn-babel-code-parser",
"@kbn/babel-preset": "link:bazel-bin/packages/kbn-babel-preset",
"@kbn/bazel-packages": "link:bazel-bin/packages/kbn-bazel-packages",
@ -582,6 +583,7 @@
"@types/kbn__analytics": "link:bazel-bin/packages/kbn-analytics/npm_module_types",
"@types/kbn__apm-config-loader": "link:bazel-bin/packages/kbn-apm-config-loader/npm_module_types",
"@types/kbn__apm-utils": "link:bazel-bin/packages/kbn-apm-utils/npm_module_types",
"@types/kbn__axe-config": "link:bazel-bin/packages/kbn-axe-config/npm_module_types",
"@types/kbn__bazel-packages": "link:bazel-bin/packages/kbn-bazel-packages/npm_module_types",
"@types/kbn__cli-dev-mode": "link:bazel-bin/packages/kbn-cli-dev-mode/npm_module_types",
"@types/kbn__config": "link:bazel-bin/packages/kbn-config/npm_module_types",

View file

@ -18,6 +18,7 @@ filegroup(
"//packages/kbn-analytics:build",
"//packages/kbn-apm-config-loader:build",
"//packages/kbn-apm-utils:build",
"//packages/kbn-axe-config:build",
"//packages/kbn-babel-code-parser:build",
"//packages/kbn-babel-preset:build",
"//packages/kbn-bazel-packages:build",
@ -103,6 +104,7 @@ filegroup(
"//packages/kbn-analytics:build_types",
"//packages/kbn-apm-config-loader:build_types",
"//packages/kbn-apm-utils:build_types",
"//packages/kbn-axe-config:build_types",
"//packages/kbn-bazel-packages:build_types",
"//packages/kbn-cli-dev-mode:build_types",
"//packages/kbn-config-schema:build_types",

View file

@ -0,0 +1,123 @@
load("@npm//@bazel/typescript:index.bzl", "ts_config")
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
load("//src/dev/bazel:index.bzl", "jsts_transpiler", "pkg_npm", "pkg_npm_types", "ts_project")
PKG_DIRNAME = "kbn-axe-config"
PKG_REQUIRE_NAME = "@kbn/axe-config"
SOURCE_FILES = glob(
[
"src/**/*.ts",
"src/**/*.tsx",
],
exclude = [
"**/*.test.*",
],
)
SRCS = SOURCE_FILES
filegroup(
name = "srcs",
srcs = SRCS,
)
NPM_MODULE_EXTRA_FILES = [
"package.json",
]
# In this array place runtime dependencies, including other packages and NPM packages
# which must be available for this code to run.
#
# To reference other packages use:
# "//repo/relative/path/to/package"
# eg. "//packages/kbn-utils"
#
# To reference a NPM package use:
# "@npm//name-of-package"
# eg. "@npm//lodash"
RUNTIME_DEPS = [
]
# In this array place dependencies necessary to build the types, which will include the
# :npm_module_types target of other packages and packages from NPM, including @types/*
# packages.
#
# To reference the types for another package use:
# "//repo/relative/path/to/package:npm_module_types"
# eg. "//packages/kbn-utils:npm_module_types"
#
# References to NPM packages work the same as RUNTIME_DEPS
TYPES_DEPS = [
"@npm//@types/node",
"@npm//@types/jest",
"@npm//axe-core",
]
jsts_transpiler(
name = "target_node",
srcs = SRCS,
build_pkg_name = package_name(),
)
jsts_transpiler(
name = "target_web",
srcs = SRCS,
build_pkg_name = package_name(),
web = True,
)
ts_config(
name = "tsconfig",
src = "tsconfig.json",
deps = [
"//:tsconfig.base.json",
"//:tsconfig.bazel.json",
],
)
ts_project(
name = "tsc_types",
args = ['--pretty'],
srcs = SRCS,
deps = TYPES_DEPS,
declaration = True,
emit_declaration_only = True,
out_dir = "target_types",
root_dir = "src",
tsconfig = ":tsconfig",
)
js_library(
name = PKG_DIRNAME,
srcs = NPM_MODULE_EXTRA_FILES,
deps = RUNTIME_DEPS + [":target_node", ":target_web"],
package_name = PKG_REQUIRE_NAME,
visibility = ["//visibility:public"],
)
pkg_npm(
name = "npm_module",
deps = [":" + PKG_DIRNAME],
)
filegroup(
name = "build",
srcs = [":npm_module"],
visibility = ["//visibility:public"],
)
pkg_npm_types(
name = "npm_module_types",
srcs = SRCS,
deps = [":tsc_types"],
package_name = PKG_REQUIRE_NAME,
tsconfig = ":tsconfig",
visibility = ["//visibility:public"],
)
filegroup(
name = "build_types",
srcs = [":npm_module_types"],
visibility = ["//visibility:public"],
)

View file

@ -0,0 +1,3 @@
# @kbn/axe-config
This is package shares [axe](https://www.deque.com/axe/) rule configuration and options between various axe tests and test runners (e.g., Kibana FTR, Cypress, jest). The API remains the same between each axe runner, and should ideally be shared between each to maintain consistency across Kibana.

View file

@ -0,0 +1,11 @@
{
"name": "@kbn/axe-config",
"private": true,
"version": "1.0.0",
"main": "./target_node/index.js",
"browser": "./target_web/index.js",
"license": "SSPL-1.0 OR Elastic License 2.0",
"kibana": {
"devOnly": true
}
}

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { ReporterVersion } from 'axe-core';
import type { ReporterVersion } from 'axe-core';
export const AXE_CONFIG = {
rules: [

View file

@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.bazel.json",
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "target_types",
"rootDir": "src",
"stripInternal": false,
"types": [
"jest",
"node"
]
},
"include": [
"src/**/*"
]
}

View file

@ -34,7 +34,7 @@ NPM_MODULE_EXTRA_FILES = [
RUNTIME_DEPS = [
"//packages/kbn-dev-utils",
"//packages/kbn-i18n-react",
"//packages/kbn-test",
"//packages/kbn-axe-config",
"//packages/kbn-std",
"//packages/kbn-utils",
"@npm//@elastic/elasticsearch",
@ -78,7 +78,7 @@ TYPES_DEPS = [
"//packages/kbn-dev-utils:npm_module_types",
"//packages/kbn-i18n-react:npm_module_types",
"//packages/kbn-std:npm_module_types",
"//packages/kbn-test:npm_module_types",
"//packages/kbn-axe-config:npm_module_types",
"//packages/kbn-utils:npm_module_types",
"@npm//@elastic/elasticsearch",
"@npm//axios",

View file

@ -8,7 +8,7 @@
import { configureAxe } from 'jest-axe';
import { Result } from 'axe-core';
import { AXE_OPTIONS, AXE_CONFIG } from '@kbn/test';
import { AXE_OPTIONS, AXE_CONFIG } from '@kbn/axe-config';
import { ReactWrapper } from './testbed/types';
const axeRunner = configureAxe({ globalOptions: { ...AXE_CONFIG } });

View file

@ -69,5 +69,3 @@ export { runJest } from './jest/run';
export * from './kbn_archiver_cli';
export * from './kbn_client';
export { AXE_CONFIG, AXE_OPTIONS } from './a11y/config';

View file

@ -8,7 +8,7 @@
import chalk from 'chalk';
import testSubjectToCss from '@kbn/test-subj-selector';
import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/test';
import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/axe-config';
import { FtrService } from '../../ftr_provider_context';
import { AxeReport, printResult } from './axe_report';

View file

@ -8,8 +8,7 @@ import 'cypress-real-events/support';
import { Interception } from 'cypress/types/net-stubbing';
import 'cypress-axe';
import moment from 'moment';
// Commenting this out since it's breaking the tests. It was caused by https://github.com/elastic/kibana/commit/bef90a58663b6c4b668a7fe0ce45a002fb68c474#diff-8a4659c6955a712376fe5ca0d81636164d1b783a63fe9d1a23da4850bd0dfce3R10
// import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/test';
import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/axe-config';
Cypress.Commands.add('loginAsReadOnlyUser', () => {
cy.loginAs({ username: 'apm_read_user', password: 'changeme' });
@ -88,13 +87,11 @@ Cypress.Commands.add(
// A11y configuration
const axeConfig = {
// See comment on line 11
// ...AXE_CONFIG,
...AXE_CONFIG,
};
const axeOptions = {
// See comment on line 11
// ...AXE_OPTIONS,
// runOnly: [...AXE_OPTIONS.runOnly, 'best-practice'],
...AXE_OPTIONS,
runOnly: [...AXE_OPTIONS.runOnly, 'best-practice'],
};
export const checkA11y = ({ skipFailures }: { skipFailures: boolean }) => {

View file

@ -42,7 +42,7 @@ export const login = ({
// eslint-disable-next-line import/no-extraneous-dependencies
import 'cypress-axe';
// eslint-disable-next-line import/no-extraneous-dependencies
import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/test';
import { AXE_CONFIG, AXE_OPTIONS } from '@kbn/axe-config';
const axeConfig = {
...AXE_CONFIG,

View file

@ -2932,6 +2932,10 @@
version "0.0.0"
uid ""
"@kbn/axe-config@link:bazel-bin/packages/kbn-axe-config":
version "0.0.0"
uid ""
"@kbn/babel-code-parser@link:bazel-bin/packages/kbn-babel-code-parser":
version "0.0.0"
uid ""
@ -5954,6 +5958,10 @@
version "0.0.0"
uid ""
"@types/kbn__axe-config@link:bazel-bin/packages/kbn-axe-config/npm_module_types":
version "0.0.0"
uid ""
"@types/kbn__bazel-packages@link:bazel-bin/packages/kbn-bazel-packages/npm_module_types":
version "0.0.0"
uid ""