Browse Source

Setup headless test

pull/3671/head
Artur Arseniev 5 years ago
parent
commit
7c38d21f44
  1. 14
      src/code_manager/model/CodeMirrorEditor.js
  2. 4
      src/css_composer/model/CssRule.js
  3. 5
      src/keymaps/index.js
  4. 2
      src/utils/ColorPicker.js
  5. 2
      src/utils/extender.js
  6. 9
      src/utils/fetch.js
  7. 4
      src/utils/mixins.js
  8. 3
      src/utils/polyfills.js

14
src/code_manager/model/CodeMirrorEditor.js

@ -1,9 +1,15 @@
import { bindAll } from 'underscore'; import { bindAll } from 'underscore';
import Backbone from 'backbone'; import Backbone from 'backbone';
import CodeMirror from 'codemirror/lib/codemirror'; import { hasWin } from 'utils/mixins';
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/mode/css/css'; let CodeMirror;
import 'codemirror-formatting';
if (hasWin()) {
CodeMirror = require('codemirror/lib/codemirror');
require('codemirror/mode/htmlmixed/htmlmixed');
require('codemirror/mode/css/css');
require('codemirror-formatting');
}
export default Backbone.Model.extend({ export default Backbone.Model.extend({
CodeMirror, CodeMirror,

4
src/css_composer/model/CssRule.js

@ -3,9 +3,9 @@ import { Model } from 'backbone';
import Styleable from 'domain_abstract/model/Styleable'; import Styleable from 'domain_abstract/model/Styleable';
import { isEmpty, forEach, isString } from 'underscore'; import { isEmpty, forEach, isString } from 'underscore';
import Selectors from 'selector_manager/model/Selectors'; import Selectors from 'selector_manager/model/Selectors';
import { isEmptyObj } from 'utils/mixins'; import { isEmptyObj, hasWin } from 'utils/mixins';
const { CSS } = window; const { CSS } = hasWin() ? window : {};
export default class CssRule extends Model.extend(Styleable) { export default class CssRule extends Model.extend(Styleable) {
defaults() { defaults() {

5
src/keymaps/index.js

@ -32,7 +32,10 @@
*/ */
import { isString } from 'underscore'; import { isString } from 'underscore';
import keymaster from 'keymaster'; import { hasWin } from 'utils/mixins';
import keymaster from 'utils/keymaster';
hasWin() && keymaster.init(window);
export default () => { export default () => {
let em; let em;

2
src/utils/ColorPicker.js

@ -4,9 +4,11 @@
// https://github.com/bgrins/spectrum // https://github.com/bgrins/spectrum
// Author: Brian Grinstead // Author: Brian Grinstead
// License: MIT // License: MIT
import { hasWin } from 'utils/mixins';
export default function($, undefined) { export default function($, undefined) {
'use strict'; 'use strict';
if (!hasWin()) return;
var defaultOpts = { var defaultOpts = {
// Callbacks // Callbacks

2
src/utils/extender.js

@ -1,7 +1,7 @@
import { isObject, isString, each, isUndefined } from 'underscore'; import { isObject, isString, each, isUndefined } from 'underscore';
export default ({ $ }) => { export default ({ $ }) => {
if ($ && $.prototype.constructor.name !== 'jQuery') { if ($ && $.prototype && $.prototype.constructor.name !== 'jQuery') {
const fn = $.fn; const fn = $.fn;
// Additional helpers // Additional helpers

9
src/utils/fetch.js

@ -1,8 +1,11 @@
import Promise from 'promise-polyfill'; import Promise from 'promise-polyfill';
import { hasWin } from 'utils/mixins';
window.Promise = window.Promise || Promise; if (hasWin()) {
window.Promise = window.Promise || Promise;
}
export default (typeof fetch == 'function' export default typeof fetch == 'function'
? fetch.bind() ? fetch.bind()
: (url, options) => { : (url, options) => {
return new Promise((res, rej) => { return new Promise((res, rej) => {
@ -30,4 +33,4 @@ export default (typeof fetch == 'function'
// Include body only if present // Include body only if present
options.body ? req.send(options.body) : req.send(); options.body ? req.send(options.body) : req.send();
}); });
}); };

4
src/utils/mixins.js

@ -1,6 +1,8 @@
import { keys, isUndefined, isElement, isArray } from 'underscore'; import { keys, isUndefined, isElement, isArray } from 'underscore';
const elProt = window.Element.prototype; export const hasWin = () => typeof window !== 'undefined';
const elProt = hasWin() ? window.Element.prototype : {};
const matches = const matches =
elProt.matches || elProt.matches ||
elProt.webkitMatchesSelector || elProt.webkitMatchesSelector ||

3
src/utils/polyfills.js

@ -2,6 +2,7 @@
* File made for IE/Edge support * File made for IE/Edge support
* https://github.com/artf/grapesjs/issues/214 * https://github.com/artf/grapesjs/issues/214
*/ */
import { hasWin } from './mixins';
export default () => { export default () => {
/** /**
@ -27,7 +28,7 @@ export default () => {
return !!match; return !!match;
}; };
if (isIE()) { if (hasWin() && isIE()) {
const originalCreateHTMLDocument = const originalCreateHTMLDocument =
DOMImplementation.prototype.createHTMLDocument; DOMImplementation.prototype.createHTMLDocument;
DOMImplementation.prototype.createHTMLDocument = title => { DOMImplementation.prototype.createHTMLDocument = title => {

Loading…
Cancel
Save