html-validate 8.7.3 → 8.8.0
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/browser.js +7 -21
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/cli.js +468 -451
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/core-browser.js +9 -20
- package/dist/cjs/core-browser.js.map +1 -1
- package/dist/cjs/core-nodejs.js +203 -297
- package/dist/cjs/core-nodejs.js.map +1 -1
- package/dist/cjs/core.js +9511 -10450
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/elements.js +2293 -2296
- package/dist/cjs/elements.js.map +1 -1
- package/dist/cjs/html-validate.js +148 -169
- package/dist/cjs/html-validate.js.map +1 -1
- package/dist/cjs/html5.js.map +1 -1
- package/dist/cjs/index.js +8 -21
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/jest-diff.js +26 -36
- package/dist/cjs/jest-diff.js.map +1 -1
- package/dist/cjs/jest.js +8 -8
- package/dist/cjs/jest.js.map +1 -1
- package/dist/cjs/matcher-utils.js +12 -28
- package/dist/cjs/matcher-utils.js.map +1 -1
- package/dist/cjs/matchers-jestonly.js +38 -47
- package/dist/cjs/matchers-jestonly.js.map +1 -1
- package/dist/cjs/matchers.js +196 -196
- package/dist/cjs/matchers.js.map +1 -1
- package/dist/cjs/meta-helper.js +40 -60
- package/dist/cjs/meta-helper.js.map +1 -1
- package/dist/cjs/test-utils.js +26 -47
- package/dist/cjs/test-utils.js.map +1 -1
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/cjs/utils/natural-join.js +10 -23
- package/dist/cjs/utils/natural-join.js.map +1 -1
- package/dist/cjs/vitest.js +6 -6
- package/dist/cjs/vitest.js.map +1 -1
- package/dist/es/browser.js +2 -2
- package/dist/es/cli.js +467 -454
- package/dist/es/cli.js.map +1 -1
- package/dist/es/core-browser.js +10 -21
- package/dist/es/core-browser.js.map +1 -1
- package/dist/es/core-nodejs.js +204 -299
- package/dist/es/core-nodejs.js.map +1 -1
- package/dist/es/core.js +9506 -10451
- package/dist/es/core.js.map +1 -1
- package/dist/es/elements.js +2293 -2296
- package/dist/es/elements.js.map +1 -1
- package/dist/es/html-validate.js +150 -171
- package/dist/es/html-validate.js.map +1 -1
- package/dist/es/html5.js.map +1 -1
- package/dist/es/index.js +3 -3
- package/dist/es/jest-diff.js +11 -21
- package/dist/es/jest-diff.js.map +1 -1
- package/dist/es/jest.js +8 -8
- package/dist/es/jest.js.map +1 -1
- package/dist/es/matcher-utils.js +12 -28
- package/dist/es/matcher-utils.js.map +1 -1
- package/dist/es/matchers-jestonly.js +39 -48
- package/dist/es/matchers-jestonly.js.map +1 -1
- package/dist/es/matchers.js +196 -196
- package/dist/es/matchers.js.map +1 -1
- package/dist/es/meta-helper.js +40 -60
- package/dist/es/meta-helper.js.map +1 -1
- package/dist/es/test-utils.js +26 -47
- package/dist/es/test-utils.js.map +1 -1
- package/dist/es/utils/natural-join.js +10 -23
- package/dist/es/utils/natural-join.js.map +1 -1
- package/dist/es/vitest.js +6 -6
- package/dist/es/vitest.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +62 -30
- package/dist/types/index.d.ts +89 -32
- package/package.json +22 -18
|
@@ -1,67 +1,58 @@
|
|
|
1
1
|
import kleur from 'kleur';
|
|
2
2
|
import { toMatchSnapshot, toMatchInlineSnapshot } from 'jest-snapshot';
|
|
3
|
-
import {
|
|
3
|
+
import { I as codeframe } from './core.js';
|
|
4
4
|
import { g as getResults } from './matchers.js';
|
|
5
5
|
import { d as diverge, i as isThenable } from './matcher-utils.js';
|
|
6
6
|
|
|
7
7
|
const options$1 = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
showLink: false,
|
|
9
|
+
showSummary: false,
|
|
10
|
+
showSelector: true
|
|
11
11
|
};
|
|
12
12
|
function createMatcher$1() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
* the implementation works but the declarations doesn't allow it */
|
|
24
|
-
return toMatchSnapshot.call(this, snapshot, ...rest);
|
|
25
|
-
}
|
|
26
|
-
return diverge(toMatchCodeframe);
|
|
13
|
+
function toMatchCodeframe(actual, ...rest) {
|
|
14
|
+
const filename = this.testPath ?? "inline";
|
|
15
|
+
const results = getResults(filename, actual);
|
|
16
|
+
const enabled = kleur.enabled;
|
|
17
|
+
kleur.enabled = false;
|
|
18
|
+
const snapshot = codeframe(results, options$1).replace(/\s+$/gm, "");
|
|
19
|
+
kleur.enabled = enabled;
|
|
20
|
+
return toMatchSnapshot.call(this, snapshot, ...rest);
|
|
21
|
+
}
|
|
22
|
+
return diverge(toMatchCodeframe);
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
const options = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
showLink: false,
|
|
27
|
+
showSummary: false,
|
|
28
|
+
showSelector: true
|
|
33
29
|
};
|
|
34
30
|
function toMatchInlineCodeframeImpl(context, actual, ...rest) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
kleur.enabled = enabled;
|
|
43
|
-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call --
|
|
44
|
-
* the implementation works but the declarations doesn't allow it */
|
|
45
|
-
return toMatchInlineSnapshot.call(context, snapshot, ...rest);
|
|
31
|
+
const filename = context.testPath ?? "inline";
|
|
32
|
+
const results = getResults(filename, actual);
|
|
33
|
+
const enabled = kleur.enabled;
|
|
34
|
+
kleur.enabled = false;
|
|
35
|
+
const snapshot = codeframe(results, options).replace(/\s+$/gm, "");
|
|
36
|
+
kleur.enabled = enabled;
|
|
37
|
+
return toMatchInlineSnapshot.call(context, snapshot, ...rest);
|
|
46
38
|
}
|
|
47
39
|
function createMatcher() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
62
|
-
}
|
|
40
|
+
function toMatchInlineCodeframe(actual, ...rest) {
|
|
41
|
+
const context = {
|
|
42
|
+
...this,
|
|
43
|
+
/* Capture the original stack frames as they are needed by "jest-snapshot"
|
|
44
|
+
* to determine where to write the inline snapshots. When resolving the
|
|
45
|
+
* promise the original stack frames are lost and the snapshot will be
|
|
46
|
+
* written in this files instaed. */
|
|
47
|
+
error: new Error()
|
|
48
|
+
};
|
|
49
|
+
if (isThenable(actual)) {
|
|
50
|
+
return actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));
|
|
51
|
+
} else {
|
|
52
|
+
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
63
53
|
}
|
|
64
|
-
|
|
54
|
+
}
|
|
55
|
+
return toMatchInlineCodeframe;
|
|
65
56
|
}
|
|
66
57
|
|
|
67
58
|
export { createMatcher as a, createMatcher$1 as c };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matchers-jestonly.js","sources":["
|
|
1
|
+
{"version":3,"file":"matchers-jestonly.js","sources":["../../src/jest/matchers/to-match-codeframe.ts","../../src/jest/matchers/to-match-inline-codeframe.ts"],"sourcesContent":["import kleur from \"kleur\";\nimport { toMatchSnapshot } from \"jest-snapshot\";\nimport { codeframe, type CodeframeOptions } from \"../../formatters/codeframe\";\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype MatcherContext,\n\ttype MatcherResult,\n\ttype MaybeAsyncCallback,\n\tdiverge,\n} from \"../utils\";\nimport { getResults } from \"./get-results\";\n\nconst options: CodeframeOptions = {\n\tshowLink: false,\n\tshowSummary: false,\n\tshowSelector: true,\n};\n\nfunction createMatcher(): MaybeAsyncCallback<Report | string, [Array<string | object>]> {\n\tfunction toMatchCodeframe(\n\t\tthis: MatcherContext,\n\t\tactual: Report | string,\n\t\t...rest: Array<string | object>\n\t): MatcherResult {\n\t\t/* istanbul ignore next: cant figure out when this would be unset */\n\t\tconst filename = this.testPath ?? \"inline\";\n\t\tconst results = getResults(filename, actual);\n\t\tconst enabled = kleur.enabled;\n\t\tkleur.enabled = false;\n\t\tconst snapshot = codeframe(results, options).replace(/\\s+$/gm, \"\");\n\t\tkleur.enabled = enabled;\n\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call --\n\t\t * the implementation works but the declarations doesn't allow it */\n\t\treturn (toMatchSnapshot as any).call(this, snapshot, ...rest);\n\t}\n\treturn diverge(toMatchCodeframe);\n}\n\nexport { createMatcher as toMatchCodeframe };\n","import kleur from \"kleur\";\nimport { toMatchInlineSnapshot } from \"jest-snapshot\";\nimport { codeframe, type CodeframeOptions } from \"../../formatters/codeframe\";\nimport { type Report } from \"../../reporter\";\nimport { type MatcherContext, type MatcherResult, isThenable } from \"../utils\";\nimport { getResults } from \"./get-results\";\n\nconst options: CodeframeOptions = {\n\tshowLink: false,\n\tshowSummary: false,\n\tshowSelector: true,\n};\n\nfunction toMatchInlineCodeframeImpl(\n\tcontext: MatcherContext,\n\tactual: Report | string,\n\t...rest: Array<string | object>\n): MatcherResult {\n\t/* istanbul ignore next: cant figure out when this would be unset */\n\tconst filename = context.testPath ?? \"inline\";\n\tconst results = getResults(filename, actual);\n\tconst enabled = kleur.enabled;\n\tkleur.enabled = false;\n\tconst snapshot = codeframe(results, options).replace(/\\s+$/gm, \"\");\n\tkleur.enabled = enabled;\n\n\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call --\n\t * the implementation works but the declarations doesn't allow it */\n\treturn (toMatchInlineSnapshot as any).call(context, snapshot, ...rest);\n}\n\ntype ToMatchInlineCodeframeMatcher = (\n\tthis: MatcherContext,\n\tactual: Report | Promise<Report> | string,\n\t...rest: Array<string | object>\n) => MatcherResult | Promise<MatcherResult>;\n\nfunction createMatcher(): ToMatchInlineCodeframeMatcher {\n\tfunction toMatchInlineCodeframe(\n\t\tthis: MatcherContext,\n\t\tactual: Report | Promise<Report> | string,\n\t\t...rest: Array<string | object>\n\t): MatcherResult | Promise<MatcherResult> {\n\t\tconst context = {\n\t\t\t...this,\n\n\t\t\t/* Capture the original stack frames as they are needed by \"jest-snapshot\"\n\t\t\t * to determine where to write the inline snapshots. When resolving the\n\t\t\t * promise the original stack frames are lost and the snapshot will be\n\t\t\t * written in this files instaed. */\n\t\t\terror: new Error(),\n\t\t};\n\n\t\tif (isThenable(actual)) {\n\t\t\treturn actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));\n\t\t} else {\n\t\t\treturn toMatchInlineCodeframeImpl(context, actual, ...rest);\n\t\t}\n\t}\n\n\treturn toMatchInlineCodeframe;\n}\n\nexport { createMatcher as toMatchInlineCodeframe };\n"],"names":["options","createMatcher"],"mappings":";;;;;;AAYA,MAAMA,SAA4B,GAAA;AAAA,EACjC,QAAU,EAAA,KAAA;AAAA,EACV,WAAa,EAAA,KAAA;AAAA,EACb,YAAc,EAAA,IAAA;AACf,CAAA,CAAA;AAEA,SAASC,eAA+E,GAAA;AACvF,EAAS,SAAA,gBAAA,CAER,WACG,IACa,EAAA;AAEhB,IAAM,MAAA,QAAA,GAAW,KAAK,QAAY,IAAA,QAAA,CAAA;AAClC,IAAM,MAAA,OAAA,GAAU,UAAW,CAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAC3C,IAAA,MAAM,UAAU,KAAM,CAAA,OAAA,CAAA;AACtB,IAAA,KAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAChB,IAAA,MAAM,WAAW,SAAU,CAAA,OAAA,EAASD,SAAO,CAAE,CAAA,OAAA,CAAQ,UAAU,EAAE,CAAA,CAAA;AACjE,IAAA,KAAA,CAAM,OAAU,GAAA,OAAA,CAAA;AAIhB,IAAA,OAAQ,eAAwB,CAAA,IAAA,CAAK,IAAM,EAAA,QAAA,EAAU,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7D;AACA,EAAA,OAAO,QAAQ,gBAAgB,CAAA,CAAA;AAChC;;AC9BA,MAAM,OAA4B,GAAA;AAAA,EACjC,QAAU,EAAA,KAAA;AAAA,EACV,WAAa,EAAA,KAAA;AAAA,EACb,YAAc,EAAA,IAAA;AACf,CAAA,CAAA;AAEA,SAAS,0BAAA,CACR,OACA,EAAA,MAAA,EAAA,GACG,IACa,EAAA;AAEhB,EAAM,MAAA,QAAA,GAAW,QAAQ,QAAY,IAAA,QAAA,CAAA;AACrC,EAAM,MAAA,OAAA,GAAU,UAAW,CAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAC3C,EAAA,MAAM,UAAU,KAAM,CAAA,OAAA,CAAA;AACtB,EAAA,KAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAChB,EAAA,MAAM,WAAW,SAAU,CAAA,OAAA,EAAS,OAAO,CAAE,CAAA,OAAA,CAAQ,UAAU,EAAE,CAAA,CAAA;AACjE,EAAA,KAAA,CAAM,OAAU,GAAA,OAAA,CAAA;AAIhB,EAAA,OAAQ,qBAA8B,CAAA,IAAA,CAAK,OAAS,EAAA,QAAA,EAAU,GAAG,IAAI,CAAA,CAAA;AACtE,CAAA;AAQA,SAAS,aAA+C,GAAA;AACvD,EAAS,SAAA,sBAAA,CAER,WACG,IACsC,EAAA;AACzC,IAAA,MAAM,OAAU,GAAA;AAAA,MACf,GAAG,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAMH,KAAA,EAAO,IAAI,KAAM,EAAA;AAAA,KAClB,CAAA;AAEA,IAAI,IAAA,UAAA,CAAW,MAAM,CAAG,EAAA;AACvB,MAAO,OAAA,MAAA,CAAO,KAAK,CAAC,QAAA,KAAa,2BAA2B,OAAS,EAAA,QAAA,EAAU,GAAG,IAAI,CAAC,CAAA,CAAA;AAAA,KACjF,MAAA;AACN,MAAA,OAAO,0BAA2B,CAAA,OAAA,EAAS,MAAQ,EAAA,GAAG,IAAI,CAAA,CAAA;AAAA,KAC3D;AAAA,GACD;AAEA,EAAO,OAAA,sBAAA,CAAA;AACR;;;;"}
|
package/dist/es/matchers.js
CHANGED
|
@@ -3,234 +3,234 @@ import { d as deepmerge, H as HtmlValidate } from './core.js';
|
|
|
3
3
|
import { F as FileSystemConfigLoader } from './core-nodejs.js';
|
|
4
4
|
|
|
5
5
|
function createMatcher$4() {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
6
|
+
function toBeValid(report) {
|
|
7
|
+
if (report.valid) {
|
|
8
|
+
return {
|
|
9
|
+
pass: true,
|
|
10
|
+
message: (
|
|
11
|
+
/* istanbul ignore next */
|
|
12
|
+
() => "Result should not contain error"
|
|
13
|
+
)
|
|
14
|
+
};
|
|
15
|
+
} else {
|
|
16
|
+
const firstError = report.results[0].messages[0];
|
|
17
|
+
return {
|
|
18
|
+
pass: false,
|
|
19
|
+
message: () => `Result should be valid but had error "${firstError.message}"`
|
|
20
|
+
};
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
}
|
|
23
|
+
return diverge(toBeValid);
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
function createMatcher$3() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
function toBeInvalid(report) {
|
|
28
|
+
if (report.valid) {
|
|
29
|
+
return {
|
|
30
|
+
pass: false,
|
|
31
|
+
message: () => "Result should be invalid but had no errors"
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
return {
|
|
35
|
+
pass: true,
|
|
36
|
+
message: (
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
() => "Result should not contain error"
|
|
39
|
+
)
|
|
40
|
+
};
|
|
38
41
|
}
|
|
39
|
-
|
|
42
|
+
}
|
|
43
|
+
return diverge(toBeInvalid);
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
function isMessage(arg) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
arg.offset ||
|
|
50
|
-
arg.line ||
|
|
51
|
-
arg.column ||
|
|
52
|
-
arg.size ||
|
|
53
|
-
arg.selector ||
|
|
54
|
-
arg.context);
|
|
47
|
+
if (!arg) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return Boolean(
|
|
51
|
+
arg.ruleId || arg.severity || arg.message || arg.offset || arg.line || arg.column || arg.size || arg.selector || arg.context
|
|
52
|
+
);
|
|
55
53
|
}
|
|
56
54
|
function isConfig(arg) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
55
|
+
if (!arg) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return Boolean(
|
|
59
|
+
arg.root || arg.extends || arg.elements || arg.plugin || arg.transform || arg.rules
|
|
60
|
+
);
|
|
61
61
|
}
|
|
62
62
|
function isString(arg) {
|
|
63
|
-
|
|
63
|
+
return typeof arg === "string";
|
|
64
64
|
}
|
|
65
65
|
function getMarkup(src) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw new Error(`Failed to get markup from "${typeof src}" argument`);
|
|
75
|
-
}
|
|
66
|
+
if (typeof HTMLElement !== "undefined" && src instanceof HTMLElement) {
|
|
67
|
+
return src.outerHTML;
|
|
68
|
+
}
|
|
69
|
+
if (typeof src === "string") {
|
|
70
|
+
return src;
|
|
71
|
+
} else {
|
|
72
|
+
throw new Error(`Failed to get markup from "${typeof src}" argument`);
|
|
73
|
+
}
|
|
76
74
|
}
|
|
77
75
|
function createMatcher$2(expect, diff) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
function toHTMLValidate(actual, arg0, arg1, arg2) {
|
|
77
|
+
const markup = getMarkup(actual);
|
|
78
|
+
const message = isMessage(arg0) ? arg0 : void 0;
|
|
79
|
+
const config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : void 0;
|
|
80
|
+
const filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2;
|
|
81
|
+
return toHTMLValidateImpl.call(this, expect, diff, markup, message, config, filename);
|
|
82
|
+
}
|
|
83
|
+
return diverge(toHTMLValidate);
|
|
86
84
|
}
|
|
87
85
|
function toHTMLValidateImpl(expect, diff, actual, expectedError, userConfig, filename) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
"void-style": "off",
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const config = deepmerge(defaultConfig, userConfig !== null && userConfig !== void 0 ? userConfig : {});
|
|
97
|
-
/* istanbul ignore next: cant figure out when this would be unset */
|
|
98
|
-
const actualFilename = (_a = filename !== null && filename !== void 0 ? filename : this.testPath) !== null && _a !== void 0 ? _a : "inline";
|
|
99
|
-
const loader = new FileSystemConfigLoader({
|
|
100
|
-
extends: ["html-validate:recommended"],
|
|
101
|
-
});
|
|
102
|
-
const htmlvalidate = new HtmlValidate(loader);
|
|
103
|
-
const report = htmlvalidate.validateStringSync(actual, actualFilename, config);
|
|
104
|
-
const pass = report.valid;
|
|
105
|
-
const result = report.results[0];
|
|
106
|
-
if (pass) {
|
|
107
|
-
return { pass, message: () => "HTML is valid when an error was expected" };
|
|
86
|
+
const defaultConfig = {
|
|
87
|
+
rules: {
|
|
88
|
+
/* jsdom normalizes style so disabling rule when using this matcher or it
|
|
89
|
+
* gets quite noisy when configured with self-closing */
|
|
90
|
+
"void-style": "off"
|
|
108
91
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
92
|
+
};
|
|
93
|
+
const config = deepmerge(defaultConfig, userConfig ?? {});
|
|
94
|
+
const actualFilename = filename ?? this.testPath ?? "inline";
|
|
95
|
+
const loader = new FileSystemConfigLoader({
|
|
96
|
+
extends: ["html-validate:recommended"]
|
|
97
|
+
});
|
|
98
|
+
const htmlvalidate = new HtmlValidate(loader);
|
|
99
|
+
const report = htmlvalidate.validateStringSync(actual, actualFilename, config);
|
|
100
|
+
const pass = report.valid;
|
|
101
|
+
const result = report.results[0];
|
|
102
|
+
if (pass) {
|
|
103
|
+
return { pass, message: () => "HTML is valid when an error was expected" };
|
|
104
|
+
} else {
|
|
105
|
+
if (expectedError) {
|
|
106
|
+
const actual2 = result.messages;
|
|
107
|
+
const expected = expect.arrayContaining([expect.objectContaining(expectedError)]);
|
|
108
|
+
const errorPass = this.equals(actual2, expected);
|
|
109
|
+
const diffString = diff ? diff(expected, actual2, {
|
|
110
|
+
expand: this.expand,
|
|
111
|
+
aAnnotation: "Expected error",
|
|
112
|
+
bAnnotation: "Actual error"
|
|
113
|
+
}) : (
|
|
114
|
+
/* istanbul ignore next */
|
|
115
|
+
void 0
|
|
116
|
+
);
|
|
117
|
+
const hint = this.utils.matcherHint(".not.toHTMLValidate", void 0, void 0, {
|
|
118
|
+
comment: "expected error"
|
|
119
|
+
});
|
|
120
|
+
const expectedErrorMessage = () => [
|
|
121
|
+
hint,
|
|
122
|
+
"",
|
|
123
|
+
"Expected error to be present:",
|
|
124
|
+
this.utils.printExpected(expectedError),
|
|
125
|
+
/* istanbul ignore next */
|
|
126
|
+
diffString ? `
|
|
127
|
+
${diffString}` : ""
|
|
128
|
+
].join("\n");
|
|
129
|
+
return { pass: !errorPass, message: expectedErrorMessage, actual: actual2, expected };
|
|
138
130
|
}
|
|
131
|
+
const errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);
|
|
132
|
+
return {
|
|
133
|
+
pass,
|
|
134
|
+
message: () => ["Expected HTML to be valid but had the following errors:", ""].concat(errors).join("\n")
|
|
135
|
+
};
|
|
136
|
+
}
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
function toHaveErrorImpl(context, expect, diff, actual, expected) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
140
|
+
const flattened = flattenMessages(actual);
|
|
141
|
+
const matcher = [expect.objectContaining(expected)];
|
|
142
|
+
const pass = context.equals(flattened, matcher);
|
|
143
|
+
const diffString = diff ? diff(matcher, flattened, { expand: context.expand }) : (
|
|
144
|
+
/* istanbul ignore next */
|
|
145
|
+
void 0
|
|
146
|
+
);
|
|
147
|
+
const hint = context.utils.matcherHint(".toHaveError");
|
|
148
|
+
const prettyExpected = context.utils.printExpected(matcher);
|
|
149
|
+
const prettyReceived = context.utils.printReceived(flattened);
|
|
150
|
+
const resultMessage = () => {
|
|
151
|
+
return [
|
|
152
|
+
hint,
|
|
153
|
+
"",
|
|
154
|
+
"Expected error to equal:",
|
|
155
|
+
` ${prettyExpected}`,
|
|
156
|
+
"Received:",
|
|
157
|
+
` ${prettyReceived}`,
|
|
158
|
+
/* istanbul ignore next */
|
|
159
|
+
diffString ? `
|
|
160
|
+
Difference:
|
|
161
|
+
|
|
162
|
+
${diffString}` : ""
|
|
163
|
+
].join("\n");
|
|
164
|
+
};
|
|
165
|
+
return { pass, message: resultMessage, actual: flattened, expected: matcher };
|
|
163
166
|
}
|
|
164
167
|
function createMatcher$1(expect, diff) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
else {
|
|
178
|
-
return toHaveErrorImpl(this, expect, diff, actual, arg1);
|
|
179
|
-
}
|
|
168
|
+
function toHaveError(actual, arg1, arg2, arg3) {
|
|
169
|
+
if (typeof arg1 === "string") {
|
|
170
|
+
const expected = {
|
|
171
|
+
ruleId: arg1,
|
|
172
|
+
message: arg2
|
|
173
|
+
};
|
|
174
|
+
if (arg3) {
|
|
175
|
+
expected.context = arg3;
|
|
176
|
+
}
|
|
177
|
+
return toHaveErrorImpl(this, expect, diff, actual, expected);
|
|
178
|
+
} else {
|
|
179
|
+
return toHaveErrorImpl(this, expect, diff, actual, arg1);
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
}
|
|
182
|
+
return diverge(toHaveError);
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
/* eslint-disable prefer-template -- technical debt, should be refactored */
|
|
185
185
|
function createMatcher(expect, diff) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
186
|
+
function toHaveErrors(report, errors) {
|
|
187
|
+
const flattened = flattenMessages(report);
|
|
188
|
+
const matcher = errors.map((entry) => {
|
|
189
|
+
if (Array.isArray(entry)) {
|
|
190
|
+
const [ruleId, message] = entry;
|
|
191
|
+
return expect.objectContaining({ ruleId, message });
|
|
192
|
+
} else {
|
|
193
|
+
return expect.objectContaining(entry);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
const pass = this.equals(flattened, matcher);
|
|
197
|
+
const diffString = diff ? diff(matcher, flattened, { expand: this.expand }) : (
|
|
198
|
+
/* istanbul ignore next */
|
|
199
|
+
void 0
|
|
200
|
+
);
|
|
201
|
+
const resultMessage = () => this.utils.matcherHint(".toHaveErrors") + `
|
|
202
|
+
|
|
203
|
+
Expected error to equal:
|
|
204
|
+
${this.utils.printExpected(matcher)}
|
|
205
|
+
Received:
|
|
206
|
+
${this.utils.printReceived(flattened)}` + /* istanbul ignore next */
|
|
207
|
+
(diffString ? `
|
|
208
|
+
|
|
209
|
+
Difference:
|
|
210
|
+
|
|
211
|
+
${diffString}` : "");
|
|
212
|
+
return { pass, message: resultMessage };
|
|
213
|
+
}
|
|
214
|
+
return diverge(toHaveErrors);
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
/**
|
|
214
|
-
* @internal
|
|
215
|
-
*/
|
|
216
217
|
function getResults(filename, value) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
218
|
+
if (typeof value === "string") {
|
|
219
|
+
const loader = new FileSystemConfigLoader({
|
|
220
|
+
extends: ["html-validate:recommended"]
|
|
221
|
+
});
|
|
222
|
+
const htmlvalidate = new HtmlValidate(loader);
|
|
223
|
+
const report = htmlvalidate.validateStringSync(value, filename, {
|
|
224
|
+
rules: {
|
|
225
|
+
"void-style": "off"
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
return report.results.map((it) => {
|
|
229
|
+
return { ...it, filePath: "inline" };
|
|
230
|
+
});
|
|
231
|
+
} else {
|
|
232
|
+
return value.results;
|
|
233
|
+
}
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
export { createMatcher$3 as a, createMatcher$2 as b, createMatcher$4 as c, createMatcher$1 as d, createMatcher as e, getResults as g };
|