@elliemae/pui-cli 9.0.0-next.16 → 9.0.0-next.17
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.
- package/dist/cjs/testing/ExtendedJSDomEnv.cjs +37 -0
- package/dist/cjs/testing/extended/axe-core/getMessageAndPass.js +37 -0
- package/dist/cjs/testing/extended/axe-core/index.js +24 -0
- package/dist/cjs/testing/extended/axe-core/reporter.js +51 -0
- package/dist/cjs/testing/extended/axe-core/shouldIgnoreNodeViolation.js +31 -0
- package/dist/cjs/testing/extended/axe-core/toHaveNoViolations.js +43 -0
- package/dist/cjs/testing/jest.config.cjs +1 -1
- package/dist/cjs/testing/setup-tests.js +2 -2
- package/dist/esm/testing/ExtendedJSDomEnv.cjs +37 -0
- package/dist/esm/testing/extended/axe-core/getMessageAndPass.js +17 -0
- package/dist/esm/testing/extended/axe-core/index.js +4 -0
- package/dist/esm/testing/extended/axe-core/reporter.js +31 -0
- package/dist/esm/testing/extended/axe-core/shouldIgnoreNodeViolation.js +11 -0
- package/dist/esm/testing/extended/axe-core/toHaveNoViolations.js +23 -0
- package/dist/esm/testing/jest.config.cjs +1 -1
- package/dist/esm/testing/setup-tests.js +2 -2
- package/dist/types/testing/ExtendedJSDomEnv.d.cts +5 -0
- package/dist/types/testing/extended/axe-core/getMessageAndPass.d.ts +8 -0
- package/dist/types/testing/extended/axe-core/index.d.ts +1 -0
- package/dist/types/testing/extended/axe-core/reporter.d.ts +2 -0
- package/dist/types/testing/extended/axe-core/shouldIgnoreNodeViolation.d.ts +2 -0
- package/dist/types/testing/extended/axe-core/toHaveNoViolations.d.ts +12 -0
- package/dist/types/tests/basic.test.d.ts +0 -0
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { TestEnvironment } = require('jest-environment-jsdom');
|
|
2
|
+
|
|
3
|
+
// ICE platform is meant to be run on node > 18
|
|
4
|
+
// "jest-environment-jsdom": "~29.6.3" is instead meant to support node >16
|
|
5
|
+
// features that are supported since node 17 & 18 are not supported in jsdom env
|
|
6
|
+
// the limitation is not relevant for us since we are already running on node 18 anyway,
|
|
7
|
+
// this "ExtendedJSDomEnv" is an extension of the
|
|
8
|
+
// jest.config.cjs
|
|
9
|
+
// {
|
|
10
|
+
// ...
|
|
11
|
+
// testEnvironment: 'jsdom'
|
|
12
|
+
// ...
|
|
13
|
+
// }
|
|
14
|
+
// that actually uses node 18 features that are not supported in "jest-environment-jsdom": "~29.6.3"
|
|
15
|
+
|
|
16
|
+
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
|
|
17
|
+
class FixJSDOMEnvironment extends TestEnvironment {
|
|
18
|
+
constructor(...args) {
|
|
19
|
+
super(...args);
|
|
20
|
+
|
|
21
|
+
// From here on we are using "node" (currently running version of it) to polyfill jsdom this.global
|
|
22
|
+
|
|
23
|
+
// FIXME https://github.com/jsdom/jsdom/issues/3363
|
|
24
|
+
if (structuredClone) this.global.structuredClone = structuredClone;
|
|
25
|
+
|
|
26
|
+
// FIXME https://github.com/jsdom/jsdom/issues/1724
|
|
27
|
+
if (fetch) this.global.fetch = fetch;
|
|
28
|
+
if (Headers) this.global.Headers = Headers;
|
|
29
|
+
if (Request) this.global.Request = Request;
|
|
30
|
+
if (Response) this.global.Response = Response;
|
|
31
|
+
|
|
32
|
+
// FIXME https://github.com/jsdom/jsdom/issues/1721
|
|
33
|
+
if (URL) this.global.URL = URL;
|
|
34
|
+
if (Blob) this.global.Blob = Blob;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
module.exports = FixJSDOMEnvironment;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getMessageAndPass_exports = {};
|
|
20
|
+
__export(getMessageAndPass_exports, {
|
|
21
|
+
getMessageAndPass: () => getMessageAndPass
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getMessageAndPass_exports);
|
|
24
|
+
var import_jest_matcher_utils = require("jest-matcher-utils");
|
|
25
|
+
var import_reporter = require("./reporter.js");
|
|
26
|
+
const getMessageAndPass = (violations) => {
|
|
27
|
+
const formatedViolations = (0, import_reporter.reporter)(violations);
|
|
28
|
+
const pass = formatedViolations.length === 0;
|
|
29
|
+
if (pass)
|
|
30
|
+
return { message: () => "", pass };
|
|
31
|
+
return {
|
|
32
|
+
message: () => `${(0, import_jest_matcher_utils.matcherHint)(".toHaveNoViolations")}
|
|
33
|
+
|
|
34
|
+
${formatedViolations}`,
|
|
35
|
+
pass
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var axe_core_exports = {};
|
|
20
|
+
__export(axe_core_exports, {
|
|
21
|
+
toHaveNoViolations: () => import_toHaveNoViolations.toHaveNoViolations
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(axe_core_exports);
|
|
24
|
+
var import_toHaveNoViolations = require("./toHaveNoViolations.js");
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var reporter_exports = {};
|
|
20
|
+
__export(reporter_exports, {
|
|
21
|
+
reporter: () => reporter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(reporter_exports);
|
|
24
|
+
var import_jest_matcher_utils = require("jest-matcher-utils");
|
|
25
|
+
const colorYellow = (arg) => `\x1B[93m ${arg ?? ""} \x1B[0m`;
|
|
26
|
+
const colorGrey = (arg) => `\x1B[90m ${arg ?? ""} \x1B[0m`;
|
|
27
|
+
const colorBlue = (arg) => `\x1B[34m ${arg ?? ""} \x1B[0m`;
|
|
28
|
+
const reporter = (violToFormat) => {
|
|
29
|
+
if (violToFormat.length === 0)
|
|
30
|
+
return "";
|
|
31
|
+
const lineBreak = "\n\n";
|
|
32
|
+
const horizontalLine = "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500";
|
|
33
|
+
return violToFormat.map((violation) => {
|
|
34
|
+
const errorBody = violation.nodes.map((node) => {
|
|
35
|
+
const selector = node.target.join(", ");
|
|
36
|
+
const expectedText = `Expected the HTML found at $('${selector}') to have no violations:${lineBreak}`;
|
|
37
|
+
let violationHelpUrl = "";
|
|
38
|
+
if (violation.helpUrl)
|
|
39
|
+
violationHelpUrl = `You can find more information on this issue here:
|
|
40
|
+
${colorBlue(
|
|
41
|
+
violation.helpUrl
|
|
42
|
+
)}`;
|
|
43
|
+
return `${expectedText + colorGrey(node.html) + lineBreak}Received:${lineBreak}${(0, import_jest_matcher_utils.printReceived)(
|
|
44
|
+
`${violation.help} (${violation.id})`
|
|
45
|
+
)}${lineBreak}${colorYellow(
|
|
46
|
+
node.failureSummary
|
|
47
|
+
)}${lineBreak}${violationHelpUrl}`;
|
|
48
|
+
}).join(lineBreak);
|
|
49
|
+
return errorBody;
|
|
50
|
+
}).join(lineBreak + horizontalLine + lineBreak);
|
|
51
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var shouldIgnoreNodeViolation_exports = {};
|
|
20
|
+
__export(shouldIgnoreNodeViolation_exports, {
|
|
21
|
+
shouldIgnoreNodeViolation: () => shouldIgnoreNodeViolation
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(shouldIgnoreNodeViolation_exports);
|
|
24
|
+
const dataAttributeRegexp = /(data-[\S]*)=["']([\S]*)["']/gm;
|
|
25
|
+
const shouldIgnoreNodeViolation = (node, violation) => [...node.html.matchAll(dataAttributeRegexp)].map(([fullMatch, dataKey, dataValue]) => ({
|
|
26
|
+
fullMatch,
|
|
27
|
+
dataKey,
|
|
28
|
+
dataValue
|
|
29
|
+
})).some(
|
|
30
|
+
({ dataKey, dataValue }) => dataKey === `data-axe-ignore-${violation.id}` && dataValue === "true"
|
|
31
|
+
);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var toHaveNoViolations_exports = {};
|
|
20
|
+
__export(toHaveNoViolations_exports, {
|
|
21
|
+
toHaveNoViolations: () => toHaveNoViolations
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(toHaveNoViolations_exports);
|
|
24
|
+
var import_getMessageAndPass = require("./getMessageAndPass.js");
|
|
25
|
+
var import_shouldIgnoreNodeViolation = require("./shouldIgnoreNodeViolation.js");
|
|
26
|
+
const toHaveNoViolations = {
|
|
27
|
+
toHaveNoViolations(results) {
|
|
28
|
+
const { violations } = results;
|
|
29
|
+
const finalViolations = [];
|
|
30
|
+
violations.forEach((violation) => {
|
|
31
|
+
const { nodes } = violation;
|
|
32
|
+
const newNodes = [];
|
|
33
|
+
nodes.forEach((node) => {
|
|
34
|
+
if (!(0, import_shouldIgnoreNodeViolation.shouldIgnoreNodeViolation)(node, violation))
|
|
35
|
+
newNodes.push(node);
|
|
36
|
+
});
|
|
37
|
+
if (newNodes.length > 0) {
|
|
38
|
+
finalViolations.push({ ...violation, nodes: newNodes });
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return { actual: violations, ...(0, import_getMessageAndPass.getMessageAndPass)(finalViolations) };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
@@ -94,7 +94,7 @@ const jestConfig = {
|
|
|
94
94
|
url: `http://localhost:3111${basePath}`,
|
|
95
95
|
resources: 'usable',
|
|
96
96
|
},
|
|
97
|
-
testEnvironment: '
|
|
97
|
+
testEnvironment: path.resolve(__dirname, './ExtendedJSDomEnv.cjs'),
|
|
98
98
|
watchPlugins: [
|
|
99
99
|
'jest-watch-typeahead/filename',
|
|
100
100
|
'jest-watch-typeahead/testname',
|
|
@@ -23,8 +23,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
));
|
|
24
24
|
var import_runtime = require("regenerator-runtime/runtime");
|
|
25
25
|
var import_jest_globals = require("@testing-library/jest-dom/jest-globals");
|
|
26
|
-
var import_jest_axe = __toESM(require("jest-axe"), 1);
|
|
27
26
|
var import_resize_observer_polyfill = __toESM(require("resize-observer-polyfill"), 1);
|
|
27
|
+
var import_axe_core = require("./extended/axe-core");
|
|
28
28
|
var import_matchMedia = require("./mocks/matchMedia.js");
|
|
29
29
|
var import_pui_diagnostics = require("./mocks/pui-diagnostics.js");
|
|
30
30
|
const originalError = console.error;
|
|
@@ -47,7 +47,7 @@ console.error = (...args) => {
|
|
|
47
47
|
return originalError(...args);
|
|
48
48
|
};
|
|
49
49
|
if (expect)
|
|
50
|
-
expect.extend(
|
|
50
|
+
expect.extend(import_axe_core.toHaveNoViolations);
|
|
51
51
|
const addElementToBody = (element) => {
|
|
52
52
|
const documentEle = (window || {}).document;
|
|
53
53
|
if (!documentEle)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const { TestEnvironment } = require('jest-environment-jsdom');
|
|
2
|
+
|
|
3
|
+
// ICE platform is meant to be run on node > 18
|
|
4
|
+
// "jest-environment-jsdom": "~29.6.3" is instead meant to support node >16
|
|
5
|
+
// features that are supported since node 17 & 18 are not supported in jsdom env
|
|
6
|
+
// the limitation is not relevant for us since we are already running on node 18 anyway,
|
|
7
|
+
// this "ExtendedJSDomEnv" is an extension of the
|
|
8
|
+
// jest.config.cjs
|
|
9
|
+
// {
|
|
10
|
+
// ...
|
|
11
|
+
// testEnvironment: 'jsdom'
|
|
12
|
+
// ...
|
|
13
|
+
// }
|
|
14
|
+
// that actually uses node 18 features that are not supported in "jest-environment-jsdom": "~29.6.3"
|
|
15
|
+
|
|
16
|
+
// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string
|
|
17
|
+
class FixJSDOMEnvironment extends TestEnvironment {
|
|
18
|
+
constructor(...args) {
|
|
19
|
+
super(...args);
|
|
20
|
+
|
|
21
|
+
// From here on we are using "node" (currently running version of it) to polyfill jsdom this.global
|
|
22
|
+
|
|
23
|
+
// FIXME https://github.com/jsdom/jsdom/issues/3363
|
|
24
|
+
if (structuredClone) this.global.structuredClone = structuredClone;
|
|
25
|
+
|
|
26
|
+
// FIXME https://github.com/jsdom/jsdom/issues/1724
|
|
27
|
+
if (fetch) this.global.fetch = fetch;
|
|
28
|
+
if (Headers) this.global.Headers = Headers;
|
|
29
|
+
if (Request) this.global.Request = Request;
|
|
30
|
+
if (Response) this.global.Response = Response;
|
|
31
|
+
|
|
32
|
+
// FIXME https://github.com/jsdom/jsdom/issues/1721
|
|
33
|
+
if (URL) this.global.URL = URL;
|
|
34
|
+
if (Blob) this.global.Blob = Blob;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
module.exports = FixJSDOMEnvironment;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { matcherHint } from "jest-matcher-utils";
|
|
2
|
+
import { reporter } from "./reporter.js";
|
|
3
|
+
const getMessageAndPass = (violations) => {
|
|
4
|
+
const formatedViolations = reporter(violations);
|
|
5
|
+
const pass = formatedViolations.length === 0;
|
|
6
|
+
if (pass)
|
|
7
|
+
return { message: () => "", pass };
|
|
8
|
+
return {
|
|
9
|
+
message: () => `${matcherHint(".toHaveNoViolations")}
|
|
10
|
+
|
|
11
|
+
${formatedViolations}`,
|
|
12
|
+
pass
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
getMessageAndPass
|
|
17
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { printReceived } from "jest-matcher-utils";
|
|
2
|
+
const colorYellow = (arg) => `\x1B[93m ${arg ?? ""} \x1B[0m`;
|
|
3
|
+
const colorGrey = (arg) => `\x1B[90m ${arg ?? ""} \x1B[0m`;
|
|
4
|
+
const colorBlue = (arg) => `\x1B[34m ${arg ?? ""} \x1B[0m`;
|
|
5
|
+
const reporter = (violToFormat) => {
|
|
6
|
+
if (violToFormat.length === 0)
|
|
7
|
+
return "";
|
|
8
|
+
const lineBreak = "\n\n";
|
|
9
|
+
const horizontalLine = "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500";
|
|
10
|
+
return violToFormat.map((violation) => {
|
|
11
|
+
const errorBody = violation.nodes.map((node) => {
|
|
12
|
+
const selector = node.target.join(", ");
|
|
13
|
+
const expectedText = `Expected the HTML found at $('${selector}') to have no violations:${lineBreak}`;
|
|
14
|
+
let violationHelpUrl = "";
|
|
15
|
+
if (violation.helpUrl)
|
|
16
|
+
violationHelpUrl = `You can find more information on this issue here:
|
|
17
|
+
${colorBlue(
|
|
18
|
+
violation.helpUrl
|
|
19
|
+
)}`;
|
|
20
|
+
return `${expectedText + colorGrey(node.html) + lineBreak}Received:${lineBreak}${printReceived(
|
|
21
|
+
`${violation.help} (${violation.id})`
|
|
22
|
+
)}${lineBreak}${colorYellow(
|
|
23
|
+
node.failureSummary
|
|
24
|
+
)}${lineBreak}${violationHelpUrl}`;
|
|
25
|
+
}).join(lineBreak);
|
|
26
|
+
return errorBody;
|
|
27
|
+
}).join(lineBreak + horizontalLine + lineBreak);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
reporter
|
|
31
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const dataAttributeRegexp = /(data-[\S]*)=["']([\S]*)["']/gm;
|
|
2
|
+
const shouldIgnoreNodeViolation = (node, violation) => [...node.html.matchAll(dataAttributeRegexp)].map(([fullMatch, dataKey, dataValue]) => ({
|
|
3
|
+
fullMatch,
|
|
4
|
+
dataKey,
|
|
5
|
+
dataValue
|
|
6
|
+
})).some(
|
|
7
|
+
({ dataKey, dataValue }) => dataKey === `data-axe-ignore-${violation.id}` && dataValue === "true"
|
|
8
|
+
);
|
|
9
|
+
export {
|
|
10
|
+
shouldIgnoreNodeViolation
|
|
11
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getMessageAndPass } from "./getMessageAndPass.js";
|
|
2
|
+
import { shouldIgnoreNodeViolation } from "./shouldIgnoreNodeViolation.js";
|
|
3
|
+
const toHaveNoViolations = {
|
|
4
|
+
toHaveNoViolations(results) {
|
|
5
|
+
const { violations } = results;
|
|
6
|
+
const finalViolations = [];
|
|
7
|
+
violations.forEach((violation) => {
|
|
8
|
+
const { nodes } = violation;
|
|
9
|
+
const newNodes = [];
|
|
10
|
+
nodes.forEach((node) => {
|
|
11
|
+
if (!shouldIgnoreNodeViolation(node, violation))
|
|
12
|
+
newNodes.push(node);
|
|
13
|
+
});
|
|
14
|
+
if (newNodes.length > 0) {
|
|
15
|
+
finalViolations.push({ ...violation, nodes: newNodes });
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return { actual: violations, ...getMessageAndPass(finalViolations) };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
toHaveNoViolations
|
|
23
|
+
};
|
|
@@ -94,7 +94,7 @@ const jestConfig = {
|
|
|
94
94
|
url: `http://localhost:3111${basePath}`,
|
|
95
95
|
resources: 'usable',
|
|
96
96
|
},
|
|
97
|
-
testEnvironment: '
|
|
97
|
+
testEnvironment: path.resolve(__dirname, './ExtendedJSDomEnv.cjs'),
|
|
98
98
|
watchPlugins: [
|
|
99
99
|
'jest-watch-typeahead/filename',
|
|
100
100
|
'jest-watch-typeahead/testname',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "regenerator-runtime/runtime";
|
|
2
2
|
import "@testing-library/jest-dom/jest-globals";
|
|
3
|
-
import jestAxe from "jest-axe";
|
|
4
3
|
import ResizeObserver from "resize-observer-polyfill";
|
|
4
|
+
import { toHaveNoViolations } from "./extended/axe-core";
|
|
5
5
|
import { addMatchMedia } from "./mocks/matchMedia.js";
|
|
6
6
|
import { logger } from "./mocks/pui-diagnostics.js";
|
|
7
7
|
const originalError = console.error;
|
|
@@ -24,7 +24,7 @@ console.error = (...args) => {
|
|
|
24
24
|
return originalError(...args);
|
|
25
25
|
};
|
|
26
26
|
if (expect)
|
|
27
|
-
expect.extend(
|
|
27
|
+
expect.extend(toHaveNoViolations);
|
|
28
28
|
const addElementToBody = (element) => {
|
|
29
29
|
const documentEle = (window || {}).document;
|
|
30
30
|
if (!documentEle)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { toHaveNoViolations } from './toHaveNoViolations.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AxeResults, Result } from 'axe-core';
|
|
2
|
+
export declare const toHaveNoViolations: {
|
|
3
|
+
toHaveNoViolations(results: AxeResults): {
|
|
4
|
+
message: () => string;
|
|
5
|
+
pass: true;
|
|
6
|
+
actual: Result[];
|
|
7
|
+
} | {
|
|
8
|
+
message: () => string;
|
|
9
|
+
pass: false;
|
|
10
|
+
actual: Result[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
File without changes
|