html-validate 11.5.3 → 11.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli.js +11 -14
- package/dist/cjs/cli.js.map +1 -1
- package/dist/cjs/core-browser.js +4 -4
- package/dist/cjs/core-browser.js.map +1 -1
- package/dist/cjs/core-nodejs.js +17 -25
- package/dist/cjs/core-nodejs.js.map +1 -1
- package/dist/cjs/core.js +424 -435
- package/dist/cjs/core.js.map +1 -1
- package/dist/cjs/elements.js +11 -22
- package/dist/cjs/elements.js.map +1 -1
- package/dist/cjs/html-validate.js +1 -1
- package/dist/cjs/html-validate.js.map +1 -1
- package/dist/cjs/jest-matchers.js +49 -55
- package/dist/cjs/jest-matchers.js.map +1 -1
- package/dist/cjs/jest-utils.js +1 -2
- package/dist/cjs/jest-utils.js.map +1 -1
- package/dist/cjs/jest-worker.js.map +1 -1
- package/dist/cjs/test-utils.js +1 -2
- package/dist/cjs/test-utils.js.map +2 -2
- package/dist/cjs/tsdoc-metadata.json +1 -1
- package/dist/cjs/utils/parse-image-candidate-string.js +2 -2
- package/dist/cjs/utils/parse-image-candidate-string.js.map +1 -1
- package/dist/cjs/vitest-matchers.js +46 -50
- package/dist/cjs/vitest-matchers.js.map +1 -1
- package/dist/cjs/vitest-utils.js +1 -2
- package/dist/cjs/vitest-utils.js.map +1 -1
- package/dist/cjs/vitest-worker.js.map +1 -1
- package/dist/esm/cli.js +11 -14
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/core-browser.js +4 -4
- package/dist/esm/core-browser.js.map +1 -1
- package/dist/esm/core-nodejs.js +17 -25
- package/dist/esm/core-nodejs.js.map +1 -1
- package/dist/esm/core.js +424 -435
- package/dist/esm/core.js.map +1 -1
- package/dist/esm/elements.js +11 -22
- package/dist/esm/elements.js.map +1 -1
- package/dist/esm/html-validate.js +1 -1
- package/dist/esm/html-validate.js.map +1 -1
- package/dist/esm/jest-matchers.js +49 -55
- package/dist/esm/jest-matchers.js.map +1 -1
- package/dist/esm/jest-utils.js +1 -2
- package/dist/esm/jest-utils.js.map +1 -1
- package/dist/esm/jest-worker.js.map +1 -1
- package/dist/esm/test-utils.js +1 -2
- package/dist/esm/test-utils.js.map +2 -2
- package/dist/esm/utils/parse-image-candidate-string.js +2 -2
- package/dist/esm/utils/parse-image-candidate-string.js.map +1 -1
- package/dist/esm/vitest-matchers.js +46 -50
- package/dist/esm/vitest-matchers.js.map +1 -1
- package/dist/esm/vitest-utils.js +1 -2
- package/dist/esm/vitest-utils.js.map +1 -1
- package/dist/esm/vitest-worker.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/browser.d.ts +23 -11
- package/dist/types/index.d.ts +25 -13
- package/package.json +1 -1
|
@@ -200,7 +200,7 @@ async function run() {
|
|
|
200
200
|
});
|
|
201
201
|
const mode = getMode(argv);
|
|
202
202
|
const formatter = await cli.getFormatter(argv.formatter);
|
|
203
|
-
const maxWarnings =
|
|
203
|
+
const maxWarnings = Math.trunc(Number(argv["max-warnings"] ?? "-1"));
|
|
204
204
|
const htmlvalidate = await cli.getValidator();
|
|
205
205
|
if (Number.isNaN(maxWarnings)) {
|
|
206
206
|
console.error(`Invalid value "${String(argv["max-warnings"])}" given to --max-warnings`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html-validate.js","sources":["../../src/cli/html-validate.ts"],"sourcesContent":["/* eslint-disable no-console, n/no-process-exit -- as expected from a cli app */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport kleur from \"kleur\";\nimport { type UserErrorData, SchemaValidationError, isUserError } from \"..\";\nimport { bugs as pkgBugs, name, version } from \"../generated/package-json\";\nimport { dump } from \"./actions/dump\";\nimport { init } from \"./actions/init\";\nimport { lint } from \"./actions/lint\";\nimport { printConfig } from \"./actions/print-config\";\nimport { CLI } from \"./cli\";\nimport { ImportResolveMissingError, handleSchemaValidationError } from \"./errors\";\nimport { haveImportMetaResolve } from \"./have-import-meta-resolve\";\nimport { Mode, modeToFlag } from \"./mode\";\n\nfunction getMode(argv: Record<string, unknown>): Mode {\n\tif (argv[\"init\"]) {\n\t\treturn Mode.INIT;\n\t}\n\n\tif (argv[\"dump-events\"]) {\n\t\treturn Mode.DUMP_EVENTS;\n\t}\n\n\tif (argv[\"dump-source\"]) {\n\t\treturn Mode.DUMP_SOURCE;\n\t}\n\n\tif (argv[\"dump-tokens\"]) {\n\t\treturn Mode.DUMP_TOKENS;\n\t}\n\n\tif (argv[\"dump-tree\"]) {\n\t\treturn Mode.DUMP_TREE;\n\t}\n\n\tif (argv[\"print-config\"]) {\n\t\treturn Mode.PRINT_CONFIG;\n\t}\n\n\treturn Mode.LINT;\n}\n\nfunction requiresFilename(mode: Mode): boolean {\n\tswitch (mode) {\n\t\tcase Mode.LINT:\n\t\t\treturn true;\n\t\tcase Mode.INIT:\n\t\t\treturn false;\n\t\tcase Mode.DUMP_EVENTS:\n\t\tcase Mode.DUMP_TOKENS:\n\t\tcase Mode.DUMP_TREE:\n\t\tcase Mode.DUMP_SOURCE:\n\t\tcase Mode.PRINT_CONFIG:\n\t\t\treturn true;\n\t}\n}\n\nfunction handleUserError(err: UserErrorData): void {\n\tconst formatted = err.prettyFormat();\n\tif (formatted) {\n\t\tconsole.error(); /* blank line */\n\t\tconsole.error(formatted);\n\t\treturn;\n\t}\n\n\tconsole.error(kleur.red(\"Caught exception:\"));\n\tconsole.group();\n\t{\n\t\tconsole.error(err.prettyFormat() ?? err);\n\t}\n\tconsole.groupEnd();\n}\n\nfunction handleUnknownError(err: unknown): void {\n\tconsole.error(kleur.red(\"Caught exception:\"));\n\tconsole.group();\n\t{\n\t\tconsole.error(err);\n\t}\n\tconsole.groupEnd();\n\tconst bugUrl = `${pkgBugs}?issuable_template=Bug`;\n\tconsole.error(kleur.red(`This is a bug in ${name}-${version}.`));\n\tconsole.error(\n\t\tkleur.red(\n\t\t\t[\n\t\t\t\t`Please file a bug at ${bugUrl}`,\n\t\t\t\t`and include this message in full and if possible the content of the`,\n\t\t\t\t`file being parsed (or a reduced testcase).`,\n\t\t\t].join(\"\\n\"),\n\t\t),\n\t);\n}\n\nconst { values: argv, positionals } = (() => {\n\ttry {\n\t\treturn parseArgs({\n\t\t\targs: process.argv.slice(2),\n\t\t\toptions: {\n\t\t\t\tconfig: { type: \"string\" as const, short: \"c\" },\n\t\t\t\t\"dump-events\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-source\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-tokens\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-tree\": { type: \"boolean\" as const, default: false },\n\t\t\t\text: { type: \"string\" as const, default: \"html\" },\n\t\t\t\tformatter: { type: \"string\" as const, short: \"f\", default: \"stylish\" },\n\t\t\t\thelp: { type: \"boolean\" as const, short: \"h\", default: false },\n\t\t\t\tinit: { type: \"boolean\" as const, default: false },\n\t\t\t\t\"max-warnings\": { type: \"string\" as const },\n\t\t\t\tperformance: { type: \"boolean\" as const, default: false },\n\t\t\t\tpreset: { type: \"string\" as const, short: \"p\" },\n\t\t\t\t\"print-config\": { type: \"boolean\" as const, default: false },\n\t\t\t\trule: { type: \"string\" as const },\n\t\t\t\tstdin: { type: \"boolean\" as const, default: false },\n\t\t\t\t\"stdin-filename\": { type: \"string\" as const },\n\t\t\t\tversion: { type: \"boolean\" as const, default: false },\n\t\t\t},\n\t\t\tallowPositionals: true,\n\t\t\tstrict: true,\n\t\t});\n\t} catch (err) {\n\t\tprocess.stderr.write(`${(err as Error).message}\\n`);\n\t\tprocess.exit(1);\n\t}\n})();\n\nfunction showUsage(): void {\n\tprocess.stdout.write(`${name}-${version}\nUsage: html-validate [OPTIONS] [FILENAME..] [DIR..]\n\nCommon options:\n --ext=STRING specify file extensions (commaseparated).\n -f, --formatter=FORMATTER specify the formatter to use.\n --max-warnings=INT number of warnings to trigger nonzero exit code\n -p, --preset=STRING configuration preset to use, use\n comma-separator for multiple presets. (default:\n \"recommended\")\n --rule=RULE:SEVERITY set additional rule, use comma separator for\n multiple.\n --stdin process markup from stdin.\n --stdin-filename=STRING specify filename to report when using stdin\n\nMiscellaneous:\n -c, --config=STRING use custom configuration file.\n --init initialize project with a new configuration\n --print-config output configuration for given file.\n -h, --help show help.\n --version show version.\n\nDebugging options:\n --dump-events output events during parsing.\n --dump-source output post-transformed source data.\n --dump-tokens output tokens from lexing stage.\n --dump-tree output nodes from the dom tree.\n --performance output performance data after validation.\n\nFormatters:\n\nMultiple formatters can be specified with a comma-separated list,\ne.g. \"json,checkstyle\" to enable both.\n\nTo capture output to a file use \"formatter=/path/to/file\",\ne.g. \"checkstyle=dist/html-validate.xml\"\n`);\n}\n\nfunction showVersion(): void {\n\tprocess.stdout.write(`${name}-${version}\\n`);\n}\n\nif (argv.stdin) {\n\tpositionals.push(\"-\");\n}\n\nif (argv.version) {\n\tshowVersion();\n\tprocess.exit();\n}\n\nif (argv.help) {\n\tshowUsage();\n\tprocess.exit();\n}\n\nif (positionals.length === 0) {\n\tconst mode = getMode(argv);\n\tif (mode === Mode.LINT) {\n\t\tshowUsage();\n\t\tprocess.exit(0);\n\t} else if (requiresFilename(mode)) {\n\t\tconst flag = modeToFlag(mode);\n\t\tconsole.error(`\\`${flag}\\` requires a filename.`);\n\t\tprocess.exit(1);\n\t}\n}\n\n/* check that supplied config file exists before creating CLI */\nif (argv.config !== undefined) {\n\tconst checkPath = path.resolve(argv.config);\n\tif (!fs.existsSync(checkPath)) {\n\t\tconsole.error(`The file \"${argv.config}\" was not found.`);\n\t\tconsole.error(`The location this file was checked for at was: \"${checkPath}\"`);\n\t\tprocess.exit(1);\n\t}\n}\n\n/* eslint-disable-next-line complexity -- for now */\nasync function run(): Promise<void> {\n\tconst cli = new CLI({\n\t\tconfigFile: argv.config,\n\t\tpreset: argv.preset,\n\t\trules: argv.rule,\n\t});\n\tconst mode = getMode(argv);\n\tconst formatter = await cli.getFormatter(argv.formatter);\n\tconst maxWarnings = Number.parseInt(argv[\"max-warnings\"] ?? \"-1\", 10);\n\tconst htmlvalidate = await cli.getValidator();\n\n\t/* sanity check: ensure maxWarnings has a valid value */\n\tif (Number.isNaN(maxWarnings)) {\n\t\tconsole.error(`Invalid value \"${String(argv[\"max-warnings\"])}\" given to --max-warnings`);\n\t\tprocess.exit(1);\n\t}\n\n\t/* parse extensions (used when expanding directories) */\n\tconst extensions = argv.ext.split(\",\").map((cur: string) => {\n\t\treturn cur.startsWith(\".\") ? cur.slice(1) : cur;\n\t});\n\n\tconst files = await cli.expandFiles(positionals, { extensions });\n\tif (files.length === 0 && mode !== Mode.INIT) {\n\t\tconsole.error(\"No files matching patterns\", positionals);\n\t\tprocess.exit(1);\n\t}\n\n\ttry {\n\t\t/* istanbul ignore next -- not tested with unittests */\n\t\tif (!haveImportMetaResolve()) {\n\t\t\tthrow new ImportResolveMissingError();\n\t\t}\n\n\t\tlet success: boolean;\n\t\tswitch (mode) {\n\t\t\tcase Mode.LINT: {\n\t\t\t\tsuccess = await lint(htmlvalidate, process.stdout, process.stderr, files, {\n\t\t\t\t\tformatter,\n\t\t\t\t\tmaxWarnings,\n\t\t\t\t\tperformance: argv.performance,\n\t\t\t\t\tstdinFilename: argv[\"stdin-filename\"] ?? false,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Mode.INIT: {\n\t\t\t\tsuccess = await init(cli, process.stdout, { cwd: process.cwd() });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Mode.PRINT_CONFIG: {\n\t\t\t\tsuccess = await printConfig(htmlvalidate, process.stdout, files);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tsuccess = await dump(htmlvalidate, process.stdout, files, mode);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(success ? 0 : 1);\n\t} catch (err) {\n\t\tif (err instanceof SchemaValidationError) {\n\t\t\thandleSchemaValidationError(console, err);\n\t\t} else if (isUserError(err)) {\n\t\t\thandleUserError(err);\n\t\t} else {\n\t\t\thandleUnknownError(err);\n\t\t}\n\t\tprocess.exit(1);\n\t}\n}\n\n/* eslint-disable-next-line unicorn/prefer-top-level-await -- technical debt, as long as we bundle and ship commonjs we cannot use TLA here */\nrun().catch((err: unknown) => {\n\tconsole.error(err);\n\tprocess.exit(1);\n});\n"],"names":["argv","pkgBugs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,QAAQA,KAAAA,EAAqC;AACrD,EAAA,IAAIA,KAAAA,CAAK,MAAM,CAAA,EAAG;AACjB,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,WAAW,CAAA,EAAG;AACtB,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,cAAc,CAAA,EAAG;AACzB,IAAA,OAAO,IAAA,CAAK,YAAA;AAAA,EACb;AAEA,EAAA,OAAO,IAAA,CAAK,IAAA;AACb;AAEA,SAAS,iBAAiB,IAAA,EAAqB;AAC9C,EAAA,QAAQ,IAAA;AAAM,IACb,KAAK,IAAA,CAAK,IAAA;AACT,MAAA,OAAO,IAAA;AAAA,IACR,KAAK,IAAA,CAAK,IAAA;AACT,MAAA,OAAO,KAAA;AAAA,IACR,KAAK,IAAA,CAAK,WAAA;AAAA,IACV,KAAK,IAAA,CAAK,WAAA;AAAA,IACV,KAAK,IAAA,CAAK,SAAA;AAAA,IACV,KAAK,IAAA,CAAK,WAA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gB,CAAA,IAAK;AAAA,SACzC,CAAA;AACD,QAAA;AAAA,MACD;AAAA,MACA,KAAK,KAAK,IAAA,EAAM;AACf,QAAA,OAAA,GAAU,MAAM,IAAA,CAAK,GAAA,EAAK,OAAA,CAAQ,MAAA,EAAQ,EAAE,GAAA,EAAK,OAAA,CAAQ,GAAA,EAAI,EAAG,CAAA;AAChE,QAAA;AAAA,MACD;AAAA,MACA,KAAK,KAAK,YAAA,EAAc;AACvB,QAAA,OAAA,GAAU,MAAM,WAAA,CAAY,YAAA,EAAc,OAAA,CAAQ,QAAQ,KAAK,CAAA;AAC/D,QAAA;AAAA,MACD;AAAA,MACA,SAAS;AACR,QAAA,OAAA,GAAU,MAAM,IAAA,CAAK,YAAA,EAAc,OAAA,CAAQ,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,MAC/D;AAAA;AAED,IAAA,OAAA,CAAQ,IAAA,CAAK,OAAA,GAAU,CAAA,GAAI,CAAC,CAAA;AAAA,EAC7B,SAAS,GAAA,EAAK;AACb,IAAA,IAAI,eAAe,qBAAA,EAAuB;AACzC,MAAA,2BAAA,CAA4B,SAAS,GAAG,CAAA;AAAA,IACzC,CAAA,MAAA,IAAW,WAAA,CAAY,GAAG,CAAA,EAAG;AAC5B,MAAA,eAAA,CAAgB,GAAG,CAAA;AAAA,IACpB,CAAA,MAAO;AACN,MAAA,kBAAA,CAAmB,GAAG,CAAA;AAAA,IACvB;AACA,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,EACf;AACD;AAGA,GAAA,EAAI,CAAE,KAAA,CAAM,CAAC,GAAA,KAAiB;AAC7B,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACjB,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AACf,CAAC,CAAA"}
|
|
1
|
+
{"version":3,"file":"html-validate.js","sources":["../../src/cli/html-validate.ts"],"sourcesContent":["/* eslint-disable no-console, n/no-process-exit -- as expected from a cli app */\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport kleur from \"kleur\";\nimport { type UserErrorData, SchemaValidationError, isUserError } from \"..\";\nimport { bugs as pkgBugs, name, version } from \"../generated/package-json\";\nimport { dump } from \"./actions/dump\";\nimport { init } from \"./actions/init\";\nimport { lint } from \"./actions/lint\";\nimport { printConfig } from \"./actions/print-config\";\nimport { CLI } from \"./cli\";\nimport { ImportResolveMissingError, handleSchemaValidationError } from \"./errors\";\nimport { haveImportMetaResolve } from \"./have-import-meta-resolve\";\nimport { Mode, modeToFlag } from \"./mode\";\n\nfunction getMode(argv: Record<string, unknown>): Mode {\n\tif (argv[\"init\"]) {\n\t\treturn Mode.INIT;\n\t}\n\n\tif (argv[\"dump-events\"]) {\n\t\treturn Mode.DUMP_EVENTS;\n\t}\n\n\tif (argv[\"dump-source\"]) {\n\t\treturn Mode.DUMP_SOURCE;\n\t}\n\n\tif (argv[\"dump-tokens\"]) {\n\t\treturn Mode.DUMP_TOKENS;\n\t}\n\n\tif (argv[\"dump-tree\"]) {\n\t\treturn Mode.DUMP_TREE;\n\t}\n\n\tif (argv[\"print-config\"]) {\n\t\treturn Mode.PRINT_CONFIG;\n\t}\n\n\treturn Mode.LINT;\n}\n\nfunction requiresFilename(mode: Mode): boolean {\n\tswitch (mode) {\n\t\tcase Mode.LINT:\n\t\t\treturn true;\n\t\tcase Mode.INIT:\n\t\t\treturn false;\n\t\tcase Mode.DUMP_EVENTS:\n\t\tcase Mode.DUMP_TOKENS:\n\t\tcase Mode.DUMP_TREE:\n\t\tcase Mode.DUMP_SOURCE:\n\t\tcase Mode.PRINT_CONFIG:\n\t\t\treturn true;\n\t}\n}\n\nfunction handleUserError(err: UserErrorData): void {\n\tconst formatted = err.prettyFormat();\n\tif (formatted) {\n\t\tconsole.error(); /* blank line */\n\t\tconsole.error(formatted);\n\t\treturn;\n\t}\n\n\tconsole.error(kleur.red(\"Caught exception:\"));\n\tconsole.group();\n\t{\n\t\tconsole.error(err.prettyFormat() ?? err);\n\t}\n\tconsole.groupEnd();\n}\n\nfunction handleUnknownError(err: unknown): void {\n\tconsole.error(kleur.red(\"Caught exception:\"));\n\tconsole.group();\n\t{\n\t\tconsole.error(err);\n\t}\n\tconsole.groupEnd();\n\tconst bugUrl = `${pkgBugs}?issuable_template=Bug`;\n\tconsole.error(kleur.red(`This is a bug in ${name}-${version}.`));\n\tconsole.error(\n\t\tkleur.red(\n\t\t\t[\n\t\t\t\t`Please file a bug at ${bugUrl}`,\n\t\t\t\t`and include this message in full and if possible the content of the`,\n\t\t\t\t`file being parsed (or a reduced testcase).`,\n\t\t\t].join(\"\\n\"),\n\t\t),\n\t);\n}\n\nconst { values: argv, positionals } = (() => {\n\ttry {\n\t\treturn parseArgs({\n\t\t\targs: process.argv.slice(2),\n\t\t\toptions: {\n\t\t\t\tconfig: { type: \"string\" as const, short: \"c\" },\n\t\t\t\t\"dump-events\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-source\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-tokens\": { type: \"boolean\" as const, default: false },\n\t\t\t\t\"dump-tree\": { type: \"boolean\" as const, default: false },\n\t\t\t\text: { type: \"string\" as const, default: \"html\" },\n\t\t\t\tformatter: { type: \"string\" as const, short: \"f\", default: \"stylish\" },\n\t\t\t\thelp: { type: \"boolean\" as const, short: \"h\", default: false },\n\t\t\t\tinit: { type: \"boolean\" as const, default: false },\n\t\t\t\t\"max-warnings\": { type: \"string\" as const },\n\t\t\t\tperformance: { type: \"boolean\" as const, default: false },\n\t\t\t\tpreset: { type: \"string\" as const, short: \"p\" },\n\t\t\t\t\"print-config\": { type: \"boolean\" as const, default: false },\n\t\t\t\trule: { type: \"string\" as const },\n\t\t\t\tstdin: { type: \"boolean\" as const, default: false },\n\t\t\t\t\"stdin-filename\": { type: \"string\" as const },\n\t\t\t\tversion: { type: \"boolean\" as const, default: false },\n\t\t\t},\n\t\t\tallowPositionals: true,\n\t\t\tstrict: true,\n\t\t});\n\t} catch (err) {\n\t\tprocess.stderr.write(`${(err as Error).message}\\n`);\n\t\tprocess.exit(1);\n\t}\n})();\n\nfunction showUsage(): void {\n\tprocess.stdout.write(`${name}-${version}\nUsage: html-validate [OPTIONS] [FILENAME..] [DIR..]\n\nCommon options:\n --ext=STRING specify file extensions (commaseparated).\n -f, --formatter=FORMATTER specify the formatter to use.\n --max-warnings=INT number of warnings to trigger nonzero exit code\n -p, --preset=STRING configuration preset to use, use\n comma-separator for multiple presets. (default:\n \"recommended\")\n --rule=RULE:SEVERITY set additional rule, use comma separator for\n multiple.\n --stdin process markup from stdin.\n --stdin-filename=STRING specify filename to report when using stdin\n\nMiscellaneous:\n -c, --config=STRING use custom configuration file.\n --init initialize project with a new configuration\n --print-config output configuration for given file.\n -h, --help show help.\n --version show version.\n\nDebugging options:\n --dump-events output events during parsing.\n --dump-source output post-transformed source data.\n --dump-tokens output tokens from lexing stage.\n --dump-tree output nodes from the dom tree.\n --performance output performance data after validation.\n\nFormatters:\n\nMultiple formatters can be specified with a comma-separated list,\ne.g. \"json,checkstyle\" to enable both.\n\nTo capture output to a file use \"formatter=/path/to/file\",\ne.g. \"checkstyle=dist/html-validate.xml\"\n`);\n}\n\nfunction showVersion(): void {\n\tprocess.stdout.write(`${name}-${version}\\n`);\n}\n\nif (argv.stdin) {\n\tpositionals.push(\"-\");\n}\n\nif (argv.version) {\n\tshowVersion();\n\tprocess.exit();\n}\n\nif (argv.help) {\n\tshowUsage();\n\tprocess.exit();\n}\n\nif (positionals.length === 0) {\n\tconst mode = getMode(argv);\n\tif (mode === Mode.LINT) {\n\t\tshowUsage();\n\t\tprocess.exit(0);\n\t} else if (requiresFilename(mode)) {\n\t\tconst flag = modeToFlag(mode);\n\t\tconsole.error(`\\`${flag}\\` requires a filename.`);\n\t\tprocess.exit(1);\n\t}\n}\n\n/* check that supplied config file exists before creating CLI */\nif (argv.config !== undefined) {\n\tconst checkPath = path.resolve(argv.config);\n\tif (!fs.existsSync(checkPath)) {\n\t\tconsole.error(`The file \"${argv.config}\" was not found.`);\n\t\tconsole.error(`The location this file was checked for at was: \"${checkPath}\"`);\n\t\tprocess.exit(1);\n\t}\n}\n\n/* eslint-disable-next-line complexity -- for now */\nasync function run(): Promise<void> {\n\tconst cli = new CLI({\n\t\tconfigFile: argv.config,\n\t\tpreset: argv.preset,\n\t\trules: argv.rule,\n\t});\n\tconst mode = getMode(argv);\n\tconst formatter = await cli.getFormatter(argv.formatter);\n\tconst maxWarnings = Math.trunc(Number(argv[\"max-warnings\"] ?? \"-1\"));\n\tconst htmlvalidate = await cli.getValidator();\n\n\t/* sanity check: ensure maxWarnings has a valid value */\n\tif (Number.isNaN(maxWarnings)) {\n\t\tconsole.error(`Invalid value \"${String(argv[\"max-warnings\"])}\" given to --max-warnings`);\n\t\tprocess.exit(1);\n\t}\n\n\t/* parse extensions (used when expanding directories) */\n\tconst extensions = argv.ext.split(\",\").map((cur: string) => {\n\t\treturn cur.startsWith(\".\") ? cur.slice(1) : cur;\n\t});\n\n\tconst files = await cli.expandFiles(positionals, { extensions });\n\tif (files.length === 0 && mode !== Mode.INIT) {\n\t\tconsole.error(\"No files matching patterns\", positionals);\n\t\tprocess.exit(1);\n\t}\n\n\ttry {\n\t\t/* istanbul ignore next -- not tested with unittests */\n\t\tif (!haveImportMetaResolve()) {\n\t\t\tthrow new ImportResolveMissingError();\n\t\t}\n\n\t\tlet success: boolean;\n\t\tswitch (mode) {\n\t\t\tcase Mode.LINT: {\n\t\t\t\tsuccess = await lint(htmlvalidate, process.stdout, process.stderr, files, {\n\t\t\t\t\tformatter,\n\t\t\t\t\tmaxWarnings,\n\t\t\t\t\tperformance: argv.performance,\n\t\t\t\t\tstdinFilename: argv[\"stdin-filename\"] ?? false,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Mode.INIT: {\n\t\t\t\tsuccess = await init(cli, process.stdout, { cwd: process.cwd() });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase Mode.PRINT_CONFIG: {\n\t\t\t\tsuccess = await printConfig(htmlvalidate, process.stdout, files);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tsuccess = await dump(htmlvalidate, process.stdout, files, mode);\n\t\t\t}\n\t\t}\n\t\tprocess.exit(success ? 0 : 1);\n\t} catch (err) {\n\t\tif (err instanceof SchemaValidationError) {\n\t\t\thandleSchemaValidationError(console, err);\n\t\t} else if (isUserError(err)) {\n\t\t\thandleUserError(err);\n\t\t} else {\n\t\t\thandleUnknownError(err);\n\t\t}\n\t\tprocess.exit(1);\n\t}\n}\n\n/* eslint-disable-next-line unicorn/prefer-top-level-await, unicorn/prefer-await -- technical debt, as long as we bundle and ship commonjs we cannot use TLA here */\nrun().catch((err: unknown) => {\n\tconsole.error(err);\n\tprocess.exit(1);\n});\n"],"names":["argv","pkgBugs"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgBA,SAAS,QAAQA,KAAAA,EAAqC;AACrD,EAAA,IAAIA,KAAAA,CAAK,MAAM,CAAA,EAAG;AACjB,IAAA,OAAO,IAAA,CAAK,IAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,aAAa,CAAA,EAAG;AACxB,IAAA,OAAO,IAAA,CAAK,WAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,WAAW,CAAA,EAAG;AACtB,IAAA,OAAO,IAAA,CAAK,SAAA;AAAA,EACb;AAEA,EAAA,IAAIA,KAAAA,CAAK,cAAc,CAAA,EAAG;AACzB,IAAA,OAAO,IAAA,CAAK,YAAA;AAAA,EACb;AAEA,EAAA,OAAO,IAAA,CAAK,IAAA;AACb;AAEA,SAAS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C,CAAA;AAAA,EACf;AACD;AAGA,GAAA,EAAI,CAAE,KAAA,CAAM,CAAC,GAAA,KAAiB;AAC7B,EAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AACjB,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -12,13 +12,12 @@ function createMatcher$6() {
|
|
|
12
12
|
() => "Result should not contain error"
|
|
13
13
|
)
|
|
14
14
|
};
|
|
15
|
-
} else {
|
|
16
|
-
const firstError = report.results[0].messages[0];
|
|
17
|
-
return {
|
|
18
|
-
pass: false,
|
|
19
|
-
message: () => `Result should be valid but had error "${firstError.message}"`
|
|
20
|
-
};
|
|
21
15
|
}
|
|
16
|
+
const firstError = report.results[0].messages[0];
|
|
17
|
+
return {
|
|
18
|
+
pass: false,
|
|
19
|
+
message: () => `Result should be valid but had error "${firstError.message}"`
|
|
20
|
+
};
|
|
22
21
|
}
|
|
23
22
|
return diverge(toBeValid);
|
|
24
23
|
}
|
|
@@ -30,15 +29,14 @@ function createMatcher$5() {
|
|
|
30
29
|
pass: false,
|
|
31
30
|
message: () => "Result should be invalid but had no errors"
|
|
32
31
|
};
|
|
33
|
-
} else {
|
|
34
|
-
return {
|
|
35
|
-
pass: true,
|
|
36
|
-
message: (
|
|
37
|
-
/* istanbul ignore next */
|
|
38
|
-
() => "Result should not contain error"
|
|
39
|
-
)
|
|
40
|
-
};
|
|
41
32
|
}
|
|
33
|
+
return {
|
|
34
|
+
pass: true,
|
|
35
|
+
message: (
|
|
36
|
+
/* istanbul ignore next */
|
|
37
|
+
() => "Result should not contain error"
|
|
38
|
+
)
|
|
39
|
+
};
|
|
42
40
|
}
|
|
43
41
|
return diverge(toBeInvalid);
|
|
44
42
|
}
|
|
@@ -57,13 +55,15 @@ function isMessage(arg) {
|
|
|
57
55
|
"size",
|
|
58
56
|
"selector",
|
|
59
57
|
"context"
|
|
60
|
-
].some((key) => key
|
|
58
|
+
].some((key) => Object.hasOwn(arg, key));
|
|
61
59
|
}
|
|
62
60
|
function isConfig(arg) {
|
|
63
61
|
if (!arg || typeof arg !== "object") {
|
|
64
62
|
return false;
|
|
65
63
|
}
|
|
66
|
-
return ["root", "extends", "elements", "plugin", "transform", "rules"].some(
|
|
64
|
+
return ["root", "extends", "elements", "plugin", "transform", "rules"].some(
|
|
65
|
+
(key) => Object.hasOwn(arg, key)
|
|
66
|
+
);
|
|
67
67
|
}
|
|
68
68
|
function isString(arg) {
|
|
69
69
|
return typeof arg === "string";
|
|
@@ -74,9 +74,8 @@ function getMarkup(src) {
|
|
|
74
74
|
}
|
|
75
75
|
if (typeof src === "string") {
|
|
76
76
|
return src;
|
|
77
|
-
} else {
|
|
78
|
-
throw new TypeError(`Failed to get markup from "${typeof src}" argument`);
|
|
79
77
|
}
|
|
78
|
+
throw new TypeError(`Failed to get markup from "${typeof src}" argument`);
|
|
80
79
|
}
|
|
81
80
|
function createMatcher$4(expect) {
|
|
82
81
|
function toHTMLValidate(actual, arg0, arg1, arg2) {
|
|
@@ -101,39 +100,38 @@ function toHTMLValidateImpl(expect, actual, expectedError, userConfig, filename)
|
|
|
101
100
|
const syncFn = createSyncFn(jestWorkerPath);
|
|
102
101
|
const report = syncFn(actual, actualFilename, config);
|
|
103
102
|
const pass = report.valid;
|
|
104
|
-
const result = report.results[0];
|
|
105
103
|
if (pass) {
|
|
106
104
|
return { pass, message: () => "HTML is valid when an error was expected" };
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
105
|
+
}
|
|
106
|
+
const result = report.results[0];
|
|
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 = this.utils.diff(expected, actual2, {
|
|
112
|
+
expand: this.expand,
|
|
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
|
-
|
|
129
|
-
|
|
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 };
|
|
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, { expand: this.expand });
|
|
@@ -219,9 +215,8 @@ function getResults(filename, value) {
|
|
|
219
215
|
return report.results.map((it) => {
|
|
220
216
|
return { ...it, filePath: "inline" };
|
|
221
217
|
});
|
|
222
|
-
} else {
|
|
223
|
-
return value.results;
|
|
224
218
|
}
|
|
219
|
+
return value.results;
|
|
225
220
|
}
|
|
226
221
|
|
|
227
222
|
function createMatcher$1() {
|
|
@@ -251,9 +246,8 @@ function toMatchInlineCodeframe(actual, ...rest) {
|
|
|
251
246
|
};
|
|
252
247
|
if (isThenable(actual)) {
|
|
253
248
|
return actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));
|
|
254
|
-
} else {
|
|
255
|
-
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
256
249
|
}
|
|
250
|
+
return toMatchInlineCodeframeImpl(context, actual, ...rest);
|
|
257
251
|
}
|
|
258
252
|
function createMatcher() {
|
|
259
253
|
return toMatchInlineCodeframe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-matchers.js","sources":["../../src/jest/matchers/to-be-valid.ts","../../src/jest/matchers/to-be-invalid.ts","../../src/jest/matchers/to-htmlvalidate.ts","../../src/jest/matchers/to-have-error.ts","../../src/jest/matchers/to-have-errors.ts","../../src/jest/matchers/get-results.ts","../../src/jest/matchers/to-match-codeframe.ts","../../src/jest/matchers/to-match-inline-codeframe.ts"],"sourcesContent":["import { type SyncExpectationResult } from \"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 \"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 expect } from \"@jest/globals\";\nimport deepmerge from \"deepmerge\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, jestWorkerPath } from \"../worker\";\n\ntype JestExpect = 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: JestExpect): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherContext,\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: MatcherContext,\n\texpect: JestExpect,\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>(jestWorkerPath);\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\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\texpand: this.expand,\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\treturn { pass: !errorPass, message: expectedErrorMessage };\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 expect } from \"@jest/globals\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype JestExpect = typeof expect;\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherContext,\n\texpect: JestExpect,\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, { expand: context.expand });\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 };\n}\n\nfunction createMatcher(\n\texpect: JestExpect,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, unknown?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\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: MatcherContext,\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 expect } from \"@jest/globals\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype JestExpect = typeof expect;\n\nfunction createMatcher(\n\texpect: JestExpect,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherContext,\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\treturn expect.objectContaining({ ruleId, message });\n\t\t\t} else {\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, { expand: this.expand });\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 Report, type Result } from \"../../reporter\";\nimport { type ValidateStringFn, createSyncFn, jestWorkerPath } from \"../worker\";\n\n/**\n * @internal\n */\nexport function getResults(filename: string, value: Report | string): Result[] {\n\tif (typeof value === \"string\") {\n\t\tconst syncFn = createSyncFn<ValidateStringFn>(jestWorkerPath);\n\t\tconst report = syncFn(value, filename, {\n\t\t\trules: {\n\t\t\t\t\"void-style\": \"off\",\n\t\t\t},\n\t\t});\n\t\treturn report.results.map((it) => {\n\t\t\treturn { ...it, filePath: \"inline\" };\n\t\t});\n\t} else {\n\t\treturn value.results;\n\t}\n}\n","import { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { toMatchSnapshot } from \"jest-snapshot\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, codeframe, diverge } from \"../utils\";\nimport { getResults } from \"./get-results\";\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): SyncExpectationResult {\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 snapshot = codeframe(results).replaceAll(/\\s+$/gm, \"\");\n\n\t\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any, @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 {\n\ttype AsyncExpectationResult,\n\ttype MatcherContext,\n\ttype SyncExpectationResult,\n} from \"expect\";\nimport { toMatchInlineSnapshot } from \"jest-snapshot\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe, isThenable } from \"../utils\";\nimport { getResults } from \"./get-results\";\n\nfunction toMatchInlineCodeframeImpl(\n\tcontext: MatcherContext,\n\tactual: Report | string,\n\t...rest: Array<string | object>\n): SyncExpectationResult {\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 snapshot = codeframe(results).replaceAll(/\\s+$/gm, \"\");\n\n\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any, @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) => SyncExpectationResult | Promise<SyncExpectationResult>;\n\nfunction toMatchInlineCodeframe(\n\tthis: MatcherContext,\n\tactual: Report | Promise<Report> | string,\n\t...rest: Array<string | object>\n): SyncExpectationResult | AsyncExpectationResult {\n\tconst context = {\n\t\t...this,\n\n\t\t/* Capture the original stack frames as they are needed by \"jest-snapshot\"\n\t\t * to determine where to write the inline snapshots. When resolving the\n\t\t * promise the original stack frames are lost and the snapshot will be\n\t\t * written in this files instaed. */\n\t\terror: new Error(\"stacktrace\"),\n\t};\n\n\tif (isThenable(actual)) {\n\t\treturn actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));\n\t} else {\n\t\treturn toMatchInlineCodeframeImpl(context, actual, ...rest);\n\t}\n}\n\nfunction createMatcher(): ToMatchInlineCodeframeMatcher {\n\treturn toMatchInlineCodeframe;\n}\n\nexport { createMatcher as toMatchInlineCodeframe };\n"],"names":["createMatcher","actual"],"mappings":";;;;AAIA,SAASA,eAAA,GAAgD;AACxD,EAAA,SAAS,UAAU,MAAA,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AAQ,qBAAA,CAA8B,IAAA,CAAK,OAAA,EAAS,QAAA,EAAU,GAAG,IAAI,CAAA;AACtE;AAQA,SAAS,sBAAA,CAER,WACG,IAAA,EAC8C;AACjD,EAAA,MAAM,OAAA,GAAU;AAAA,IACf,GAAG,IAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAMH,KAAA,EAAO,IAAI,KAAA,CAAM,YAAY;AAAA,GAC9B;AAEA,EAAA,IAAI,UAAA,CAAW,MAAM,CAAA,EAAG;AACvB,IAAA,OAAO,MAAA,CAAO,KAAK,CAAC,QAAA,KAAa,2BAA2B,OAAA,EAAS,QAAA,EAAU,GAAG,IAAI,CAAC,CAAA;AAAA,EACxF,CAAA,MAAO;AACN,IAAA,OAAO,0BAAA,CAA2B,OAAA,EAAS,MAAA,EAAQ,GAAG,IAAI,CAAA;AAAA,EAC3D;AACD;AAEA,SAAS,aAAA,GAA+C;AACvD,EAAA,OAAO,sBAAA;AACR;;;;"}
|
|
1
|
+
{"version":3,"file":"jest-matchers.js","sources":["../../src/jest/matchers/to-be-valid.ts","../../src/jest/matchers/to-be-invalid.ts","../../src/jest/matchers/to-htmlvalidate.ts","../../src/jest/matchers/to-have-error.ts","../../src/jest/matchers/to-have-errors.ts","../../src/jest/matchers/get-results.ts","../../src/jest/matchers/to-match-codeframe.ts","../../src/jest/matchers/to-match-inline-codeframe.ts"],"sourcesContent":["import { type SyncExpectationResult } from \"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 \"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 expect } from \"@jest/globals\";\nimport deepmerge from \"deepmerge\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type ConfigData } from \"../../config\";\nimport { type Message } from \"../../message\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\nimport { type ValidateStringFn, createSyncFn, jestWorkerPath } from \"../worker\";\n\ntype JestExpect = 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: JestExpect): MaybeAsyncCallback<unknown, [Arg1?, Arg2?, Arg3?]> {\n\tfunction toHTMLValidate(\n\t\tthis: MatcherContext,\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: MatcherContext,\n\texpect: JestExpect,\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>(jestWorkerPath);\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\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\texpand: this.expand,\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\treturn { pass: !errorPass, message: expectedErrorMessage };\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 expect } from \"@jest/globals\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type Message } from \"../../message\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype JestExpect = typeof expect;\n\nfunction toHaveErrorImpl(\n\tcontext: MatcherContext,\n\texpect: JestExpect,\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, { expand: context.expand });\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 };\n}\n\nfunction createMatcher(\n\texpect: JestExpect,\n):\n\t| MaybeAsyncCallback<Report, [Partial<Message>]>\n\t| MaybeAsyncCallback<Report, [string, string, unknown?]> {\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\n\t\tactual: Report,\n\t\terror: Partial<Message>,\n\t): SyncExpectationResult;\n\tfunction toHaveError(\n\t\tthis: MatcherContext,\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: MatcherContext,\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 expect } from \"@jest/globals\";\nimport { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, diverge } from \"../utils\";\n\ntype JestExpect = typeof expect;\n\nfunction createMatcher(\n\texpect: JestExpect,\n): MaybeAsyncCallback<Report, [Array<[string, string] | Record<string, unknown>>]> {\n\tfunction toHaveErrors(\n\t\tthis: MatcherContext,\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\treturn expect.objectContaining({ ruleId, message });\n\t\t\t}\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, { expand: this.expand });\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 Report, type Result } from \"../../reporter\";\nimport { type ValidateStringFn, createSyncFn, jestWorkerPath } from \"../worker\";\n\n/**\n * @internal\n */\nexport function getResults(filename: string, value: Report | string): Result[] {\n\tif (typeof value === \"string\") {\n\t\tconst syncFn = createSyncFn<ValidateStringFn>(jestWorkerPath);\n\t\tconst report = syncFn(value, filename, {\n\t\t\trules: {\n\t\t\t\t\"void-style\": \"off\",\n\t\t\t},\n\t\t});\n\t\treturn report.results.map((it) => {\n\t\t\treturn { ...it, filePath: \"inline\" };\n\t\t});\n\t}\n\treturn value.results;\n}\n","import { type MatcherContext, type SyncExpectationResult } from \"expect\";\nimport { toMatchSnapshot } from \"jest-snapshot\";\nimport { type Report } from \"../../reporter\";\nimport { type MaybeAsyncCallback, codeframe, diverge } from \"../utils\";\nimport { getResults } from \"./get-results\";\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): SyncExpectationResult {\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 snapshot = codeframe(results).replaceAll(/\\s+$/gm, \"\");\n\n\t\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any, @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 {\n\ttype AsyncExpectationResult,\n\ttype MatcherContext,\n\ttype SyncExpectationResult,\n} from \"expect\";\nimport { toMatchInlineSnapshot } from \"jest-snapshot\";\nimport { type Report } from \"../../reporter\";\nimport { codeframe, isThenable } from \"../utils\";\nimport { getResults } from \"./get-results\";\n\nfunction toMatchInlineCodeframeImpl(\n\tcontext: MatcherContext,\n\tactual: Report | string,\n\t...rest: Array<string | object>\n): SyncExpectationResult {\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 snapshot = codeframe(results).replaceAll(/\\s+$/gm, \"\");\n\n\t/* eslint-disable-next-line @typescript-eslint/no-explicit-any, @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) => SyncExpectationResult | Promise<SyncExpectationResult>;\n\nfunction toMatchInlineCodeframe(\n\tthis: MatcherContext,\n\tactual: Report | Promise<Report> | string,\n\t...rest: Array<string | object>\n): SyncExpectationResult | AsyncExpectationResult {\n\tconst context = {\n\t\t...this,\n\n\t\t/* Capture the original stack frames as they are needed by \"jest-snapshot\"\n\t\t * to determine where to write the inline snapshots. When resolving the\n\t\t * promise the original stack frames are lost and the snapshot will be\n\t\t * written in this files instaed. */\n\t\terror: new Error(\"stacktrace\"),\n\t};\n\n\tif (isThenable(actual)) {\n\t\t/* eslint-disable-next-line unicorn/prefer-await -- intentional, we must return sync result if sync parameters are used */\n\t\treturn actual.then((resolved) => toMatchInlineCodeframeImpl(context, resolved, ...rest));\n\t}\n\treturn toMatchInlineCodeframeImpl(context, actual, ...rest);\n}\n\nfunction createMatcher(): ToMatchInlineCodeframeMatcher {\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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A;AACR;;;;"}
|
package/dist/esm/jest-utils.js
CHANGED
|
@@ -44,9 +44,8 @@ function diverge(fn) {
|
|
|
44
44
|
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":"jest-utils.js","sources":["../../src/jest/utils/codeframe.ts","../../src/jest/utils/is-thenable.ts","../../src/jest/utils/diverge.ts","../../src/jest/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 MatcherContext,\n\ttype SyncExpectationResult,\n} from \"expect\";\nimport { isThenable } from \"./is-thenable\";\n\ntype SyncCallback<T, TArgs extends unknown[]> = (\n\tthis: MatcherContext,\n\tactual: T,\n\t...args: TArgs\n) => SyncExpectationResult;\n\n/**\n * @internal\n */\nexport interface MaybeAsyncCallback<TActual, TArgs extends unknown[]> {\n\t(this: MatcherContext, actual: TActual, ...args: TArgs): SyncExpectationResult;\n\t(this: MatcherContext, 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: MatcherContext, actual: T, ...args: TArgs): SyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherContext,\n\t\tactual: Promise<T>,\n\t\t...args: TArgs\n\t): AsyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherContext,\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,C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CAAA;AAED,EAAA,IAAI,MAAA,GAAS,CAAA;AAEb,EAAA,MAAM,MAAA,GAAS,IAAI,IAAA,KAA2B;AAC7C,IAAA,MAAM,EAAA,GAAK,MAAA,EAAA;AACX,IAAA,MAAM,GAAA,GAA0C,EAAE,EAAA,EAAI,IAAA,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":"jest-utils.js","sources":["../../src/jest/utils/codeframe.ts","../../src/jest/utils/is-thenable.ts","../../src/jest/utils/diverge.ts","../../src/jest/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 MatcherContext,\n\ttype SyncExpectationResult,\n} from \"expect\";\nimport { isThenable } from \"./is-thenable\";\n\ntype SyncCallback<T, TArgs extends unknown[]> = (\n\tthis: MatcherContext,\n\tactual: T,\n\t...args: TArgs\n) => SyncExpectationResult;\n\n/**\n * @internal\n */\nexport interface MaybeAsyncCallback<TActual, TArgs extends unknown[]> {\n\t(this: MatcherContext, actual: TActual, ...args: TArgs): SyncExpectationResult;\n\t(this: MatcherContext, 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: MatcherContext, actual: T, ...args: TArgs): SyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherContext,\n\t\tactual: Promise<T>,\n\t\t...args: TArgs\n\t): AsyncExpectationResult;\n\tfunction diverged(\n\t\tthis: MatcherContext,\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 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,IAAA,CAAK,GAAG,CAAA;AACpD,EAAA,MAAM,MAAA,GAAS,CAAC,SAAS,CAAA;AAGzB,EAAA,IAAI,UAAA,EAAY;AACf,IAAA,MAAM,MAAA,GAAS,iBAAiB,UAAA,EAAY;AAAA,MAC3C,KAAA,EAAO,iBAAiB,OAAO,CAAA;AAAA,MAC/B,GAAA,EAAK,cAAA,CAAe,OAAA,EAAS,UAAU;AAAA,KACvC,CAAA;AACD,IAAA,MAAA,CAAO,KAAK,MAAM,CAAA;AAAA,EACnB;AAEA,EAAA,MAAA,CAAO,IAAA,CAAK,CAAA,UAAA,EAAa,OAAA,CAAQ,QAAA,IAAY,GAAG,CAAA,CAAE,CAAA;AAElD,EAAA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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jest-worker.js","sources":["../../src/jest/worker/jest-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;
|
|
1
|
+
{"version":3,"file":"jest-worker.js","sources":["../../src/jest/worker/jest-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"}
|
package/dist/esm/test-utils.js
CHANGED
|
@@ -36,9 +36,8 @@ async function transformSource(fn, source, chain) {
|
|
|
36
36
|
const result = await fn.call(context, source);
|
|
37
37
|
if (isIterable(result)) {
|
|
38
38
|
return await Promise.all(Array.from(result));
|
|
39
|
-
} else {
|
|
40
|
-
return [result];
|
|
41
39
|
}
|
|
40
|
+
return [result];
|
|
42
41
|
}
|
|
43
42
|
export {
|
|
44
43
|
transformFile,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../internal/test-utils/src/test-utils.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from \"node:fs\";\nimport {\n\ttype Source,\n\ttype TransformContext,\n\ttype Transformer,\n\ttype TransformerChainedResult,\n} from \"html-validate\";\n\nexport {\n\ttype Source,\n\ttype Transformer,\n\ttype TransformerChainedResult,\n\ttype TransformerResult,\n} from \"html-validate\";\n\nfunction isIterable(\n\tvalue: Source | Iterable<Source | Promise<Source>>,\n): value is Iterable<Source | Promise<Source>> {\n\treturn Symbol.iterator in value;\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param filename - Filename to read data from. Must be readable.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport function transformFile(\n\tfn: Transformer,\n\tfilename: string,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst data = fs.readFileSync(filename, \"utf-8\");\n\tconst source: Source = {\n\t\tfilename,\n\t\tline: 1,\n\t\tcolumn: 1,\n\t\toffset: 0,\n\t\tdata,\n\t};\n\treturn transformSource(fn, source, chain);\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param data - String to transform.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport function transformString(\n\tfn: Transformer,\n\tdata: string,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst source: Source = {\n\t\tfilename: \"inline\",\n\t\tline: 1,\n\t\tcolumn: 1,\n\t\toffset: 0,\n\t\tdata,\n\t};\n\treturn transformSource(fn, source, chain);\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param data - Source to transform.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport async function transformSource(\n\tfn: Transformer,\n\tsource: Source,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst defaultChain = (source: Source): Iterable<Source> => [source];\n\tconst context: TransformContext = {\n\t\thasChain: /* istanbul ignore next */ () => true,\n\t\tchain: chain ?? defaultChain,\n\t};\n\tconst result = await fn.call(context, source);\n\tif (isIterable(result)) {\n\t\treturn await Promise.all(Array.from(result));\n\t}
|
|
5
|
-
"mappings": ";AAAA,OAAO,QAAQ;AAef,SAAS,WACR,OAC8C;
|
|
4
|
+
"sourcesContent": ["import fs from \"node:fs\";\nimport {\n\ttype Source,\n\ttype TransformContext,\n\ttype Transformer,\n\ttype TransformerChainedResult,\n} from \"html-validate\";\n\nexport {\n\ttype Source,\n\ttype Transformer,\n\ttype TransformerChainedResult,\n\ttype TransformerResult,\n} from \"html-validate\";\n\nfunction isIterable(\n\tvalue: Source | Iterable<Source | Promise<Source>>,\n): value is Iterable<Source | Promise<Source>> {\n\t/* eslint-disable-next-line unicorn/no-computed-property-existence-check -- want to search prototype chain */\n\treturn Symbol.iterator in value;\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param filename - Filename to read data from. Must be readable.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport function transformFile(\n\tfn: Transformer,\n\tfilename: string,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst data = fs.readFileSync(filename, \"utf-8\");\n\tconst source: Source = {\n\t\tfilename,\n\t\tline: 1,\n\t\tcolumn: 1,\n\t\toffset: 0,\n\t\tdata,\n\t};\n\treturn transformSource(fn, source, chain);\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param data - String to transform.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport function transformString(\n\tfn: Transformer,\n\tdata: string,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst source: Source = {\n\t\tfilename: \"inline\",\n\t\tline: 1,\n\t\tcolumn: 1,\n\t\toffset: 0,\n\t\tdata,\n\t};\n\treturn transformSource(fn, source, chain);\n}\n\n/**\n * Helper function to call a transformer function in test-cases.\n *\n * @public\n * @param fn - Transformer function to call.\n * @param data - Source to transform.\n * @param chain - If set this function is called when chaining transformers. Default is pass-thru.\n */\nexport async function transformSource(\n\tfn: Transformer,\n\tsource: Source,\n\tchain?: (source: Source, filename: string) => TransformerChainedResult,\n): Promise<Source[]> {\n\tconst defaultChain = (source: Source): Iterable<Source> => [source];\n\tconst context: TransformContext = {\n\t\thasChain: /* istanbul ignore next */ () => true,\n\t\tchain: chain ?? defaultChain,\n\t};\n\tconst result = await fn.call(context, source);\n\tif (isIterable(result)) {\n\t\treturn await Promise.all(Array.from(result));\n\t}\n\treturn [result];\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,OAAO,QAAQ;AAef,SAAS,WACR,OAC8C;AAE9C,SAAO,OAAO,YAAY;AAC3B;AAUO,SAAS,cACf,IACA,UACA,OACoB;AACpB,QAAM,OAAO,GAAG,aAAa,UAAU,OAAO;AAC9C,QAAM,SAAiB;AAAA,IACtB;AAAA,IACA,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,EACD;AACA,SAAO,gBAAgB,IAAI,QAAQ,KAAK;AACzC;AAUO,SAAS,gBACf,IACA,MACA,OACoB;AACpB,QAAM,SAAiB;AAAA,IACtB,UAAU;AAAA,IACV,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,EACD;AACA,SAAO,gBAAgB,IAAI,QAAQ,KAAK;AACzC;AAUA,eAAsB,gBACrB,IACA,QACA,OACoB;AACpB,QAAM,eAAe,CAACA,YAAqC,CAACA,OAAM;AAClE,QAAM,UAA4B;AAAA,IACjC;AAAA;AAAA,MAAqC,MAAM;AAAA;AAAA,IAC3C,OAAO,SAAS;AAAA,EACjB;AACA,QAAM,SAAS,MAAM,GAAG,KAAK,SAAS,MAAM;AAC5C,MAAI,WAAW,MAAM,GAAG;AACvB,WAAO,MAAM,QAAQ,IAAI,MAAM,KAAK,MAAM,CAAC;AAAA,EAC5C;AACA,SAAO,CAAC,MAAM;AACf;",
|
|
6
6
|
"names": ["source"]
|
|
7
7
|
}
|
|
@@ -16,7 +16,7 @@ function parseImageCandidateString(srcset) {
|
|
|
16
16
|
return {
|
|
17
17
|
url,
|
|
18
18
|
descriptor: "width",
|
|
19
|
-
value:
|
|
19
|
+
value: Math.trunc(Number(descriptor.slice(0, -1))),
|
|
20
20
|
raw: descriptor
|
|
21
21
|
};
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ function parseImageCandidateString(srcset) {
|
|
|
24
24
|
return {
|
|
25
25
|
url,
|
|
26
26
|
descriptor: "density",
|
|
27
|
-
value: Number
|
|
27
|
+
value: Number(descriptor.slice(0, -1)),
|
|
28
28
|
raw: descriptor
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-image-candidate-string.js","sources":["../../../src/utils/parse-image-candidate-string.ts"],"sourcesContent":["/**\n * @internal\n */\nexport type ParsedImageCandidateDescriptor =\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"width\";\n\t\t\tvalue: number;\n\t\t\traw: string;\n\t }\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"density\";\n\t\t\tvalue: number;\n\t\t\traw: string;\n\t }\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"none\";\n\t\t\traw: string | null;\n\t };\n\n/**\n * Parse descriptors from an image candidate string.\n *\n * @internal\n * @param srcset - Image candidate string to parse.\n * @returns Parsed descriptors from all candidates in the string.\n */\nexport function parseImageCandidateString(srcset: string): ParsedImageCandidateDescriptor[] {\n\tif (!srcset.trim()) {\n\t\treturn [];\n\t}\n\treturn srcset.split(\",\").map((candidate): ParsedImageCandidateDescriptor => {\n\t\tconst parts = candidate.trim().split(/\\s+/);\n\t\tconst url = parts[0];\n\t\tif (!url) {\n\t\t\treturn { url: \"\", descriptor: \"none\", raw: null };\n\t\t}\n\n\t\tif (parts.length < 2) {\n\t\t\treturn { url, descriptor: \"none\", raw: null };\n\t\t}\n\n\t\t/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- parts.length >= 2 so at(-1) is always defined */\n\t\tconst descriptor = parts.at(-1)!;\n\n\t\tif (/^\\d+w$/i.test(descriptor)) {\n\t\t\treturn {\n\t\t\t\turl,\n\t\t\t\tdescriptor: \"width\",\n\t\t\t\tvalue:
|
|
1
|
+
{"version":3,"file":"parse-image-candidate-string.js","sources":["../../../src/utils/parse-image-candidate-string.ts"],"sourcesContent":["/**\n * @internal\n */\nexport type ParsedImageCandidateDescriptor =\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"width\";\n\t\t\tvalue: number;\n\t\t\traw: string;\n\t }\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"density\";\n\t\t\tvalue: number;\n\t\t\traw: string;\n\t }\n\t| {\n\t\t\turl: string;\n\t\t\tdescriptor: \"none\";\n\t\t\traw: string | null;\n\t };\n\n/**\n * Parse descriptors from an image candidate string.\n *\n * @internal\n * @param srcset - Image candidate string to parse.\n * @returns Parsed descriptors from all candidates in the string.\n */\nexport function parseImageCandidateString(srcset: string): ParsedImageCandidateDescriptor[] {\n\tif (!srcset.trim()) {\n\t\treturn [];\n\t}\n\treturn srcset.split(\",\").map((candidate): ParsedImageCandidateDescriptor => {\n\t\tconst parts = candidate.trim().split(/\\s+/);\n\t\tconst url = parts[0];\n\t\tif (!url) {\n\t\t\treturn { url: \"\", descriptor: \"none\", raw: null };\n\t\t}\n\n\t\tif (parts.length < 2) {\n\t\t\treturn { url, descriptor: \"none\", raw: null };\n\t\t}\n\n\t\t/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- parts.length >= 2 so at(-1) is always defined */\n\t\tconst descriptor = parts.at(-1)!;\n\n\t\tif (/^\\d+w$/i.test(descriptor)) {\n\t\t\treturn {\n\t\t\t\turl,\n\t\t\t\tdescriptor: \"width\",\n\t\t\t\tvalue: Math.trunc(Number(descriptor.slice(0, -1))),\n\t\t\t\traw: descriptor,\n\t\t\t};\n\t\t}\n\n\t\tif (/^(?:\\d*\\.\\d+|\\d+(?:\\.\\d+)?)x$/i.test(descriptor)) {\n\t\t\treturn {\n\t\t\t\turl,\n\t\t\t\tdescriptor: \"density\",\n\t\t\t\tvalue: Number(descriptor.slice(0, -1)),\n\t\t\t\traw: descriptor,\n\t\t\t};\n\t\t}\n\n\t\treturn { url, descriptor: \"none\", raw: descriptor };\n\t});\n}\n"],"names":[],"mappings":"AA6BO,SAAS,0BAA0B,MAAA,EAAkD;AAC3F,EAAA,IAAI,CAAC,MAAA,CAAO,IAAA,EAAK,EAAG;AACnB,IAAA,OAAO,EAAC;AAAA,EACT;AACA,EAAA,OAAO,OAAO,KAAA,CAAM,GAAG,CAAA,CAAE,GAAA,CAAI,CAAC,SAAA,KAA8C;AAC3E,IAAA,MAAM,KAAA,GAAQ,SAAA,CAAU,IAAA,EAAK,CAAE,MAAM,KAAK,CAAA;AAC1C,IAAA,MAAM,GAAA,GAAM,MAAM,CAAC,CAAA;AACnB,IAAA,IAAI,CAAC,GAAA,EAAK;AACT,MAAA,OAAO,EAAE,GAAA,EAAK,EAAA,EAAI,UAAA,EAAY,MAAA,EAAQ,KAAK,IAAA,EAAK;AAAA,IACjD;AAEA,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,EAAG;AACrB,MAAA,OAAO,EAAE,GAAA,EAAK,UAAA,EAAY,MAAA,EAAQ,KAAK,IAAA,EAAK;AAAA,IAC7C;AAGA,IAAA,MAAM,UAAA,GAAa,KAAA,CAAM,EAAA,CAAG,EAAE,CAAA;AAE9B,IAAA,IAAI,SAAA,CAAU,IAAA,CAAK,UAAU,CAAA,EAAG;AAC/B,MAAA,OAAO;AAAA,QACN,GAAA;AAAA,QACA,UAAA,EAAY,OAAA;AAAA,QACZ,KAAA,EAAO,KAAK,KAAA,CA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