fix(transformer): Loggers now are per zone and each transform runs in its own zone

This commit is contained in:
Jacob MacDonald
2015-07-23 09:06:23 -07:00
parent 09226cdd75
commit bd65b63c65
18 changed files with 91 additions and 160 deletions
@@ -20,7 +20,6 @@ void allTests() {
TestAssetReader reader = null;
beforeEach(() {
setLogger(new PrintLogger());
reader = new TestAssetReader();
});
@@ -2,12 +2,7 @@ library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show
Component,
Directive,
View,
NgElement,
LifecycleEvent;
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
@@ -2,12 +2,7 @@ library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show
Component,
Directive,
View,
NgElement,
LifecycleEvent;
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
@@ -2,12 +2,7 @@ library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show
Component,
Directive,
View,
NgElement,
LifecycleEvent;
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
@@ -2,12 +2,7 @@ library examples.hello_world.index_common_dart.ng_deps.dart;
import 'hello.dart';
import 'package:angular2/angular2.dart'
show
Component,
Directive,
View,
NgElement,
LifecycleEvent;
show Component, Directive, View, NgElement, LifecycleEvent;
var _visited = false;
void initReflector(reflector) {
@@ -19,8 +14,13 @@ void initReflector(reflector) {
'parameters': const [const []],
'annotations': const [
const Component(
lifecycle: [LifecycleEvent.onChange, LifecycleEvent.onDestroy, LifecycleEvent.onInit,
LifecycleEvent.onCheck, LifecycleEvent.onAllChangesDone])
lifecycle: [
LifecycleEvent.onChange,
LifecycleEvent.onDestroy,
LifecycleEvent.onInit,
LifecycleEvent.onCheck,
LifecycleEvent.onAllChangesDone
])
]
});
}
@@ -120,34 +120,34 @@ void _testNgDeps(String name, String inputPath,
bool isolate: false}) {
var testFn = isolate ? iit : it;
testFn(name, () async {
if (expectedLogs != null) {
log.setLogger(new RecordingLogger());
}
var logger = new RecordingLogger();
await log.setZoned(logger, () async {
var inputId = _assetIdForPath(inputPath);
if (reader == null) {
reader = new TestAssetReader();
}
if (assetId != null) {
reader.addAsset(assetId, await reader.readAsString(inputId));
inputId = assetId;
}
var expectedPath = path.join(path.dirname(inputPath), 'expected',
path.basename(inputPath).replaceFirst('.dart', '.ng_deps.dart'));
var expectedId = _assetIdForPath(expectedPath);
var inputId = _assetIdForPath(inputPath);
if (reader == null) {
reader = new TestAssetReader();
}
if (assetId != null) {
reader.addAsset(assetId, await reader.readAsString(inputId));
inputId = assetId;
}
var expectedPath = path.join(path.dirname(inputPath), 'expected',
path.basename(inputPath).replaceFirst('.dart', '.ng_deps.dart'));
var expectedId = _assetIdForPath(expectedPath);
var annotationMatcher = new AnnotationMatcher()..addAll(customDescriptors);
var output = await createNgDeps(reader, inputId, annotationMatcher,
inlineViews: inlineViews);
if (output == null) {
expect(await reader.hasInput(expectedId)).toBeFalse();
} else {
var input = await reader.readAsString(expectedId);
expect(formatter.format(output)).toEqual(formatter.format(input));
}
var annotationMatcher = new AnnotationMatcher()
..addAll(customDescriptors);
var output = await createNgDeps(reader, inputId, annotationMatcher,
inlineViews: inlineViews);
if (output == null) {
expect(await reader.hasInput(expectedId)).toBeFalse();
} else {
var input = await reader.readAsString(expectedId);
expect(formatter.format(output)).toEqual(formatter.format(input));
}
});
if (expectedLogs != null) {
expect((log.logger as RecordingLogger).logs, expectedLogs);
expect(logger.logs, expectedLogs);
}
});
}
@@ -18,7 +18,6 @@ main() => allTests();
void allTests() {
Html5LibDomAdapter.makeCurrent();
beforeEach(() => setLogger(new PrintLogger()));
describe('registrations', () {
noChangeDetectorTests();
@@ -34,7 +33,7 @@ void changeDetectorTests() {
// when https://github.com/angular/angular/issues/3019 is solved.
it('shouldn always notifyBinding for template variables', () async {
var inputPath = 'template_compiler/ng_for_files/hello.ng_deps.dart';
var output = await(process(new AssetId('a', inputPath)));
var output = await (process(new AssetId('a', inputPath)));
expect(output).toContain('notifyOnBinding');
});
}
@@ -45,27 +44,25 @@ void noChangeDetectorTests() {
it('should parse simple expressions in inline templates.', () async {
var inputPath =
'template_compiler/inline_expression_files/hello.ng_deps.dart';
'template_compiler/inline_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple methods in inline templates.', () async {
var inputPath =
'template_compiler/inline_method_files/hello.ng_deps.dart';
var inputPath = 'template_compiler/inline_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse simple expressions in linked templates.', () async {
var inputPath =
'template_compiler/url_expression_files/hello.ng_deps.dart';
var inputPath = 'template_compiler/url_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
@@ -73,7 +70,7 @@ void noChangeDetectorTests() {
it('should parse simple methods in linked templates.', () async {
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
@@ -81,33 +78,32 @@ void noChangeDetectorTests() {
it('should not generated duplicate getters/setters', () async {
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse `View` directives with a single dependency.', () async {
var inputPath =
'template_compiler/one_directive_files/hello.ng_deps.dart';
var inputPath = 'template_compiler/one_directive_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
});
it('should parse `View` directives with a single prefixed dependency.',
() async {
() async {
var inputPath = 'template_compiler/with_prefix_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
inputPath = 'template_compiler/with_prefix_files/goodbye.ng_deps.dart';
expected = readFile(
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
@@ -115,9 +111,9 @@ void noChangeDetectorTests() {
it('should parse angular directives with a prefix', () async {
var inputPath =
'template_compiler/with_prefix_files/ng2_prefix.ng_deps.dart';
'template_compiler/with_prefix_files/ng2_prefix.ng_deps.dart';
var expected = readFile(
'template_compiler/with_prefix_files/expected/ng2_prefix.ng_deps.dart');
'template_compiler/with_prefix_files/expected/ng2_prefix.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
@@ -125,9 +121,9 @@ void noChangeDetectorTests() {
it('should create the same output for multiple calls.', () async {
var inputPath =
'template_compiler/inline_expression_files/hello.ng_deps.dart';
'template_compiler/inline_expression_files/hello.ng_deps.dart';
var expected = readFile(
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
var output = await process(new AssetId('a', inputPath));
_formatThenExpectEquals(output, expected);
output = await process(new AssetId('a', inputPath));