Jest-Vue-Serializer-TJW

This commit is contained in:
The Jared Wilcurt 2020-01-19 09:30:45 -05:00 committed by GitHub
commit be3c9e17bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 2141 additions and 1251 deletions

View File

@ -16,6 +16,7 @@ NW.js + Vue-CLI 4 example
* A11Y Linting
* Jest Linting
* Jest (100% test coverage)
* Jest Serializer Vue (TJW)
*Why not include Vue-Router or Vuex?*
@ -83,7 +84,9 @@ This will download the source code for the latest version of Vue-DevTools and do
This is not for those *using* this repo, but for those *maintaining* it.
1. When updating the version of NW.js devDependency, also update these:
* `package.json` devDeps, build nwVersion
* `tests/unit/setup.js`
* `tests/unit/components/__snapshots__/HelloWorld.test.js.snap`
* `.browserslistrc`
1. Bump the version number, and all the npm scripts that reference the version number
1. Run `npm run regression` after updating dependencies or other major changes to verify builds still work correctly

View File

@ -21,7 +21,7 @@ module.exports = {
'<rootDir>/tests/unit/setup.js'
],
snapshotSerializers: [
'<rootDir>/tests/unit/serializer.js'
'<rootDir>/node_modules/jest-serializer-vue-tjw'
],
testEnvironment: 'jest-environment-jsdom-global',
testMatch: [

3297
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
"To turn spell checking off, remove it from the chromium-args in this file"
],
"name": "nw-vue",
"version": "1.3.0",
"version": "1.4.0",
"main": "http://localhost:8964",
"node-remote": "http://localhost:8964",
"node-main": "",
@ -27,10 +27,10 @@
"build:nw": "build --concurrent --tasks win-x86,linux-x86,linux-x64,mac-x64 --mirror https://dl.nwjs.io/ .",
"build:win": "npm run build:win:clean && npm run build:vue && build --tasks win-x86 --mirror https://dl.nwjs.io/ .",
"build:lin": "npm run build:lin:clean && npm run build:vue && build --tasks linux-x64 --mirror https://dl.nwjs.io/ .",
"build:win:clean": "rimraf ./dist-vue ./dist/nw-vue-1.3.0-win-x86 ./dist/nw-vue-1.3.0-win-x86.zip ./dist/nw-vue-1.3.0-win-x86.7z ./dist/nw-vue-1.3.0-win-x86-Setup.exe",
"build:lin:clean": "rimraf ./dist-vue ./dist/nw-vue-1.3.0-linux-x64 ./dist/nw-vue-1.3.0-linux-x64.zip",
"run:win": "dist\\nw-vue-1.3.0-win-x86\\nw-vue.exe",
"run:lin": "./dist/nw-vue-1.3.0-linux-x64/nw-vue",
"build:win:clean": "rimraf ./dist-vue ./dist/nw-vue-1.4.0-win-x86 ./dist/nw-vue-1.4.0-win-x86.zip ./dist/nw-vue-1.4.0-win-x86.7z ./dist/nw-vue-1.4.0-win-x86-Setup.exe",
"build:lin:clean": "rimraf ./dist-vue ./dist/nw-vue-1.4.0-linux-x64 ./dist/nw-vue-1.4.0-linux-x64.zip",
"run:win": "dist\\nw-vue-1.4.0-win-x86\\nw-vue.exe",
"run:lin": "./dist/nw-vue-1.4.0-linux-x64/nw-vue",
"regression": "rd /s /q node_modules & rd /s /q node_modules & rd /s /q node_modules & npm install && npm run lint && npm test && npm run build:win && npm run run:win",
"lint": "vue-cli-service lint --no-fix",
"fix": "vue-cli-service lint --fix",
@ -44,11 +44,11 @@
"express": "^4.17.1"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.1",
"@vue/cli-plugin-e2e-nightwatch": "^4.1.1",
"@vue/cli-plugin-eslint": "^4.1.1",
"@vue/cli-plugin-unit-jest": "^4.1.1",
"@vue/cli-service": "^4.1.1",
"@vue/cli-plugin-babel": "^4.1.2",
"@vue/cli-plugin-e2e-nightwatch": "^4.1.2",
"@vue/cli-plugin-eslint": "^4.1.2",
"@vue/cli-plugin-unit-jest": "^4.1.2",
"@vue/cli-service": "^4.1.2",
"@vue/test-utils": "1.0.0-beta.29",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "^10.0.3",
@ -59,18 +59,19 @@
"babel-preset-stage-2": "^6.24.1",
"babel-preset-vue-app": "^2.0.0",
"concurrently": "^5.0.2",
"core-js": "^3.6.1",
"core-js": "^3.6.4",
"eslint": "^6.8.0",
"eslint-config-tjw-base": "^1.0.0",
"eslint-config-tjw-vue": "^1.0.0",
"eslint-plugin-jest": "^23.1.1",
"eslint-plugin-vue": "^6.0.2",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-vue": "^6.1.2",
"eslint-plugin-vue-a11y": "^0.0.31",
"jest": "^24.9.0",
"jest-environment-jsdom": "^24.9.0",
"jest-environment-jsdom-global": "^1.2.0",
"jest-serializer-vue-tjw": "^3.3.0",
"jest-transform-stub": "^2.0.0",
"nw": "0.43.2-sdk",
"nw": "0.43.6-sdk",
"nw-vue-devtools-prebuilt": "^0.0.10",
"nwjs-builder-phoenix": "^1.15.0",
"nwjs-types": "^1.0.0",
@ -78,11 +79,11 @@
"vue": "^2.6.11",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.11",
"wait-on": "^3.3.0"
"wait-on": "^4.0.0"
},
"chromium-args": "--enable-spell-checking --load-extension='./node_modules/nw-vue-devtools-prebuilt/extension'",
"build": {
"nwVersion": "v0.43.2",
"nwVersion": "v0.43.6",
"nwFlavor": "normal",
"targets": [
"zip",
@ -131,7 +132,7 @@
"height": 600,
"min_width": 700,
"min_height": 500,
"icon": "dist-vue/vue.png"
"icon": "dist-vue/icon.png"
}
},
"win": {

View File

@ -24,10 +24,10 @@ exports[`HelloWorld.vue Render default contents 1`] = `
<h3>
You are using
Vue.js (v2.6.11),
NW.js (v0.43.2-sdk),
Node.js (v13.5.0),
NW.js (v0.43.6-sdk),
Node.js (v13.6.0),
and
Chromium (v79.0.3945.88).
Chromium (v79.0.3945.130).
</h3>
<button>
Show

View File

@ -1,42 +0,0 @@
// Based on jest-serializer-vue
const beautify = require('pretty');
function isHtmlString (received) {
return received && typeof(received) === 'string' && received.startsWith('<');
}
function isVueWrapper (received) {
return received && typeof(received) === 'object' && typeof(received.isVueInstance) === 'function';
}
// This removes data-test="whatever" from your snapshots
// If you also want to remove them from your production builds, see:
// https://forum.vuejs.org/t/how-to-remove-attributes-from-tags-inside-vue-components/24138
function removeDataTestAttributes (html) {
// [-\w]+ will catch 1 or more instaces of a-z, A-Z, 0-9, hyphen (-), or underscore (_)
return html.replace(/ data-test="[-\w]+"/g, '');
}
module.exports = {
test: function (received) {
return isHtmlString(received) || isVueWrapper(received);
},
print: function (received) {
let html = received || '';
if (isVueWrapper(received)) {
html = received.html();
}
html = removeDataTestAttributes(html);
// To see available options: https://github.com/beautify-web/js-beautify/blob/master/js/src/html/options.js
const options = {
indent_size: 2,
unformatted: ['code', 'pre'],
inline: [],
indent_inner_html: true,
indent_char: ' ',
sep: '\n'
};
return beautify(html, options);
}
};

View File

@ -22,14 +22,15 @@ window.getComputedStyle = function getComputedStyleStub (el) {
global.beforeEach(() => {
window.process = {
cwd: process.cwd,
env: {
NODE_ENV: 'development'
},
versions: {
chromium: '79.0.3945.88',
nw: '0.43.2',
chromium: '79.0.3945.130',
nw: '0.43.6',
'nw-flavor': 'sdk',
node: '13.5.0'
node: '13.6.0'
}
};
window.nw = {