chore(packaging): update import for the new file structure
This commit is contained in:
33
modules/angular2/src/test_lib/benchmark_util.js
vendored
Normal file
33
modules/angular2/src/test_lib/benchmark_util.js
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import {DOM, document, location} from 'angular2/src/facade/dom';
|
||||
import {NumberWrapper, BaseException, isBlank} from 'angular2/src/facade/lang';
|
||||
|
||||
export function getIntParameter(name:string) {
|
||||
return NumberWrapper.parseInt(getStringParameter(name), 10);
|
||||
}
|
||||
|
||||
export function getStringParameter(name:string) {
|
||||
var els = DOM.querySelectorAll(document, `input[name="${name}"]`)
|
||||
var value;
|
||||
var el;
|
||||
|
||||
for (var i=0; i<els.length; i++) {
|
||||
el = els[i];
|
||||
if ((el.type !== 'radio' && el.type !== 'checkbox') || el.checked) {
|
||||
value = el.value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBlank(value)) {
|
||||
throw new BaseException(`Could not find and input field with name ${name}`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export function bindAction(selector:string, callback:Function) {
|
||||
var el = DOM.querySelector(document, selector);
|
||||
DOM.on(el, 'click', function(_) {
|
||||
callback();
|
||||
});
|
||||
}
|
72
modules/angular2/src/test_lib/test_lib.dart
Normal file
72
modules/angular2/src/test_lib/test_lib.dart
Normal file
@ -0,0 +1,72 @@
|
||||
library test_lib.test_lib;
|
||||
|
||||
import 'package:guinness/guinness_html.dart' as gns;
|
||||
export 'package:guinness/guinness_html.dart';
|
||||
import 'package:unittest/unittest.dart' hide expect;
|
||||
import 'dart:mirrors';
|
||||
import 'dart:async';
|
||||
import 'package:angular2/src/reflection/reflection.dart';
|
||||
import 'package:angular2/src/facade/dom.dart';
|
||||
import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
|
||||
bool IS_DARTIUM = true;
|
||||
|
||||
Expect expect(actual, [matcher]) {
|
||||
final expect = new Expect(actual);
|
||||
if (matcher != null) expect.to(matcher);
|
||||
return expect;
|
||||
}
|
||||
|
||||
class Expect extends gns.Expect {
|
||||
Expect(actual) : super(actual);
|
||||
|
||||
NotExpect get not => new NotExpect(actual);
|
||||
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
void toThrowError([message=""]) => this.toThrowWith(message: message);
|
||||
void toBePromise() => _expect(actual is Future, equals(true));
|
||||
void toImplement(expected) => toBeA(expected);
|
||||
Function get _expect => gns.guinness.matchers.expect;
|
||||
}
|
||||
|
||||
class NotExpect extends gns.NotExpect {
|
||||
NotExpect(actual) : super(actual);
|
||||
|
||||
void toEqual(expected) => toHaveSameProps(expected);
|
||||
}
|
||||
|
||||
beforeEach(fn) {
|
||||
gns.guinnessEnableHtmlMatchers();
|
||||
gns.beforeEach(_enableReflection(fn));
|
||||
}
|
||||
|
||||
it(name, fn) {
|
||||
gns.it(name, _enableReflection(_handleAsync(fn)));
|
||||
}
|
||||
|
||||
iit(name, fn) {
|
||||
gns.iit(name, _enableReflection(_handleAsync(fn)));
|
||||
}
|
||||
|
||||
_enableReflection(fn) {
|
||||
return () {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
return fn();
|
||||
};
|
||||
}
|
||||
|
||||
_handleAsync(fn) {
|
||||
ClosureMirror cm = reflect(fn);
|
||||
MethodMirror mm = cm.function;
|
||||
|
||||
var completer = new Completer();
|
||||
|
||||
if (mm.parameters.length == 1) {
|
||||
return () {
|
||||
cm.apply([completer.complete]);
|
||||
return completer.future;
|
||||
};
|
||||
}
|
||||
|
||||
return fn;
|
||||
}
|
164
modules/angular2/src/test_lib/test_lib.es6
Normal file
164
modules/angular2/src/test_lib/test_lib.es6
Normal file
@ -0,0 +1,164 @@
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
|
||||
export var describe = window.describe;
|
||||
export var xdescribe = window.xdescribe;
|
||||
export var ddescribe = window.ddescribe;
|
||||
export var it = window.it;
|
||||
export var xit = window.xit;
|
||||
export var iit = window.iit;
|
||||
export var beforeEach = window.beforeEach;
|
||||
export var afterEach = window.afterEach;
|
||||
export var expect = window.expect;
|
||||
export var IS_DARTIUM = false;
|
||||
|
||||
// To make testing consistent between dart and js
|
||||
window.print = function(msg) {
|
||||
if (window.dump) {
|
||||
window.dump(msg);
|
||||
} else {
|
||||
window.console.log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
// Some Map polyfills don't polyfill Map.toString correctly, which
|
||||
// gives us bad error messages in tests.
|
||||
// The only way to do this in Jasmine is to monkey patch a method
|
||||
// to the object :-(
|
||||
window.Map.prototype.jasmineToString = function() {
|
||||
var m = this;
|
||||
if (!m) {
|
||||
return ''+m;
|
||||
}
|
||||
var res = [];
|
||||
m.forEach( (v,k) => {
|
||||
res.push(`${k}:${v}`);
|
||||
});
|
||||
return `{ ${res.join(',')} }`;
|
||||
}
|
||||
|
||||
window.beforeEach(function() {
|
||||
jasmine.addMatchers({
|
||||
// Custom handler for Map as Jasmine does not support it yet
|
||||
toEqual: function(util, customEqualityTesters) {
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
return {
|
||||
pass: util.equals(actual, expected, [compareMap])
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
function compareMap(actual, expected) {
|
||||
if (actual instanceof Map) {
|
||||
var pass = actual.size === expected.size;
|
||||
if (pass) {
|
||||
actual.forEach( (v,k) => {
|
||||
pass = pass && util.equals(v, expected.get(k));
|
||||
});
|
||||
}
|
||||
return pass;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
toBePromise: function() {
|
||||
return {
|
||||
compare: function (actual, expectedClass) {
|
||||
var pass = typeof actual === 'object' && typeof actual.then === 'function';
|
||||
return {
|
||||
pass: pass,
|
||||
get message() {
|
||||
return 'Expected ' + actual + ' to be a promise';
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toBeAnInstanceOf: function() {
|
||||
return {
|
||||
compare: function(actual, expectedClass) {
|
||||
var pass = typeof actual === 'object' && actual instanceof expectedClass;
|
||||
return {
|
||||
pass: pass,
|
||||
get message() {
|
||||
return 'Expected ' + actual + ' to be an instance of ' + expectedClass;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toHaveText: function() {
|
||||
return {
|
||||
compare: function(actual, expectedText) {
|
||||
var actualText = elementText(actual);
|
||||
return {
|
||||
pass: actualText == expectedText,
|
||||
get message() {
|
||||
return 'Expected ' + actualText + ' to be equal to ' + expectedText;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
toImplement: function() {
|
||||
return {
|
||||
compare: function(actualObject, expectedInterface) {
|
||||
var objProps = Object.keys(actualObject.constructor.prototype);
|
||||
var intProps = Object.keys(expectedInterface.prototype);
|
||||
|
||||
var missedMethods = [];
|
||||
intProps.forEach((k) => {
|
||||
if (!actualObject.constructor.prototype[k]) missedMethods.push(k);
|
||||
});
|
||||
|
||||
return {
|
||||
pass: missedMethods.length == 0,
|
||||
get message() {
|
||||
return 'Expected ' + actualObject + ' to have the following methods: ' + missedMethods.join(", ");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export class SpyObject {
|
||||
spy(name){
|
||||
if (! this[name]) {
|
||||
this[name] = this._createGuinnessCompatibleSpy();
|
||||
}
|
||||
return this[name];
|
||||
}
|
||||
|
||||
rttsAssert(value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
_createGuinnessCompatibleSpy(){
|
||||
var newSpy = jasmine.createSpy();
|
||||
newSpy.andCallFake = newSpy.and.callFake;
|
||||
return newSpy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function elementText(n) {
|
||||
var hasShadowRoot = (n) => n instanceof Element && n.shadowRoot;
|
||||
var hasNodes = (n) => n.childNodes && n.childNodes.length > 0;
|
||||
|
||||
if (n instanceof Comment) return '';
|
||||
|
||||
if (n instanceof Array) return n.map((nn) => elementText(nn)).join("");
|
||||
if (n instanceof Element && n.tagName == 'CONTENT')
|
||||
return elementText(Array.prototype.slice.apply(n.getDistributedNodes()));
|
||||
if (hasShadowRoot(n)) return elementText(DOM.childNodesAsList(n.shadowRoot));
|
||||
if (hasNodes(n)) return elementText(DOM.childNodesAsList(n));
|
||||
|
||||
return n.textContent;
|
||||
}
|
43
modules/angular2/src/test_lib/utils.js
vendored
Normal file
43
modules/angular2/src/test_lib/utils.js
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
|
||||
export class Log {
|
||||
_result:List;
|
||||
|
||||
constructor() {
|
||||
this._result = [];
|
||||
}
|
||||
|
||||
add(value) {
|
||||
ListWrapper.push(this._result, value);
|
||||
}
|
||||
|
||||
fn(value) {
|
||||
return () => {
|
||||
ListWrapper.push(this._result, value);
|
||||
}
|
||||
}
|
||||
|
||||
result() {
|
||||
return ListWrapper.join(this._result, "; ");
|
||||
}
|
||||
}
|
||||
|
||||
export function queryView(view, selector) {
|
||||
for (var i = 0; i < view.nodes.length; ++i) {
|
||||
var res = DOM.querySelector(view.nodes[i], selector);
|
||||
if (isPresent(res)) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function dispatchEvent(element, eventType) {
|
||||
DOM.dispatchEvent(element, DOM.createEvent(eventType));
|
||||
}
|
||||
|
||||
export function el(html) {
|
||||
return DOM.firstChild(DOM.createTemplate(html).content);
|
||||
}
|
Reference in New Issue
Block a user