Skip to content

Commit 2ff2ce3

Browse files
committed
refactor(test_lib): remove IS_NODEJS
Closes angular#1015
1 parent ab5ed6f commit 2ff2ce3

File tree

14 files changed

+82
-44
lines changed

14 files changed

+82
-44
lines changed

modules/angular2/src/dom/browser_adapter.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
234234
return node.nodeType === Node.TEXT_NODE;
235235
}
236236
isCommentNode(node:Node):boolean {
237-
return node.nodeType === Node.TEXT_NODE;
237+
return node.nodeType === Node.COMMENT_NODE;
238238
}
239239
isElementNode(node:Node):boolean {
240240
return node.nodeType === Node.ELEMENT_NODE;

modules/angular2/src/dom/dom_adapter.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export class DomAdapter {
144144
getShadowRoot(el) {
145145
throw _abstract();
146146
}
147+
getDistributedNodes(el) {
148+
throw _abstract();
149+
}
147150
clone(node) {
148151
throw _abstract();
149152
}
@@ -249,4 +252,10 @@ export class DomAdapter {
249252
cssToRules(css:string): List {
250253
throw _abstract();
251254
}
255+
supportsDOMEvents(): boolean {
256+
throw _abstract();
257+
}
258+
supportsNativeShadowDOM(): boolean {
259+
throw _abstract();
260+
}
252261
}

modules/angular2/src/dom/generic_browser_adapter.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import {ABSTRACT} from 'angular2/src/facade/lang';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
3-
import {isPresent} from 'angular2/src/facade/lang';
3+
import {isPresent, isFunction} from 'angular2/src/facade/lang';
44
import {DomAdapter} from './dom_adapter';
55

66
/**
77
* Provides DOM operations in any browser environment.
88
*/
99
@ABSTRACT()
1010
export class GenericBrowserDomAdapter extends DomAdapter {
11+
getDistributedNodes(el) {
12+
return el.getDistributedNodes();
13+
}
1114
resolveAndSetHref(el, baseUrl:string, href:string) {
1215
el.href = href == null ? baseUrl : baseUrl + '/../' + href;
1316
}
@@ -34,4 +37,10 @@ export class GenericBrowserDomAdapter extends DomAdapter {
3437
this.remove(style);
3538
return rules;
3639
}
40+
supportsDOMEvents(): boolean {
41+
return true;
42+
}
43+
supportsNativeShadowDOM(): boolean {
44+
return isFunction(this.defaultDoc().body.createShadowRoot);
45+
}
3746
}

modules/angular2/src/dom/html5lib_adapter.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,13 @@ class Html5LibDomAdapter implements DomAdapter {
223223
List cssToRules(String css) {
224224
throw 'not implemented';
225225
}
226+
List getDistributedNodes(Node) {
227+
throw 'not implemented';
228+
}
229+
bool supportsDOMEvents() {
230+
throw 'not implemented';
231+
}
232+
bool supportsNativeShadowDOM() {
233+
throw 'not implemented';
234+
}
226235
}

modules/angular2/src/dom/parse5_adapter.cjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
33
var serializer = new parse5.Serializer(parse5.TreeAdapters.htmlparser2);
44
var treeAdapter = parser.treeAdapter;
55

6-
var cssParse = require('css-parse');
6+
var cssParse = require('css').parse;
77

88
var url = require('url');
99

@@ -252,6 +252,9 @@ export class Parse5DomAdapter extends DomAdapter {
252252
getShadowRoot(el) {
253253
return el.shadowRoot;
254254
}
255+
getDistributedNodes(el) {
256+
throw _notImplemented('getDistributedNodes');
257+
}
255258
clone(node) {
256259
var temp = treeAdapter.createElement("template", null, []);
257260
treeAdapter.appendChild(temp, node);
@@ -384,7 +387,7 @@ export class Parse5DomAdapter extends DomAdapter {
384387
return treeAdapter.isTextNode(node);
385388
}
386389
isCommentNode(node):boolean {
387-
throw treeAdapter.isCommentNode(node);
390+
return treeAdapter.isCommentNode(node);
388391
}
389392
isElementNode(node):boolean {
390393
return node ? treeAdapter.isElementNode(node) : false;
@@ -455,6 +458,12 @@ export class Parse5DomAdapter extends DomAdapter {
455458
}
456459
return rules;
457460
}
461+
supportsDOMEvents(): boolean {
462+
return false;
463+
}
464+
supportsNativeShadowDOM(): boolean {
465+
return false;
466+
}
458467
}
459468

460469
//TODO: build a proper list, this one is all the keys of a HTMLInputElement

modules/angular2/src/facade/lang.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class IMPLEMENTS {
2424
bool isPresent(obj) => obj != null;
2525
bool isBlank(obj) => obj == null;
2626
bool isString(obj) => obj is String;
27+
bool isFunction(obj) => obj is Function;
2728

2829
String stringify(obj) => obj.toString();
2930

modules/angular2/src/facade/lang.es6

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export function isString(obj):boolean {
3838
return typeof obj === "string";
3939
}
4040

41+
export function isFunction(obj):boolean {
42+
return typeof obj === "function";
43+
}
44+
4145
export function stringify(token):string {
4246
if (typeof token === 'string') {
4347
return token;

modules/angular2/src/test_lib/test_lib.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import './test_injector.dart';
1818
export './test_injector.dart' show inject;
1919

2020
bool IS_DARTIUM = true;
21-
bool IS_NODEJS = false;
2221

2322
List _testBindings = [];
2423
Injector _injector;
@@ -165,11 +164,11 @@ String elementText(n) {
165164
}
166165

167166
if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') {
168-
return elementText(n.getDistributedNodes());
167+
return elementText(DOM.getDistributedNodes(n));
169168
}
170169

171170
if (DOM.hasShadowRoot(n)) {
172-
return elementText(DOM.childNodesAsList(n.shadowRoot));
171+
return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n)));
173172
}
174173

175174
if (hasNodes(n)) {

modules/angular2/src/test_lib/test_lib.es6

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export var afterEach = _global.afterEach;
1414
export var expect = _global.expect;
1515

1616
export var IS_DARTIUM = false;
17-
export var IS_NODEJS = typeof window === 'undefined';
1817

1918
export class AsyncTestCompleter {
2019
_done: Function;
@@ -293,23 +292,26 @@ export class SpyObject {
293292

294293
function elementText(n) {
295294
var hasNodes = (n) => {var children = DOM.childNodes(n); return children && children.length > 0;}
296-
if (!IS_NODEJS) {
297-
if (n instanceof Comment) return '';
298295

299-
if (n instanceof Array) return n.map((nn) => elementText(nn)).join("");
300-
if (n instanceof Element && DOM.tagName(n) == 'CONTENT')
301-
return elementText(Array.prototype.slice.apply(n.getDistributedNodes()));
302-
if (DOM.hasShadowRoot(n)) return elementText(DOM.childNodesAsList(n.shadowRoot));
303-
if (hasNodes(n)) return elementText(DOM.childNodesAsList(n));
296+
if (n instanceof Array) {
297+
return n.map((nn) => elementText(nn)).join("");
298+
}
304299

305-
return n.textContent;
306-
} else {
307-
if (n instanceof Array) {
308-
return n.map((nn) => elementText(nn)).join("");
309-
} else if (hasNodes(n)) {
310-
return elementText(DOM.childNodesAsList(n));
311-
} else {
312-
return DOM.getText(n);
313-
}
300+
if (DOM.isCommentNode(n)) {
301+
return '';
302+
}
303+
304+
if (DOM.isElementNode(n) && DOM.tagName(n) == 'CONTENT') {
305+
return elementText(Array.prototype.slice.apply(DOM.getDistributedNodes(n)));
314306
}
307+
308+
if (DOM.hasShadowRoot(n)) {
309+
return elementText(DOM.childNodesAsList(DOM.getShadowRoot(n)));
310+
}
311+
312+
if (hasNodes(n)) {
313+
return elementText(DOM.childNodesAsList(n));
314+
}
315+
316+
return DOM.getText(n);
315317
}

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {describe, beforeEach, it, expect, ddescribe, iit, SpyObject, el, IS_NODEJS} from 'angular2/test_lib';
1+
import {describe, beforeEach, it, expect, ddescribe, iit, SpyObject, el} from 'angular2/test_lib';
22
import {ShadowCss} from 'angular2/src/core/compiler/shadow_dom_emulation/shadow_css';
33

44
import {RegExpWrapper, StringWrapper} from 'angular2/src/facade/lang';
@@ -91,16 +91,13 @@ export function main() {
9191
expect(StringWrapper.contains(css, '#menu > .bar {;background: blue;}')).toBeTruthy();
9292
});
9393

94-
if (!IS_NODEJS) {
95-
//TODO: reactivate once CSS parser is fixed: https://github.com/reworkcss/css/issues/65
96-
it('should support polyfill-rule', () => {
97-
var css = s("polyfill-rule {content: ':host.foo .bar';background: blue;}", 'a', 'a-host');
98-
expect(css).toEqual('[a-host].foo .bar {background: blue;}');
94+
it('should support polyfill-rule', () => {
95+
var css = s("polyfill-rule {content: ':host.foo .bar';background: blue;}", 'a', 'a-host');
96+
expect(css).toEqual('[a-host].foo .bar {background: blue;}');
9997

100-
css = s('polyfill-rule {content: ":host.foo .bar";background: blue;}', 'a', 'a-host');
101-
expect(css).toEqual('[a-host].foo .bar {background: blue;}');
102-
});
103-
}
98+
css = s('polyfill-rule {content: ":host.foo .bar";background: blue;}', 'a', 'a-host');
99+
expect(css).toEqual('[a-host].foo .bar {background: blue;}');
100+
});
104101

105102
it('should handle ::shadow', () => {
106103
var css = s('x::shadow > y {}', 'a');

0 commit comments

Comments
 (0)