hermione-assert-view-extended
Advanced tools
Comparing version 2.1.0 to 3.0.0
70
index.js
@@ -6,5 +6,4 @@ 'use strict'; | ||
const globalStyles = opts.globalStyles || {}; | ||
const globalExecute = opts.globalExecute || {}; | ||
const elementProps = ['ignoreElements', 'invisibleElements', 'hideElements']; | ||
const otherProps = ['animationDisabled', 'customCSS']; | ||
const otherProps = ['animationDisabled', 'customCSS', 'redraw']; | ||
@@ -18,9 +17,12 @@ hermione.on(hermione.events.NEW_BROWSER, (browser) => { | ||
// Merge global and local selectors without excluded selectors. | ||
[...elementProps, ...otherProps].forEach(prop => { | ||
elementProps.forEach(prop => { | ||
options[prop] = merge( | ||
globalStyles[prop], | ||
elementProps.includes(prop) ? normalize(options[prop]) : options[prop], | ||
normalize(options[prop]), | ||
options.excludeElements | ||
); | ||
}); | ||
otherProps.forEach(prop => { | ||
options[prop] = options[prop] !== undefined ? options[prop] : globalStyles[prop] || false; | ||
}); | ||
@@ -34,6 +36,8 @@ // Remove captured selector from all types of ignore. | ||
options.animationDisabled = options.animationDisabled || false; | ||
let styleString = ''; | ||
if (options.redraw) { | ||
styleString += getPreRedrawStyles(); | ||
} | ||
if (options.animationDisabled) { | ||
@@ -55,14 +59,2 @@ styleString += getAnimationDisabledStyles(); | ||
let beforeExecute, afterExecute; | ||
if (globalExecute.beforeEach) { | ||
globalExecute.beforeEach = normalizeExecute(globalExecute.beforeEach); | ||
beforeExecute = globalExecute.beforeEach[0].bind(null, ...globalExecute.beforeEach.splice(1)); | ||
} | ||
if (globalExecute.afterEach) { | ||
globalExecute.afterEach = normalizeExecute(globalExecute.afterEach); | ||
afterExecute = globalExecute.afterEach[0].bind(null, ...globalExecute.afterEach.splice(1)); | ||
} | ||
if (hooks.beforeEach && typeof hooks.beforeEach.call !== 'undefined') { | ||
@@ -72,7 +64,3 @@ await browser.then(() => hooks.beforeEach.call({ browser }, name, selector, options)); | ||
await browser.execute(function(styleString, beforeExecute) { | ||
if (beforeExecute && typeof beforeExecute.call !== 'undefined') { | ||
beforeExecute(); | ||
} | ||
await browser.execute(function(styleString, redraw) { | ||
var head = document.head || document.getElementsByTagName('head')[0]; | ||
@@ -88,13 +76,19 @@ var style = document.createElement('style'); | ||
// Force repaint page | ||
if (window.getComputedStyle) { | ||
window.getComputedStyle(document.body, null).getPropertyValue('height'); | ||
} else { | ||
document.body.currentStyle.height; | ||
// Force redraw page | ||
if (redraw) { | ||
var oldBodyStylesTransform = document.body.style.transform; | ||
var oldBodyStylesDisplay = document.body.style.display; | ||
document.body.style.transform = 'translateZ(0)'; | ||
document.body.style.display = 'none'; | ||
// No need to store this anywhere, the reference is enough | ||
document.body.offsetHeight; | ||
document.body.style.display = oldBodyStylesDisplay; | ||
document.body.style.transform = oldBodyStylesTransform; | ||
} | ||
}, styleString, beforeExecute); | ||
}, styleString, options.redraw); | ||
await baseAssertView(name, selector, options); | ||
await browser.execute(function(afterExecute) { | ||
await browser.execute(function() { | ||
var head = document.head || document.getElementsByTagName('head')[0]; | ||
@@ -105,8 +99,4 @@ var style = document.getElementById('hermione-assert-view-extended'); | ||
head.removeChild(style); | ||
}); | ||
if (afterExecute && typeof afterExecute.call !== 'undefined') { | ||
afterExecute(); | ||
} | ||
}, afterExecute); | ||
if (hooks.afterEach && typeof hooks.afterEach.call !== 'undefined') { | ||
@@ -148,4 +138,8 @@ await browser.then(() => hooks.afterEach.call({ browser }, name, selector, options)); | ||
function normalizeExecute(value) { | ||
return [].concat(value); | ||
} | ||
function getPreRedrawStyles() { | ||
return ` | ||
body { | ||
will-change: transform; | ||
} | ||
`; | ||
} |
{ | ||
"name": "hermione-assert-view-extended", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "Hermione plugin for extend assertView command.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,3 +14,3 @@ # hermione-assert-view-extended | ||
Set options for the plugin in your hermione config: | ||
``` | ||
```js | ||
{ | ||
@@ -27,8 +27,12 @@ hooks: { | ||
animationDisabled: true, | ||
redraw: true, | ||
// Elements will be covered with black rect. | ||
ignoreElements: [ | ||
'.classname1' | ||
], | ||
// Elements will be hidden with `opacity: 0`. | ||
invisibleElements: [ | ||
'.classname3' | ||
], | ||
// Elements will be hidden with `display: none`. | ||
hideElements: [ | ||
@@ -42,13 +46,2 @@ '.classname2' | ||
` | ||
}, | ||
globalExecute: { | ||
beforeEach: [ | ||
function(message) { | ||
alert(message); | ||
}, | ||
'Hello, world!' | ||
], | ||
afterEach: function() { | ||
alert('Bye bye!'); | ||
} | ||
} | ||
@@ -67,2 +60,3 @@ } | ||
| `globalStyles.animationDisabled` | `false` | Disable CSS animation (`transition-duration: 0s`, `animation-duration: 0s`, etc.). | | ||
| `globalStyles.redraw` | `false` | Bowser redraw page after apply styles. | | ||
| `globalStyles.ignoreElements` | | Elements will be covered with black rect. | | ||
@@ -72,5 +66,2 @@ | `globalStyles.invisibleElements` | | Elements will be hidden with `opacity: 0`. | | ||
| `globalStyles.customCSS` | | Custom styles. | | ||
| `globalExecute` | | Scripts executed before/after call assertView in the inner execut with other manipulation. | | ||
| `globalExecute.beforeEach` | | JS function executed before call assertView. | | ||
| `globalExecute.afterEach` | | JS function executed after call assertView. | | ||
@@ -77,0 +68,0 @@ ## Licence |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9130
112
66