@sa11y/jest 6.9.5-alpha.3 → 6.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,6 @@ export type AutoCheckOpts = {
6
6
  cleanupAfterEach?: boolean;
7
7
  consolidateResults?: boolean;
8
8
  filesFilter?: string[];
9
- runDOMMutationObserver?: boolean;
10
9
  };
11
10
  export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
12
11
  export declare const getOriginalDocumentBodyHtml: () => string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAgBF,eAAO,MAAM,2BAA2B,aAAc,MAAM,GAAG,IAAI,SAElE,CAAC;AAEF,eAAO,MAAM,2BAA2B,qBAEvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAUtF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,GAAE,aAAoC,GAAG,OAAO,CAAC,IAAI,CAAC,CA6E9F;AAoBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAmB7F"}
1
+ {"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAcF,eAAO,MAAM,2BAA2B,aAAc,MAAM,GAAG,IAAI,SAElE,CAAC;AAEF,eAAO,MAAM,2BAA2B,qBAEvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAUtF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,GAAE,aAAoC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD9F;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAQ7F"}
package/dist/automatic.js CHANGED
@@ -24,7 +24,6 @@ const defaultAutoCheckOpts = {
24
24
  filesFilter: [],
25
25
  };
26
26
  let originalDocumentBodyHtml = null;
27
- let mutatedNodes = [];
28
27
  const setOriginalDocumentBodyHtml = (bodyHtml) => {
29
28
  originalDocumentBodyHtml = bodyHtml ?? null;
30
29
  };
@@ -66,47 +65,24 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
66
65
  // Create a DOM walker filtering only elements (skipping text, comment nodes etc)
67
66
  const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
68
67
  let currNode = walker.firstChild();
69
- let customRules = (0, common_1.useCustomRules)();
68
+ const customRules = (0, common_1.useCustomRules)();
70
69
  try {
71
- if (!opts.runDOMMutationObserver) {
72
- while (currNode !== null) {
73
- // TODO (spike): Use a logger lib with log levels selectable at runtime
74
- // console.log(
75
- // `♿ [DEBUG] Automatically checking a11y of ${currNode.nodeName}
76
- // for test "${expect.getState().currentTestName}"
77
- // : ${testPath}`
78
- // );
79
- // W-10004832 - Exclude descendancy based rules from automatic checks
80
- if (customRules.length === 0)
81
- violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
82
- else
83
- violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
84
- currNode = walker.nextSibling();
85
- }
86
- }
87
- else {
88
- customRules = [];
89
- // loop mutated nodes
90
- for (let i = 0; i < mutatedNodes.length; i++) {
91
- if (mutatedNodes[i]) {
92
- document.body.innerHTML = mutatedNodes[i];
93
- const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
94
- let currNode = walker.firstChild();
95
- while (currNode !== null) {
96
- if (customRules.length === 0)
97
- violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
98
- else
99
- violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
100
- currNode = walker.nextSibling();
101
- }
102
- }
103
- }
70
+ while (currNode !== null) {
71
+ // TODO (spike): Use a logger lib with log levels selectable at runtime
72
+ // console.log(
73
+ // `♿ [DEBUG] Automatically checking a11y of ${currNode.nodeName}
74
+ // for test "${expect.getState().currentTestName}"
75
+ // : ${testPath}`
76
+ // );
77
+ // W-10004832 - Exclude descendancy based rules from automatic checks
78
+ if (customRules.length === 0)
79
+ violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
80
+ else
81
+ violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
82
+ currNode = walker.nextSibling();
104
83
  }
105
84
  }
106
85
  finally {
107
- if (opts.runDOMMutationObserver) {
108
- mutatedNodes = [];
109
- }
110
86
  (0, exports.setOriginalDocumentBodyHtml)(null);
111
87
  document.body.innerHTML = currentDocumentHtml;
112
88
  if (opts.cleanupAfterEach)
@@ -121,40 +97,15 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
121
97
  }
122
98
  }
123
99
  exports.automaticCheck = automaticCheck;
124
- function observerCallback(mutations, _observer) {
125
- for (const mutation of mutations) {
126
- mutation.addedNodes.forEach((node) => {
127
- if (node?.parentElement?.innerHTML) {
128
- mutatedNodes.push(node.parentElement.innerHTML);
129
- }
130
- });
131
- }
132
- }
133
- // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit
134
- const observerOptions = {
135
- subtree: true,
136
- childList: true,
137
- attributes: true,
138
- characterData: true, // monitor changes to the character data contained within nodes
139
- };
140
100
  /**
141
101
  * Register accessibility checks to be run automatically after each test
142
102
  * @param opts - Options for automatic checks {@link AutoCheckOpts}
143
103
  */
144
104
  function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
145
105
  if (opts.runAfterEach) {
146
- const observer = new MutationObserver(observerCallback);
147
106
  // TODO (fix): Make registration idempotent
148
107
  (0, common_1.log)('Registering sa11y checks to be run automatically after each test');
149
- beforeEach(() => {
150
- if (opts.runDOMMutationObserver) {
151
- observer.observe(document.body, observerOptions);
152
- }
153
- });
154
108
  afterEach(async () => {
155
- if (opts.runDOMMutationObserver) {
156
- observer.disconnect(); // stop mutation observer
157
- }
158
109
  await automaticCheck(opts);
159
110
  });
160
111
  }
@@ -1 +1 @@
1
- {"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AAkLlF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAa5E;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAaxF"}
1
+ {"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AA6MlF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAa5E;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAaxF"}
@@ -3,44 +3,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resultsProcessorManualChecks = exports.resultsProcessor = void 0;
4
4
  const common_1 = require("@sa11y/common");
5
5
  const format_1 = require("@sa11y/format");
6
- const formatSpacing = '\t'.repeat(8);
7
- const formatForAxeMessage = `\n${formatSpacing}\t\t`;
6
+ const formatSpacing = '\t'.repeat(4);
7
+ const formatForAxeMessage = `\n${formatSpacing}\t`;
8
8
  const axeMessages = {
9
9
  toSolveAny: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix at least (1) of the following:\n`,
10
10
  toSolveFirst: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix one of the following:\n`,
11
11
  toSolveSecond: `${formatForAxeMessage}- And fix the following:\n`,
12
+ relatedNodes: `${formatForAxeMessage}- Related Nodes: \n`,
12
13
  };
13
14
  /**
14
15
  * Create a test failure html elements array grouped by rule violation
15
16
  */
16
17
  function createA11yErrorElements(errorElements) {
17
18
  const a11yErrorElements = [];
19
+ let onlyOneSummary = false;
20
+ const appendRelatedNodes = (errorMessage, relatedNodes) => {
21
+ return relatedNodes ? `${errorMessage}${axeMessages.relatedNodes}${relatedNodes}` : errorMessage;
22
+ };
18
23
  errorElements.forEach((errorElement, index) => {
19
- let errorMessage = `${formatSpacing}(${index + 1}) - HTML element : ${errorElement.html
24
+ let errorMessage = `${formatSpacing}(${index + 1}) - HTML element : ${errorElement.html
20
25
  .replace(/&lt;/g, '<')
21
- .replace(/&gt;/, '>')}
22
- - CSS selector(s) : ${errorElement.selectors.replace(/&gt;/, '>')}
23
- - HTML Tag Hierarchy : ${errorElement.hierarchy}`;
24
- if (errorElement.any && errorElement.any.length > 0) {
25
- errorMessage += `${axeMessages.toSolveAny}${errorElement.any}`;
26
- if (errorElement.all && errorElement.all.length > 0) {
27
- errorMessage += `${axeMessages.toSolveSecond}${errorElement.all}`;
26
+ .replace(/&gt;/, '>')}`;
27
+ errorMessage += `${formatForAxeMessage}- CSS selector(s) : ${errorElement.selectors.replace(/&gt;/, '>')}`;
28
+ errorMessage += `${formatForAxeMessage}- HTML Tag Hierarchy : ${errorElement.hierarchy}`;
29
+ const isAny = errorElement.any?.length > 0;
30
+ const isAll = errorElement.all?.length > 0;
31
+ const isNone = errorElement.none?.length > 0;
32
+ if (!onlyOneSummary) {
33
+ if (isAny) {
34
+ errorMessage += `${axeMessages.toSolveAny}${errorElement.any}`;
35
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAny);
36
+ if (isAll) {
37
+ errorMessage += `${axeMessages.toSolveSecond}${errorElement.all}`;
38
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAll);
39
+ }
40
+ if (isNone) {
41
+ errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
42
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
43
+ }
28
44
  }
29
- if (errorElement.none && errorElement.none.length > 0) {
30
- errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
45
+ else if (isAll) {
46
+ errorMessage += `${axeMessages.toSolveFirst}${errorElement.all}`;
47
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAll);
48
+ if (isNone) {
49
+ errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
50
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
51
+ }
31
52
  }
32
- }
33
- else if (errorElement.all && errorElement.all.length > 0) {
34
- errorMessage += `${axeMessages.toSolveFirst}${errorElement.all}`;
35
- if (errorElement.none && errorElement.none.length > 0) {
36
- errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
53
+ else {
54
+ if (isNone) {
55
+ errorMessage += `${axeMessages.toSolveFirst}${errorElement.none}`;
56
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
57
+ }
37
58
  }
38
59
  }
39
60
  else {
40
- if (errorElement.none && errorElement.none.length > 0) {
41
- errorMessage += `${axeMessages.toSolveFirst}${errorElement.none}`;
42
- }
61
+ errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAny);
43
62
  }
63
+ onlyOneSummary = isAny && !isAll && !isNone;
44
64
  a11yErrorElements.push(errorMessage);
45
65
  });
46
66
  return a11yErrorElements.join('\n');
@@ -83,21 +103,24 @@ function processA11yDetailsAndMessages(error, a11yFailureMessages) {
83
103
  any: a11yResult.any,
84
104
  all: a11yResult.all,
85
105
  none: a11yResult.none,
106
+ relatedNodeAny: a11yResult.relatedNodeAny,
107
+ relatedNodeAll: a11yResult.relatedNodeAll,
108
+ relatedNodeNone: a11yResult.relatedNodeNone,
86
109
  });
87
110
  });
88
111
  const a11yFailureMessage = `
89
- The test has failed the accessibility check. Accessibility Stacktrace/Issues:
90
- ${a11yErrorElementsCount} HTML elements have accessibility issue(s). ${a11yRuleViolationsCount} rules failed.
112
+ The test has failed the accessibility check. Accessibility Stacktrace/Issues:
113
+ ${a11yErrorElementsCount} HTML elements have accessibility issue(s). ${a11yRuleViolationsCount} rules failed.
91
114
 
92
- ${Object.values(a11yRuleViolations)
115
+ ${Object.values(a11yRuleViolations)
93
116
  .map((a11yRuleViolation, index) => createA11yRuleViolation(a11yRuleViolation, index + 1))
94
117
  .join('\n')}
95
118
 
96
-
97
- For more info about automated accessibility testing: https://sfdc.co/a11y-test
98
- For tips on fixing accessibility bugs: https://sfdc.co/a11y
99
- For technical questions regarding Salesforce accessibility tools, contact our Sa11y team: http://sfdc.co/sa11y-users
100
- For guidance on accessibility related specifics, contact our A11y team: http://sfdc.co/tmp-a11y
119
+
120
+ For more info about automated accessibility testing: https://sfdc.co/a11y-test
121
+ For tips on fixing accessibility bugs: https://sfdc.co/a11y
122
+ For technical questions regarding Salesforce accessibility tools, contact our Sa11y team: http://sfdc.co/sa11y-users
123
+ For guidance on accessibility related specifics, contact our A11y team: http://sfdc.co/tmp-a11y
101
124
  `;
102
125
  a11yFailureMessages.push(a11yFailureMessage);
103
126
  }
@@ -1 +1 @@
1
- {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAA6C,MAAM,eAAe,CAAC;AACtF,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;AAmCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAkD9D;AACD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C;AACD;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,UAAU,CAKhG;AACD,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAM3F"}
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAA6C,MAAM,eAAe,CAAC;AACtF,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;AAkCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CA6C9D;AACD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C;AACD;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,UAAU,CAKhG;AACD,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAM3F"}
package/dist/setup.js CHANGED
@@ -38,7 +38,6 @@ const defaultSa11yOpts = {
38
38
  runAfterEach: false,
39
39
  cleanupAfterEach: false,
40
40
  consolidateResults: false,
41
- runDOMMutationObserver: false,
42
41
  },
43
42
  };
44
43
  function registerRemoveChild() {
@@ -104,9 +103,6 @@ function setup(opts = defaultSa11yOpts) {
104
103
  'ui-help-components/modules/forceHelp/searchResults/__tests__/searchResults.spec.js',
105
104
  'ui-help-components/modules/forceHelp/linkToKnownIssue/__tests__/linkToKnownIssue.spec.js',
106
105
  ]);
107
- // TODO: For testing purposes, using SA11Y_CUSTOM_RULES config
108
- // autoCheckOpts.runDOMMutationObserver ||= !!process.env.SA11Y_ENABLE_DOM_MUTATION_CHECKS;
109
- autoCheckOpts.runDOMMutationObserver || (autoCheckOpts.runDOMMutationObserver = !!process.env.SA11Y_CUSTOM_RULES);
110
106
  (0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
111
107
  }
112
108
  exports.setup = setup;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sa11y/jest",
3
- "version": "6.9.5-alpha.3",
3
+ "version": "6.9.5",
4
4
  "description": "Accessibility testing matcher for Jest",
5
5
  "license": "BSD-3-Clause",
6
6
  "homepage": "https://github.com/salesforce/sa11y/tree/master/packages/jest#readme",
@@ -24,9 +24,9 @@
24
24
  ],
25
25
  "dependencies": {
26
26
  "@jest/test-result": "^27",
27
- "@sa11y/assert": "6.9.5-alpha.3",
28
- "@sa11y/format": "6.9.5-alpha.3",
29
- "@sa11y/preset-rules": "6.9.5-alpha.3",
27
+ "@sa11y/assert": "6.9.5",
28
+ "@sa11y/format": "6.9.5",
29
+ "@sa11y/preset-rules": "6.9.5",
30
30
  "jest-matcher-utils": "^27"
31
31
  },
32
32
  "peerDependencies": {
@@ -34,8 +34,8 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "@jest/globals": "28.1.3",
37
- "@sa11y/common": "6.9.5-alpha.3",
38
- "@sa11y/test-utils": "6.9.5-alpha.3"
37
+ "@sa11y/common": "6.9.5",
38
+ "@sa11y/test-utils": "6.9.5"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -43,5 +43,5 @@
43
43
  "engines": {
44
44
  "node": "^16 || ^18 || ^20"
45
45
  },
46
- "gitHead": "362bb39cafda7276d81f030370ffa9392660d120"
46
+ "gitHead": "20778083b656180c2b077a4a7148cf813c05d040"
47
47
  }