refactor: simplify and make tests work in JS and Dart

* remove `wraps` syntax enhancements for imports
  and support new `import * as module from ...` syntax

  - default imports are the wrong construct for importing
    everything from a module

* moved tests from transpiler to jasmine and karma

  - transpiler tests are included when running karma in main project folder
  - transpiler is reloaded after every test run in karma,
    so no need to restart karma when the transpiler has been changed.
  - removed own gulp build for transpiler and `postinstall.sh`
    as they are no more needed.
  - transpiler tests are now executed in Dart AND JavaScript (used to be executed
    only in Dart), which allowed to catch some bugs (see the bug with the
    import specification above).

* made tests work in dart as well by using the following hack:

  - dependencies are loaded from the `build` folder, which makes
    running `gulp build` necessary before running karma for dart
  - for this to work,
    the dependencies are included in main `pubspec.yaml` of project
  - reason for the hack: `karma-dart` loads all `packages` urls
    directly from disc (should rather use the karma file list)

* added explicit annotations `FIELD`, `ABSTRACT`, ... to `facade/lang.*`

  - needed for now that we can run tests and don't get errors for undefined
    annotations.

* added `README.md` with details about the build and tests
This commit is contained in:
Tobias Bosch
2014-09-28 13:55:01 -07:00
parent 817c005845
commit c79f0c3472
47 changed files with 338 additions and 508 deletions

View File

@ -5,3 +5,5 @@ dependencies:
dev_dependencies:
test_lib:
path: ../test_lib
facade:
path: ../facade

View File

@ -1,5 +1,6 @@
import {WatchGroup} from './watch_group';
import {Record} from './record';
import {FIELD} from 'facade/lang';
export class ChangeDetection {

View File

@ -1,4 +1,5 @@
//import {ProtoWatchGroup, WatchGroup} from './watch_group';
import {FIELD} from 'facade/lang';
export class ProtoRecord {
@ -53,28 +54,28 @@ export class ProtoRecord {
/**
* Represents a Record for keeping track of changes. A change is a difference between previous
* and current value.
*
* and current value.
*
* By default changes are detected using dirty checking, but a notifier can be present which can
* notify the records of changes by means other than dirty checking. For example Object.observe
* or events on DOM elements.
*
* DESIGN NOTES:
* - No inheritance allowed so that code is monomorphic for performance.
*
* DESIGN NOTES:
* - No inheritance allowed so that code is monomorphic for performance.
* - Atomic watch operations
* - Defaults to dirty checking
* - Keep this object as lean as possible. (Lean in number of fields)
*
*
* MEMORY COST: 13 Words;
*/
export class Record {
@FIELD('final watchGroup:WatchGroup')
@FIELD('final protoRecord:ProtoRecord')
/// order list of all records. Including head/tail markers
@FIELD('_next:Record')
@FIELD('_prev:Record')
/// next record to dirty check
/// next record to dirty check
@FIELD('_checkNext:Record')
@FIELD('_checkPrev:Record')
// next notifier
@ -120,7 +121,7 @@ export class Record {
var notify = mode & MODE_MASK_NOTIFY;
var currentValue;
switch (state) {
case MODE_STATE_MARKER:
case MODE_STATE_MARKER:
return false;
case MODE_STATE_PROPERTY:
currentValue = this._getter(this._context);
@ -136,7 +137,7 @@ export class Record {
}
var previousValue = this.previousValue;
if (isSame(previousValue, currentValue)) return false;
if (previousValue instanceof String && currentValue instanceof String
if (previousValue instanceof String && currentValue instanceof String
&& previousValue == currentValue) {
this.previousValue = currentValue;
return false
@ -178,4 +179,4 @@ function isSame(a, b) {
} else {
return false;
}
}
}

View File

@ -1,4 +1,5 @@
import {ProtoRecord, Record} from './record';
import {FIELD} from 'facade/lang';
export class ProtoWatchGroup {
@FIELD('final _headRecord:ProtoRecord')

View File

@ -1,5 +1,7 @@
import {Type} from 'facade/lang';
import {ElementServicesFunction} from './facade';
import {ABSTRACT} from 'facade/lang';
@ABSTRACT
export class Directive {

View File

@ -2,6 +2,7 @@ import {Future, Type} from 'facade/lang';
import {Element} from 'facade/dom';
import {ProtoView} from './view';
import {TemplateLoader} from './template_loader';
import {FIELD} from 'facade/lang';
export class Compiler {

View File

@ -1,4 +1,4 @@
import {FIELD} from 'facade/lang';
/**

View File

@ -1,10 +1,12 @@
import {DOM, Node, DocumentFragment, TemplateElement} from 'facade/dom';
import {ListWrapper wraps List} from 'facade/collection';
import {ListWrapper} from 'facade/collection';
import {ProtoWatchGroup, WatchGroup, WatchGroupDispatcher} from 'change_detection/watch_group';
import {Record} from 'change_detection/record';
import {Module} from 'di/di';
import {ProtoElementInjector, ElementInjector} from './element_injector';
import {SetterFn} from 'change_detection/facade';
import {FIELD, IMPLEMENTS} from 'facade/lang';
import {List} from 'facade/collection';
@IMPLEMENTS(WatchGroupDispatcher)
export class View {

View File

@ -1,9 +1,11 @@
import {FIELD} from 'facade/lang';
export class LifeCycle {
@FIELD('final _changeDetection:ChangeDetection')
@FIELD('final _onChangeDispatcher:OnChangeDispatcher')
constructor() {}
digest() {
_changeDetection.detectChanges();
_onChangeDispatcher.done();

View File

@ -1,9 +1,9 @@
import {describe, id} from 'test_lib/test_lib';
import {Compiler} from './compiler';
import {describe, it, expect} from 'test_lib/test_lib';
import {Compiler} from 'core/compiler/compiler';
export function main() {
describe('compiler', () => {
it('should hello', () => {
describe('compiler', function() {
it('should hello', function() {
print('I am working');
});
});

View File

@ -1,11 +1,11 @@
import {describe, id} from 'test_lib/test_lib';
import {ProtoView, View} from './view';
import {describe, it, expect} from 'test_lib/test_lib';
import {ProtoView, View} from 'core/compiler/view';
import {DOM} from 'facade/dom';
export function main() {
describe('view', () => {
describe('ProtoView', () => {
it('should create an instance of view', () => {
describe('view', function() {
describe('ProtoView', function() {
it('should create an instance of view', function() {
var template = DOM.createTemplate('Hello <b>world</b>!');
var pv = new ProtoView(template, null, null, null);
var view:View = pv.instantiate();

View File

@ -1,5 +1,6 @@
import {FIELD} from 'facade/lang';
import {Type} from 'facade/lang';
import {Map, MapWrapper wraps Map} from 'facade/collection';
import {Map, MapWrapper} from 'facade/collection';
import {Key} from './key';
/// becouse we need to know when toValue was not set.

View File

@ -14,12 +14,17 @@ class DOM {
static getInnerHTML(el) {
return el.innerHtml;
}
static setInnerHTML(el:, value) {
static setInnerHTML(el, value) {
el.innerHtml = value;
}
static setText(Text text, String value) {
text.text = value;
}
static createTemplate(html) {
var t = document.createElement('template');
t.setInnerHtml(html);
return t;
}
static clone(Node node) {
return node.clone(true);
}

View File

@ -1,4 +1,12 @@
library angular.core.facade.async;
export 'dart:async' show Future;
export 'dart:core' show Type;
export 'dart:core' show Type;
class FIELD {
const constructor(this.definition);
}
class CONST {}
class ABSTRACT {}
class IMPLEMENTS {}

View File

@ -1,2 +1,12 @@
export var Future = Promise;
export var Type = Function;
export var Type = Function;
export class FIELD {
constructor(definition) {
this.definition = definition;
}
}
export class CONST {}
export class ABSTRACT {}
export class IMPLEMENTS {}

View File

@ -1 +1 @@
export 'package:guinness/guinness.dart' show describe, it, beforeEach, afterEach, expect;
export 'package:guinness/guinness.dart' show describe, ddescribe, it, iit, beforeEach, afterEach, expect;

View File

@ -1,5 +1,7 @@
export var describe = window.describe;
export var ddescribe = window.ddescribe;
export var it = window.it;
export var iit = window.iit;
export var beforeEach = window.beforeEach;
export var afterEach = window.afterEach;
export var expect = window.expect;