html-validate 8.7.4 → 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 +9512 -10460
- 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 +9507 -10461
- 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 +61 -30
- package/dist/types/index.d.ts +88 -32
- package/package.json +12 -12
|
@@ -1,40 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function isThenable(
|
|
4
|
-
|
|
3
|
+
function isThenable(value) {
|
|
4
|
+
return value && typeof value === "object" && "then" in value && typeof value.then === "function";
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Creates a wrapped function based on the passed function.
|
|
9
|
-
*
|
|
10
|
-
* The returned function takes either a `T` or `Promise<T>`. If `T` the result
|
|
11
|
-
* will be synchronous or if `Promise<T>` the result will be asynchronous.
|
|
12
|
-
*
|
|
13
|
-
* In practice this means that if you pass a synchronous object into it you will
|
|
14
|
-
* maintain synchronous code but if you pass an asynchronous object you must
|
|
15
|
-
* await the result.
|
|
16
|
-
*
|
|
17
|
-
* @internal
|
|
18
|
-
*/
|
|
19
7
|
function diverge(fn) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return fn.call(this, actual, ...args);
|
|
26
|
-
}
|
|
8
|
+
function diverged(actual, ...args) {
|
|
9
|
+
if (isThenable(actual)) {
|
|
10
|
+
return actual.then((resolved) => fn.call(this, resolved, ...args));
|
|
11
|
+
} else {
|
|
12
|
+
return fn.call(this, actual, ...args);
|
|
27
13
|
}
|
|
28
|
-
|
|
14
|
+
}
|
|
15
|
+
return diverged;
|
|
29
16
|
}
|
|
30
17
|
|
|
31
|
-
/**
|
|
32
|
-
* Takes all messages from all files and flattens to a single array.
|
|
33
|
-
*/
|
|
34
18
|
function flattenMessages(report) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
return report.results.reduce((aggregated, result) => {
|
|
20
|
+
return aggregated.concat(result.messages);
|
|
21
|
+
}, []);
|
|
38
22
|
}
|
|
39
23
|
|
|
40
24
|
exports.diverge = diverge;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matcher-utils.js","sources":["
|
|
1
|
+
{"version":3,"file":"matcher-utils.js","sources":["../../src/jest/utils/is-thenable.ts","../../src/jest/utils/diverge.ts","../../src/jest/utils/flatten-messages.ts"],"sourcesContent":["/**\n * @internal\n */\nexport function isThenable<T>(value: T | Promise<T>): value is Promise<T> {\n\treturn value && typeof value === \"object\" && \"then\" in value && typeof value.then === \"function\";\n}\n","import { isThenable } from \"./is-thenable\";\nimport { type MatcherContext } from \"./matcher-context\";\nimport { type MatcherResult } from \"./matcher-result\";\n\ntype SyncCallback<T, TArgs extends any[]> = (\n\tthis: MatcherContext,\n\tactual: T,\n\t...args: TArgs\n) => MatcherResult;\n\n/**\n * @internal\n */\nexport interface MaybeAsyncCallback<TActual, TArgs extends any[]> {\n\t(this: MatcherContext, actual: TActual, ...args: TArgs): MatcherResult;\n\t(this: MatcherContext, actual: Promise<TActual>, ...args: TArgs): Promise<MatcherResult>;\n}\n\n/**\n * Creates a wrapped function based on the passed function.\n *\n * The returned function takes either a `T` or `Promise<T>`. If `T` the result\n * will be synchronous or if `Promise<T>` the result will be asynchronous.\n *\n * In practice this means that if you pass a synchronous object into it you will\n * maintain synchronous code but if you pass an asynchronous object you must\n * await the result.\n *\n * @internal\n */\nexport function diverge<T, TArgs extends any[]>(\n\tfn: SyncCallback<T, TArgs>,\n): MaybeAsyncCallback<T, TArgs> {\n\tfunction diverged(this: MatcherContext, actual: T, ...args: TArgs): MatcherResult;\n\tfunction diverged(\n\t\tthis: MatcherContext,\n\t\tactual: Promise<T>,\n\t\t...args: TArgs\n\t): Promise<MatcherResult>;\n\tfunction diverged(\n\t\tthis: MatcherContext,\n\t\tactual: T | Promise<T>,\n\t\t...args: TArgs\n\t): MatcherResult | Promise<MatcherResult> {\n\t\tif (isThenable(actual)) {\n\t\t\treturn actual.then((resolved) => fn.call(this, resolved, ...args));\n\t\t} else {\n\t\t\treturn fn.call(this, actual, ...args);\n\t\t}\n\t}\n\treturn diverged;\n}\n","import { type Message, type Report, type Result } from \"../../reporter\";\n\n/**\n * Takes all messages from all files and flattens to a single array.\n */\nexport function flattenMessages(report: Report): Message[] {\n\treturn report.results.reduce((aggregated: Message[], result: Result) => {\n\t\treturn aggregated.concat(result.messages);\n\t}, []);\n}\n"],"names":[],"mappings":";;AAGO,SAAS,WAAc,KAA4C,EAAA;AACzE,EAAO,OAAA,KAAA,IAAS,OAAO,KAAU,KAAA,QAAA,IAAY,UAAU,KAAS,IAAA,OAAO,MAAM,IAAS,KAAA,UAAA,CAAA;AACvF;;ACyBO,SAAS,QACf,EAC+B,EAAA;AAO/B,EAAS,SAAA,QAAA,CAER,WACG,IACsC,EAAA;AACzC,IAAI,IAAA,UAAA,CAAW,MAAM,CAAG,EAAA;AACvB,MAAO,OAAA,MAAA,CAAO,IAAK,CAAA,CAAC,QAAa,KAAA,EAAA,CAAG,KAAK,IAAM,EAAA,QAAA,EAAU,GAAG,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3D,MAAA;AACN,MAAA,OAAO,EAAG,CAAA,IAAA,CAAK,IAAM,EAAA,MAAA,EAAQ,GAAG,IAAI,CAAA,CAAA;AAAA,KACrC;AAAA,GACD;AACA,EAAO,OAAA,QAAA,CAAA;AACR;;AC9CO,SAAS,gBAAgB,MAA2B,EAAA;AAC1D,EAAA,OAAO,MAAO,CAAA,OAAA,CAAQ,MAAO,CAAA,CAAC,YAAuB,MAAmB,KAAA;AACvE,IAAO,OAAA,UAAA,CAAW,MAAO,CAAA,MAAA,CAAO,QAAQ,CAAA,CAAA;AAAA,GACzC,EAAG,EAAE,CAAA,CAAA;AACN;;;;;;"}
|
|
@@ -11,63 +11,54 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
11
11
|
var kleur__default = /*#__PURE__*/_interopDefault(kleur);
|
|
12
12
|
|
|
13
13
|
const options$1 = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
showLink: false,
|
|
15
|
+
showSummary: false,
|
|
16
|
+
showSelector: true
|
|
17
17
|
};
|
|
18
18
|
function createMatcher$1() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
* the implementation works but the declarations doesn't allow it */
|
|
30
|
-
return jestSnapshot.toMatchSnapshot.call(this, snapshot, ...rest);
|
|
31
|
-
}
|
|
32
|
-
return matcherUtils.diverge(toMatchCodeframe);
|
|
19
|
+
function toMatchCodeframe(actual, ...rest) {
|
|
20
|
+
const filename = this.testPath ?? "inline";
|
|
21
|
+
const results = matchers.getResults(filename, actual);
|
|
22
|
+
const enabled = kleur__default.default.enabled;
|
|
23
|
+
kleur__default.default.enabled = false;
|
|
24
|
+
const snapshot = core.codeframe(results, options$1).replace(/\s+$/gm, "");
|
|
25
|
+
kleur__default.default.enabled = enabled;
|
|
26
|
+
return jestSnapshot.toMatchSnapshot.call(this, snapshot, ...rest);
|
|
27
|
+
}
|
|
28
|
+
return matcherUtils.diverge(toMatchCodeframe);
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
const options = {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
showLink: false,
|
|
33
|
+
showSummary: false,
|
|
34
|
+
showSelector: true
|
|
39
35
|
};
|
|
40
36
|
function toMatchInlineCodeframeImpl(context, actual, ...rest) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
kleur__default.default.enabled = enabled;
|
|
49
|
-
/* eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call --
|
|
50
|
-
* the implementation works but the declarations doesn't allow it */
|
|
51
|
-
return jestSnapshot.toMatchInlineSnapshot.call(context, snapshot, ...rest);
|
|
37
|
+
const filename = context.testPath ?? "inline";
|
|
38
|
+
const results = matchers.getResults(filename, actual);
|
|
39
|
+
const enabled = kleur__default.default.enabled;
|
|
40
|
+
kleur__default.default.enabled = false;
|
|
41
|
+
const snapshot = core.codeframe(results, options).replace(/\s+$/gm, "");
|
|
42
|
+
kleur__default.default.enabled = enabled;
|
|
43
|
+
return jestSnapshot.toMatchInlineSnapshot.call(context, snapshot, ...rest);
|
|
52
44
|
}
|
|
53
45
|
function createMatcher() {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
68
|
-
}
|
|
46
|
+
function toMatchInlineCodeframe(actual, ...rest) {
|
|
47
|
+
const context = {
|
|
48
|
+
...this,
|
|
49
|
+
/* Capture the original stack frames as they are needed by "jest-snapshot"
|
|
50
|
+
* to determine where to write the inline snapshots. When resolving the
|
|
51
|
+
* promise the original stack frames are lost and the snapshot will be
|
|
52
|
+
* written in this files instaed. */
|
|
53
|
+
error: new Error()
|
|
54
|
+
};
|
|
55
|
+
if (matcherUtils.isThenable(actual)) {
|
|
56
|
+
return actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));
|
|
57
|
+
} else {
|
|
58
|
+
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
69
59
|
}
|
|
70
|
-
|
|
60
|
+
}
|
|
61
|
+
return toMatchInlineCodeframe;
|
|
71
62
|
}
|
|
72
63
|
|
|
73
64
|
exports.createMatcher = createMatcher$1;
|
|
@@ -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","getResults","kleur","codeframe","toMatchSnapshot","diverge","toMatchInlineSnapshot","isThenable"],"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,GAAUC,mBAAW,CAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAC3C,IAAA,MAAM,UAAUC,sBAAM,CAAA,OAAA,CAAA;AACtB,IAAAA,sBAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAChB,IAAA,MAAM,WAAWC,cAAU,CAAA,OAAA,EAASJ,SAAO,CAAE,CAAA,OAAA,CAAQ,UAAU,EAAE,CAAA,CAAA;AACjE,IAAAG,sBAAA,CAAM,OAAU,GAAA,OAAA,CAAA;AAIhB,IAAA,OAAQE,4BAAwB,CAAA,IAAA,CAAK,IAAM,EAAA,QAAA,EAAU,GAAG,IAAI,CAAA,CAAA;AAAA,GAC7D;AACA,EAAA,OAAOC,qBAAQ,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,GAAUJ,mBAAW,CAAA,QAAA,EAAU,MAAM,CAAA,CAAA;AAC3C,EAAA,MAAM,UAAUC,sBAAM,CAAA,OAAA,CAAA;AACtB,EAAAA,sBAAA,CAAM,OAAU,GAAA,KAAA,CAAA;AAChB,EAAA,MAAM,WAAWC,cAAU,CAAA,OAAA,EAAS,OAAO,CAAE,CAAA,OAAA,CAAQ,UAAU,EAAE,CAAA,CAAA;AACjE,EAAAD,sBAAA,CAAM,OAAU,GAAA,OAAA,CAAA;AAIhB,EAAA,OAAQI,kCAA8B,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,IAAAC,uBAAA,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/cjs/matchers.js
CHANGED
|
@@ -5,234 +5,234 @@ var core = require('./core.js');
|
|
|
5
5
|
var coreNodejs = require('./core-nodejs.js');
|
|
6
6
|
|
|
7
7
|
function createMatcher$4() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
8
|
+
function toBeValid(report) {
|
|
9
|
+
if (report.valid) {
|
|
10
|
+
return {
|
|
11
|
+
pass: true,
|
|
12
|
+
message: (
|
|
13
|
+
/* istanbul ignore next */
|
|
14
|
+
() => "Result should not contain error"
|
|
15
|
+
)
|
|
16
|
+
};
|
|
17
|
+
} else {
|
|
18
|
+
const firstError = report.results[0].messages[0];
|
|
19
|
+
return {
|
|
20
|
+
pass: false,
|
|
21
|
+
message: () => `Result should be valid but had error "${firstError.message}"`
|
|
22
|
+
};
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
}
|
|
25
|
+
return matcherUtils.diverge(toBeValid);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
function createMatcher$3() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
function toBeInvalid(report) {
|
|
30
|
+
if (report.valid) {
|
|
31
|
+
return {
|
|
32
|
+
pass: false,
|
|
33
|
+
message: () => "Result should be invalid but had no errors"
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
return {
|
|
37
|
+
pass: true,
|
|
38
|
+
message: (
|
|
39
|
+
/* istanbul ignore next */
|
|
40
|
+
() => "Result should not contain error"
|
|
41
|
+
)
|
|
42
|
+
};
|
|
40
43
|
}
|
|
41
|
-
|
|
44
|
+
}
|
|
45
|
+
return matcherUtils.diverge(toBeInvalid);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
function isMessage(arg) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
arg.offset ||
|
|
52
|
-
arg.line ||
|
|
53
|
-
arg.column ||
|
|
54
|
-
arg.size ||
|
|
55
|
-
arg.selector ||
|
|
56
|
-
arg.context);
|
|
49
|
+
if (!arg) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return Boolean(
|
|
53
|
+
arg.ruleId || arg.severity || arg.message || arg.offset || arg.line || arg.column || arg.size || arg.selector || arg.context
|
|
54
|
+
);
|
|
57
55
|
}
|
|
58
56
|
function isConfig(arg) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
if (!arg) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return Boolean(
|
|
61
|
+
arg.root || arg.extends || arg.elements || arg.plugin || arg.transform || arg.rules
|
|
62
|
+
);
|
|
63
63
|
}
|
|
64
64
|
function isString(arg) {
|
|
65
|
-
|
|
65
|
+
return typeof arg === "string";
|
|
66
66
|
}
|
|
67
67
|
function getMarkup(src) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
throw new Error(`Failed to get markup from "${typeof src}" argument`);
|
|
77
|
-
}
|
|
68
|
+
if (typeof HTMLElement !== "undefined" && src instanceof HTMLElement) {
|
|
69
|
+
return src.outerHTML;
|
|
70
|
+
}
|
|
71
|
+
if (typeof src === "string") {
|
|
72
|
+
return src;
|
|
73
|
+
} else {
|
|
74
|
+
throw new Error(`Failed to get markup from "${typeof src}" argument`);
|
|
75
|
+
}
|
|
78
76
|
}
|
|
79
77
|
function createMatcher$2(expect, diff) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
78
|
+
function toHTMLValidate(actual, arg0, arg1, arg2) {
|
|
79
|
+
const markup = getMarkup(actual);
|
|
80
|
+
const message = isMessage(arg0) ? arg0 : void 0;
|
|
81
|
+
const config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : void 0;
|
|
82
|
+
const filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2;
|
|
83
|
+
return toHTMLValidateImpl.call(this, expect, diff, markup, message, config, filename);
|
|
84
|
+
}
|
|
85
|
+
return matcherUtils.diverge(toHTMLValidate);
|
|
88
86
|
}
|
|
89
87
|
function toHTMLValidateImpl(expect, diff, actual, expectedError, userConfig, filename) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
"void-style": "off",
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
const config = core.deepmerge(defaultConfig, userConfig !== null && userConfig !== void 0 ? userConfig : {});
|
|
99
|
-
/* istanbul ignore next: cant figure out when this would be unset */
|
|
100
|
-
const actualFilename = (_a = filename !== null && filename !== void 0 ? filename : this.testPath) !== null && _a !== void 0 ? _a : "inline";
|
|
101
|
-
const loader = new coreNodejs.FileSystemConfigLoader({
|
|
102
|
-
extends: ["html-validate:recommended"],
|
|
103
|
-
});
|
|
104
|
-
const htmlvalidate = new core.HtmlValidate(loader);
|
|
105
|
-
const report = htmlvalidate.validateStringSync(actual, actualFilename, config);
|
|
106
|
-
const pass = report.valid;
|
|
107
|
-
const result = report.results[0];
|
|
108
|
-
if (pass) {
|
|
109
|
-
return { pass, message: () => "HTML is valid when an error was expected" };
|
|
88
|
+
const defaultConfig = {
|
|
89
|
+
rules: {
|
|
90
|
+
/* jsdom normalizes style so disabling rule when using this matcher or it
|
|
91
|
+
* gets quite noisy when configured with self-closing */
|
|
92
|
+
"void-style": "off"
|
|
110
93
|
}
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
94
|
+
};
|
|
95
|
+
const config = core.deepmerge(defaultConfig, userConfig ?? {});
|
|
96
|
+
const actualFilename = filename ?? this.testPath ?? "inline";
|
|
97
|
+
const loader = new coreNodejs.FileSystemConfigLoader({
|
|
98
|
+
extends: ["html-validate:recommended"]
|
|
99
|
+
});
|
|
100
|
+
const htmlvalidate = new core.HtmlValidate(loader);
|
|
101
|
+
const report = htmlvalidate.validateStringSync(actual, actualFilename, config);
|
|
102
|
+
const pass = report.valid;
|
|
103
|
+
const result = report.results[0];
|
|
104
|
+
if (pass) {
|
|
105
|
+
return { pass, message: () => "HTML is valid when an error was expected" };
|
|
106
|
+
} else {
|
|
107
|
+
if (expectedError) {
|
|
108
|
+
const actual2 = result.messages;
|
|
109
|
+
const expected = expect.arrayContaining([expect.objectContaining(expectedError)]);
|
|
110
|
+
const errorPass = this.equals(actual2, expected);
|
|
111
|
+
const diffString = diff ? diff(expected, actual2, {
|
|
112
|
+
expand: this.expand,
|
|
113
|
+
aAnnotation: "Expected error",
|
|
114
|
+
bAnnotation: "Actual error"
|
|
115
|
+
}) : (
|
|
116
|
+
/* istanbul ignore next */
|
|
117
|
+
void 0
|
|
118
|
+
);
|
|
119
|
+
const hint = this.utils.matcherHint(".not.toHTMLValidate", void 0, void 0, {
|
|
120
|
+
comment: "expected error"
|
|
121
|
+
});
|
|
122
|
+
const expectedErrorMessage = () => [
|
|
123
|
+
hint,
|
|
124
|
+
"",
|
|
125
|
+
"Expected error to be present:",
|
|
126
|
+
this.utils.printExpected(expectedError),
|
|
127
|
+
/* istanbul ignore next */
|
|
128
|
+
diffString ? `
|
|
129
|
+
${diffString}` : ""
|
|
130
|
+
].join("\n");
|
|
131
|
+
return { pass: !errorPass, message: expectedErrorMessage, actual: actual2, expected };
|
|
140
132
|
}
|
|
133
|
+
const errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);
|
|
134
|
+
return {
|
|
135
|
+
pass,
|
|
136
|
+
message: () => ["Expected HTML to be valid but had the following errors:", ""].concat(errors).join("\n")
|
|
137
|
+
};
|
|
138
|
+
}
|
|
141
139
|
}
|
|
142
140
|
|
|
143
141
|
function toHaveErrorImpl(context, expect, diff, actual, expected) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
142
|
+
const flattened = matcherUtils.flattenMessages(actual);
|
|
143
|
+
const matcher = [expect.objectContaining(expected)];
|
|
144
|
+
const pass = context.equals(flattened, matcher);
|
|
145
|
+
const diffString = diff ? diff(matcher, flattened, { expand: context.expand }) : (
|
|
146
|
+
/* istanbul ignore next */
|
|
147
|
+
void 0
|
|
148
|
+
);
|
|
149
|
+
const hint = context.utils.matcherHint(".toHaveError");
|
|
150
|
+
const prettyExpected = context.utils.printExpected(matcher);
|
|
151
|
+
const prettyReceived = context.utils.printReceived(flattened);
|
|
152
|
+
const resultMessage = () => {
|
|
153
|
+
return [
|
|
154
|
+
hint,
|
|
155
|
+
"",
|
|
156
|
+
"Expected error to equal:",
|
|
157
|
+
` ${prettyExpected}`,
|
|
158
|
+
"Received:",
|
|
159
|
+
` ${prettyReceived}`,
|
|
160
|
+
/* istanbul ignore next */
|
|
161
|
+
diffString ? `
|
|
162
|
+
Difference:
|
|
163
|
+
|
|
164
|
+
${diffString}` : ""
|
|
165
|
+
].join("\n");
|
|
166
|
+
};
|
|
167
|
+
return { pass, message: resultMessage, actual: flattened, expected: matcher };
|
|
165
168
|
}
|
|
166
169
|
function createMatcher$1(expect, diff) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
else {
|
|
180
|
-
return toHaveErrorImpl(this, expect, diff, actual, arg1);
|
|
181
|
-
}
|
|
170
|
+
function toHaveError(actual, arg1, arg2, arg3) {
|
|
171
|
+
if (typeof arg1 === "string") {
|
|
172
|
+
const expected = {
|
|
173
|
+
ruleId: arg1,
|
|
174
|
+
message: arg2
|
|
175
|
+
};
|
|
176
|
+
if (arg3) {
|
|
177
|
+
expected.context = arg3;
|
|
178
|
+
}
|
|
179
|
+
return toHaveErrorImpl(this, expect, diff, actual, expected);
|
|
180
|
+
} else {
|
|
181
|
+
return toHaveErrorImpl(this, expect, diff, actual, arg1);
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
}
|
|
184
|
+
return matcherUtils.diverge(toHaveError);
|
|
184
185
|
}
|
|
185
186
|
|
|
186
|
-
/* eslint-disable prefer-template -- technical debt, should be refactored */
|
|
187
187
|
function createMatcher(expect, diff) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
188
|
+
function toHaveErrors(report, errors) {
|
|
189
|
+
const flattened = matcherUtils.flattenMessages(report);
|
|
190
|
+
const matcher = errors.map((entry) => {
|
|
191
|
+
if (Array.isArray(entry)) {
|
|
192
|
+
const [ruleId, message] = entry;
|
|
193
|
+
return expect.objectContaining({ ruleId, message });
|
|
194
|
+
} else {
|
|
195
|
+
return expect.objectContaining(entry);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
const pass = this.equals(flattened, matcher);
|
|
199
|
+
const diffString = diff ? diff(matcher, flattened, { expand: this.expand }) : (
|
|
200
|
+
/* istanbul ignore next */
|
|
201
|
+
void 0
|
|
202
|
+
);
|
|
203
|
+
const resultMessage = () => this.utils.matcherHint(".toHaveErrors") + `
|
|
204
|
+
|
|
205
|
+
Expected error to equal:
|
|
206
|
+
${this.utils.printExpected(matcher)}
|
|
207
|
+
Received:
|
|
208
|
+
${this.utils.printReceived(flattened)}` + /* istanbul ignore next */
|
|
209
|
+
(diffString ? `
|
|
210
|
+
|
|
211
|
+
Difference:
|
|
212
|
+
|
|
213
|
+
${diffString}` : "");
|
|
214
|
+
return { pass, message: resultMessage };
|
|
215
|
+
}
|
|
216
|
+
return matcherUtils.diverge(toHaveErrors);
|
|
213
217
|
}
|
|
214
218
|
|
|
215
|
-
/**
|
|
216
|
-
* @internal
|
|
217
|
-
*/
|
|
218
219
|
function getResults(filename, value) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
220
|
+
if (typeof value === "string") {
|
|
221
|
+
const loader = new coreNodejs.FileSystemConfigLoader({
|
|
222
|
+
extends: ["html-validate:recommended"]
|
|
223
|
+
});
|
|
224
|
+
const htmlvalidate = new core.HtmlValidate(loader);
|
|
225
|
+
const report = htmlvalidate.validateStringSync(value, filename, {
|
|
226
|
+
rules: {
|
|
227
|
+
"void-style": "off"
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
return report.results.map((it) => {
|
|
231
|
+
return { ...it, filePath: "inline" };
|
|
232
|
+
});
|
|
233
|
+
} else {
|
|
234
|
+
return value.results;
|
|
235
|
+
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
exports.createMatcher = createMatcher$4;
|