ohif-viewer/platform/viewer/cypress/support/index.js
Danny Brown 70532a6cc6
test: percy snapshot workaround (#1111)
* Try workaround for percy snapshot

* Return our modified document

* test: some dark magic to make it possible to take screenshots of WebGL canvases

* Apply transformation directly to test DOM

* investigate: window:before:load

* Register flag in correct place; add experimental-webgl check

* Remaining canvas fixes

* Remove comment
2019-10-28 12:43:37 -04:00

36 lines
1.2 KiB
JavaScript

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************
import './commands';
Cypress.on('window:before:load', window => {
// Override our `getContext` function so all contexts that are webGl are
// Created with `preserveDrawingBuffer = true`; this is required for percy
// Snapshot
window.HTMLCanvasElement.prototype.getContext = (function(oldGetContextFn) {
return function(type, attrs) {
attrs = attrs || {};
if (
type === 'webgl' ||
type === 'webgl2' ||
type === 'experimental-webgl'
) {
attrs.preserveDrawingBuffer = true;
}
return oldGetContextFn.apply(this, [type, attrs]);
};
})(HTMLCanvasElement.prototype.getContext);
});