diff --git a/package.json b/package.json index 9d6646560..8b5c58da6 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "@rollup/plugin-replace": "^2.4.2", "@types/jest": "26.0.22", "@types/node": "14.14.37", + "@types/pretty": "^2.0.0", "@vue/compiler-sfc": "3.0.11", "babel-jest": "^26.6.3", "babel-preset-jest": "^26.6.2", @@ -31,6 +32,7 @@ "jsdom-global": "^3.0.2", "lint-staged": "^10.5.4", "prettier": "^2.2.1", + "pretty": "^2.0.0", "reflect-metadata": "^0.1.13", "rollup": "^2.44.0", "rollup-plugin-typescript2": "^0.30.0", diff --git a/src/vueWrapper.ts b/src/vueWrapper.ts index 5937238e9..f78525fac 100644 --- a/src/vueWrapper.ts +++ b/src/vueWrapper.ts @@ -2,6 +2,7 @@ import { ComponentPublicInstance, nextTick, App } from 'vue' import { ShapeFlags } from '@vue/shared' // @ts-ignore todo - No DefinitelyTyped package exists for this import eventTypes from 'dom-event-types' +import pretty from 'pretty' import { config } from './config' import { DOMWrapper } from './domWrapper' @@ -90,10 +91,10 @@ export class VueWrapper html() { // cover cases like , multiple root nodes. if (this.parentElement['__vue_app__']) { - return this.parentElement.innerHTML + return pretty(this.parentElement.innerHTML) } - return this.element.outerHTML + return pretty(this.element.outerHTML) } find( diff --git a/tests/html.spec.ts b/tests/html.spec.ts index 57e5335ed..30420484a 100644 --- a/tests/html.spec.ts +++ b/tests/html.spec.ts @@ -24,7 +24,9 @@ describe('html', () => { const wrapper = mount(Component) - expect(wrapper.html()).toBe('
foo
bar
baz
') + expect(wrapper.html()).toBe( + '
foo
\n' + '
bar
\n' + '
baz
' + ) }) it('returns the html when mounting a Suspense component', () => { diff --git a/tests/mountingOptions/global.components.spec.ts b/tests/mountingOptions/global.components.spec.ts index b9809c97e..4fb4c38c1 100644 --- a/tests/mountingOptions/global.components.spec.ts +++ b/tests/mountingOptions/global.components.spec.ts @@ -41,7 +41,9 @@ describe('global.components', () => { expect(spy).not.toHaveBeenCalled() spy.mockRestore() expect(wrapper.html()).toBe( - `
` + '
\n' + + ' \n' + + '
' ) }) diff --git a/tests/mountingOptions/stubs.global.spec.ts b/tests/mountingOptions/stubs.global.spec.ts index fa6d7c183..434518253 100644 --- a/tests/mountingOptions/stubs.global.spec.ts +++ b/tests/mountingOptions/stubs.global.spec.ts @@ -34,7 +34,7 @@ describe('mounting options: stubs', () => { } }) - expect(wrapper.html()).toBe('
') + expect(wrapper.html()).toBe('
\n' + '') }) // https://github.com/vuejs/vue-test-utils-next/issues/249 @@ -57,7 +57,7 @@ describe('mounting options: stubs', () => { }) expect(wrapper.html()).toBe( - '
' + '
\n' + ' \n' + '
' ) expect(wrapper.getComponent(RouterLinkStub).vm.to).toBe('/foo') }) @@ -79,7 +79,7 @@ describe('mounting options: stubs', () => { }) expect(wrapper.html()).toEqual( - '
' + '
\n' + ' \n' + '
' ) }) @@ -94,7 +94,9 @@ describe('mounting options: stubs', () => { } }) - expect(wrapper.html()).toEqual('
') + expect(wrapper.html()).toEqual( + '
\n' + ' \n' + '
' + ) }) it('passes all attributes to stubbed components', () => { @@ -116,7 +118,9 @@ describe('mounting options: stubs', () => { }) expect(wrapper.html()).toEqual( - '
' + '
\n' + + ' \n' + + '
' ) }) @@ -141,7 +145,7 @@ describe('mounting options: stubs', () => { } }) - expect(wrapper.html()).toBe('
') + expect(wrapper.html()).toBe('
\n' + '') }) it('prevents lifecycle hooks triggering in a stub', () => { @@ -236,7 +240,7 @@ describe('mounting options: stubs', () => { expect(created).not.toHaveBeenCalled() expect(wrapper.html()).toBe( - '
Hello world
' + '
\n' + '
Hello world
\n' + '
' ) }) @@ -274,7 +278,7 @@ describe('mounting options: stubs', () => { } }) - expect(wrapper.html()).toBe('
') + expect(wrapper.html()).toBe('\n' + '
') }) it('stubs a component with a kabeb-case name', () => { @@ -341,7 +345,9 @@ describe('mounting options: stubs', () => { const wrapper = mount(Comp) expect(wrapper.html()).toBe( - '
' + '\n' + + '
\n' + + '
' ) }) @@ -440,7 +446,9 @@ describe('mounting options: stubs', () => { } }) expect(wrapper.html()).toBe( - `
Default
` + '
\n' + + ' Default\n' + + '
' ) }) @@ -452,7 +460,9 @@ describe('mounting options: stubs', () => { } }) expect(wrapper.html()).toBe( - '
' + '
\n' + + ' \n' + + '
' ) }) @@ -485,10 +495,10 @@ describe('mounting options: stubs', () => { }) expect(wrapper.html()).toEqual( - '' + - '' + - 'nested content' + - '' + + '\n' + + ' \n' + + ' nested content\n' + + ' \n' + '' ) }) diff --git a/tests/shallowMount.spec.ts b/tests/shallowMount.spec.ts index d1837ca1e..4b8f5eb01 100644 --- a/tests/shallowMount.spec.ts +++ b/tests/shallowMount.spec.ts @@ -40,12 +40,12 @@ describe('shallowMount', () => { it('stubs all components automatically using { shallow: true }', () => { const wrapper = mount(ComponentWithChildren, { shallow: true }) expect(wrapper.html()).toEqual( - '
' + - '' + - '' + - '' + - '' + - '' + + '
\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + '
' ) }) @@ -53,12 +53,12 @@ describe('shallowMount', () => { it('stubs all components automatically using shallowMount', () => { const wrapper = shallowMount(ComponentWithChildren) expect(wrapper.html()).toEqual( - '
' + - '' + - '' + - '' + - '' + - '' + + '
\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + '
' ) }) @@ -73,12 +73,12 @@ describe('shallowMount', () => { } }) expect(wrapper.html()).toEqual( - '
' + - '
Override
' + - '' + - '' + - '' + - '' + + '
\n' + + '
Override
\n' + + ' \n' + + ' \n' + + ' \n' + + ' \n' + '
' ) }) @@ -93,10 +93,10 @@ describe('shallowMount', () => { } }) expect(wrapper.html()).toEqual( - '
Override
' + - '' + - '' + - '' + + '
Override
\n' + + '\n' + + '\n' + + '\n' + '' ) }) diff --git a/yarn.lock b/yarn.lock index cf812f244..66cb8fe5c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1463,6 +1463,11 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-1.19.1.tgz#33509849f8e679e4add158959fdb086440e9553f" integrity sha512-5qOlnZscTn4xxM5MeGXAMOsIOIKIbh9e85zJWfBRVPlRMEVawzoPhINYbRGkBZCI8LxvBe7tJCdWiarA99OZfQ== +"@types/pretty@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@types/pretty/-/pretty-2.0.0.tgz#4e8ce2f200db5de424791d0bc8d023f24ff312a9" + integrity sha512-nojaE6CV03swMxoHnAisV2Rl0Ma6WPUtQo87hUmaotu/YPugPlmiRB60sthbyppXdMFTdJV3wm6zCENY4q1tKA== + "@types/resolve@1.17.1": version "1.17.1" resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6" @@ -1625,6 +1630,11 @@ abab@^2.0.0, abab@^2.0.3, abab@^2.0.5: resolved "https://registry.yarnpkg.com/abab/-/abab-2.0.5.tgz#c0b678fb32d60fc1219c784d6a826fe385aeb79a" integrity sha512-9IK9EadsbHo6jLWIpxpR6pL0sazTXV6+SQv25ZB+F7Bj9mJNaOc4nCRabwd5M/JwmUa8idz6Eci6eKfJryPs6Q== +abbrev@1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" + integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q== + accepts@~1.3.5: version "1.3.7" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd" @@ -2317,6 +2327,11 @@ combined-stream@^1.0.6, combined-stream@~1.0.6: dependencies: delayed-stream "~1.0.0" +commander@^2.19.0: + version "2.20.3" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" + integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== + commander@^6.2.0: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" @@ -2357,6 +2372,23 @@ concat-map@0.0.1: resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= +condense-newlines@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/condense-newlines/-/condense-newlines-0.2.1.tgz#3de985553139475d32502c83b02f60684d24c55f" + integrity sha1-PemFVTE5R10yUCyDsC9gaE0kxV8= + dependencies: + extend-shallow "^2.0.1" + is-whitespace "^0.3.0" + kind-of "^3.0.2" + +config-chain@^1.1.12: + version "1.1.12" + resolved "https://registry.yarnpkg.com/config-chain/-/config-chain-1.1.12.tgz#0fde8d091200eb5e808caf25fe618c02f48e4efa" + integrity sha512-a1eOIcu8+7lUInge4Rpf/n4Krkf3Dd9lqhljRzII1/Zno/kRtUWnznPO3jOKBmTEktkt3fkxisUcivoj0ebzoA== + dependencies: + ini "^1.3.4" + proto-list "~1.2.1" + consolidate@^0.16.0: version "0.16.0" resolved "https://registry.yarnpkg.com/consolidate/-/consolidate-0.16.0.tgz#a11864768930f2f19431660a65906668f5fbdc16" @@ -2626,6 +2658,16 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" +editorconfig@^0.15.3: + version "0.15.3" + resolved "https://registry.yarnpkg.com/editorconfig/-/editorconfig-0.15.3.tgz#bef84c4e75fb8dcb0ce5cee8efd51c15999befc5" + integrity sha512-M9wIMFx96vq0R4F+gRpY3o2exzb8hEj/n9S8unZtHSvYjibBp/iMufSzvmOcV/laG0ZtuTVGtiJggPOSW2r93g== + dependencies: + commander "^2.19.0" + lru-cache "^4.1.5" + semver "^5.6.0" + sigmund "^1.0.1" + electron-to-chromium@^1.3.649: version "1.3.650" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.650.tgz#24e821fff2ed61fd71fee092f2a0631b3c0c22a6" @@ -3314,6 +3356,11 @@ inherits@2, inherits@^2.0.3, inherits@^2.0.4: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== +ini@^1.3.4: + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== + ip-regex@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-2.1.0.tgz#fa78bf5d2e6913c911ce9f819ee5146bb6d844e9" @@ -3494,6 +3541,11 @@ is-typedarray@^1.0.0, is-typedarray@~1.0.0: resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo= +is-whitespace@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/is-whitespace/-/is-whitespace-0.3.0.tgz#1639ecb1be036aec69a54cbb401cfbed7114ab7f" + integrity sha1-Fjnssb4DauxppUy7QBz77XEUq38= + is-windows@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" @@ -4011,6 +4063,17 @@ jest@25.5.4: import-local "^3.0.2" jest-cli "^25.5.4" +js-beautify@^1.6.12: + version "1.13.5" + resolved "https://registry.yarnpkg.com/js-beautify/-/js-beautify-1.13.5.tgz#a08a97890cae55daf1d758d3f6577bd4a64d7014" + integrity sha512-MsXlH6Z/BiRYSkSRW3clNDqDjSpiSNOiG8xYVUBXt4k0LnGvDhlTGOlHX1VFtAdoLmtwjxMG5qiWKy/g+Ipv5w== + dependencies: + config-chain "^1.1.12" + editorconfig "^0.15.3" + glob "^7.1.3" + mkdirp "^1.0.4" + nopt "^5.0.0" + js-tokens@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" @@ -4331,6 +4394,14 @@ lolex@^5.0.0: dependencies: "@sinonjs/commons" "^1.7.0" +lru-cache@^4.1.5: + version "4.1.5" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" + integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== + dependencies: + pseudomap "^1.0.2" + yallist "^2.1.2" + lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -4524,7 +4595,7 @@ mixin-deep@^1.2.0: for-in "^1.0.2" is-extendable "^1.0.1" -mkdirp@1.x: +mkdirp@1.x, mkdirp@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== @@ -4602,6 +4673,13 @@ node-releases@^1.1.70: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.70.tgz#66e0ed0273aa65666d7fe78febe7634875426a08" integrity sha512-Slf2s69+2/uAD79pVVQo8uSiC34+g8GWY8UH2Qtqv34ZfhYrxpYpfzs9Js9d6O0mbDmALuxaTlplnBTnSELcrw== +nopt@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-5.0.0.tgz#530942bb58a512fccafe53fe210f13a25355dc88" + integrity sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ== + dependencies: + abbrev "1" + normalize-package-data@^2.5.0: version "2.5.0" resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.5.0.tgz#e66db1838b200c1dfc233225d12cb36520e234a8" @@ -4984,6 +5062,15 @@ pretty-format@^26.0.0, pretty-format@^26.6.2: ansi-styles "^4.0.0" react-is "^17.0.1" +pretty@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pretty/-/pretty-2.0.0.tgz#adbc7960b7bbfe289a557dc5f737619a220d06a5" + integrity sha1-rbx5YLe7/iiaVX3F9zdhmiINBqU= + dependencies: + condense-newlines "^0.2.1" + extend-shallow "^2.0.1" + js-beautify "^1.6.12" + prismjs@^1.23.0: version "1.23.0" resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.23.0.tgz#d3b3967f7d72440690497652a9d40ff046067f33" @@ -5004,6 +5091,16 @@ prompts@^2.0.1: kleur "^3.0.3" sisteransi "^1.0.4" +proto-list@~1.2.1: + version "1.2.4" + resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" + integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= + +pseudomap@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + integrity sha1-8FKijacOYYkX7wqKw0wa5aaChrM= + psl@^1.1.28, psl@^1.1.33: version "1.8.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24" @@ -5368,7 +5465,7 @@ semver-compare@^1.0.0: resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc" integrity sha1-De4hahyUGrN+nvsXiPavxf9VN/w= -"semver@2 || 3 || 4 || 5", semver@^5.5.0: +"semver@2 || 3 || 4 || 5", semver@^5.5.0, semver@^5.6.0: version "5.7.1" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7" integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== @@ -5427,6 +5524,11 @@ shellwords@^0.1.1: resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww== +sigmund@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" + integrity sha1-P/IfGYytIXX587eBhT/ZTQ0ZtZA= + signal-exit@^3.0.0, signal-exit@^3.0.2: version "3.0.3" resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" @@ -6300,6 +6402,11 @@ y18n@^4.0.0: resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.1.tgz#8db2b83c31c5d75099bb890b23f3094891e247d4" integrity sha512-wNcy4NvjMYL8gogWWYAO7ZFWFfHcbdbE57tZO8e4cbpj8tfUcwrwqSl3ad8HxpYWCdXcJUCeKKZS62Av1affwQ== +yallist@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" + integrity sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI= + yallist@^3.0.2: version "3.1.1" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"