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:
parent
c735644c57
commit
4e82cc0861
|
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
|
@ -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]')]
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -3,7 +3,7 @@ library web_foo;
|
|||
import 'package:angular2/src/core/application.dart';
|
||||
import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
import 'bar.dart';
|
||||
import 'a:web/bar.ng_deps.dart' as i0;
|
||||
import 'bar.ng_deps.dart' as i0;
|
||||
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
|
@ -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]')]
|
||||
});
|
||||
}
|
|
@ -4,7 +4,8 @@ import 'package:angular2/src/core/application.dart';
|
|||
import 'package:angular2/src/reflection/reflection_capabilities.dart';
|
||||
import 'bar.dart';
|
||||
|
||||
void main() {
|
||||
reflector.reflectionCapabilities = new ReflectionCapabilities();
|
||||
bootstrap(MyComponent);
|
||||
bool _visited = false;
|
||||
void setupReflection(reflector) {
|
||||
if (_visited) return;
|
||||
_visited = true;
|
||||
}
|
|
@ -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])
|
||||
]
|
||||
});
|
||||
}
|
|
@ -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]')]
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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]')]
|
||||
});
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -96,17 +96,6 @@ void allTests() {
|
|||
outputs: {
|
||||
'a|web/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'
|
||||
})
|
||||
];
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
library foo;
|
||||
|
||||
import 'package:angular2/src/core/annotations/annotations.dart';
|
||||
|
||||
@Component(selector: '[salad]')
|
||||
class DependencyComponent {
|
||||
DependencyComponent();
|
||||
}
|
|
@ -4,6 +4,7 @@ import 'package:unittest/unittest.dart';
|
|||
import 'package:unittest/vm_config.dart';
|
||||
|
||||
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 'integration/all_tests.dart' as integration;
|
||||
import 'reflection_remover/all_tests.dart' as reflectionRemover;
|
||||
|
@ -12,6 +13,7 @@ import 'template_compiler/all_tests.dart' as templateCompiler;
|
|||
main() {
|
||||
useVMConfiguration();
|
||||
group('Bind Generator', bindGenerator.allTests);
|
||||
group('Directive Linker', directiveLinker.allTests);
|
||||
group('Directive Processor', directiveProcessor.allTests);
|
||||
group('Reflection Remover', reflectionRemover.allTests);
|
||||
group('Template Compiler', templateCompiler.allTests);
|
||||
|
|
Loading…
Reference in New Issue