UNPKG

cypress-html-validate

Version:

Cypress plugin for html-validate

356 lines (348 loc) 11.9 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/deepmerge/dist/cjs.js var require_cjs = __commonJS({ "node_modules/deepmerge/dist/cjs.js"(exports2, module2) { "use strict"; var isMergeableObject = function isMergeableObject2(value) { return isNonNullObject(value) && !isSpecial(value); }; function isNonNullObject(value) { return !!value && typeof value === "object"; } function isSpecial(value) { var stringValue = Object.prototype.toString.call(value); return stringValue === "[object RegExp]" || stringValue === "[object Date]" || isReactElement(value); } var canUseSymbol = typeof Symbol === "function" && Symbol.for; var REACT_ELEMENT_TYPE = canUseSymbol ? Symbol.for("react.element") : 60103; function isReactElement(value) { return value.$$typeof === REACT_ELEMENT_TYPE; } function emptyTarget(val) { return Array.isArray(val) ? [] : {}; } function cloneUnlessOtherwiseSpecified(value, options2) { return options2.clone !== false && options2.isMergeableObject(value) ? deepmerge2(emptyTarget(value), value, options2) : value; } function defaultArrayMerge(target, source, options2) { return target.concat(source).map(function(element) { return cloneUnlessOtherwiseSpecified(element, options2); }); } function getMergeFunction(key, options2) { if (!options2.customMerge) { return deepmerge2; } var customMerge = options2.customMerge(key); return typeof customMerge === "function" ? customMerge : deepmerge2; } function getEnumerableOwnPropertySymbols(target) { return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(target).filter(function(symbol) { return Object.propertyIsEnumerable.call(target, symbol); }) : []; } function getKeys(target) { return Object.keys(target).concat(getEnumerableOwnPropertySymbols(target)); } function propertyIsOnObject(object, property) { try { return property in object; } catch (_) { return false; } } function propertyIsUnsafe(target, key) { return propertyIsOnObject(target, key) && !(Object.hasOwnProperty.call(target, key) && Object.propertyIsEnumerable.call(target, key)); } function mergeObject(target, source, options2) { var destination = {}; if (options2.isMergeableObject(target)) { getKeys(target).forEach(function(key) { destination[key] = cloneUnlessOtherwiseSpecified(target[key], options2); }); } getKeys(source).forEach(function(key) { if (propertyIsUnsafe(target, key)) { return; } if (propertyIsOnObject(target, key) && options2.isMergeableObject(source[key])) { destination[key] = getMergeFunction(key, options2)(target[key], source[key], options2); } else { destination[key] = cloneUnlessOtherwiseSpecified(source[key], options2); } }); return destination; } function deepmerge2(target, source, options2) { options2 = options2 || {}; options2.arrayMerge = options2.arrayMerge || defaultArrayMerge; options2.isMergeableObject = options2.isMergeableObject || isMergeableObject; options2.cloneUnlessOtherwiseSpecified = cloneUnlessOtherwiseSpecified; var sourceIsArray = Array.isArray(source); var targetIsArray = Array.isArray(target); var sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; if (!sourceAndTargetTypesMatch) { return cloneUnlessOtherwiseSpecified(source, options2); } else if (sourceIsArray) { return options2.arrayMerge(target, source, options2); } else { return mergeObject(target, source, options2); } } deepmerge2.all = function deepmergeAll(array, options2) { if (!Array.isArray(array)) { throw new Error("first argument should be an array"); } return array.reduce(function(prev, next) { return deepmerge2(prev, next, options2); }, {}); }; var deepmerge_1 = deepmerge2; module2.exports = deepmerge_1; } }); // src/plugin.ts var plugin_exports = {}; __export(plugin_exports, { default: () => plugin_default, install: () => install }); module.exports = __toCommonJS(plugin_exports); var import_html_validate = require("html-validate"); // node_modules/kleur/index.mjs var FORCE_COLOR; var NODE_DISABLE_COLORS; var NO_COLOR; var TERM; var isTTY = true; if (typeof process !== "undefined") { ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {}); isTTY = process.stdout && process.stdout.isTTY; } var $ = { enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY), // modifiers reset: init(0, 0), bold: init(1, 22), dim: init(2, 22), italic: init(3, 23), underline: init(4, 24), inverse: init(7, 27), hidden: init(8, 28), strikethrough: init(9, 29), // colors black: init(30, 39), red: init(31, 39), green: init(32, 39), yellow: init(33, 39), blue: init(34, 39), magenta: init(35, 39), cyan: init(36, 39), white: init(37, 39), gray: init(90, 39), grey: init(90, 39), // background colors bgBlack: init(40, 49), bgRed: init(41, 49), bgGreen: init(42, 49), bgYellow: init(43, 49), bgBlue: init(44, 49), bgMagenta: init(45, 49), bgCyan: init(46, 49), bgWhite: init(47, 49) }; function run(arr, str) { let i = 0, tmp, beg = "", end = ""; for (; i < arr.length; i++) { tmp = arr[i]; beg += tmp.open; end += tmp.close; if (!!~str.indexOf(tmp.close)) { str = str.replace(tmp.rgx, tmp.close + tmp.open); } } return beg + str + end; } function chain(has, keys) { let ctx = { has, keys }; ctx.reset = $.reset.bind(ctx); ctx.bold = $.bold.bind(ctx); ctx.dim = $.dim.bind(ctx); ctx.italic = $.italic.bind(ctx); ctx.underline = $.underline.bind(ctx); ctx.inverse = $.inverse.bind(ctx); ctx.hidden = $.hidden.bind(ctx); ctx.strikethrough = $.strikethrough.bind(ctx); ctx.black = $.black.bind(ctx); ctx.red = $.red.bind(ctx); ctx.green = $.green.bind(ctx); ctx.yellow = $.yellow.bind(ctx); ctx.blue = $.blue.bind(ctx); ctx.magenta = $.magenta.bind(ctx); ctx.cyan = $.cyan.bind(ctx); ctx.white = $.white.bind(ctx); ctx.gray = $.gray.bind(ctx); ctx.grey = $.grey.bind(ctx); ctx.bgBlack = $.bgBlack.bind(ctx); ctx.bgRed = $.bgRed.bind(ctx); ctx.bgGreen = $.bgGreen.bind(ctx); ctx.bgYellow = $.bgYellow.bind(ctx); ctx.bgBlue = $.bgBlue.bind(ctx); ctx.bgMagenta = $.bgMagenta.bind(ctx); ctx.bgCyan = $.bgCyan.bind(ctx); ctx.bgWhite = $.bgWhite.bind(ctx); return ctx; } function init(open, close) { let blk = { open: `\x1B[${open}m`, close: `\x1B[${close}m`, rgx: new RegExp(`\\x1b\\[${close}m`, "g") }; return function(txt) { if (this !== void 0 && this.has !== void 0) { !!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk)); return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + ""; } return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + ""; }; } var kleur_default = $; // src/config.ts var import_deepmerge = __toESM(require_cjs()); function overwriteMerge(_a, b) { return b; } function createConfig() { return { root: true, extends: ["html-validate:recommended", "html-validate:document"], rules: { /* doctype is not passed when requesting source */ "missing-doctype": "off", /* some frameworks (such as jQuery) often uses inline style, e.g. for * showing/hiding elements */ "no-inline-style": "off", /* scripts will often add markup with trailing whitespace */ "no-trailing-whitespace": "off", /* browser normalizes boolean attributes */ "attribute-boolean-style": "off", "attribute-empty-style": "off", /* the browser will often do what it wants, out of users control */ "void-style": "off", "no-self-closing": "off" } }; } function mergeConfig(a, b) { return (0, import_deepmerge.default)(a, b != null ? b : {}, { arrayMerge: overwriteMerge }); } var config_default = createConfig(); // src/formatter.ts function formatter(messages) { if (messages.length === 0) { return; } const rows = messages.map((it) => { return { rule: it.ruleId, message: it.message, selector: it.selector }; }); const n = messages.length; const preamble = `${String(n)} html-validate error${n === 1 ? "" : "s"} ${n === 1 ? "was" : "were"} detected`; console.log(preamble); console.table(rows); } // src/options.ts var options = { exclude: [], include: [], formatter }; var options_default = options; // src/plugin.ts var pkg = require("../package.json"); function install(on, userConfig, userOptions) { const range = pkg.peerDependencies["html-validate"]; (0, import_html_validate.compatibilityCheck)(pkg.name, range, { logger(text) { console.log(kleur_default.red(text)); } }); const config = mergeConfig(config_default, userConfig); const htmlvalidate = new import_html_validate.HtmlValidate(config); const options2 = { ...options_default, ...userOptions }; if (!Array.isArray(options2.exclude)) { throw new Error( `Invalid cypress-html-validate configuration, "exclude" must be array, got ${typeof options2.exclude}` ); } if (!Array.isArray(options2.include)) { throw new Error( `Invalid cypress-html-validate configuration, "include" must be array, got ${typeof options2.include}` ); } on("task", { async htmlvalidate(options3) { const filename = "cypress"; const source = { data: options3.markup, filename, line: 1, column: 1, offset: 0 }; return await htmlvalidate.validateSource(source, options3.config); }, "htmlvalidate:options"() { return options2; }, "htmlvalidate:format"(messages) { const { formatter: formatter2 } = options2; if (formatter2) { formatter2(messages); } return null; } }); } var plugin_default = { install }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { install }); //# sourceMappingURL=plugin.js.map