html-validate 11.5.3 → 11.5.4

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.
Files changed (57) hide show
  1. package/dist/cjs/cli.js +11 -14
  2. package/dist/cjs/cli.js.map +1 -1
  3. package/dist/cjs/core-browser.js +4 -4
  4. package/dist/cjs/core-browser.js.map +1 -1
  5. package/dist/cjs/core-nodejs.js +17 -25
  6. package/dist/cjs/core-nodejs.js.map +1 -1
  7. package/dist/cjs/core.js +420 -435
  8. package/dist/cjs/core.js.map +1 -1
  9. package/dist/cjs/elements.js +11 -22
  10. package/dist/cjs/elements.js.map +1 -1
  11. package/dist/cjs/html-validate.js +1 -1
  12. package/dist/cjs/html-validate.js.map +1 -1
  13. package/dist/cjs/jest-matchers.js +49 -55
  14. package/dist/cjs/jest-matchers.js.map +1 -1
  15. package/dist/cjs/jest-utils.js +1 -2
  16. package/dist/cjs/jest-utils.js.map +1 -1
  17. package/dist/cjs/jest-worker.js.map +1 -1
  18. package/dist/cjs/test-utils.js +1 -2
  19. package/dist/cjs/test-utils.js.map +2 -2
  20. package/dist/cjs/tsdoc-metadata.json +1 -1
  21. package/dist/cjs/utils/parse-image-candidate-string.js +2 -2
  22. package/dist/cjs/utils/parse-image-candidate-string.js.map +1 -1
  23. package/dist/cjs/vitest-matchers.js +46 -50
  24. package/dist/cjs/vitest-matchers.js.map +1 -1
  25. package/dist/cjs/vitest-utils.js +1 -2
  26. package/dist/cjs/vitest-utils.js.map +1 -1
  27. package/dist/cjs/vitest-worker.js.map +1 -1
  28. package/dist/esm/cli.js +11 -14
  29. package/dist/esm/cli.js.map +1 -1
  30. package/dist/esm/core-browser.js +4 -4
  31. package/dist/esm/core-browser.js.map +1 -1
  32. package/dist/esm/core-nodejs.js +17 -25
  33. package/dist/esm/core-nodejs.js.map +1 -1
  34. package/dist/esm/core.js +420 -435
  35. package/dist/esm/core.js.map +1 -1
  36. package/dist/esm/elements.js +11 -22
  37. package/dist/esm/elements.js.map +1 -1
  38. package/dist/esm/html-validate.js +1 -1
  39. package/dist/esm/html-validate.js.map +1 -1
  40. package/dist/esm/jest-matchers.js +49 -55
  41. package/dist/esm/jest-matchers.js.map +1 -1
  42. package/dist/esm/jest-utils.js +1 -2
  43. package/dist/esm/jest-utils.js.map +1 -1
  44. package/dist/esm/jest-worker.js.map +1 -1
  45. package/dist/esm/test-utils.js +1 -2
  46. package/dist/esm/test-utils.js.map +2 -2
  47. package/dist/esm/utils/parse-image-candidate-string.js +2 -2
  48. package/dist/esm/utils/parse-image-candidate-string.js.map +1 -1
  49. package/dist/esm/vitest-matchers.js +46 -50
  50. package/dist/esm/vitest-matchers.js.map +1 -1
  51. package/dist/esm/vitest-utils.js +1 -2
  52. package/dist/esm/vitest-utils.js.map +1 -1
  53. package/dist/esm/vitest-worker.js.map +1 -1
  54. package/dist/tsdoc-metadata.json +1 -1
  55. package/dist/types/browser.d.ts +21 -11
  56. package/dist/types/index.d.ts +23 -13
  57. package/package.json +1 -1
@@ -13,13 +13,12 @@ function createMatcher$6() {
13
13
  () => "Result should not contain error"
14
14
  )
15
15
  };
16
- } else {
17
- const firstError = report.results[0].messages[0];
18
- return {
19
- pass: false,
20
- message: () => `Result should be valid but had error "${firstError.message}"`
21
- };
22
16
  }
17
+ const firstError = report.results[0].messages[0];
18
+ return {
19
+ pass: false,
20
+ message: () => `Result should be valid but had error "${firstError.message}"`
21
+ };
23
22
  }
24
23
  return diverge(toBeValid);
25
24
  }
@@ -31,15 +30,14 @@ function createMatcher$5() {
31
30
  pass: false,
32
31
  message: () => "Result should be invalid but had no errors"
33
32
  };
34
- } else {
35
- return {
36
- pass: true,
37
- message: (
38
- /* istanbul ignore next */
39
- () => "Result should not contain error"
40
- )
41
- };
42
33
  }
34
+ return {
35
+ pass: true,
36
+ message: (
37
+ /* istanbul ignore next */
38
+ () => "Result should not contain error"
39
+ )
40
+ };
43
41
  }
44
42
  return diverge(toBeInvalid);
45
43
  }
@@ -58,13 +56,15 @@ function isMessage(arg) {
58
56
  "size",
59
57
  "selector",
60
58
  "context"
61
- ].some((key) => key in arg);
59
+ ].some((key) => Object.hasOwn(arg, key));
62
60
  }
63
61
  function isConfig(arg) {
64
62
  if (!arg || typeof arg !== "object") {
65
63
  return false;
66
64
  }
67
- return ["root", "extends", "elements", "plugin", "transform", "rules"].some((key) => key in arg);
65
+ return ["root", "extends", "elements", "plugin", "transform", "rules"].some(
66
+ (key) => Object.hasOwn(arg, key)
67
+ );
68
68
  }
69
69
  function isString(arg) {
70
70
  return typeof arg === "string";
@@ -75,9 +75,8 @@ function getMarkup(src) {
75
75
  }
76
76
  if (typeof src === "string") {
77
77
  return src;
78
- } else {
79
- throw new TypeError(`Failed to get markup from "${typeof src}" argument`);
80
78
  }
79
+ throw new TypeError(`Failed to get markup from "${typeof src}" argument`);
81
80
  }
82
81
  function createMatcher$4(expect) {
83
82
  function toHTMLValidate(actual, arg0, arg1, arg2) {
@@ -102,38 +101,37 @@ function toHTMLValidateImpl(expect, actual, expectedError, userConfig, filename)
102
101
  const syncFn = createSyncFn(vitestWorkerPath);
103
102
  const report = syncFn(actual, actualFilename, config);
104
103
  const pass = report.valid;
105
- const result = report.results[0];
106
104
  if (pass) {
107
105
  return { pass, message: () => "HTML is valid when an error was expected" };
108
- } else {
109
- if (expectedError) {
110
- const actual2 = result.messages;
111
- const expected = expect.arrayContaining([expect.objectContaining(expectedError)]);
112
- const errorPass = this.equals(actual2, expected);
113
- const diffString = this.utils.diff(expected, actual2, {
114
- aAnnotation: "Expected error",
115
- bAnnotation: "Actual error"
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 ? `
106
+ }
107
+ const result = report.results[0];
108
+ if (expectedError) {
109
+ const actual2 = result.messages;
110
+ const expected = expect.arrayContaining([expect.objectContaining(expectedError)]);
111
+ const errorPass = this.equals(actual2, expected);
112
+ const diffString = this.utils.diff(expected, actual2, {
113
+ aAnnotation: "Expected error",
114
+ bAnnotation: "Actual error"
115
+ });
116
+ const hint = this.utils.matcherHint(".not.toHTMLValidate", void 0, void 0, {
117
+ comment: "expected error"
118
+ });
119
+ const expectedErrorMessage = () => [
120
+ hint,
121
+ "",
122
+ "Expected error to be present:",
123
+ this.utils.printExpected(expectedError),
124
+ /* istanbul ignore next */
125
+ diffString ? `
127
126
  ${diffString}` : ""
128
- ].join("\n");
129
- return { pass: !errorPass, message: expectedErrorMessage, actual: actual2, expected };
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
- };
127
+ ].join("\n");
128
+ return { pass: !errorPass, message: expectedErrorMessage, actual: actual2, expected };
136
129
  }
130
+ const errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);
131
+ return {
132
+ pass,
133
+ message: () => ["Expected HTML to be valid but had the following errors:", ""].concat(errors).join("\n")
134
+ };
137
135
  }
138
136
 
139
137
  function toHaveErrorImpl(context, expect, actual, expected) {
@@ -172,9 +170,8 @@ function createMatcher$3(expect) {
172
170
  expected.context = arg3;
173
171
  }
174
172
  return toHaveErrorImpl(this, expect, actual, expected);
175
- } else {
176
- return toHaveErrorImpl(this, expect, actual, arg1);
177
173
  }
174
+ return toHaveErrorImpl(this, expect, actual, arg1);
178
175
  }
179
176
  return diverge(toHaveError);
180
177
  }
@@ -186,9 +183,8 @@ function createMatcher$2(expect) {
186
183
  if (Array.isArray(entry)) {
187
184
  const [ruleId, message] = entry;
188
185
  return expect.objectContaining({ ruleId, message });
189
- } else {
190
- return expect.objectContaining(entry);
191
186
  }
187
+ return expect.objectContaining(entry);
192
188
  });
193
189
  const pass = this.equals(flattened, matcher);
194
190
  const diffString = this.utils.diff(matcher, flattened);
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-matchers.js","sources":["../../src/vitest/matchers/to-be-valid.ts","../../src/vitest/matchers/to-be-invalid.ts","../../src/vitest/matchers/to-htmlvalidate.ts","../../src/vitest/matchers/to-have-error.ts","../../src/vitest/matchers/to-have-errors.ts","../../src/vitest/matchers/to-match-codeframe.ts","../../src/vitest/matchers/to-match-inline-codeframe.ts"],"sourcesContent":["import { type SyncExpectationResult } from \"@vitest/expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeValid(report: Report): SyncExpectationResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t} else {\n\t\t\tconst firstError = report.results[0].messages[0];\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => `Result should be valid but had error \"${firstError.message}\"`,\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeValid);\n}\n\nexport { createMatcher as toBeValid };\n","import { type SyncExpectationResult } from \"@vitest/expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeInvalid(report: Report): SyncExpectationResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => \"Result should be invalid but had no errors\",\n\t\t\t};\n\t\t} else {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t}\n\t}\n\treturn diverge(toBeInvalid);\n}\n\nexport { createMatcher as toBeInvalid };\n","import { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport deepmerge from \"deepmerge\";\nimport { type expect } from \"vitest\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, vitestWorkerPath } from \"../worker\";\n\ntype VitestExpect = typeof expect;\n\nfunction isMessage(arg: Arg1 | undefined): arg is Partial<Message> {\n\tif (!arg || typeof arg !== \"object\") {\n\t\treturn false;\n\t}\n\treturn [\n\t\t\"ruleId\",\n\t\t\"severity\",\n\t\t\"message\",\n\t\t\"offset\",\n\t\t\"line\",\n\t\t\"column\",\n\t\t\"size\",\n\t\t\"selector\",\n\t\t\"context\",\n\t].some((key) => key in arg);\n}\n\nfunction isConfig(arg: Arg1 | undefined): arg is ConfigData {\n\tif (!arg || typeof arg !== \"object\") {\n\t\treturn false;\n\t}\n\treturn [\"root\", \"extends\", \"elements\", \"plugin\", \"transform\", \"rules\"].some((key) => key in arg);\n}\n\nfunction isString(arg: Arg1 | undefined): arg is string {\n\treturn typeof arg === \"string\";\n}\n\nfunction getMarkup(src: unknown): string {\n\tif (typeof HTMLElement !== \"undefined\" && src instanceof HTMLElement) {\n\t\treturn (src as { outerHTML: string }).outerHTML;\n\t}\n\t/* istanbul ignore else: prototype only allows string or HTMLElement */\n\tif (typeof src === \"string\") {\n\t\treturn src;\n\t} else {\n\t\tthrow new TypeError(`Failed to get markup from \"${typeof src}\" argument`);\n\t}\n}\n\ntype Arg1 = Partial<Message> | ConfigData | string;\ntype Arg2 = ConfigData | string;\ntype Arg3 = string;\n\nfunction createMatcher(expect: VitestExpect): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherState,\n\t\tactual: unknown,\n\t\targ0?: Arg1,\n\t\targ1?: Arg2,\n\t\targ2?: Arg3,\n\t): SyncExpectationResult {\n\t\tconst markup = getMarkup(actual);\n\t\tconst message = isMessage(arg0) ? arg0 : undefined;\n\t\tconst config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : undefined; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\tconst filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\treturn toHTMLValidateImpl.call(this, expect, markup, message, config, filename);\n\t}\n\treturn diverge(toHTMLValidate);\n}\n\n/* eslint-disable-next-line @typescript-eslint/max-params -- technical debt */\nfunction toHTMLValidateImpl(\n\tthis: MatcherState,\n\texpect: VitestExpect,\n\tactual: string,\n\texpectedError?: Partial<Message>,\n\tuserConfig?: ConfigData,\n\tfilename?: string,\n): SyncExpectationResult {\n\tconst defaultConfig = {\n\t\trules: {\n\t\t\t/* jsdom normalizes style so disabling rule when using this matcher or it\n\t\t\t * gets quite noisy when configured with self-closing */\n\t\t\t\"void-style\": \"off\",\n\t\t},\n\t};\n\tconst config = deepmerge(defaultConfig, userConfig ?? {});\n\t/* istanbul ignore next: cant figure out when this would be unset */\n\tconst actualFilename = filename ?? this.testPath ?? \"inline\";\n\n\tconst syncFn = createSyncFn<ValidateStringFn>(vitestWorkerPath);\n\tconst report = syncFn(actual, actualFilename, config);\n\tconst pass = report.valid;\n\tconst result = report.results[0];\n\tif (pass) {\n\t\treturn { pass, message: () => \"HTML is valid when an error was expected\" };\n\t} else {\n\t\tif (expectedError) {\n\t\t\tconst actual = result.messages;\n\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- upstream typing */\n\t\t\tconst expected = expect.arrayContaining([expect.objectContaining(expectedError)]);\n\t\t\tconst errorPass = this.equals(actual, expected);\n\t\t\tconst diffString = this.utils.diff(expected, actual, {\n\t\t\t\taAnnotation: \"Expected error\",\n\t\t\t\tbAnnotation: \"Actual error\",\n\t\t\t});\n\t\t\tconst hint = this.utils.matcherHint(\".not.toHTMLValidate\", undefined, undefined, {\n\t\t\t\tcomment: \"expected error\",\n\t\t\t});\n\t\t\tconst expectedErrorMessage = (): string =>\n\t\t\t\t[\n\t\t\t\t\thint,\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"Expected error to be present:\",\n\t\t\t\t\tthis.utils.printExpected(expectedError),\n\t\t\t\t\t/* istanbul ignore next */ diffString ? `\\n${diffString}` : \"\",\n\t\t\t\t].join(\"\\n\");\n\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- upstream typing */\n\t\t\treturn { pass: !errorPass, message: expectedErrorMessage, actual, expected };\n\t\t}\n\n\t\tconst errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);\n\t\treturn {\n\t\t\tpass,\n\t\t\tmessage: () =>\n\t\t\t\t[\"Expected HTML to be valid but had the following errors:\", \"\"].concat(errors).join(\"\\n\"),\n\t\t};\n\t}\n}\n\nexport { createMatcher as toHTMLValidate };\n","import { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport { type expect } from \"vitest\";\nimport { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype VitestExpect = typeof expect;\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherState,\n\texpect: VitestExpect,\n\tactual: Report,\n\texpected: Partial<Message>,\n): SyncExpectationResult {\n\tconst flattened = actual.results.flatMap((result) => result.messages);\n\tconst matcher = [expect.objectContaining(expected)];\n\tconst pass = context.equals(flattened, matcher);\n\tconst diffString = context.utils.diff(matcher, flattened);\n\tconst hint = context.utils.matcherHint(\".toHaveError\");\n\tconst prettyExpected = context.utils.printExpected(matcher);\n\tconst prettyReceived = context.utils.printReceived(flattened);\n\tconst resultMessage = (): string => {\n\t\treturn [\n\t\t\thint,\n\t\t\t\"\",\n\t\t\t\"Expected error to equal:\",\n\t\t\t` ${prettyExpected}`,\n\t\t\t\"Received:\",\n\t\t\t` ${prettyReceived}`,\n\t\t\t/* istanbul ignore next */ diffString ? `\\nDifference:\\n\\n${diffString}` : \"\",\n\t\t].join(\"\\n\");\n\t};\n\treturn { pass, message: resultMessage, actual: flattened, expected: matcher };\n}\n\nfunction createMatcher(\n\texpect: VitestExpect,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, unknown?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\truleId: string,\n\t\tmessage: string,\n\t\tcontext?: unknown,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\targ1: string | Partial<Message>,\n\t\targ2?: string,\n\t\targ3?: unknown,\n\t): SyncExpectationResult {\n\t\tif (typeof arg1 === \"string\") {\n\t\t\tconst expected: Partial<Message> = {\n\t\t\t\truleId: arg1,\n\t\t\t\tmessage: arg2,\n\t\t\t};\n\t\t\tif (arg3 !== undefined) {\n\t\t\t\texpected.context = arg3;\n\t\t\t}\n\t\t\treturn toHaveErrorImpl(this, expect, actual, expected);\n\t\t} else {\n\t\t\treturn toHaveErrorImpl(this, expect, actual, arg1);\n\t\t}\n\t}\n\treturn diverge(toHaveError);\n}\n\nexport { createMatcher as toHaveError };\n","/* eslint-disable prefer-template -- technical debt, should be refactored */\n\nimport { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport { type expect } from \"vitest\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype VitestExpect = typeof expect;\n\nfunction createMatcher(\n\texpect: VitestExpect,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherState,\n\t\treport: Report,\n\t\terrors: Array<[string, string] | Record<string, unknown>>,\n\t): SyncExpectationResult {\n\t\tconst flattened = report.results.flatMap((result) => result.messages);\n\t\tconst matcher = errors.map((entry) => {\n\t\t\tif (Array.isArray(entry)) {\n\t\t\t\tconst [ruleId, message] = entry;\n\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return -- upstream typing */\n\t\t\t\treturn expect.objectContaining({ ruleId, message });\n\t\t\t} else {\n\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return -- upstream typing */\n\t\t\t\treturn expect.objectContaining(entry);\n\t\t\t}\n\t\t});\n\t\tconst pass = this.equals(flattened, matcher);\n\t\tconst diffString = this.utils.diff(matcher, flattened);\n\t\tconst resultMessage = (): string =>\n\t\t\tthis.utils.matcherHint(\".toHaveErrors\") +\n\t\t\t\"\\n\\n\" +\n\t\t\t\"Expected error to equal:\\n\" +\n\t\t\t` ${this.utils.printExpected(matcher)}\\n` +\n\t\t\t\"Received:\\n\" +\n\t\t\t` ${this.utils.printReceived(flattened)}` +\n\t\t\t/* istanbul ignore next */ (diffString ? `\\n\\nDifference:\\n\\n${diffString}` : \"\");\n\n\t\treturn { pass, message: resultMessage };\n\t}\n\treturn diverge(toHaveErrors);\n}\n\nexport { createMatcher as toHaveErrors };\n","import { type AsyncExpectationResult, type MatcherState } from \"@vitest/expect\";\nimport * as vitest from \"vitest\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe } from \"../utils\";\n\ntype ToMatchCodeframeMatcher = (\n\tthis: MatcherState,\n\treceived: Report | string | Promise<Report> | Promise<string>,\n\thint?: string,\n) => AsyncExpectationResult;\n\nfunction createMatcher(): ToMatchCodeframeMatcher {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\n\tasync function toMatchCodeframe(\n\t\tthis: MatcherState,\n\t\treceived: Report | string | Promise<Report> | Promise<string>,\n\t\thint?: string,\n\t): AsyncExpectationResult {\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for backwards compatibility with older vitest versions */\n\t\tif (!vitest.Snapshots) {\n\t\t\tthrow new Error(\"toMatchCodeframe() requires vitest 4.1.3 or later. Please upgrade vitest.\");\n\t\t}\n\n\t\tconst resolved = await received;\n\n\t\tlet report: Report;\n\t\tif (typeof resolved === \"string\") {\n\t\t\tconst filename = this.testPath ?? \"inline\";\n\t\t\treport = await htmlvalidate.validateString(resolved, filename, {\n\t\t\t\trules: {\n\t\t\t\t\t\"void-style\": \"off\",\n\t\t\t\t},\n\t\t\t});\n\t\t} else {\n\t\t\treport = resolved;\n\t\t}\n\n\t\tconst snapshot = codeframe(report.results).replaceAll(/\\s+$/gm, \"\");\n\n\t\treturn vitest.Snapshots.toMatchSnapshot.call(this, snapshot, hint);\n\t}\n\n\treturn toMatchCodeframe;\n}\n\nexport { createMatcher as toMatchCodeframe };\n","import { type AsyncExpectationResult, type MatcherState } from \"@vitest/expect\";\nimport * as vitest from \"vitest\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe } from \"../utils\";\n\ntype ToMatchInlineCodeframeMatcher = (\n\tthis: MatcherState,\n\treceived: Report | string | Promise<Report> | Promise<string>,\n\tinlineSnapshot?: string,\n) => AsyncExpectationResult;\n\nfunction createMatcher(): ToMatchInlineCodeframeMatcher {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\n\tasync function toMatchInlineCodeframe(\n\t\tthis: MatcherState,\n\t\treceived: Report | string | Promise<Report> | Promise<string>,\n\t\tinlineSnapshot?: string,\n\t): AsyncExpectationResult {\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for backwards compatibility with older vitest versions */\n\t\tif (!vitest.Snapshots) {\n\t\t\tthrow new Error(\n\t\t\t\t\"toMatchInlineCodeframe() requires vitest 4.1.3 or later. Please upgrade vitest.\",\n\t\t\t);\n\t\t}\n\n\t\t/* Capture the call site synchronously before any await — vitest needs this\n\t\t * to determine where to rewrite the inline snapshot in the source file. */\n\t\tvitest.chai.util.flag(this.assertion, \"error\", new Error(\"stacktrace\"));\n\n\t\tconst resolved = await received;\n\n\t\tlet report: Report;\n\t\tif (typeof resolved === \"string\") {\n\t\t\tconst filename = this.testPath ?? \"inline\";\n\t\t\treport = await htmlvalidate.validateString(resolved, filename, {\n\t\t\t\trules: {\n\t\t\t\t\t\"void-style\": \"off\",\n\t\t\t\t},\n\t\t\t});\n\t\t} else {\n\t\t\treport = resolved;\n\t\t}\n\n\t\tconst snapshot = codeframe(report.results).replaceAll(/\\s+$/gm, \"\");\n\n\t\treturn vitest.Snapshots.toMatchInlineSnapshot.call(this, snapshot, inlineSnapshot);\n\t}\n\n\treturn toMatchInlineCodeframe;\n}\n\nexport { createMatcher as toMatchInlineCodeframe };\n"],"names":["createMatcher","actual"],"mappings":";;;;;AAIA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,UAAU,MAAA,EAAuC;AACzD,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA;AAAA,UAAoC,MAAM;AAAA;AAAA,OAC3C;AAAA,IACD,CAAA,MAAO;AACN,MAAA,MAAM,aAAa,MAAA,CAAO,OAAA,CAAQ,CAAC,CAAA,CAAE,SAAS,CAAC,CAAA;AAC/C,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,OAAA,EAAS,MAAM,CAAA,sCAAA,EAAyC,UAAA,CAAW,OAAO,CAAA,CAAA;AAAA,OAC3E;AAAA,IACD;AAAA,EACD;AACA,EAAA,OAAO,QAAQ,SAAS,CAAA;AACzB;;AChBA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,YAAY,MAAA,EAAuC;AAC3D,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,SAAS,MAAM;A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,IAAA,CAAK,IAAA,EAAM,UAAU,cAAc,CAAA;AAAA,EAClF;AAEA,EAAA,OAAO,sBAAA;AACR;;;;"}
1
+ {"version":3,"file":"vitest-matchers.js","sources":["../../src/vitest/matchers/to-be-valid.ts","../../src/vitest/matchers/to-be-invalid.ts","../../src/vitest/matchers/to-htmlvalidate.ts","../../src/vitest/matchers/to-have-error.ts","../../src/vitest/matchers/to-have-errors.ts","../../src/vitest/matchers/to-match-codeframe.ts","../../src/vitest/matchers/to-match-inline-codeframe.ts"],"sourcesContent":["import { type SyncExpectationResult } from \"@vitest/expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeValid(report: Report): SyncExpectationResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: true,\n\t\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t\t};\n\t\t}\n\t\tconst firstError = report.results[0].messages[0];\n\t\treturn {\n\t\t\tpass: false,\n\t\t\tmessage: () => `Result should be valid but had error \"${firstError.message}\"`,\n\t\t};\n\t}\n\treturn diverge(toBeValid);\n}\n\nexport { createMatcher as toBeValid };\n","import { type SyncExpectationResult } from \"@vitest/expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\nfunction createMatcher(): MaybeAsyncCallback<Report, []> {\n\tfunction toBeInvalid(report: Report): SyncExpectationResult {\n\t\tif (report.valid) {\n\t\t\treturn {\n\t\t\t\tpass: false,\n\t\t\t\tmessage: () => \"Result should be invalid but had no errors\",\n\t\t\t};\n\t\t}\n\t\treturn {\n\t\t\tpass: true,\n\t\t\tmessage: /* istanbul ignore next */ () => \"Result should not contain error\",\n\t\t};\n\t}\n\treturn diverge(toBeInvalid);\n}\n\nexport { createMatcher as toBeInvalid };\n","import { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport deepmerge from \"deepmerge\";\nimport { type expect } from \"vitest\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, vitestWorkerPath } from \"../worker\";\n\ntype VitestExpect = typeof expect;\n\nfunction isMessage(arg: Arg1 | undefined): arg is Partial<Message> {\n\tif (!arg || typeof arg !== \"object\") {\n\t\treturn false;\n\t}\n\treturn [\n\t\t\"ruleId\",\n\t\t\"severity\",\n\t\t\"message\",\n\t\t\"offset\",\n\t\t\"line\",\n\t\t\"column\",\n\t\t\"size\",\n\t\t\"selector\",\n\t\t\"context\",\n\t].some((key) => Object.hasOwn(arg, key));\n}\n\nfunction isConfig(arg: Arg1 | undefined): arg is ConfigData {\n\tif (!arg || typeof arg !== \"object\") {\n\t\treturn false;\n\t}\n\treturn [\"root\", \"extends\", \"elements\", \"plugin\", \"transform\", \"rules\"].some((key) =>\n\t\tObject.hasOwn(arg, key),\n\t);\n}\n\nfunction isString(arg: Arg1 | undefined): arg is string {\n\treturn typeof arg === \"string\";\n}\n\nfunction getMarkup(src: unknown): string {\n\tif (typeof HTMLElement !== \"undefined\" && src instanceof HTMLElement) {\n\t\treturn (src as { outerHTML: string }).outerHTML;\n\t}\n\t/* istanbul ignore else: prototype only allows string or HTMLElement */\n\tif (typeof src === \"string\") {\n\t\treturn src;\n\t}\n\tthrow new TypeError(`Failed to get markup from \"${typeof src}\" argument`);\n}\n\ntype Arg1 = Partial<Message> | ConfigData | string;\ntype Arg2 = ConfigData | string;\ntype Arg3 = string;\n\nfunction createMatcher(expect: VitestExpect): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherState,\n\t\tactual: unknown,\n\t\targ0?: Arg1,\n\t\targ1?: Arg2,\n\t\targ2?: Arg3,\n\t): SyncExpectationResult {\n\t\tconst markup = getMarkup(actual);\n\t\tconst message = isMessage(arg0) ? arg0 : undefined;\n\t\tconst config = isConfig(arg0) ? arg0 : isConfig(arg1) ? arg1 : undefined; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\tconst filename = isString(arg0) ? arg0 : isString(arg1) ? arg1 : arg2; // eslint-disable-line sonarjs/no-nested-conditional -- easier to read than the alternative */\n\t\treturn toHTMLValidateImpl.call(this, expect, markup, message, config, filename);\n\t}\n\treturn diverge(toHTMLValidate);\n}\n\n/* eslint-disable-next-line @typescript-eslint/max-params -- technical debt */\nfunction toHTMLValidateImpl(\n\tthis: MatcherState,\n\texpect: VitestExpect,\n\tactual: string,\n\texpectedError?: Partial<Message>,\n\tuserConfig?: ConfigData,\n\tfilename?: string,\n): SyncExpectationResult {\n\tconst defaultConfig = {\n\t\trules: {\n\t\t\t/* jsdom normalizes style so disabling rule when using this matcher or it\n\t\t\t * gets quite noisy when configured with self-closing */\n\t\t\t\"void-style\": \"off\",\n\t\t},\n\t};\n\tconst config = deepmerge(defaultConfig, userConfig ?? {});\n\t/* istanbul ignore next: cant figure out when this would be unset */\n\tconst actualFilename = filename ?? this.testPath ?? \"inline\";\n\n\tconst syncFn = createSyncFn<ValidateStringFn>(vitestWorkerPath);\n\tconst report = syncFn(actual, actualFilename, config);\n\tconst pass = report.valid;\n\tif (pass) {\n\t\treturn { pass, message: () => \"HTML is valid when an error was expected\" };\n\t}\n\n\tconst result = report.results[0];\n\tif (expectedError) {\n\t\tconst actual = result.messages;\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- upstream typing */\n\t\tconst expected = expect.arrayContaining([expect.objectContaining(expectedError)]);\n\t\tconst errorPass = this.equals(actual, expected);\n\t\tconst diffString = this.utils.diff(expected, actual, {\n\t\t\taAnnotation: \"Expected error\",\n\t\t\tbAnnotation: \"Actual error\",\n\t\t});\n\t\tconst hint = this.utils.matcherHint(\".not.toHTMLValidate\", undefined, undefined, {\n\t\t\tcomment: \"expected error\",\n\t\t});\n\t\tconst expectedErrorMessage = (): string =>\n\t\t\t[\n\t\t\t\thint,\n\t\t\t\t\"\",\n\t\t\t\t\"Expected error to be present:\",\n\t\t\t\tthis.utils.printExpected(expectedError),\n\t\t\t\t/* istanbul ignore next */ diffString ? `\\n${diffString}` : \"\",\n\t\t\t].join(\"\\n\");\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- upstream typing */\n\t\treturn { pass: !errorPass, message: expectedErrorMessage, actual, expected };\n\t}\n\n\tconst errors = result.messages.map((message) => ` ${message.message} [${message.ruleId}]`);\n\treturn {\n\t\tpass,\n\t\tmessage: () =>\n\t\t\t[\"Expected HTML to be valid but had the following errors:\", \"\"].concat(errors).join(\"\\n\"),\n\t};\n}\n\nexport { createMatcher as toHTMLValidate };\n","import { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport { type expect } from \"vitest\";\nimport { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype VitestExpect = typeof expect;\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherState,\n\texpect: VitestExpect,\n\tactual: Report,\n\texpected: Partial<Message>,\n): SyncExpectationResult {\n\tconst flattened = actual.results.flatMap((result) => result.messages);\n\tconst matcher = [expect.objectContaining(expected)];\n\tconst pass = context.equals(flattened, matcher);\n\tconst diffString = context.utils.diff(matcher, flattened);\n\tconst hint = context.utils.matcherHint(\".toHaveError\");\n\tconst prettyExpected = context.utils.printExpected(matcher);\n\tconst prettyReceived = context.utils.printReceived(flattened);\n\tconst resultMessage = (): string => {\n\t\treturn [\n\t\t\thint,\n\t\t\t\"\",\n\t\t\t\"Expected error to equal:\",\n\t\t\t` ${prettyExpected}`,\n\t\t\t\"Received:\",\n\t\t\t` ${prettyReceived}`,\n\t\t\t/* istanbul ignore next */ diffString ? `\\nDifference:\\n\\n${diffString}` : \"\",\n\t\t].join(\"\\n\");\n\t};\n\treturn { pass, message: resultMessage, actual: flattened, expected: matcher };\n}\n\nfunction createMatcher(\n\texpect: VitestExpect,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, unknown?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\truleId: string,\n\t\tmessage: string,\n\t\tcontext?: unknown,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherState,\n\t\tactual: Report,\n\t\targ1: string | Partial<Message>,\n\t\targ2?: string,\n\t\targ3?: unknown,\n\t): SyncExpectationResult {\n\t\tif (typeof arg1 === \"string\") {\n\t\t\tconst expected: Partial<Message> = {\n\t\t\t\truleId: arg1,\n\t\t\t\tmessage: arg2,\n\t\t\t};\n\t\t\tif (arg3 !== undefined) {\n\t\t\t\texpected.context = arg3;\n\t\t\t}\n\t\t\treturn toHaveErrorImpl(this, expect, actual, expected);\n\t\t}\n\t\treturn toHaveErrorImpl(this, expect, actual, arg1);\n\t}\n\treturn diverge(toHaveError);\n}\n\nexport { createMatcher as toHaveError };\n","/* eslint-disable prefer-template -- technical debt, should be refactored */\n\nimport { type MatcherState, type SyncExpectationResult } from \"@vitest/expect\";\nimport { type expect } from \"vitest\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype VitestExpect = typeof expect;\n\nfunction createMatcher(\n\texpect: VitestExpect,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherState,\n\t\treport: Report,\n\t\terrors: Array<[string, string] | Record<string, unknown>>,\n\t): SyncExpectationResult {\n\t\tconst flattened = report.results.flatMap((result) => result.messages);\n\t\tconst matcher = errors.map((entry) => {\n\t\t\tif (Array.isArray(entry)) {\n\t\t\t\tconst [ruleId, message] = entry;\n\t\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return -- upstream typing */\n\t\t\t\treturn expect.objectContaining({ ruleId, message });\n\t\t\t}\n\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unsafe-return -- upstream typing */\n\t\t\treturn expect.objectContaining(entry);\n\t\t});\n\t\tconst pass = this.equals(flattened, matcher);\n\t\tconst diffString = this.utils.diff(matcher, flattened);\n\t\tconst resultMessage = (): string =>\n\t\t\tthis.utils.matcherHint(\".toHaveErrors\") +\n\t\t\t\"\\n\\n\" +\n\t\t\t\"Expected error to equal:\\n\" +\n\t\t\t` ${this.utils.printExpected(matcher)}\\n` +\n\t\t\t\"Received:\\n\" +\n\t\t\t` ${this.utils.printReceived(flattened)}` +\n\t\t\t/* istanbul ignore next */ (diffString ? `\\n\\nDifference:\\n\\n${diffString}` : \"\");\n\n\t\treturn { pass, message: resultMessage };\n\t}\n\treturn diverge(toHaveErrors);\n}\n\nexport { createMatcher as toHaveErrors };\n","import { type AsyncExpectationResult, type MatcherState } from \"@vitest/expect\";\nimport * as vitest from \"vitest\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe } from \"../utils\";\n\ntype ToMatchCodeframeMatcher = (\n\tthis: MatcherState,\n\treceived: Report | string | Promise<Report> | Promise<string>,\n\thint?: string,\n) => AsyncExpectationResult;\n\nfunction createMatcher(): ToMatchCodeframeMatcher {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\n\tasync function toMatchCodeframe(\n\t\tthis: MatcherState,\n\t\treceived: Report | string | Promise<Report> | Promise<string>,\n\t\thint?: string,\n\t): AsyncExpectationResult {\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for backwards compatibility with older vitest versions */\n\t\tif (!vitest.Snapshots) {\n\t\t\tthrow new Error(\"toMatchCodeframe() requires vitest 4.1.3 or later. Please upgrade vitest.\");\n\t\t}\n\n\t\tconst resolved = await received;\n\n\t\tlet report: Report;\n\t\tif (typeof resolved === \"string\") {\n\t\t\tconst filename = this.testPath ?? \"inline\";\n\t\t\treport = await htmlvalidate.validateString(resolved, filename, {\n\t\t\t\trules: {\n\t\t\t\t\t\"void-style\": \"off\",\n\t\t\t\t},\n\t\t\t});\n\t\t} else {\n\t\t\treport = resolved;\n\t\t}\n\n\t\tconst snapshot = codeframe(report.results).replaceAll(/\\s+$/gm, \"\");\n\n\t\treturn vitest.Snapshots.toMatchSnapshot.call(this, snapshot, hint);\n\t}\n\n\treturn toMatchCodeframe;\n}\n\nexport { createMatcher as toMatchCodeframe };\n","import { type AsyncExpectationResult, type MatcherState } from \"@vitest/expect\";\nimport * as vitest from \"vitest\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe } from \"../utils\";\n\ntype ToMatchInlineCodeframeMatcher = (\n\tthis: MatcherState,\n\treceived: Report | string | Promise<Report> | Promise<string>,\n\tinlineSnapshot?: string,\n) => AsyncExpectationResult;\n\nfunction createMatcher(): ToMatchInlineCodeframeMatcher {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\n\tasync function toMatchInlineCodeframe(\n\t\tthis: MatcherState,\n\t\treceived: Report | string | Promise<Report> | Promise<string>,\n\t\tinlineSnapshot?: string,\n\t): AsyncExpectationResult {\n\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- for backwards compatibility with older vitest versions */\n\t\tif (!vitest.Snapshots) {\n\t\t\tthrow new Error(\n\t\t\t\t\"toMatchInlineCodeframe() requires vitest 4.1.3 or later. Please upgrade vitest.\",\n\t\t\t);\n\t\t}\n\n\t\t/* Capture the call site synchronously before any await — vitest needs this\n\t\t * to determine where to rewrite the inline snapshot in the source file. */\n\t\tvitest.chai.util.flag(this.assertion, \"error\", new Error(\"stacktrace\"));\n\n\t\tconst resolved = await received;\n\n\t\tlet report: Report;\n\t\tif (typeof resolved === \"string\") {\n\t\t\tconst filename = this.testPath ?? \"inline\";\n\t\t\treport = await htmlvalidate.validateString(resolved, filename, {\n\t\t\t\trules: {\n\t\t\t\t\t\"void-style\": \"off\",\n\t\t\t\t},\n\t\t\t});\n\t\t} else {\n\t\t\treport = resolved;\n\t\t}\n\n\t\tconst snapshot = codeframe(report.results).replaceAll(/\\s+$/gm, \"\");\n\n\t\treturn vitest.Snapshots.toMatchInlineSnapshot.call(this, snapshot, inlineSnapshot);\n\t}\n\n\treturn toMatchInlineCodeframe;\n}\n\nexport { createMatcher as toMatchInlineCodeframe };\n"],"names":["createMatcher","actual"],"mappings":";;;;;AAIA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,UAAU,MAAA,EAAuC;AACzD,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,IAAA;AAAA,QACN,OAAA;AAAA;AAAA,UAAoC,MAAM;AAAA;AAAA,OAC3C;AAAA,IACD;AACA,IAAA,MAAM,aAAa,MAAA,CAAO,OAAA,CAAQ,CAAC,CAAA,CAAE,SAAS,CAAC,CAAA;AAC/C,IAAA,OAAO;AAAA,MACN,IAAA,EAAM,KAAA;AAAA,MACN,OAAA,EAAS,MAAM,CAAA,sCAAA,EAAyC,UAAA,CAAW,OAAO,CAAA,CAAA;AAAA,KAC3E;AAAA,EACD;AACA,EAAA,OAAO,QAAQ,SAAS,CAAA;AACzB;;ACfA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,YAAY,MAAA,EAAuC;AAC3D,IAAA,IAAI,OAAO,KAAA,EAAO;AACjB,MAAA,OAAO;AAAA,QACN,IAAA,EAAM,KAAA;AAAA,QACN,SAAS,MAAM;AAAA,OAChB;AAAA,IACD;AACA,IAAA,OAAO;AAAA,MACN,IAAA,EAAM,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
  function diverged(actual, ...args) {
45
45
  if (isThenable(actual)) {
46
46
  return actual.then((resolved) => fn.call(this, resolved, ...args));
47
- } else {
48
- return fn.call(this, actual, ...args);
49
47
  }
48
+ return fn.call(this, actual, ...args);
50
49
  }
51
50
  return diverged;
52
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vitest-utils.js","sources":["../../src/vitest/utils/codeframe.ts","../../src/vitest/utils/is-thenable.ts","../../src/vitest/utils/diverge.ts","../../src/vitest/worker/create-sync-fn.ts"],"sourcesContent":["import { type Message } from \"../../message\";\nimport { type Result } from \"../../reporter\";\nimport { codeFrameColumns } from \"../../utils/code-frame-columns\";\nimport { getEndLocation, getStartLocation } from \"../../utils/message-location\";\n\n/**\n * Gets the formatted output for a given message.\n * @param message - The object that represents this message.\n * @param parentResult - The result object that this message belongs to.\n * @returns The formatted output.\n */\nfunction formatMessage(message: Message, parentResult: Result): string {\n\tconst type = message.severity === 2 ? \"error\" : \"warning\";\n\tconst msg = message.message.replace(/([^ ])\\.$/, \"$1\");\n\tconst ruleId = `(${message.ruleId})`;\n\tconst sourceCode = parentResult.source;\n\tconst firstLine = [`${type}:`, msg, ruleId].join(\" \");\n\tconst result = [firstLine];\n\n\t/* istanbul ignore next: safety check from original implementation */\n\tif (sourceCode) {\n\t\tconst output = codeFrameColumns(sourceCode, {\n\t\t\tstart: getStartLocation(message),\n\t\t\tend: getEndLocation(message, sourceCode),\n\t\t});\n\t\tresult.push(output);\n\t}\n\n\tresult.push(`Selector: ${message.selector ?? \"-\"}`);\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Codeframe formatter based on ESLint codeframe.\n *\n * @internal\n */\nexport function codeframe(results: Result[]): string {\n\tlet errors = 0;\n\tlet warnings = 0;\n\n\tconst resultsWithMessages = results.filter((result) => result.messages.length > 0);\n\n\tconst output = resultsWithMessages\n\t\t.reduce<string[]>((resultsOutput, result) => {\n\t\t\tconst messages = result.messages.map((message) => {\n\t\t\t\treturn `${formatMessage(message, result)}\\n\\n`;\n\t\t\t});\n\n\t\t\terrors += result.errorCount;\n\t\t\twarnings += result.warningCount;\n\n\t\t\treturn resultsOutput.concat(messages);\n\t\t}, [])\n\t\t.join(\"\\n\");\n\n\treturn errors + warnings > 0 ? output : \"\";\n}\n","/**\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 {\n\ttype AsyncExpectationResult,\n\ttype MatcherState,\n\ttype SyncExpectationResult,\n} from \"@vitest/expect\";\nimport { isThenable } from \"./is-thenable\";\n\ntype SyncCallback<T, TArgs extends unknown[]> = (\n\tthis: MatcherState,\n\tactual: T,\n\t...args: TArgs\n) => SyncExpectationResult;\n\n/**\n * @internal\n */\nexport interface MaybeAsyncCallback<TActual, TArgs extends unknown[]> {\n\t(this: MatcherState, actual: TActual, ...args: TArgs): SyncExpectationResult;\n\t(this: MatcherState, actual: Promise<TActual>, ...args: TArgs): AsyncExpectationResult;\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 unknown[]>(\n\tfn: SyncCallback<T, TArgs>,\n): MaybeAsyncCallback<T, TArgs> {\n\tfunction diverged(this: MatcherState, actual: T, ...args: TArgs): SyncExpectationResult;\n\tfunction diverged(this: MatcherState, actual: Promise<T>, ...args: TArgs): AsyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherState,\n\t\tactual: T | Promise<T>,\n\t\t...args: TArgs\n\t): SyncExpectationResult | AsyncExpectationResult {\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 {\n\ttype MessagePort,\n\tMessageChannel,\n\tWorker,\n\treceiveMessageOnPort,\n} from \"node:worker_threads\";\nimport { legacyRequire } from \"../../resolve\";\nimport {\n\ttype AnyAsyncFn,\n\ttype AnyFn,\n\ttype MainToWorkerCommandMessage,\n\ttype MainToWorkerMessage,\n\ttype Syncify,\n\ttype WorkerToMainError,\n\ttype WorkerToMainMessage,\n} from \"./types\";\n\n/**\n * This is all based on the synckit library but without all the extra stuff such\n * as typescript, esbuld, pnp etc.\n */\n\nconst INT32_BYTES = 4;\nconst syncFnCache = new Map<string, AnyFn>();\nconst sharedBuffer = new SharedArrayBuffer(INT32_BYTES);\nconst sharedBufferView = new Int32Array(sharedBuffer, 0, 1);\n\nfunction isWorkerError<T>(value: WorkerToMainMessage<T>): value is WorkerToMainError {\n\treturn \"error\" in value;\n}\n\nfunction receiveMessageWithId<R>(port: MessagePort, expectedId: number): WorkerToMainMessage<R> {\n\t/* wait for the semaphore to be raised before receiving message */\n\tconst timeout = 30000;\n\tconst status = Atomics.wait(sharedBufferView, 0, 0, timeout);\n\tAtomics.store(sharedBufferView, 0, 0);\n\n\t/* handle timeout or unexpected errors */\n\tif (![\"ok\", \"not-equal\"].includes(status)) {\n\t\tconst abortMsg: MainToWorkerCommandMessage = {\n\t\t\tid: expectedId,\n\t\t\tcmd: \"abort\",\n\t\t};\n\t\tport.postMessage(abortMsg);\n\t\tthrow new Error(`Internal error: Atomics.wait() failed: ${status}`);\n\t}\n\n\t/* the worker process will post the message before raising the semaphore, we\n\t * should not reach this part of the code unless there is a message waiting to\n\t * be read */\n\tconst reply = receiveMessageOnPort(port) as { message: WorkerToMainMessage<R> };\n\tconst { id, ...message } = reply.message;\n\n\tif (id < expectedId) {\n\t\treturn receiveMessageWithId(port, expectedId);\n\t}\n\n\tif (expectedId !== id) {\n\t\tthrow new Error(`Internal error: Expected id ${String(expectedId)} but got id ${String(id)}`);\n\t}\n\n\treturn { id, ...message };\n}\n\nfunction startWorkerThread<R, T extends AnyAsyncFn<R>>(\n\tworkerPath: string,\n): (...args: Parameters<T>) => R {\n\tconst { port1: mainPort, port2: workerPort } = new MessageChannel();\n\tconst workerPathUrl = legacyRequire.resolve(workerPath);\n\tconst worker = new Worker(workerPathUrl, {\n\t\teval: false,\n\t\tworkerData: { sharedBuffer, workerPort },\n\t\ttransferList: [workerPort],\n\t});\n\n\tlet nextID = 0;\n\n\tconst syncFn = (...args: Parameters<T>): R => {\n\t\tconst id = nextID++;\n\t\tconst msg: MainToWorkerMessage<Parameters<T>> = { id, args };\n\n\t\tworker.postMessage(msg);\n\n\t\tconst reply = receiveMessageWithId<R>(mainPort, id);\n\n\t\tif (isWorkerError(reply)) {\n\t\t\tthrow new Error(reply.error);\n\t\t}\n\n\t\treturn reply.result;\n\t};\n\n\tworker.unref();\n\n\treturn syncFn;\n}\n\nexport function createSyncFn<T extends AnyAsyncFn<R>, R = unknown>(workerPath: string): Syncify<T> {\n\tconst cachedSyncFn = syncFnCache.get(workerPath);\n\tif (cachedSyncFn) {\n\t\treturn cachedSyncFn as Syncify<T>;\n\t}\n\n\tconst syncFn = startWorkerThread<R, T>(workerPath);\n\tsyncFnCache.set(workerPath, syncFn);\n\treturn syncFn as Syncify<T>;\n}\n"],"names":[],"mappings":";;;;AAWA,SAAS,aAAA,CAAc,SAAkB,YAAA,EAA8B;AACtE,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,QAAA,KAAa,CAAA,GAAI,OAAA,GAAU,SAAA;AAChD,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,OAAA,CAAQ,OAAA,CAAQ,aAAa,IAAI,CAAA;AACrD,EAAA,MAAM,MAAA,GAAS,CAAA,CAAA,EAAI,OAAA,CAAQ,MAAM,CAAA,CAAA,CAAA;AACjC,EAAA,MAAM,aAAa,YAAA,CAAa,MAAA;AAChC,EAAA,MAAM,SAAA,GAAY,CAAC,CAAA,EAAG,IAAI,KAAK,GAAA,EAAK,MAAM,CAAA,CAAE,I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,EAAK;AAE3D,IAAA,MAAA,CAAO,YAAY,GAAG,CAAA;AAEtB,IAAA,MAAM,KAAA,GAAQ,oBAAA,CAAwB,QAAA,EAAU,EAAE,CAAA;AAElD,IAAA,IAAI,aAAA,CAAc,KAAK,CAAA,EAAG;AACzB,MAAA,MAAM,IAAI,KAAA,CAAM,KAAA,CAAM,KAAK,CAAA;AAAA,IAC5B;AAEA,IAAA,OAAO,KAAA,CAAM,MAAA;AAAA,EACd,CAAA;AAEA,EAAA,MAAA,CAAO,KAAA,EAAM;AAEb,EAAA,OAAO,MAAA;AACR;AAEO,SAAS,aAAmD,UAAA,EAAgC;AAClG,EAAA,MAAM,YAAA,GAAe,WAAA,CAAY,GAAA,CAAI,UAAU,CAAA;AAC/C,EAAA,IAAI,YAAA,EAAc;AACjB,IAAA,OAAO,YAAA;AAAA,EACR;AAEA,EAAA,MAAM,MAAA,GAAS,kBAAwB,UAAU,CAAA;AACjD,EAAA,WAAA,CAAY,GAAA,CAAI,YAAY,MAAM,CAAA;AAClC,EAAA,OAAO,MAAA;AACR;;;;"}
1
+ {"version":3,"file":"vitest-utils.js","sources":["../../src/vitest/utils/codeframe.ts","../../src/vitest/utils/is-thenable.ts","../../src/vitest/utils/diverge.ts","../../src/vitest/worker/create-sync-fn.ts"],"sourcesContent":["import { type Message } from \"../../message\";\nimport { type Result } from \"../../reporter\";\nimport { codeFrameColumns } from \"../../utils/code-frame-columns\";\nimport { getEndLocation, getStartLocation } from \"../../utils/message-location\";\n\n/**\n * Gets the formatted output for a given message.\n * @param message - The object that represents this message.\n * @param parentResult - The result object that this message belongs to.\n * @returns The formatted output.\n */\nfunction formatMessage(message: Message, parentResult: Result): string {\n\tconst type = message.severity === 2 ? \"error\" : \"warning\";\n\tconst msg = message.message.replace(/([^ ])\\.$/, \"$1\");\n\tconst ruleId = `(${message.ruleId})`;\n\tconst sourceCode = parentResult.source;\n\tconst firstLine = [`${type}:`, msg, ruleId].join(\" \");\n\tconst result = [firstLine];\n\n\t/* istanbul ignore next: safety check from original implementation */\n\tif (sourceCode) {\n\t\tconst output = codeFrameColumns(sourceCode, {\n\t\t\tstart: getStartLocation(message),\n\t\t\tend: getEndLocation(message, sourceCode),\n\t\t});\n\t\tresult.push(output);\n\t}\n\n\tresult.push(`Selector: ${message.selector ?? \"-\"}`);\n\n\treturn result.join(\"\\n\");\n}\n\n/**\n * Codeframe formatter based on ESLint codeframe.\n *\n * @internal\n */\nexport function codeframe(results: Result[]): string {\n\tlet errors = 0;\n\tlet warnings = 0;\n\n\tconst resultsWithMessages = results.filter((result) => result.messages.length > 0);\n\n\tconst output = resultsWithMessages\n\t\t.reduce<string[]>((resultsOutput, result) => {\n\t\t\tconst messages = result.messages.map((message) => {\n\t\t\t\treturn `${formatMessage(message, result)}\\n\\n`;\n\t\t\t});\n\n\t\t\terrors += result.errorCount;\n\t\t\twarnings += result.warningCount;\n\n\t\t\treturn resultsOutput.concat(messages);\n\t\t}, [])\n\t\t.join(\"\\n\");\n\n\treturn errors + warnings > 0 ? output : \"\";\n}\n","/**\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 {\n\ttype AsyncExpectationResult,\n\ttype MatcherState,\n\ttype SyncExpectationResult,\n} from \"@vitest/expect\";\nimport { isThenable } from \"./is-thenable\";\n\ntype SyncCallback<T, TArgs extends unknown[]> = (\n\tthis: MatcherState,\n\tactual: T,\n\t...args: TArgs\n) => SyncExpectationResult;\n\n/**\n * @internal\n */\nexport interface MaybeAsyncCallback<TActual, TArgs extends unknown[]> {\n\t(this: MatcherState, actual: TActual, ...args: TArgs): SyncExpectationResult;\n\t(this: MatcherState, actual: Promise<TActual>, ...args: TArgs): AsyncExpectationResult;\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 unknown[]>(\n\tfn: SyncCallback<T, TArgs>,\n): MaybeAsyncCallback<T, TArgs> {\n\tfunction diverged(this: MatcherState, actual: T, ...args: TArgs): SyncExpectationResult;\n\tfunction diverged(this: MatcherState, actual: Promise<T>, ...args: TArgs): AsyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherState,\n\t\tactual: T | Promise<T>,\n\t\t...args: TArgs\n\t): SyncExpectationResult | AsyncExpectationResult {\n\t\tif (isThenable(actual)) {\n\t\t\t/* eslint-disable-next-line unicorn/prefer-await -- intentional, we must return sync result if sync parameters are used */\n\t\t\treturn actual.then((resolved) => fn.call(this, resolved, ...args));\n\t\t}\n\t\treturn fn.call(this, actual, ...args);\n\t}\n\treturn diverged;\n}\n","import {\n\ttype MessagePort,\n\tMessageChannel,\n\tWorker,\n\treceiveMessageOnPort,\n} from \"node:worker_threads\";\nimport { legacyRequire } from \"../../resolve\";\nimport {\n\ttype AnyAsyncFn,\n\ttype AnyFn,\n\ttype MainToWorkerCommandMessage,\n\ttype MainToWorkerMessage,\n\ttype Syncify,\n\ttype WorkerToMainError,\n\ttype WorkerToMainMessage,\n} from \"./types\";\n\n/**\n * This is all based on the synckit library but without all the extra stuff such\n * as TypeScript, esbuld, pnpm etc.\n */\n\nconst INT32_BYTES = 4;\nconst syncFnCache = new Map<string, AnyFn>();\nconst sharedBuffer = new SharedArrayBuffer(INT32_BYTES);\nconst sharedBufferView = new Int32Array(sharedBuffer, 0, 1);\n\nfunction isWorkerError<T>(value: WorkerToMainMessage<T>): value is WorkerToMainError {\n\treturn \"error\" in value;\n}\n\nfunction receiveMessageWithId<R>(port: MessagePort, expectedId: number): WorkerToMainMessage<R> {\n\t/* wait for the semaphore to be raised before receiving message */\n\tconst timeout = 30000;\n\tconst status = Atomics.wait(sharedBufferView, 0, 0, timeout);\n\tAtomics.store(sharedBufferView, 0, 0);\n\n\t/* handle timeout or unexpected errors */\n\tif (![\"ok\", \"not-equal\"].includes(status)) {\n\t\tconst abortMsg: MainToWorkerCommandMessage = {\n\t\t\tid: expectedId,\n\t\t\tcmd: \"abort\",\n\t\t};\n\t\tport.postMessage(abortMsg);\n\t\tthrow new Error(`Internal error: Atomics.wait() failed: ${status}`);\n\t}\n\n\t/* the worker process will post the message before raising the semaphore, we\n\t * should not reach this part of the code unless there is a message waiting to\n\t * be read */\n\tconst reply = receiveMessageOnPort(port) as { message: WorkerToMainMessage<R> };\n\tconst { id, ...message } = reply.message;\n\n\tif (id < expectedId) {\n\t\t/* eslint-disable-next-line unicorn/no-useless-recursion -- technical debt */\n\t\treturn receiveMessageWithId(port, expectedId);\n\t}\n\n\tif (expectedId !== id) {\n\t\tthrow new Error(`Internal error: Expected id ${String(expectedId)} but got id ${String(id)}`);\n\t}\n\n\treturn { id, ...message };\n}\n\nfunction startWorkerThread<R, T extends AnyAsyncFn<R>>(\n\tworkerPath: string,\n): (...args: Parameters<T>) => R {\n\tconst { port1: mainPort, port2: workerPort } = new MessageChannel();\n\tconst workerPathUrl = legacyRequire.resolve(workerPath);\n\tconst worker = new Worker(workerPathUrl, {\n\t\teval: false,\n\t\tworkerData: { sharedBuffer, workerPort },\n\t\ttransferList: [workerPort],\n\t});\n\n\tlet nextID = 0;\n\n\tconst syncFn = (...args: Parameters<T>): R => {\n\t\tconst id = nextID++;\n\t\tconst msg: MainToWorkerMessage<Parameters<T>> = { id, args };\n\n\t\tworker.postMessage(msg);\n\n\t\tconst reply = receiveMessageWithId<R>(mainPort, id);\n\n\t\tif (isWorkerError(reply)) {\n\t\t\tthrow new Error(reply.error);\n\t\t}\n\n\t\treturn reply.result;\n\t};\n\n\tworker.unref();\n\n\treturn syncFn;\n}\n\nexport function createSyncFn<T extends AnyAsyncFn<R>, R = unknown>(workerPath: string): Syncify<T> {\n\tconst cachedSyncFn = syncFnCache.get(workerPath);\n\tif (cachedSyncFn) {\n\t\treturn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1 @@
1
- {"version":3,"file":"vitest-worker.js","sources":["../../src/vitest/worker/vitest-worker.ts"],"sourcesContent":["import { type MessagePort, parentPort, workerData } from \"node:worker_threads\";\nimport { type ConfigData } from \"../../config\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype AnyAsyncFn,\n\ttype MainToWorkerCommandMessage,\n\ttype MainToWorkerMessage,\n\ttype WorkerToMainMessage,\n} from \"./types\";\n\ninterface WorkerData {\n\tsharedBuffer: SharedArrayBuffer;\n\tworkerPort: MessagePort;\n}\n\n/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- false positive, it is used in nested functions */\nfunction runAsWorker<R = unknown, T extends AnyAsyncFn<R> = AnyAsyncFn<R>>(fn: T): void {\n\tif (!workerData) {\n\t\treturn;\n\t}\n\n\tconst { workerPort, sharedBuffer } = workerData as WorkerData;\n\tconst sharedBufferView = new Int32Array(sharedBuffer, 0, 1);\n\n\t/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- better crash at runtime if not set */\n\tparentPort!.on(\"message\", ({ id, args }: MainToWorkerMessage<Parameters<T>>) => {\n\t\tasync function inner(): Promise<void> {\n\t\t\tlet isAborted = false;\n\t\t\tconst handleAbortMessage = (msg: MainToWorkerCommandMessage): void => {\n\t\t\t\tif (msg.id === id && msg.cmd === \"abort\") {\n\t\t\t\t\tisAborted = true;\n\t\t\t\t}\n\t\t\t};\n\t\t\tworkerPort.on(\"message\", handleAbortMessage);\n\t\t\tlet msg: WorkerToMainMessage<R>;\n\t\t\ttry {\n\t\t\t\tmsg = { id, result: await fn(...args) };\n\t\t\t} catch (error: unknown) {\n\t\t\t\tmsg = {\n\t\t\t\t\tid,\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t};\n\t\t\t}\n\t\t\tworkerPort.off(\"message\", handleAbortMessage);\n\n\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- it may have been set by `handleAbortMessage` */\n\t\t\tif (isAborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tworkerPort.postMessage(msg);\n\t\t\tAtomics.add(sharedBufferView, 0, 1);\n\t\t\tAtomics.notify(sharedBufferView, 0);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises -- should not happen\n\t\tinner();\n\t});\n}\n\nfunction validateString(markup: string, filename: string, config: ConfigData): Promise<Report> {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\treturn htmlvalidate.validateString(markup, filename, config);\n}\n\nexport type ValidateStringFn = typeof validateString;\n\nrunAsWorker(validateString);\n"],"names":["msg"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAS,YAAkE,EAAA,EAAa;AACvF,EAAA,IAAI,CAAC,UAAA,EAAY;AAChB,IAAA;AAAA,EACD;AAEA,EAAA,MAAM,EAAE,UAAA,EAAY,YAAA,EAAa,GAAI,UAAA;AACrC,EAAA,MAAM,gBAAA,GAAmB,IAAI,UAAA,CAAW,YAAA,EAAc,GAAG,CAAC,CAAA;AAG1D,EAAA,UAAA,CAAY,GAAG,SAAA,EAAW,CAAC,EAAE,EAAA,EAAI,MAAK,KAA0C;AAC/E,IAAA,eAAe,KAAA,GAAuB;AACrC,MAAA,IAAI,SAAA,GAAY,KAAA;AAChB,MAAA,MAAM,kBAAA,GAAqB,CAACA,IAAAA,KAA0C;AACrE,QAAA,IAAIA,IAAAA,CAAI,EAAA,KAAO,EAAA,IAAMA,IAAAA,CAAI,QAAQ,OAAA,EAAS;AACzC,UAAA,SAAA,GAAY,IAAA;AAAA,QACb;AAAA,MACD,CAAA;AACA,MAAA,UAAA,CAAW,EAAA,CAAG,WAAW,kBAAkB,CAAA;AAC3C,MAAA,IAAI,GAAA;AACJ,MAAA,IAAI;AACH,QAAA,GAAA,GAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,MAAM,EAAA,CAAG,GAAG,IAAI,CAAA,EAAE;AAAA,MACvC,SAAS,KAAA,EAAgB;AACxB,QAAA,GAAA,GAAM;AAAA,UACL,EAAA;AAAA,UACA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK;AAAA,SAC7D;AAAA,MACD;AACA,MAAA,UAAA,CAAW,GAAA,CAAI,WAAW,kBAAkB,CAAA;AAG5C,MAAA,IAAI,SAAA,EAAW;AACd,QAAA;AAAA,MACD;AACA,MAAA,UAAA,CAAW,YAAY,GAAG,CAAA;AAC1B,MAAA,OAAA,CAAQ,GAAA,CAAI,gBAAA,EAAkB,CAAA,EAAG,CAAC,CAAA;AAClC,MAAA,OAAA,CAAQ,MAAA,CAAO,kBAAkB,CAAC,CAAA;AAAA,IACnC;AAEA,IAAA,KAAA,EAAM;AAAA,EACP,CAAC,CAAA;AACF;AAEA,SAAS,cAAA,CAAe,MAAA,EAAgB,QAAA,EAAkB,MAAA,EAAqC;AAC9F,EAAA,MAAM,MAAA,GAAS,IAAI,sBAAA,CAAuB;AAAA,IACzC,OAAA,EAAS,CAAC,2BAA2B;AAAA,GACrC,CAAA;AACD,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,CAAa,MAAM,CAAA;AAC5C,EAAA,OAAO,YAAA,CAAa,cAAA,CAAe,MAAA,EAAQ,QAAA,EAAU,MAAM,CAAA;AAC5D;AAIA,WAAA,CAAY,cAAc,CAAA"}
1
+ {"version":3,"file":"vitest-worker.js","sources":["../../src/vitest/worker/vitest-worker.ts"],"sourcesContent":["import { type MessagePort, parentPort, workerData } from \"node:worker_threads\";\nimport { type ConfigData } from \"../../config\";\nimport { FileSystemConfigLoader } from \"../../config/loaders/file-system\";\nimport { HtmlValidate } from \"../../htmlvalidate\";\nimport { type Report } from \"../../reporter\";\nimport {\n\ttype AnyAsyncFn,\n\ttype MainToWorkerCommandMessage,\n\ttype MainToWorkerMessage,\n\ttype WorkerToMainMessage,\n} from \"./types\";\n\ninterface WorkerData {\n\tsharedBuffer: SharedArrayBuffer;\n\tworkerPort: MessagePort;\n}\n\n/* eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- false positive, it is used in nested functions */\nfunction runAsWorker<R = unknown, T extends AnyAsyncFn<R> = AnyAsyncFn<R>>(fn: T): void {\n\tif (!workerData) {\n\t\treturn;\n\t}\n\n\tconst { workerPort, sharedBuffer } = workerData as WorkerData;\n\tconst sharedBufferView = new Int32Array(sharedBuffer, 0, 1);\n\n\t/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- better crash at runtime if not set */\n\tparentPort!.on(\"message\", ({ id, args }: MainToWorkerMessage<Parameters<T>>) => {\n\t\tasync function inner(): Promise<void> {\n\t\t\tlet isAborted = false;\n\t\t\tconst handleAbortMessage = (msg: MainToWorkerCommandMessage): void => {\n\t\t\t\tif (msg.id === id && msg.cmd === \"abort\") {\n\t\t\t\t\tisAborted = true;\n\t\t\t\t}\n\t\t\t};\n\t\t\tworkerPort.on(\"message\", handleAbortMessage);\n\t\t\tlet msg: WorkerToMainMessage<R>;\n\t\t\ttry {\n\t\t\t\tmsg = { id, result: await fn(...args) };\n\t\t\t} catch (error: unknown) {\n\t\t\t\tmsg = {\n\t\t\t\t\tid,\n\t\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\t};\n\t\t\t}\n\t\t\tworkerPort.off(\"message\", handleAbortMessage);\n\n\t\t\t/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- it may have been set by `handleAbortMessage` */\n\t\t\tif (isAborted) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tworkerPort.postMessage(msg);\n\t\t\tAtomics.add(sharedBufferView, 0, 1);\n\t\t\tAtomics.notify(sharedBufferView, 0);\n\t\t}\n\t\t// eslint-disable-next-line @typescript-eslint/no-floating-promises -- should not happen\n\t\tinner();\n\t});\n}\n\nfunction validateString(markup: string, filename: string, config: ConfigData): Promise<Report> {\n\tconst loader = new FileSystemConfigLoader({\n\t\textends: [\"html-validate:recommended\"],\n\t});\n\tconst htmlvalidate = new HtmlValidate(loader);\n\treturn htmlvalidate.validateString(markup, filename, config);\n}\n\nexport type ValidateStringFn = typeof validateString;\n\n/* eslint-disable-next-line unicorn/no-top-level-side-effects -- needed for worker to function */\nrunAsWorker(validateString);\n"],"names":["msg"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,SAAS,YAAkE,EAAA,EAAa;AACvF,EAAA,IAAI,CAAC,UAAA,EAAY;AAChB,IAAA;AAAA,EACD;AAEA,EAAA,MAAM,EAAE,UAAA,EAAY,YAAA,EAAa,GAAI,UAAA;AACrC,EAAA,MAAM,gBAAA,GAAmB,IAAI,UAAA,CAAW,YAAA,EAAc,GAAG,CAAC,CAAA;AAG1D,EAAA,UAAA,CAAY,GAAG,SAAA,EAAW,CAAC,EAAE,EAAA,EAAI,MAAK,KAA0C;AAC/E,IAAA,eAAe,KAAA,GAAuB;AACrC,MAAA,IAAI,SAAA,GAAY,KAAA;AAChB,MAAA,MAAM,kBAAA,GAAqB,CAACA,IAAAA,KAA0C;AACrE,QAAA,IAAIA,IAAAA,CAAI,EAAA,KAAO,EAAA,IAAMA,IAAAA,CAAI,QAAQ,OAAA,EAAS;AACzC,UAAA,SAAA,GAAY,IAAA;AAAA,QACb;AAAA,MACD,CAAA;AACA,MAAA,UAAA,CAAW,EAAA,CAAG,WAAW,kBAAkB,CAAA;AAC3C,MAAA,IAAI,GAAA;AACJ,MAAA,IAAI;AACH,QAAA,GAAA,GAAM,EAAE,EAAA,EAAI,MAAA,EAAQ,MAAM,EAAA,CAAG,GAAG,IAAI,CAAA,EAAE;AAAA,MACvC,SAAS,KAAA,EAAgB;AACxB,QAAA,GAAA,GAAM;AAAA,UACL,EAAA;AAAA,UACA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK;AAAA,SAC7D;AAAA,MACD;AACA,MAAA,UAAA,CAAW,GAAA,CAAI,WAAW,kBAAkB,CAAA;AAG5C,MAAA,IAAI,SAAA,EAAW;AACd,QAAA;AAAA,MACD;AACA,MAAA,UAAA,CAAW,YAAY,GAAG,CAAA;AAC1B,MAAA,OAAA,CAAQ,GAAA,CAAI,gBAAA,EAAkB,CAAA,EAAG,CAAC,CAAA;AAClC,MAAA,OAAA,CAAQ,MAAA,CAAO,kBAAkB,CAAC,CAAA;AAAA,IACnC;AAEA,IAAA,KAAA,EAAM;AAAA,EACP,CAAC,CAAA;AACF;AAEA,SAAS,cAAA,CAAe,MAAA,EAAgB,QAAA,EAAkB,MAAA,EAAqC;AAC9F,EAAA,MAAM,MAAA,GAAS,IAAI,sBAAA,CAAuB;AAAA,IACzC,OAAA,EAAS,CAAC,2BAA2B;AAAA,GACrC,CAAA;AACD,EAAA,MAAM,YAAA,GAAe,IAAI,YAAA,CAAa,MAAM,CAAA;AAC5C,EAAA,OAAO,YAAA,CAAa,cAAA,CAAe,MAAA,EAAQ,QAAA,EAAU,MAAM,CAAA;AAC5D;AAKA,WAAA,CAAY,cAAc,CAAA"}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.58.7"
8
+ "packageVersion": "7.58.9"
9
9
  }
10
10
  ]
11
11
  }
@@ -38,7 +38,7 @@ export declare class Attribute {
38
38
  * @param keyLocation - Source location of attribute name.
39
39
  * @param valueLocation - Source location of attribute value.
40
40
  * @param originalAttribute - If this attribute was dynamically added via a
41
- * transformation (e.g. vuejs `:id` generating the `id` attribute) this
41
+ * transformation (e.g. Vue.js `:id` generating the `id` attribute) this
42
42
  * parameter should be set to the attribute name of the source attribute (`:id`).
43
43
  */
44
44
  constructor(key: string, value: string | DynamicValue | null | undefined, keyLocation: Location_2, valueLocation: Location_2 | null, originalAttribute?: string);
@@ -254,10 +254,10 @@ export declare interface ConfigData {
254
254
  *
255
255
  * The following sources are allowed:
256
256
  *
257
- * - One of the [predefined presets](http://html-validate.org/rules/presets.html).
257
+ * - One of the [predefined presets](https://html-validate.org/rules/presets.html).
258
258
  * - Node module exporting a preset.
259
259
  * - Plugin exporting a named preset.
260
- * - Local path to a json or js file exporting a preset.
260
+ * - Local path to a JSON or js file exporting a preset.
261
261
  */
262
262
  extends?: string[];
263
263
  /**
@@ -267,7 +267,7 @@ export declare interface ConfigData {
267
267
  *
268
268
  * - "html5" (default) for the builtin metadata.
269
269
  * - node module which export metadata
270
- * - local path to json or js file exporting metadata.
270
+ * - local path to JSON or js file exporting metadata.
271
271
  * - object with inline metadata
272
272
  *
273
273
  * If elements isn't specified it defaults to `["html5"]`
@@ -1008,7 +1008,17 @@ export declare class HtmlElement extends DOMNode {
1008
1008
  * @param text - Text to add.
1009
1009
  * @param location - Source code location of this text.
1010
1010
  */
1011
- appendText(text: string | DynamicValue, location: Location_2): void;
1011
+ appendText(text: string | {
1012
+ dynamic: string;
1013
+ }, location: Location_2): void;
1014
+ /**
1015
+ * Add text as a child node to this element.
1016
+ *
1017
+ * @deprecated `appendText()` with `DynamicValue` is not safe to use, use `appendText({ dynamic: "expr" })` instead.
1018
+ * @param text - Text to add.
1019
+ * @param location - Source code location of this text.
1020
+ */
1021
+ appendText(text: DynamicValue, location: Location_2): void;
1012
1022
  /**
1013
1023
  * Return a list of all known classes on the element. Dynamic values are
1014
1024
  * ignored.
@@ -1197,7 +1207,7 @@ export declare class HtmlValidate {
1197
1207
  * If a filename is given the configured plugins can extend the
1198
1208
  * schema. Filename must not be an existing file or a filetype normally
1199
1209
  * handled by html-validate but the path will be used when resolving
1200
- * configuration. As a rule-of-thumb, set it to the elements json file.
1210
+ * configuration. As a rule-of-thumb, set it to the elements JSON file.
1201
1211
  */
1202
1212
  getElementsSchema(filename?: string): Promise<SchemaObject>;
1203
1213
  /**
@@ -1206,7 +1216,7 @@ export declare class HtmlValidate {
1206
1216
  * If a filename is given the configured plugins can extend the
1207
1217
  * schema. Filename must not be an existing file or a filetype normally
1208
1218
  * handled by html-validate but the path will be used when resolving
1209
- * configuration. As a rule-of-thumb, set it to the elements json file.
1219
+ * configuration. As a rule-of-thumb, set it to the elements JSON file.
1210
1220
  */
1211
1221
  getElementsSchemaSync(filename?: string): SchemaObject;
1212
1222
  /**
@@ -2145,7 +2155,7 @@ declare interface Plugin_2 {
2145
2155
  * to use the name/path the user used when loading the plugin. To be less
2146
2156
  * confusing for users you should use the same name as your package.
2147
2157
  *
2148
- * The name must be a valid package name according to NPM (basically lowercase
2158
+ * The name must be a valid package name according to npm (basically lowercase
2149
2159
  * characters, must not begin with dot, slash or non-url safe characters).
2150
2160
  *
2151
2161
  * Hint: import and use the name from `package.json`.
@@ -2506,7 +2516,7 @@ export declare abstract class Rule<ContextType = void, OptionsType = void> {
2506
2516
  * @public
2507
2517
  * @virtual
2508
2518
  * @param context - Error context given by a reported error.
2509
- * @returns Rule documentation and url with additional details or `null` if no
2519
+ * @returns Rule documentation and URL with additional details or `null` if no
2510
2520
  * additional documentation is available.
2511
2521
  */
2512
2522
  documentation(_context: ContextType): RuleDocumentation | null;
@@ -2990,9 +3000,9 @@ export declare interface TransformFS {
2990
3000
  /** read file from filesystem */
2991
3001
  readFileSync(this: void, path: string | number, options: {
2992
3002
  encoding: "utf8";
2993
- }): {
3003
+ }): string | {
2994
3004
  toString(encoding: "utf8"): string;
2995
- } | string;
3005
+ };
2996
3006
  }
2997
3007
 
2998
3008
  /**
@@ -38,7 +38,7 @@ export declare class Attribute {
38
38
  * @param keyLocation - Source location of attribute name.
39
39
  * @param valueLocation - Source location of attribute value.
40
40
  * @param originalAttribute - If this attribute was dynamically added via a
41
- * transformation (e.g. vuejs `:id` generating the `id` attribute) this
41
+ * transformation (e.g. Vue.js `:id` generating the `id` attribute) this
42
42
  * parameter should be set to the attribute name of the source attribute (`:id`).
43
43
  */
44
44
  constructor(key: string, value: string | DynamicValue | null | undefined, keyLocation: Location_2, valueLocation: Location_2 | null, originalAttribute?: string);
@@ -130,7 +130,7 @@ export declare interface AvailableFormatters {
130
130
  export declare type CategoryOrTag = string;
131
131
 
132
132
  /**
133
- * Create a new resolver for NodeJS packages using `require(..)`.
133
+ * Create a new resolver for Node.js packages using `require(..)`.
134
134
  *
135
135
  * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be
136
136
  * expanded relative to the root directory either explicitly set by the
@@ -352,10 +352,10 @@ export declare interface ConfigData {
352
352
  *
353
353
  * The following sources are allowed:
354
354
  *
355
- * - One of the [predefined presets](http://html-validate.org/rules/presets.html).
355
+ * - One of the [predefined presets](https://html-validate.org/rules/presets.html).
356
356
  * - Node module exporting a preset.
357
357
  * - Plugin exporting a named preset.
358
- * - Local path to a json or js file exporting a preset.
358
+ * - Local path to a JSON or js file exporting a preset.
359
359
  */
360
360
  extends?: string[];
361
361
  /**
@@ -365,7 +365,7 @@ export declare interface ConfigData {
365
365
  *
366
366
  * - "html5" (default) for the builtin metadata.
367
367
  * - node module which export metadata
368
- * - local path to json or js file exporting metadata.
368
+ * - local path to JSON or js file exporting metadata.
369
369
  * - object with inline metadata
370
370
  *
371
371
  * If elements isn't specified it defaults to `["html5"]`
@@ -807,7 +807,7 @@ export declare interface ErrorDescriptor<ContextType> {
807
807
  export declare type ESMResolver = Required<Resolver>;
808
808
 
809
809
  /**
810
- * Create a new resolver for NodeJS packages using `import(..)`.
810
+ * Create a new resolver for Node.js packages using `import(..)`.
811
811
  *
812
812
  * If the module name contains `<rootDir>` (e.g. `<rootDir/foo`) it will be
813
813
  * expanded relative to the root directory either explicitly set by the
@@ -1310,7 +1310,17 @@ export declare class HtmlElement extends DOMNode {
1310
1310
  * @param text - Text to add.
1311
1311
  * @param location - Source code location of this text.
1312
1312
  */
1313
- appendText(text: string | DynamicValue, location: Location_2): void;
1313
+ appendText(text: string | {
1314
+ dynamic: string;
1315
+ }, location: Location_2): void;
1316
+ /**
1317
+ * Add text as a child node to this element.
1318
+ *
1319
+ * @deprecated `appendText()` with `DynamicValue` is not safe to use, use `appendText({ dynamic: "expr" })` instead.
1320
+ * @param text - Text to add.
1321
+ * @param location - Source code location of this text.
1322
+ */
1323
+ appendText(text: DynamicValue, location: Location_2): void;
1314
1324
  /**
1315
1325
  * Return a list of all known classes on the element. Dynamic values are
1316
1326
  * ignored.
@@ -1499,7 +1509,7 @@ export declare class HtmlValidate {
1499
1509
  * If a filename is given the configured plugins can extend the
1500
1510
  * schema. Filename must not be an existing file or a filetype normally
1501
1511
  * handled by html-validate but the path will be used when resolving
1502
- * configuration. As a rule-of-thumb, set it to the elements json file.
1512
+ * configuration. As a rule-of-thumb, set it to the elements JSON file.
1503
1513
  */
1504
1514
  getElementsSchema(filename?: string): Promise<SchemaObject>;
1505
1515
  /**
@@ -1508,7 +1518,7 @@ export declare class HtmlValidate {
1508
1518
  * If a filename is given the configured plugins can extend the
1509
1519
  * schema. Filename must not be an existing file or a filetype normally
1510
1520
  * handled by html-validate but the path will be used when resolving
1511
- * configuration. As a rule-of-thumb, set it to the elements json file.
1521
+ * configuration. As a rule-of-thumb, set it to the elements JSON file.
1512
1522
  */
1513
1523
  getElementsSchemaSync(filename?: string): SchemaObject;
1514
1524
  /**
@@ -2454,7 +2464,7 @@ declare interface Plugin_2 {
2454
2464
  * to use the name/path the user used when loading the plugin. To be less
2455
2465
  * confusing for users you should use the same name as your package.
2456
2466
  *
2457
- * The name must be a valid package name according to NPM (basically lowercase
2467
+ * The name must be a valid package name according to npm (basically lowercase
2458
2468
  * characters, must not begin with dot, slash or non-url safe characters).
2459
2469
  *
2460
2470
  * Hint: import and use the name from `package.json`.
@@ -2815,7 +2825,7 @@ export declare abstract class Rule<ContextType = void, OptionsType = void> {
2815
2825
  * @public
2816
2826
  * @virtual
2817
2827
  * @param context - Error context given by a reported error.
2818
- * @returns Rule documentation and url with additional details or `null` if no
2828
+ * @returns Rule documentation and URL with additional details or `null` if no
2819
2829
  * additional documentation is available.
2820
2830
  */
2821
2831
  documentation(_context: ContextType): RuleDocumentation | null;
@@ -3299,9 +3309,9 @@ export declare interface TransformFS {
3299
3309
  /** read file from filesystem */
3300
3310
  readFileSync(this: void, path: string | number, options: {
3301
3311
  encoding: "utf8";
3302
- }): {
3312
+ }): string | {
3303
3313
  toString(encoding: "utf8"): string;
3304
- } | string;
3314
+ };
3305
3315
  }
3306
3316
 
3307
3317
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "html-validate",
3
- "version": "11.5.3",
3
+ "version": "11.5.4",
4
4
  "description": "Offline HTML5 validator and linter",
5
5
  "keywords": [
6
6
  "html",