Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 3acc97c

Browse files
committed
chore(tests): clean up modules in tests
1 parent faaeb32 commit 3acc97c

18 files changed

+107
-221
lines changed

demo/web/main.dart

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,11 @@ class ChapterDirective {
8383

8484
main() {
8585
// Set up the Angular directives.
86-
var module = new AngularModule();
87-
module.value(Expando, new Expando());
88-
angularModule(module);
86+
var module = new AngularModule()
87+
..register(NgBindAttrDirective)
88+
..register(NgRepeatAttrDirective)
89+
..register(BookComponent)
90+
..register(ChapterDirective);
8991
Injector injector = new Injector([module]);
90-
injector.get(DirectiveRegistry)
91-
..register(NgBindAttrDirective)
92-
..register(NgRepeatAttrDirective)
93-
..register(BookComponent)
94-
..register(ChapterDirective);
95-
9692
injector.get(AngularBootstrap)();
97-
98-
9993
}

lib/angular.dart

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,25 @@ class AngularModule extends Module {
124124
type(Parser, Parser);
125125
type(Interpolate, Interpolate);
126126
type(Http, Http);
127+
128+
value(ScopeDigestTTL, new ScopeDigestTTL(5));
129+
130+
directive(NgTextMustacheDirective);
131+
directive(NgAttrMustacheDirective);
132+
133+
directive(NgBindAttrDirective);
134+
directive(NgClassAttrDirective);
135+
directive(NgClickAttrDirective);
136+
directive(NgCloakAttrDirective);
137+
directive(NgControllerAttrDirective);
138+
directive(NgHideAttrDirective);
139+
directive(NgIfAttrDirective);
140+
directive(NgRepeatAttrDirective);
141+
directive(NgShowAttrDirective);
127142
}
128143

129144
directive(Type directive) {
130145
_directives.register(directive);
131146
return this;
132147
}
133148
}
134-
135-
angularModule(AngularModule module) {
136-
module.value(ScopeDigestTTL, new ScopeDigestTTL(5));
137-
138-
module.directive(NgTextMustacheDirective);
139-
module.directive(NgAttrMustacheDirective);
140-
141-
module.directive(NgBindAttrDirective);
142-
module.directive(NgClassAttrDirective);
143-
module.directive(NgClickAttrDirective);
144-
module.directive(NgCloakAttrDirective);
145-
module.directive(NgControllerAttrDirective);
146-
module.directive(NgHideAttrDirective);
147-
module.directive(NgIfAttrDirective);
148-
module.directive(NgRepeatAttrDirective);
149-
module.directive(NgShowAttrDirective);
150-
}

test/_log.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
library ng_log;
22

3+
//TODO(misko): merge with Logger
34
class Log {
45
List<String> output = [];
56
call(s) { output.add(s); }

test/_specs.dart

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,44 @@ class Logger implements List {
151151
}
152152

153153
class SpecInjector {
154+
Injector moduleInjector;
154155
Injector injector;
155-
List<Module> modules = [new Module()..value(Expando, new Expando('specExpando'))];
156+
List<Module> modules = [];
157+
DirectiveRegistry directives = new DirectiveRegistry();
158+
List<Function> initFns = [];
159+
160+
SpecInjector() {
161+
var moduleModule = new Module()
162+
..factory(AngularModule, () => addModule(new AngularModule()))
163+
..factory(Module, () => addModule(new Module()));
164+
moduleInjector = new Injector([moduleModule], false);
165+
}
156166

157-
module(Function fn) {
158-
Module module = new AngularModule()
159-
..type(Log, Log)
160-
..type(Logger, Logger);
167+
addModule(module) {
161168
modules.add(module);
162-
fn(module);
169+
return module;
163170
}
164171

165-
inject(Function fn, declarationStack) {
166-
if (injector == null) {
167-
injector = new Injector(modules, false); // Implicit injection is disabled.
172+
module(Function fn, declarationStack) {
173+
try {
174+
var initFn = moduleInjector.invoke(fn);
175+
if (initFn is Function) {
176+
initFns.add(initFn);
177+
}
178+
} catch (e, s) {
179+
throw "$e\n$s\nDECLARED AT:$declarationStack";
168180
}
181+
}
182+
183+
inject(Function fn, declarationStack) {
169184
try {
185+
if (injector == null) {
186+
injector = new Injector(modules, false); // Implicit injection is disabled.
187+
initFns.forEach((fn) => injector.invoke(fn));
188+
}
170189
injector.invoke(fn);
171190
} catch (e, s) {
172-
var msg;
173-
if (e is mirror.MirroredUncaughtExceptionError) {
174-
msg = e.exception_string + "\nORIGINAL Stack trace:\n" + e.stacktrace.toString();
175-
} else {
176-
msg = '$e\nORIGINAL Stack trace:\n$s';
177-
}
178-
var frames = declarationStack.toString().split('\n');
179-
frames.removeAt(0);
180-
var declaredAt = frames.join('\n');
181-
throw msg + "\nDECLARED AT:\n" + declaredAt;
191+
throw "$e\n$s\nDECLARED AT:$declarationStack";
182192
}
183193
}
184194

@@ -187,33 +197,34 @@ class SpecInjector {
187197

188198
SpecInjector currentSpecInjector = null;
189199
inject(Function fn) {
190-
var stack = null;
191-
try {
192-
throw '';
193-
} catch (e, s) {
194-
stack = s;
195-
}
196-
if (currentSpecInjector == null ) {
197-
return () {
200+
try { throw ''; } catch (e, stack) {
201+
if (currentSpecInjector == null ) {
202+
return () {
203+
return currentSpecInjector.inject(fn, stack);
204+
};
205+
} else {
198206
return currentSpecInjector.inject(fn, stack);
199-
};
200-
} else {
201-
return currentSpecInjector.inject(fn, stack);
207+
}
202208
}
203209
}
204210
module(Function fn) {
205-
if (currentSpecInjector == null ) {
206-
return () {
207-
return currentSpecInjector.module(fn);
208-
};
209-
} else {
210-
return currentSpecInjector.module(fn);
211+
try { throw ''; } catch(e, stack) {
212+
if (currentSpecInjector == null ) {
213+
return () {
214+
return currentSpecInjector.module(fn, stack);
215+
};
216+
} else {
217+
return currentSpecInjector.module(fn, stack);
218+
}
211219
}
212220
}
213221

214222
main() {
215223
beforeEach(() => id = 1);
216224
beforeEach(() => currentSpecInjector = new SpecInjector());
217-
beforeEach(module(angularModule));
225+
beforeEach(module((AngularModule module) {
226+
module.type(Logger, Logger);
227+
module.type(Log, Log);
228+
}));
218229
afterEach(() => currentSpecInjector = null);
219230
}

test/block_spec.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class ShadowBlockDirective {
3131

3232
main() {
3333
describe('Block', () {
34-
beforeEach(module(angularModule));
35-
3634
var anchor;
3735
var $rootElement;
3836
var blockCache;

0 commit comments

Comments
 (0)