diff --git a/README.md b/README.md index f076c1d..a79694e 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,8 @@ stringifyObjects | `false` | **EXPERIMENTAL** Replaces `title="[ob * `data-testid="whatever" ` * `data-test-id="whatever"` 1. All `data-v-whatever=""` will be removed. These are attributes added by Vue to help scope styles. Removing them from your snapshots makes updating scoped dependencies easier. +1. Any empty HTML attributes will be trimmed to remove the empty assignment. So `
` becomes `
`. +1. Some optionally self-closing tags, will now become self-closing. So `` becomes ``. **Example:** These are the kind of diffs you can expect to see when migrating from v2 to v3. @@ -166,6 +168,11 @@ stringifyObjects | `false` | **EXPERIMENTAL** Replaces `title="[ob - + + +- ++ +- ++ + ``` @@ -173,7 +180,7 @@ stringifyObjects | `false` | **EXPERIMENTAL** Replaces `title="[ob ### Avoiding breaking changes (not recommended) -Though all default settings are designed to be the best choice for most people, if you want to opt out of these (or opt-in to other changes, like removing HTML comments from snapshots) you can via a settings object in your Vue config. +Though all default settings are designed to be the best choice for most people, if you want to opt out of these (or opt-in to other changes, like removing HTML comments from snapshots) you can via a settings object in your Vue config. Note, some changes cannot currently be avoided (self-closing enforcement and empty attribute trimming). 1. Edit your `vue.config.js` in the root of your project (or create it, if you do not have one). 1. The following are the `jest-serializer-vue` v2.0.2 settings: diff --git a/index.js b/index.js index 619e6d0..d01f4fc 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,7 @@ const beautify = require('js-beautify').html; const fs = require('fs'); -const JSDOM = require('jsdom').JSDOM; +const helpers = require('./src/helpers.js'); const loadOptions = require('./src/loadOptions.js'); const replaceObjectObject = require('./src/replaceObjectObject.js'); const removeTestTokens = require('./src/removeTestTokens.js'); @@ -43,14 +43,11 @@ function isVueWrapper (received) { */ function removeServerRenderedText (html, options) { if (!options || options.removeServerRendered) { - const dom = new JSDOM(html); + const $ = helpers.$(html); - let elements = dom.window.document.querySelectorAll('[data-server-rendered]'); - elements.forEach(function (element) { - element.removeAttribute('data-server-rendered'); - }); + $('[data-server-rendered]').removeAttr('data-server-rendered'); - return dom.window.document.body.innerHTML; + return $.html(); } return html; } @@ -65,10 +62,15 @@ function removeServerRenderedText (html, options) { function removeScopedStylesDataVIDAttributes (html, options) { if (!options || options.removeDataVId) { // [-\w]+ will catch 1 or more instaces of a-z, A-Z, 0-9, hyphen (-), or underscore (_) - const regex = / data-v-[-\w]+=""/g; + const regexA = / data-v-[-\w]+=""/g; + const regexB = / data-v-[-\w]+/g; // [[' data-v-asdf=""'], [' data-v-qwer=""'], [' data-v-asdf=""']] - let dataVIds = Array.from(html.matchAll(regex)); + let dataVIdsA = Array.from(html.matchAll(regexA)); + // [[' data-v-asdf'], [' data-v-qwer'], [' data-v-asdf']] + let dataVIdsB = Array.from(html.matchAll(regexB)); + // [...dataVIdsA, ...dataVIdsB] + let dataVIds = [].concat(dataVIdsA, dataVIdsB); // ['data-v-asdf', 'data-v-qwer', 'data-v-asdf'] dataVIds = dataVIds.map(function (match) { return match[0].trim().replace('=""', ''); @@ -76,15 +78,12 @@ function removeScopedStylesDataVIDAttributes (html, options) { // ['data-v-asdf', 'data-v-qwer'] dataVIds = Array.from(new Set(dataVIds)); - const dom = new JSDOM(html); + const $ = helpers.$(html); dataVIds.forEach(function (attribute) { - let elements = dom.window.document.querySelectorAll('[' + attribute + ']'); - elements.forEach(function (element) { - element.removeAttribute(attribute); - }); + $('[' + attribute + ']').removeAttr(attribute); }); - html = dom.window.document.body.innerHTML; + html = $.html(); } return html; } diff --git a/package-lock.json b/package-lock.json index 3ab11ec..e61b397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "jest-serializer-vue-tjw", - "version": "3.9.0", + "version": "3.10.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -3431,8 +3431,7 @@ "@types/node": { "version": "13.1.6", "resolved": "https://registry.npmjs.org/@types/node/-/node-13.1.6.tgz", - "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==", - "dev": true + "integrity": "sha512-Jg1F+bmxcpENHP23sVKkNuU3uaxPnsBMW0cLjleiikFKomJQbsn0Cqk2yDvQArqzZN6ABfBkZ0To7pQ8sLdWDg==" }, "@types/stack-utils": { "version": "1.0.1", @@ -5081,6 +5080,11 @@ "integrity": "sha512-ItfYfPLkWHUjckQCk8xC+LwxgK8NYcXywGigJgSwOP8Y2iyWT4f2vsZnoOXTTbo+o5yXmIUJ4gn5538SO5S3gA==", "dev": true }, + "boolbase": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz", + "integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24=" + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -5391,6 +5395,60 @@ "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==", "dev": true }, + "cheerio": { + "version": "1.0.0-rc.3", + "resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz", + "integrity": "sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==", + "requires": { + "css-select": "~1.2.0", + "dom-serializer": "~0.1.1", + "entities": "~1.1.1", + "htmlparser2": "^3.9.1", + "lodash": "^4.15.0", + "parse5": "^3.0.1" + }, + "dependencies": { + "domhandler": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz", + "integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==", + "requires": { + "domelementtype": "1" + } + }, + "htmlparser2": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz", + "integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==", + "requires": { + "domelementtype": "^1.3.1", + "domhandler": "^2.3.0", + "domutils": "^1.5.1", + "entities": "^1.1.1", + "inherits": "^2.0.1", + "readable-stream": "^3.1.1" + } + }, + "parse5": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz", + "integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==", + "requires": { + "@types/node": "*" + } + }, + "readable-stream": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz", + "integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + } + } + }, "chokidar": { "version": "2.1.8", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-2.1.8.tgz", @@ -5860,6 +5918,22 @@ } } }, + "css-select": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz", + "integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=", + "requires": { + "boolbase": "~1.0.0", + "css-what": "2.1", + "domutils": "1.5.1", + "nth-check": "~1.0.1" + } + }, + "css-what": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz", + "integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg==" + }, "cssom": { "version": "0.3.8", "resolved": "https://registry.npmjs.org/cssom/-/cssom-0.3.8.tgz", @@ -6087,12 +6161,26 @@ "integrity": "sha512-2G2Vwi2zXTHBGqXHsJ4+ak/iP0N8Ar+G8a7LiD2oup5o4sQWytwqqrZu/O6hIMV0KMID2PL69OhpshLO0n7UJQ==", "dev": true }, + "dom-serializer": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz", + "integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==", + "requires": { + "domelementtype": "^1.3.0", + "entities": "^1.1.1" + } + }, "domain-browser": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz", "integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA==", "dev": true }, + "domelementtype": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz", + "integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==" + }, "domexception": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/domexception/-/domexception-1.0.1.tgz", @@ -6102,6 +6190,30 @@ "webidl-conversions": "^4.0.2" } }, + "domhandler": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-3.0.0.tgz", + "integrity": "sha512-eKLdI5v9m67kbXQbJSNn1zjh0SDzvzWVWtX+qEI3eMjZw8daH9k8rlj1FZY9memPwjiskQFbe7vHVVJIAqoEhw==", + "requires": { + "domelementtype": "^2.0.1" + }, + "dependencies": { + "domelementtype": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", + "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==" + } + } + }, + "domutils": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz", + "integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=", + "requires": { + "dom-serializer": "0", + "domelementtype": "1" + } + }, "duplexify": { "version": "3.7.1", "resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.7.1.tgz", @@ -6206,6 +6318,11 @@ } } }, + "entities": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz", + "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==" + }, "errno": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", @@ -7903,6 +8020,48 @@ "integrity": "sha512-a4u9BeERWGu/S8JiWEAQcdrg9v4QArtP9keViQjGMdff20fBdd8waotXaNmODqBe6uZ3Nafi7K/ho4gCQHV3Ig==", "dev": true }, + "htmlparser2": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-4.0.0.tgz", + "integrity": "sha512-cChwXn5Vam57fyXajDtPXL1wTYc8JtLbr2TN76FYu05itVVVealxLowe2B3IEznJG4p9HAYn/0tJaRlGuEglFQ==", + "requires": { + "domelementtype": "^2.0.1", + "domhandler": "^3.0.0", + "domutils": "^2.0.0", + "entities": "^2.0.0" + }, + "dependencies": { + "dom-serializer": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.2.2.tgz", + "integrity": "sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==", + "requires": { + "domelementtype": "^2.0.1", + "entities": "^2.0.0" + } + }, + "domelementtype": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.0.1.tgz", + "integrity": "sha512-5HOHUDsYZWV8FGWN0Njbr/Rn7f/eWSQi1v7+HsUVwXgn8nWWlL64zKDkS0n8ZmQ3mlWOMuXOnR+7Nx/5tMO5AQ==" + }, + "domutils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-2.0.0.tgz", + "integrity": "sha512-n5SelJ1axbO636c2yUtOGia/IcJtVtlhQbFiVDBZHKV5ReJO1ViX7sFEemtuyoAnBxk5meNSYgA8V4s0271efg==", + "requires": { + "dom-serializer": "^0.2.1", + "domelementtype": "^2.0.1", + "domhandler": "^3.0.0" + } + }, + "entities": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-2.0.0.tgz", + "integrity": "sha512-D9f7V0JSRwIxlRI2mjMqufDrRDnx8p+eEOz7aUM9SuvF8gsBzra0/6tbjl1m8eQHrZlYj6PxqE00hZ1SAIKPLw==" + } + } + }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -9651,8 +9810,7 @@ "lodash": { "version": "4.17.15", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", - "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==", - "dev": true + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.assign": { "version": "4.2.0", @@ -10237,6 +10395,14 @@ "path-key": "^2.0.0" } }, + "nth-check": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz", + "integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==", + "requires": { + "boolbase": "~1.0.0" + } + }, "nwsapi": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.0.tgz", @@ -11350,8 +11516,7 @@ "safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "safe-regex": { "version": "1.1.0", @@ -11920,7 +12085,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "requires": { "safe-buffer": "~5.1.0" } @@ -12497,8 +12661,7 @@ "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "util.promisify": { "version": "1.0.0", diff --git a/package.json b/package.json index a02f18f..2a04c65 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jest-serializer-vue-tjw", "description": "A superb jest serializer for Vue snapshots", - "version": "3.9.0", + "version": "3.10.0", "main": "index.js", "scripts": { "lint": "eslint --ext .js,.vue .", @@ -11,12 +11,14 @@ "coverage": "jest --coverage --runInBand --coverageReporters=text-lcov | coveralls", "validate": "npm run lint && npm test", "remote": "git remote rm eddyerburgh && git remote", - "travis": "npm run lint && npm run coverage" + "travis": "npm run lint && npm run coverage && jest --runInBand" }, "ManifestComments": [ "Jest 25.1.0 is broken on Windows. Pinning to 24.9.0 until Jest issue #9459 is resolved." ], "dependencies": { + "cheerio": "^1.0.0-rc.3", + "htmlparser2": "^4.0.0", "js-beautify": "^1.10.3", "lodash.clonedeep": "^4.5.0" }, diff --git a/src/helpers.js b/src/helpers.js new file mode 100644 index 0000000..6659813 --- /dev/null +++ b/src/helpers.js @@ -0,0 +1,27 @@ +const cheerio = require('cheerio'); +const htmlparser2 = require('htmlparser2'); + +const helpers = { + /** + * Load the markup into Cheerio + * + * @param {string} html Markup for the snapshot + * @return {object} Cheerio object + */ + $: function (html) { + // https://github.com/fb55/DomHandler + // https://github.com/fb55/htmlparser2/wiki/Parser-options + const xmlOptions = { + decodeEntities: false, + lowerCaseAttributeNames: false, + normalizeWhitespace: false, + recognizeSelfClosing: false, + xmlMode: false + }; + const dom = htmlparser2.parseDOM(html, xmlOptions); + const $ = cheerio.load(dom, { xml: xmlOptions }); + return $; + } +}; + +module.exports = helpers; diff --git a/src/removeTestTokens.js b/src/removeTestTokens.js index 0c3c594..b33d19b 100644 --- a/src/removeTestTokens.js +++ b/src/removeTestTokens.js @@ -1,67 +1,59 @@ -const JSDOM = require('jsdom').JSDOM; +const helpers = require('./helpers.js'); /** * Removes any data-* attribute passed in. * - * @param {object} dom The markup as a JSDOM node. + * @param {object} $ The markup as a Cheerio DOM node. * @param {string} attribute The attribute suffix. */ -function removeDataAttribute (dom, attribute) { - let elements = dom.window.document.querySelectorAll('[data-' + attribute + ']'); - elements.forEach(function (element) { - element.removeAttribute('data-' + attribute); - }); +function removeDataAttribute ($, attribute) { + $('[data-' + attribute + ']').removeAttr('data-' + attribute); } /** * Removes ID attributes from elements where the id starts with `test`. * - * @param {object} dom The markup as a JSDOM node. + * @param {object} $ The markup as a Cheerio DOM node. * @param {object} options User options */ -function removeIdTest (dom, options) { +function removeIdTest ($, options) { if (options && options.removeIdTest) { - const elements = dom.window.document.querySelectorAll('[id]'); - elements.forEach(function (element) { - if (element.attributes.id.value.startsWith('test')) { - element.removeAttribute('id'); + $('[id]').each(function (index, element) { + if ($(element).attr('id').startsWith('test')) { + $(element).removeAttr('id'); } }); } } + /** * Removes classes from elements where the class starts with `test`. * - * @param {object} dom The markup as a JSDOM node. + * @param {object} $ The markup as a Cheerio DOM node. * @param {object} options User options */ -function removeClassTest (dom, options) { +function removeClassTest ($, options) { if (options && options.removeClassTest) { - const elements = dom.window.document.querySelectorAll('[class]'); - elements.forEach(function (element) { - const classes = element.classList; - let classesToRemove = []; - - classes.forEach(function (className) { - if (className.startsWith('test')) { - classesToRemove.push(className); - } - }); - - // If a element has 3 or more classes that need removed, - // then removing them in the above loop would mess up the index - // as we are looping, skipping classes. There is a test in place - // for that edge case. That's why we build a temp list of - // classes to remove and then loop over it. - classesToRemove.forEach(function (className) { - element.classList.remove(className); + $('[class]').each(function (index, element) { + let classesWereRemoved = false; + $(element).removeClass(function (index, css) { + return css + .split(' ') + .filter(function (className) { + if (className.toLowerCase().startsWith('test')) { + classesWereRemoved = true; + return true; + } + return false; + }) + .join(' '); }); // Only remove the empty class attributes on elements that had test-classes. // There is a test case for this. - if (!element.classList.length && classesToRemove.length) { - element.removeAttribute('class'); + if (!$(element).attr('class') && classesWereRemoved) { + $(element).removeAttr('class'); } }); } @@ -84,25 +76,25 @@ function removeClassTest (dom, options) { * @return {string} Modified HTML string */ function removeTestTokens (html, options) { - const dom = new JSDOM(html); + const $ = helpers.$(html); if (!options || options.removeDataTest) { - removeDataAttribute(dom, 'test'); + removeDataAttribute($, 'test'); } if (!options || options.removeDataTestid) { - removeDataAttribute(dom, 'testid'); + removeDataAttribute($, 'testid'); } if (!options || options.removeDataTestId) { - removeDataAttribute(dom, 'test-id'); + removeDataAttribute($, 'test-id'); } if (options && options.removeDataQa) { - removeDataAttribute(dom, 'qa'); + removeDataAttribute($, 'qa'); } - removeIdTest(dom, options); - removeClassTest(dom, options); + removeIdTest($, options); + removeClassTest($, options); - html = dom.window.document.body.innerHTML; + html = $.html(); return html; } diff --git a/tests/SvgDemo.test.js b/tests/SvgDemo.test.js new file mode 100644 index 0000000..144a194 --- /dev/null +++ b/tests/SvgDemo.test.js @@ -0,0 +1,14 @@ +const helpers = require('./helpers.js'); + +import { mount } from '@vue/test-utils'; +import SvgDemo from './components/SvgDemo.vue'; + +describe('SvgDemo.vue', () => { + test('SVG renders properly', () => { + helpers.mockSettings({}); + const wrapper = mount(SvgDemo); + + expect(wrapper) + .toMatchSnapshot(); + }); +}); diff --git a/tests/Zoom.test.js b/tests/Zoom.test.js new file mode 100644 index 0000000..e290b2b --- /dev/null +++ b/tests/Zoom.test.js @@ -0,0 +1,27 @@ +const helpers = require('./helpers.js'); + +import { mount } from '@vue/test-utils'; +import Zoom from './components/Zoom.vue'; + +describe('Zoom.vue', () => { + let wrapper; + + beforeEach(() => { + helpers.mockSettings({}); + wrapper = mount(Zoom); + }); + + test('Zoom in on a child element', () => { + const article = wrapper.find('[data-test="article"]'); + + expect(article) + .toMatchSnapshot(); + }); + + test('Zoom in on a table row', () => { + const tr = wrapper.find('[data-test="tr"]'); + + expect(tr) + .toMatchSnapshot(); + }); +}); diff --git a/tests/__snapshots__/Demo.test.js.snap b/tests/__snapshots__/Demo.test.js.snap index 84a7756..4eaae79 100644 --- a/tests/__snapshots__/Demo.test.js.snap +++ b/tests/__snapshots__/Demo.test.js.snap @@ -37,7 +37,7 @@ exports[`Demo Inverted settings 1`] = ` The above specific data-attrubutes are removed by default.
- + These data-v ID's are removed too by default.
@@ -56,7 +56,7 @@ exports[`Demo v2.0.2 settings 1`] = ` The above specific data-attrubutes are removed by default.
- + These data-v ID's are removed too by default. diff --git a/tests/__snapshots__/ScopedStylesInDependency.test.js.snap b/tests/__snapshots__/ScopedStylesInDependency.test.js.snap index 12f3155..b7df66a 100644 --- a/tests/__snapshots__/ScopedStylesInDependency.test.js.snap +++ b/tests/__snapshots__/ScopedStylesInDependency.test.js.snap @@ -8,18 +8,18 @@ exports[`ScopedStylesInDependency.vue Snapshot data-v ids remain 1`] = `
- - - + + - - + - + + + + +`; diff --git a/tests/components/SvgDemo.vue b/tests/components/SvgDemo.vue new file mode 100644 index 0000000..cfc8412 --- /dev/null +++ b/tests/components/SvgDemo.vue @@ -0,0 +1,37 @@ + + + diff --git a/tests/components/Zoom.vue b/tests/components/Zoom.vue new file mode 100644 index 0000000..63ad720 --- /dev/null +++ b/tests/components/Zoom.vue @@ -0,0 +1,27 @@ + + +
- Name +
+ Name - Favorite data-v-id="" + + Favorite data-v-id=""
Dave @@ -58,7 +58,7 @@ exports[`ScopedStylesInDependency.vue Snapshot data-v ids removed 1`] = `
Dave diff --git a/tests/__snapshots__/SvgDemo.test.js.snap b/tests/__snapshots__/SvgDemo.test.js.snap new file mode 100644 index 0000000..5f23e2c --- /dev/null +++ b/tests/__snapshots__/SvgDemo.test.js.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`SvgDemo.vue SVG renders properly 1`] = ` +
+ + Example Triangle + + + + + +
+`; diff --git a/tests/__snapshots__/TestTokens.test.js.snap b/tests/__snapshots__/TestTokens.test.js.snap index 3b822c2..14f268c 100644 --- a/tests/__snapshots__/TestTokens.test.js.snap +++ b/tests/__snapshots__/TestTokens.test.js.snap @@ -41,7 +41,7 @@ exports[`TestTokens.vue Only class="test" removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -88,7 +88,7 @@ exports[`TestTokens.vue Only data-qa removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -135,7 +135,7 @@ exports[`TestTokens.vue Only data-server-rendered removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -182,7 +182,7 @@ exports[`TestTokens.vue Only data-test removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -229,7 +229,7 @@ exports[`TestTokens.vue Only data-test-id removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -276,7 +276,7 @@ exports[`TestTokens.vue Only data-testid removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -323,7 +323,7 @@ exports[`TestTokens.vue Only id="test" removed 1`] = `
  • class="test active"
  • -
  • +
  • class=""
  • @@ -370,7 +370,7 @@ exports[`TestTokens.vue Remove data-server-rendered, data-test, data-testid, dat
  • class="test active"
  • -
  • +
  • class=""
  • diff --git a/tests/__snapshots__/Zoom.test.js.snap b/tests/__snapshots__/Zoom.test.js.snap new file mode 100644 index 0000000..2e9c334 --- /dev/null +++ b/tests/__snapshots__/Zoom.test.js.snap @@ -0,0 +1,20 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Zoom.vue Zoom in on a child element 1`] = ` +
    +

    + Lorem ipsum dolor sit amet, consectetur adipisicing elit. +

    +
    +`; + +exports[`Zoom.vue Zoom in on a table row 1`] = ` +
    + first + + second +