Skip to content

Commit c67194a

Browse files
committed
fix(test_lib): remove getDistributedNodes emulation in NodeJS
1 parent dd3e627 commit c67194a

2 files changed

Lines changed: 13 additions & 34 deletions

File tree

modules/angular2/src/test_lib/test_lib.es6

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,8 @@ export class SpyObject {
153153

154154

155155
function elementText(n) {
156+
var hasNodes = (n) => {var children = DOM.childNodes(n); return children && children.length > 0;}
156157
if (!IS_NODEJS) {
157-
var hasNodes = (n) => {var children = DOM.childNodes(n); return children && children.length > 0;}
158-
159158
if (n instanceof Comment) return '';
160159

161160
if (n instanceof Array) return n.map((nn) => elementText(nn)).join("");
@@ -166,33 +165,10 @@ function elementText(n) {
166165

167166
return n.textContent;
168167
} else {
169-
if (DOM.hasShadowRoot(n)) {
170-
return elementText(DOM.getShadowRoot(n).childNodes);
171-
} else if (n instanceof Array) {
168+
if (n instanceof Array) {
172169
return n.map((nn) => elementText(nn)).join("");
173-
} else if (DOM.tagName(n) == 'content') {
174-
//minimal implementation of getDistributedNodes()
175-
var host = null;
176-
var temp = n;
177-
while (temp.parent) {
178-
if (DOM.hasShadowRoot(temp)) {
179-
host = temp;
180-
}
181-
temp = temp.parent;
182-
}
183-
if (host) {
184-
var list = [];
185-
var select = DOM.getAttribute(n, "select");
186-
var selectClass = select? select.substring(1): null;
187-
DOM.childNodes(host).forEach((child) => {
188-
var classList = DOM.classList(child);
189-
if (selectClass && classList.indexOf(selectClass) > -1 || selectClass == null && classList.length == 0) {
190-
list.push(child);
191-
}
192-
});
193-
return list.length > 0? elementText(list): "";
194-
}
195-
return "";
170+
} else if (hasNodes(n)) {
171+
return elementText(DOM.childNodesAsList(n));
196172
} else {
197173
return DOM.getText(n);
198174
}

modules/angular2/test/core/compiler/shadow_dom/shadow_dom_emulation_integration_spec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el} from 'angular2/test_lib';
1+
import {describe, xit, it, expect, beforeEach, ddescribe, iit, el, IS_NODEJS} from 'angular2/test_lib';
22

33
import {StringMapWrapper, List} from 'angular2/src/facade/collection';
44
import {Type} from 'angular2/src/facade/lang';
@@ -40,12 +40,15 @@ export function main() {
4040
var urlResolver = new UrlResolver();
4141
var styleUrlResolver = new StyleUrlResolver(urlResolver);
4242
var styleInliner = new StyleInliner(null, styleUrlResolver, urlResolver);
43+
var strategies = {
44+
"scoped" : new EmulatedScopedShadowDomStrategy(styleInliner, styleUrlResolver, DOM.createElement('div')),
45+
"unscoped" : new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, DOM.createElement('div'))
46+
}
47+
if (!IS_NODEJS) {
48+
StringMapWrapper.set(strategies, "native", new NativeShadowDomStrategy(styleUrlResolver));
49+
}
4350

44-
StringMapWrapper.forEach({
45-
"native" : new NativeShadowDomStrategy(styleUrlResolver),
46-
"scoped" : new EmulatedScopedShadowDomStrategy(styleInliner, styleUrlResolver, DOM.createElement('div')),
47-
"unscoped" : new EmulatedUnscopedShadowDomStrategy(styleUrlResolver, DOM.createElement('div')),
48-
},
51+
StringMapWrapper.forEach(strategies,
4952
(strategy, name) => {
5053

5154
describe(`${name} shadow dom strategy`, () => {

0 commit comments

Comments
 (0)