From 4d1ea6c86f85db657b21b26198c4ec40aa3093fa Mon Sep 17 00:00:00 2001 From: Cory Date: Thu, 13 Oct 2016 15:09:10 -0400 Subject: [PATCH] Run tests on ember beta, release, canary * Fix failing tests when using ember with glimmer2. * Access DOM helper using a method that is safe for both pre-glimmer2 and glimmer2. * Wrap the renderedMobiledoc documentFragment in a wrapper div (necessary for glimmer2 teardown, see https://github.com/tildeio/glimmer/pull/331 and https://github.com/yapplabs/ember-wormhole/issues/66#issuecomment-246207622) * Fixes #18. * Update travis node version. * Update package keywords and description. --- .travis.yml | 15 +++++++++------ addon/components/render-mobiledoc.js | 15 +++++++++++---- addon/utils/dom.js | 10 ++++++++++ config/ember-try.js | 18 +++++++++++++++--- package.json | 6 ++++-- 5 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 addon/utils/dom.js diff --git a/.travis.yml b/.travis.yml index b3d12e2..3890c1f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ --- language: node_js node_js: - - "0.12" + - "6.2.0" -sudo: false +sudo: required +dist: trusty cache: directories: @@ -12,18 +13,20 @@ cache: env: - EMBER_TRY_SCENARIO=1.13 - EMBER_TRY_SCENARIO=default - - EMBER_TRY_SCENARIO=2.3 + - EMBER_TRY_SCENARIO=ember-release + - EMBER_TRY_SCENARIO=ember-beta - EMBER_TRY_SCENARIO=ember-canary matrix: fast_finish: true allow_failures: + - env: EMBER_TRY_SCENARIO=ember-beta - env: EMBER_TRY_SCENARIO=ember-canary before_install: - - export PATH=/usr/local/phantomjs-2.0.0/bin:$PATH - - "npm config set spin false" - - "npm install -g npm@^2" + - npm install -g npm@^3 + - npm config set progress false + - npm install -g phantomjs-prebuilt install: - npm install -g bower diff --git a/addon/components/render-mobiledoc.js b/addon/components/render-mobiledoc.js index 05e222b..b46d612 100644 --- a/addon/components/render-mobiledoc.js +++ b/addon/components/render-mobiledoc.js @@ -2,6 +2,7 @@ import Ember from 'ember'; import Renderer from 'ember-mobiledoc-dom-renderer'; import { RENDER_TYPE } from 'ember-mobiledoc-dom-renderer'; import layout from '../templates/components/render-mobiledoc'; +import { getDOM } from '../utils/dom'; const { assert, @@ -92,9 +93,8 @@ export default Ember.Component.extend({ }), willRender() { - let emberRenderer = this.get('renderer'); - let dom = emberRenderer && emberRenderer._dom; - assert('Unable to get renderer dom helper', !!dom); + let domHelper = getDOM(this); + let dom = domHelper.document; let cards = this.get('_mdcCards'); let atoms = this.get('_mdcAtoms'); @@ -104,7 +104,14 @@ export default Ember.Component.extend({ let renderer = new Renderer({atoms, cards, cardOptions, dom}); let { result, teardown } = renderer.render(mobiledoc); - this.set('renderedMobiledoc', result); + // result is a document fragment, and glimmer2 errors when cleaning it up. + // We must append the document fragment to a static wrapper. + // Related: https://github.com/tildeio/glimmer/pull/331 and + // https://github.com/yapplabs/ember-wormhole/issues/66#issuecomment-246207622 + let wrapper = this._createElement(dom, 'div'); + wrapper.appendChild(result); + + this.set('renderedMobiledoc', wrapper); this._teardownRender = teardown; this._super(...arguments); diff --git a/addon/utils/dom.js b/addon/utils/dom.js new file mode 100644 index 0000000..c1394a1 --- /dev/null +++ b/addon/utils/dom.js @@ -0,0 +1,10 @@ +export function getDOM(context) { + let { renderer } = context; + if (renderer._dom) { // pre glimmer2 + return renderer._dom; + } else if (renderer._env && renderer._env.getDOM) { // glimmer 2 + return renderer._env.getDOM(); + } else { + throw new Error('Unable to get DOM helper'); + } +} diff --git a/config/ember-try.js b/config/ember-try.js index f67cbe4..89cf333 100644 --- a/config/ember-try.js +++ b/config/ember-try.js @@ -3,7 +3,7 @@ module.exports = { { name: '1.13', dependencies: { - "ember": "~1.13.7" + "ember": "^1.13" } }, { @@ -11,9 +11,21 @@ module.exports = { dependencies: { } }, { - name: '2.3', + name: 'ember-release', dependencies: { - 'ember': '2.3.0-beta.1' + 'ember': 'components/ember#release' + }, + resolutions: { + 'ember': 'release' + } + }, + { + name: 'ember-beta', + dependencies: { + 'ember': 'components/ember#beta' + }, + resolutions: { + 'ember': 'beta' } }, { diff --git a/package.json b/package.json index bbe1a2b..5dbfd29 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ember-mobiledoc-dom-renderer", "version": "0.5.2", - "description": "provides mobiledoc-dom-renderer to ember apps", + "description": "provides a runtime mobiledoc dom-renderer to ember apps", "directories": { "doc": "doc", "test": "tests" @@ -38,7 +38,9 @@ "ember-try": "0.0.6" }, "keywords": [ - "ember-addon" + "ember-addon", + "mobiledoc", + "mobiledoc-kit" ], "dependencies": { "broccoli-funnel": "^1.0.0",