refactor(dart/transform): Test `directive_linker` as a unit

Formerly, it was tested only as a piece of the transformer pipeline. Add
its own directory and test the linker on its own.
This commit is contained in:
Tim Blasi 2015-03-18 11:17:13 -07:00 committed by Misko Hevery
parent c735644c57
commit 4e82cc0861
17 changed files with 188 additions and 32 deletions

View File

@ -0,0 +1,52 @@
library angular2.test.transform.directive_linker.all_tests;
import 'package:barback/barback.dart';
import 'package:angular2/src/transform/common/logging.dart' hide init;
import 'package:angular2/src/transform/common/formatter.dart' hide init;
import 'package:angular2/src/transform/directive_linker/linker.dart';
import 'package:code_transformers/tests.dart';
import 'package:dart_style/dart_style.dart';
import 'package:path/path.dart' as path;
import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart';
import '../common/logger.dart';
import '../common/read_file.dart';
var formatter = new DartFormatter();
void allTests() {
var reader = new TestAssetReader();
setLogger(new NullLogger());
test('should ensure that dependencies are property chained.', () async {
for (var inputPath in [
'bar.ng_deps.dart',
'foo.ng_deps.dart',
'index.ng_deps.dart'
]) {
var expected =
readFile('directive_linker/simple_files/expected/$inputPath');
inputPath = 'directive_linker/simple_files/$inputPath';
var actual = formatter
.format(await linkNgDeps(reader, new AssetId('a', inputPath)));
expect(actual, equals(expected));
}
});
test('should ensure that exported dependencies are property chained.',
() async {
for (var inputPath in [
'bar.ng_deps.dart',
'foo.ng_deps.dart',
'index.ng_deps.dart'
]) {
var expected =
readFile('directive_linker/simple_export_files/expected/$inputPath');
inputPath = 'directive_linker/simple_export_files/$inputPath';
var actual = formatter
.format(await linkNgDeps(reader, new AssetId('a', inputPath)));
expect(actual, equals(expected));
}
});
}

View File

@ -0,0 +1,17 @@
library bar;
import 'bar.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
export 'foo.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(MyComponent, {
'factory': () => new MyComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[soup]')]
});
}

View File

@ -0,0 +1,20 @@
library bar;
import 'bar.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
import 'foo.ng_deps.dart' as i0;
export 'foo.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(MyComponent, {
'factory': () => new MyComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[soup]')]
});
i0.setupReflection(reflector);
}

View File

@ -3,7 +3,7 @@ library web_foo;
import 'package:angular2/src/core/application.dart'; import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart'; import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart'; import 'bar.dart';
import 'a:web/bar.ng_deps.dart' as i0; import 'bar.ng_deps.dart' as i0;
bool _visited = false; bool _visited = false;
void setupReflection(reflector) { void setupReflection(reflector) {

View File

@ -0,0 +1,16 @@
library foo;
import 'foo.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(DependencyComponent, {
'factory': () => new DependencyComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[salad]')]
});
}

View File

@ -4,7 +4,8 @@ import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart'; import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart'; import 'bar.dart';
void main() { bool _visited = false;
reflector.reflectionCapabilities = new ReflectionCapabilities(); void setupReflection(reflector) {
bootstrap(MyComponent); if (_visited) return;
_visited = true;
} }

View File

@ -0,0 +1,20 @@
library bar;
import 'bar.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
import 'foo.dart' as dep;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(MyComponent, {
'factory': () => new MyComponent(),
'parameters': const [],
'annotations': const [
const Component(
selector: '[soup]', services: const [dep.DependencyComponent])
]
});
}

View File

@ -0,0 +1,16 @@
library foo;
import 'foo.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(DependencyComponent, {
'factory': () => new DependencyComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[salad]')]
});
}

View File

@ -0,0 +1,13 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
import 'bar.ng_deps.dart' as i0;
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
i0.setupReflection(reflector);
}

View File

@ -0,0 +1,16 @@
library foo;
import 'foo.dart';
import 'package:angular2/src/core/annotations/annotations.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
reflector
..registerType(DependencyComponent, {
'factory': () => new DependencyComponent(),
'parameters': const [],
'annotations': const [const Component(selector: '[salad]')]
});
}

View File

@ -0,0 +1,11 @@
library web_foo;
import 'package:angular2/src/core/application.dart';
import 'package:angular2/src/reflection/reflection_capabilities.dart';
import 'bar.dart';
bool _visited = false;
void setupReflection(reflector) {
if (_visited) return;
_visited = true;
}

View File

@ -96,17 +96,6 @@ void allTests() {
outputs: { outputs: {
'a|web/bar.ng_deps.dart': 'a|web/bar.ng_deps.dart':
'two_annotations_files/expected/bar.ng_deps.dart' 'two_annotations_files/expected/bar.ng_deps.dart'
}),
new IntegrationTestConfig(
'should ensure that dependencies are property chained.',
inputs: {
'a|web/index.dart': 'chained_deps_files/index.dart',
'a|web/foo.dart': 'chained_deps_files/foo.dart',
'a|web/bar.dart': 'chained_deps_files/bar.dart'
},
outputs: {
'a|web/bar.ng_deps.dart': 'chained_deps_files/expected/bar.ng_deps.dart',
'a|web/foo.ng_deps.dart': 'chained_deps_files/expected/foo.ng_deps.dart'
}) })
]; ];

View File

@ -1,9 +0,0 @@
library bar;
import 'package:angular2/src/core/annotations/annotations.dart';
import 'foo.dart' as dep;
@Component(selector: '[soup]', services: const [dep.DependencyComponent])
class MyComponent {
MyComponent();
}

View File

@ -1,8 +0,0 @@
library foo;
import 'package:angular2/src/core/annotations/annotations.dart';
@Component(selector: '[salad]')
class DependencyComponent {
DependencyComponent();
}

View File

@ -4,6 +4,7 @@ import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart'; import 'package:unittest/vm_config.dart';
import 'bind_generator/all_tests.dart' as bindGenerator; import 'bind_generator/all_tests.dart' as bindGenerator;
import 'directive_linker/all_tests.dart' as directiveLinker;
import 'directive_processor/all_tests.dart' as directiveProcessor; import 'directive_processor/all_tests.dart' as directiveProcessor;
import 'integration/all_tests.dart' as integration; import 'integration/all_tests.dart' as integration;
import 'reflection_remover/all_tests.dart' as reflectionRemover; import 'reflection_remover/all_tests.dart' as reflectionRemover;
@ -12,6 +13,7 @@ import 'template_compiler/all_tests.dart' as templateCompiler;
main() { main() {
useVMConfiguration(); useVMConfiguration();
group('Bind Generator', bindGenerator.allTests); group('Bind Generator', bindGenerator.allTests);
group('Directive Linker', directiveLinker.allTests);
group('Directive Processor', directiveProcessor.allTests); group('Directive Processor', directiveProcessor.allTests);
group('Reflection Remover', reflectionRemover.allTests); group('Reflection Remover', reflectionRemover.allTests);
group('Template Compiler', templateCompiler.allTests); group('Template Compiler', templateCompiler.allTests);