From 241d26b468a12344088d5e506be3e7d09f7d5dda Mon Sep 17 00:00:00 2001 From: Victor Savkin Date: Sun, 27 Apr 2014 17:07:51 -0400 Subject: [PATCH] chore(jasmine_syntax): use the guinness testing library instead of jasmine_syntax Replace the jasmine syntax implemented by jasmine_syntax.dart and _specs.dart with Guinness: - remove jasmine_syntax.dart - update _specs.dart to use guinness instead of jasmine_syntax.dart - change karma config files to initialize guinness - replace all references to jasmine with guinness Closes #549 --- benchmark/dom/_perf.dart | 2 - karma-perf.conf.js | 6 +- karma.conf.js | 7 +- pubspec.lock | 4 + pubspec.yaml | 1 + test/_specs.dart | 239 ++++-------------- test/config/filter_tests.dart | 15 -- test/config/init_guinness.dart | 8 + test/core/scope_spec.dart | 4 +- test/core_dom/http_spec.dart | 34 +-- test/directive/ng_switch_spec.dart | 2 +- test/io/expression_extractor_spec.dart | 5 +- test/io/source_metadata_extractor_spec.dart | 5 +- test/io/template_cache_generator_spec.dart | 4 +- test/jasmine_syntax.dart | 153 ----------- test/jasmines_syntax_spec.dart | 63 ----- test/mock/http_backend_spec.dart | 34 +-- test/tools/html_extractor_spec.dart | 4 +- test/tools/selector_spec.dart | 4 +- .../tools/source_metadata_extractor_spec.dart | 4 +- .../symbol_inspector_spec.dart | 6 +- .../expression_generator_spec.dart | 3 +- .../transformer/metadata_generator_spec.dart | 3 +- .../static_angular_generator_spec.dart | 3 +- 24 files changed, 132 insertions(+), 481 deletions(-) delete mode 100644 test/config/filter_tests.dart create mode 100644 test/config/init_guinness.dart delete mode 100644 test/jasmine_syntax.dart delete mode 100644 test/jasmines_syntax_spec.dart diff --git a/benchmark/dom/_perf.dart b/benchmark/dom/_perf.dart index 7701331a4..f30229225 100644 --- a/benchmark/dom/_perf.dart +++ b/benchmark/dom/_perf.dart @@ -1,5 +1,4 @@ import '../../test/_specs.dart' as perf; -import '../../test/jasmine_syntax.dart' as jasmine; import '../_perf.dart' hide xtime, time; import 'package:angular/mock/module.dart'; @@ -17,6 +16,5 @@ time(name, body, {verify:_noop, cleanUp:_noop}) { } main() { - jasmine.main(); perf.main(); } diff --git a/karma-perf.conf.js b/karma-perf.conf.js index cce806145..c8461b003 100644 --- a/karma-perf.conf.js +++ b/karma-perf.conf.js @@ -10,7 +10,7 @@ module.exports = function(config) { files: [ 'benchmark/dom/*.dart', 'benchmark/*_perf.dart', - 'test/config/filter_tests.dart', + 'test/config/init_guinness.dart', {pattern: '**/*.dart', watched: true, included: false, served: true}, 'packages/browser/dart.js', 'packages/browser/interop.js' @@ -29,6 +29,10 @@ module.exports = function(config) { '../../../karma-parser-getter-setter' ], + karmaDartImports: { + guinness: 'package:guinness/guinness_html.dart' + }, + preprocessors: { 'test/core/parser/generated_getter_setter.dart': ['parser-getter-setter'] }, diff --git a/karma.conf.js b/karma.conf.js index 95b93b8a8..7888090db 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -8,10 +8,9 @@ module.exports = function(config) { // all tests must be 'included', but all other libraries must be 'served' and // optionally 'watched' only. files: [ - 'test/jasmine_syntax.dart', 'test/*.dart', 'test/**/*_spec.dart', - 'test/config/filter_tests.dart', + 'test/config/init_guinness.dart', {pattern: '**/*.dart', watched: true, included: false, served: true}, 'packages/browser/dart.js', 'packages/browser/interop.js', @@ -40,6 +39,10 @@ module.exports = function(config) { '../../../karma-parser-getter-setter' ], + karmaDartImports: { + guinness: 'package:guinness/guinness_html.dart' + }, + customLaunchers: { ChromeNoSandbox: { base: 'Chrome', flags: ['--no-sandbox'] } }, diff --git a/pubspec.lock b/pubspec.lock index 0f41014c0..a03af1bda 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -33,6 +33,10 @@ packages: description: di source: hosted version: "0.0.40" + guinness: + description: guinness + source: hosted + version: "0.1.1" html5lib: description: html5lib source: hosted diff --git a/pubspec.yaml b/pubspec.yaml index 1ca47308c..8feea5d34 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -29,3 +29,4 @@ dev_dependencies: benchmark_harness: '>=1.0.0' unittest: '>=0.10.1 <0.12.0' mock: '>=0.10.0 <0.12.0' + guinness: '>=0.1.1 <0.2.0' \ No newline at end of file diff --git a/test/_specs.dart b/test/_specs.dart index 75b19770b..62d15aacd 100644 --- a/test/_specs.dart +++ b/test/_specs.dart @@ -4,12 +4,14 @@ import 'dart:html' hide Animation; import 'package:angular/angular.dart'; import 'package:angular/mock/module.dart'; -import 'package:unittest/unittest.dart' as unit; -import 'jasmine_syntax.dart' as jasmine_syntax; +import 'package:guinness/guinness_html.dart' as gns; export 'dart:html' hide Animation; -export 'package:unittest/unittest.dart'; + +export 'package:unittest/unittest.dart' hide expect; +export 'package:guinness/guinness_html.dart'; + export 'package:mock/mock.dart'; export 'package:di/di.dart'; export 'package:di/dynamic_injector.dart'; @@ -37,194 +39,42 @@ es(String html) { e(String html) => es(html).first; -Expect expect(actual, [unit.Matcher matcher = null]) { - if (matcher != null) unit.expect(actual, matcher); - return new Expect(actual); -} - -class Expect { - var actual; - NotExpect not; - - Expect(this.actual) { - not = new NotExpect(this); - } - toEqual(expected) => unit.expect(actual, unit.equals(expected)); - toContain(expected) => unit.expect(actual, unit.contains(expected)); - toBe(expected) => unit.expect(actual, - unit.predicate((actual) => identical(expected, actual), '$expected')); - toThrow([exception]) => unit.expect(actual, exception == null ? - unit.throws: - unit.throwsA(new ExceptionContains(exception))); - toBeFalsy() => unit.expect(actual, _isFalsy, - reason: '"$actual" is not Falsy'); - toBeTruthy() => unit.expect(actual, (v) => !_isFalsy(v), - reason: '"$actual" is not Truthy'); - toBeDefined() => unit.expect(actual, unit.isNotNull); - toBeNull() => unit.expect(actual, unit.isNull); - toBeNotNull() => unit.expect(actual, unit.isNotNull); - - toHaveHtml(expected) => unit.expect(_toHtml(actual), unit.equals(expected)); - toHaveText(expected) => - unit.expect(_elementText(actual), unit.equals(expected)); - - toHaveBeenCalled() => - unit.expect(actual.called, true, reason: 'method not called'); - toHaveBeenCalledOnce() => unit.expect(actual.count, 1, - reason: 'method invoked ${actual.count} expected once'); - toHaveBeenCalledWith([a,b,c,d,e,f]) => - unit.expect(actual.firstArgsMatch(a,b,c,d,e,f), true, - reason: 'method invoked with correct arguments'); - toHaveBeenCalledOnceWith([a,b,c,d,e,f]) => - unit.expect(actual.count == 1 && actual.firstArgsMatch(a,b,c,d,e,f), - true, - reason: 'method invoked once with correct arguments. ' - '(Called ${actual.count} times)'); - - toHaveClass(cls) => unit.expect(actual.classes.contains(cls), true, - reason: ' Expected ${actual} to have css class ${cls}'); - - toHaveAttribute(name, [value = null]) { - unit.expect(actual.attributes.containsKey(name), true, - reason: 'Epxected $actual to have attribute $name'); - if (value != null) { - unit.expect(actual.attributes[name], value, - reason: 'Epxected $actual attribute "$name" to be "$value"'); - } +Expect expect(actual, [matcher]) { + final expect = new Expect(actual); + if (matcher != null) { + expect.to(matcher); } + return expect; +} - toEqualSelect(options) { - var actualOptions = []; +class Expect extends gns.Expect { + Expect(actual) : super(actual); - for (var option in actual.querySelectorAll('option')) { - actualOptions.add(option.selected ? [option.value] : option.value); - } - return unit.expect(actualOptions, options); - } + NotExpect get not => new NotExpect(actual); - toBeValid() => unit.expect(actual.valid && !actual.invalid, true, + toBeValid() => _expect(actual.valid && !actual.invalid, true, reason: 'Form is not valid'); - toBePristine() => - unit.expect(actual.pristine && !actual.dirty, true, - reason: 'Form is dirty'); - - _isFalsy(v) => v == null ? true: v is bool ? v == false : false; - - _toHtml(node, [bool outer = false]) { - if (node is Comment) { - return ''; - } else if (node is DocumentFragment) { - var acc = ''; - node.childNodes.forEach((n) { acc += _toHtml(n, true); }); - return acc; - } else if (node is List) { - var acc = ''; - node.forEach((n) { acc += _toHtml(n); }); - return acc; - } else if (node is Element) { - // Remove all the "ng-binding" internal classes - node = node.clone(true) as Element; - node.classes.remove('ng-binding'); - node.querySelectorAll(".ng-binding").forEach((Element e) { - e.classes.remove('ng-binding'); - }); - var htmlString = outer ? node.outerHtml : node.innerHtml; - // Strip out empty class attributes. This seems like a Dart bug... - return htmlString.replaceAll(' class=""', '').trim(); - } else if (node is Text) { - return node.text; - } else { - throw "JQuery._toHtml not implemented for node type [${node.nodeType}]"; - } - } - _elementText(n, [bool notShadow = false]) { - if (n is Iterable) { - return n.map((nn) => _elementText(nn)).join(""); - } - - if (n is Comment) return ''; - - if (!notShadow && n is Element && n.shadowRoot != null) { - var cShadows = n.shadowRoot.nodes.map((n) => n.clone(true)).toList(); - for (var i = 0, ii = cShadows.length; i < ii; i++) { - var n = cShadows[i]; - if (n is Element) { - var updateElement = (e) { - var text = new Text('SHADOW-CONTENT'); - if (e.parent == null) { - cShadows[i] = text; - } else { - e.parent.insertBefore(text, e); - } - e.nodes = []; - }; - if (n is ContentElement) { updateElement(n); } - n.querySelectorAll('content').forEach(updateElement); - } - }; - var shadowText = _elementText(cShadows, true); - var domText = _elementText(n, true); - - return shadowText.replaceFirst("SHADOW-CONTENT", domText); - } - - if (n.nodes == null || n.nodes.length == 0) return n.text; - - return n.nodes.map((cn) => _elementText(cn)).join(""); - } -} + toBePristine() => _expect(actual.pristine && !actual.dirty, true, + reason: 'Form is dirty'); -class NotExpect { - Expect _expect; - get actual => _expect.actual; - - NotExpect(this._expect); - - toHaveBeenCalled() => - unit.expect(actual.called, false, reason: 'method called'); - toThrow() => actual(); - - toHaveClass(cls) => unit.expect(actual.classes.contains(cls), false, - reason: ' Expected ${actual} to not have css class ${cls}'); - toHaveAttribute(name) => unit.expect(actual.attributes.containsKey(name), - false, reason: ' Expected $actual to not have attribute "$name"'); - toBe(expected) => unit.expect(actual, - unit.predicate((actual) => !identical(expected, actual), 'not $expected')); - toEqual(expected) => unit.expect(actual, - unit.predicate((actual) => expected != actual, 'not $expected')); - toContain(expected) => unit.expect(actual, - unit.predicate((actual) => !actual.contains(expected), 'not $expected')); - toBePristine() => unit.expect(actual.pristine && !actual.dirty, false, - reason: 'Form is pristine'); - toBeValid() => unit.expect(actual.valid && !actual.invalid, false, - reason: 'Form is valid'); + get _expect => gns.guinness.matchers.expect; } -class ExceptionContains extends unit.Matcher { - - final _expected; - - const ExceptionContains(this._expected); +class NotExpect extends gns.NotExpect { + NotExpect(actual) : super(actual); - bool matches(item, Map matchState) { - if (item is String) { - return item.indexOf(_expected) >= 0; - } - return matches('$item', matchState); - } + toBeValid() => _expect(actual.valid && !actual.invalid, false, + reason: 'Form is valid'); - unit.Description describe(unit.Description description) => - description.add('exception contains ').addDescriptionOf(_expected); + toBePristine() => _expect(actual.pristine && !actual.dirty, false, + reason: 'Form is pristine'); - unit.Description describeMismatch(item, unit.Description mismatchDescription, - Map matchState, bool verbose) { - return super.describeMismatch('$item', mismatchDescription, matchState, - verbose); - } + get _expect => gns.guinness.matchers.expect; } + _injectify(fn) { // The function does two things: // First: if the it() passed a function, we wrap it in @@ -236,20 +86,29 @@ _injectify(fn) { return fn.outer(inject(fn.inner)); } -// Jasmine syntax -beforeEachModule(fn) => jasmine_syntax.beforeEach(module(fn), priority:1); -beforeEach(fn) => jasmine_syntax.beforeEach(_injectify(fn)); -afterEach(fn) => jasmine_syntax.afterEach(_injectify(fn)); -it(name, fn) => jasmine_syntax.it(name, _injectify(fn)); -iit(name, fn) => jasmine_syntax.iit(name, _injectify(fn)); -xit(name, fn) => jasmine_syntax.xit(name, fn); -xdescribe(name, fn) => jasmine_syntax.xdescribe(name, fn); -ddescribe(name, fn) => jasmine_syntax.ddescribe(name, fn); -describe(name, fn) => jasmine_syntax.describe(name, fn); - -var jasmine = jasmine_syntax.jasmine; +// Replace guinness syntax elements to inject dependencies. +beforeEachModule(fn) => gns.beforeEach(module(fn), priority:1); +beforeEach(fn) => gns.beforeEach(_injectify(fn)); +afterEach(fn) => gns.afterEach(_injectify(fn)); +it(name, fn) => gns.it(name, _injectify(fn)); +iit(name, fn) => gns.iit(name, _injectify(fn)); + +_removeNgBinding(node) { + if (node is Element) { + node = node.clone(true) as Element; + node.classes.remove('ng-binding'); + node.querySelectorAll(".ng-binding").forEach((Element e) { + e.classes.remove('ng-binding'); + }); + return node; + } + return node; +} main() { - jasmine_syntax.beforeEach(setUpInjector, priority:3); - jasmine_syntax.afterEach(tearDownInjector); + gns.beforeEach(setUpInjector, priority:3); + gns.afterEach(tearDownInjector); + + gns.guinnessEnableHtmlMatchers(); + gns.guinness.matchers.config.preprocessHtml = _removeNgBinding; } diff --git a/test/config/filter_tests.dart b/test/config/filter_tests.dart deleted file mode 100644 index fcc6acb1e..000000000 --- a/test/config/filter_tests.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:unittest/unittest.dart' as unit; -import '../jasmine_syntax.dart' as jasmine; - -main() { - unit.filterStacks = true; - unit.formatStacks = false; - unit.filterTests((test) { - if (jasmine.ddescribeActive) { - String name = test.currentGroup; - return name.indexOf('DDESCRIBE: ') != -1; - } else { - return true; - } - }); -} diff --git a/test/config/init_guinness.dart b/test/config/init_guinness.dart new file mode 100644 index 000000000..2c8a9e6ab --- /dev/null +++ b/test/config/init_guinness.dart @@ -0,0 +1,8 @@ +import 'package:guinness/guinness.dart'; +import 'package:unittest/unittest.dart' as unit; + +main() { + unit.filterStacks = true; + unit.formatStacks = false; + guinness.initSpecs(); +} diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index 4113c7e26..54bd20506 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -1167,7 +1167,7 @@ void main() { it(r'should return a function that allows listeners to be unregistered', inject( (RootScope rootScope) { - var listener = jasmine.createSpy('watch listener'); + var listener = guinness.createSpy('watch listener'); var watch; watch = rootScope.watch('foo', listener); @@ -1248,7 +1248,7 @@ void main() { ..watch('numberValue', logger) ..digest(); - expect(log.removeAt(0).isNaN).toEqual(true); //jasmine's toBe and toEqual don't work well with NaNs + expect(log.removeAt(0).isNaN).toEqual(true); //guinness's toBe and toEqual don't work well with NaNs expect(log).toEqual([null, '', false, 23]); log = []; rootScope.digest(); diff --git a/test/core_dom/http_spec.dart b/test/core_dom/http_spec.dart index b7502620b..b15f7a856 100644 --- a/test/core_dom/http_spec.dart +++ b/test/core_dom/http_spec.dart @@ -64,7 +64,7 @@ void main() { beforeEach((Http h) { http = h; - callback = jasmine.createSpy('callback'); + callback = guinness.createSpy('callback'); }); @@ -629,7 +629,7 @@ void main() { microLeap(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content'); })); @@ -660,7 +660,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content2'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content2'); })); @@ -672,7 +672,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content2'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content2'); })); @@ -695,7 +695,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content2'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content2'); })); @@ -777,7 +777,7 @@ void main() { microLeap(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content'); // Invalidate cache entry. http.defaults.cache.remove("/url"); @@ -807,7 +807,7 @@ void main() { microLeap(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content-default-cache'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content-default-cache'); callback.reset(); // Serve request from local cache when it is given (but default filled too). @@ -815,7 +815,7 @@ void main() { microLeap(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('content-local-cache'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('content-local-cache'); })); it('should be skipped if {cache: false} is passed in request config', async(() { @@ -893,7 +893,7 @@ void main() { expect(http.pendingRequests.length).toEqual(0); http(method: 'get', url: '/cached', cache: true); - jasmine.spyOn(http.pendingRequests, 'add').andCallThrough(); + guinness.spyOn(http.pendingRequests, 'add').andCallThrough(); //expect(http.pendingRequests.add).toHaveBeenCalledOnce(); expect(http.pendingRequests.length).toEqual(0); @@ -1171,7 +1171,7 @@ void main() { beforeEach((Http h) { http = h; - callback = jasmine.createSpy('callback'); + callback = guinness.createSpy('callback'); }); describe('request', () { @@ -1250,7 +1250,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual({'foo': 'bar', 'baz': 23}); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual({'foo': 'bar', 'baz': 23}); })); @@ -1260,7 +1260,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo': 'bar'}]); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual([1, 'abc', {'foo': 'bar'}]); })); @@ -1270,7 +1270,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual([1, 'abc', {'foo':'bar'}]); })); @@ -1280,7 +1280,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual([1, 'abc', {'foo':'bar'}]); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual([1, 'abc', {'foo':'bar'}]); })); @@ -1309,7 +1309,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('{{some}}'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('{{some}}'); })); }); @@ -1324,7 +1324,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('header1'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('header1'); })); it('should pipeline more functions', async(() { @@ -1339,7 +1339,7 @@ void main() { flush(); expect(callback).toHaveBeenCalledOnce(); - expect(callback.mostRecentCall.args[0].data).toEqual('RESP-FIRST:V1'); + expect(callback.mostRecentCall.positionalArguments[0].data).toEqual('RESP-FIRST:V1'); })); }); }); diff --git a/test/directive/ng_switch_spec.dart b/test/directive/ng_switch_spec.dart index 86e415092..e289113aa 100644 --- a/test/directive/ng_switch_spec.dart +++ b/test/directive/ng_switch_spec.dart @@ -186,7 +186,7 @@ void main() { var child1 = getChildScope(); expect(child1).toBeNotNull(); expect(element.text).toEqual('works'); - var destroyListener = jasmine.createSpy('watch listener'); + var destroyListener = guinness.createSpy('watch listener'); var watcher = child1.on(ScopeEvent.DESTROY).listen(destroyListener); _.rootScope.context['url'] = 'x'; diff --git a/test/io/expression_extractor_spec.dart b/test/io/expression_extractor_spec.dart index cf04340a3..f9ce6a0c4 100644 --- a/test/io/expression_extractor_spec.dart +++ b/test/io/expression_extractor_spec.dart @@ -8,8 +8,9 @@ import 'package:angular/tools/io_impl.dart'; import 'package:angular/tools/source_crawler_impl.dart'; import 'package:angular/tools/html_extractor.dart'; import 'package:angular/tools/source_metadata_extractor.dart'; -import '../jasmine_syntax.dart'; -import 'package:unittest/unittest.dart'; + +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; void main() { describe('expression_extractor', () { diff --git a/test/io/source_metadata_extractor_spec.dart b/test/io/source_metadata_extractor_spec.dart index 808da469e..e4cdf9fe0 100644 --- a/test/io/source_metadata_extractor_spec.dart +++ b/test/io/source_metadata_extractor_spec.dart @@ -3,8 +3,9 @@ library ng.tool.source_metadata_extractor_spec; import 'package:angular/tools/common.dart'; import 'package:angular/tools/source_crawler_impl.dart'; import 'package:angular/tools/source_metadata_extractor.dart'; -import '../jasmine_syntax.dart'; -import 'package:unittest/unittest.dart'; + +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; void main() { describe('source_metadata_extractor', () { diff --git a/test/io/template_cache_generator_spec.dart b/test/io/template_cache_generator_spec.dart index 90395fbf2..91c4748c2 100644 --- a/test/io/template_cache_generator_spec.dart +++ b/test/io/template_cache_generator_spec.dart @@ -4,8 +4,8 @@ import 'dart:async'; import 'dart:io'; import 'package:angular/tools/template_cache_generator.dart' as generator; -import '../jasmine_syntax.dart'; -import 'package:unittest/unittest.dart'; + +import 'package:guinness/guinness.dart'; void main() { describe('template_cache_generator', () { diff --git a/test/jasmine_syntax.dart b/test/jasmine_syntax.dart deleted file mode 100644 index 1dd3723eb..000000000 --- a/test/jasmine_syntax.dart +++ /dev/null @@ -1,153 +0,0 @@ -library jasmine; - -import 'package:unittest/unittest.dart' as unit; -import 'package:angular/utils.dart' as utils; - -var _beforeEachFnsForCurrentTest = []; -var _afterEachFnsForCurrentTest = []; - -_withSetup(fn) => () { - _beforeEachFnsForCurrentTest.sort((a, b) => Comparable.compare(b[1], a[1])); - _beforeEachFnsForCurrentTest.forEach((fn) => fn[0]()); - try { - return fn(); - } finally { - _beforeEachFnsForCurrentTest = []; - var _aeFns = _afterEachFnsForCurrentTest; - _afterEachFnsForCurrentTest = []; - _aeFns.reversed.forEach((fn) => fn()); - } -}; - - - -it(name, fn) => unit.test(name, _withSetup(fn)); -iit(name, fn) => unit.solo_test(name, _withSetup(fn)); -xit(name, fn) {} -xdescribe(name, fn) {} -ddescribe(name, fn) => describe(name, fn, true); - -class Describe { - Describe parent; - String name; - bool exclusive; - List beforeEachFns = []; - List afterEachFns = []; - - Describe(this.name, this.parent, [bool this.exclusive=false]) { - if (parent != null && parent.exclusive) { - exclusive = true; - } - } - - setUp() { - _beforeEachFnsForCurrentTest.addAll(beforeEachFns); - _afterEachFnsForCurrentTest.addAll(afterEachFns); - } -} - -Describe currentDescribe = new Describe('', null); -bool ddescribeActive = false; - -describe(name, fn, [bool exclusive=false]) { - var lastDescribe = currentDescribe; - currentDescribe = new Describe(name, lastDescribe, exclusive); - if (exclusive) { - name = 'DDESCRIBE: $name'; - ddescribeActive = true; - } - try { - unit.group(name, () { - unit.setUp(currentDescribe.setUp); - fn(); - }); - } finally { - currentDescribe = lastDescribe; - } -} - -beforeEach(fn, {priority: 0}) => currentDescribe.beforeEachFns.add([fn, priority]); -afterEach(fn) => currentDescribe.afterEachFns.insert(0, fn); - -var jasmine = new Jasmine(); - -class SpyFunctionInvocationResult { - final List args; - SpyFunctionInvocationResult(this.args); -} - -class SpyFunction { - String name; - List> invocations = []; - List> invocationsWithoutTrailingNulls = []; - var _andCallFakeFn; - - SpyFunction([this.name]); - call([a0, a1, a2, a3, a4, a5]) { - var args = []; - args.add(a0); - args.add(a1); - args.add(a2); - args.add(a3); - args.add(a4); - args.add(a5); - invocations.add(args); - - var withoutNulls = new List.from(args); - while (!withoutNulls.isEmpty && withoutNulls.last == null) { - withoutNulls.removeLast(); - } - invocationsWithoutTrailingNulls.add(withoutNulls); - - if (_andCallFakeFn != null) { - utils.relaxFnApply(_andCallFakeFn, args); - } - } - - andCallFake(fn) { - _andCallFakeFn = fn; - return this; - } - - reset() => invocations = []; - - num get count => invocations.length; - bool get called => count > 0; - - num get callCount => count; - get argsForCall => invocationsWithoutTrailingNulls; - - firstArgsMatch(a,b,c,d,e,f) { - var fi = invocations.first; - assert(fi.length == 6); - if ("${fi[0]}" != "$a") return false; - if ("${fi[1]}" != "$b") return false; - if ("${fi[2]}" != "$c") return false; - if ("${fi[3]}" != "$d") return false; - if ("${fi[4]}" != "$e") return false; - if ("${fi[5]}" != "$f") return false; - - return true; - } - - get mostRecentCall { - if (invocations.isEmpty) { - throw ["No calls"]; - } - return new SpyFunctionInvocationResult(invocations.last); - } -} - -class Jasmine { - createSpy([String name]) { - return new SpyFunction(name); - } - - SpyFunction spyOn(receiver, methodName) { - throw ["spyOn not implemented"]; - } -} - -main(){ - unit.setUp(currentDescribe.setUp); -} diff --git a/test/jasmines_syntax_spec.dart b/test/jasmines_syntax_spec.dart deleted file mode 100644 index 9fe6968fa..000000000 --- a/test/jasmines_syntax_spec.dart +++ /dev/null @@ -1,63 +0,0 @@ -library jasmine_syntax_spec; - -import 'jasmine_syntax.dart'; -import 'package:unittest/unittest.dart' as unit; - -main() { - describe('jasmine syntax', () { - describe('beforeEach priority', () { - var log = []; - beforeEach(() { - log.add("first p0"); - }); - - beforeEach(() { - log.add("p0"); - }, priority: 0); - - beforeEach(() { - log.add("p1"); - }, priority: 1); - - it('should call beforeEach in the correct order', () { - unit.expect(log.join(';'), unit.equals('p1;first p0;p0')); - }); - }); - - describe('beforeEach priority with nested describes', () { - var log; - beforeEach(() { - log = []; - }, priority: 2); - - beforeEach(() { - log.add("p0Outer"); - }, priority: 0); - - beforeEach(() { - log.add("p1Outer"); - }, priority: 1); - - it('should call beforeEach in the correct order', () { - unit.expect(log.join(';'), unit.equals('p1Outer;p0Outer')); - }); - - describe('inner', () { - beforeEach(() { - log.add("p0Inner"); - }, priority: 0); - - beforeEach(() { - log.add("p1Inner"); - }, priority: 1); - - - it('should call beforeEach in the correct order', () { - unit.expect(log.join(';'), unit.equals('p1Outer;p1Inner;p0Outer;p0Inner')); - }); - }); - - - }); - }); -} diff --git a/test/mock/http_backend_spec.dart b/test/mock/http_backend_spec.dart index 763e5b22f..d9bdfc601 100644 --- a/test/mock/http_backend_spec.dart +++ b/test/mock/http_backend_spec.dart @@ -22,7 +22,7 @@ void main() { var undefined = null; beforeEach((HttpBackend httpBackend) { - callback = jasmine.createSpy('callback'); + callback = guinness.createSpy('callback'); hb = httpBackend; }); @@ -31,7 +31,7 @@ void main() { hb.when('GET', '/url1').respond(200, 'content', {}); hb.when('GET', '/url1').respond(201, 'another', {}); - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(200); expect(response).toBe('content'); }); @@ -48,7 +48,7 @@ void main() { hb.when('GET', '/url2').respond(200, {'key': 'value'}, {}); - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(200); logger(response); }); @@ -87,17 +87,17 @@ void main() { hb.when('GET', '/url', null, {'X': 'val2'}).respond(202, 'content2'); hb.when('GET', '/url').respond(203, 'content3'); - hb('GET', '/url', null, (status, response) { + hb('GET', '/url', null, (status, response, _) { expect(status).toBe(203); expect(response).toBe('content3'); }); - hb('GET', '/url', null, (status, response) { + hb('GET', '/url', null, (status, response, _) { expect(status).toBe(201); expect(response).toBe('content1'); }, {'X': 'val1'}); - hb('GET', '/url', null, (status, response) { + hb('GET', '/url', null, (status, response, _) { expect(status).toBe(202); expect(response).toBe('content2'); }, {'X': 'val2'}); @@ -127,7 +127,7 @@ void main() { it('should match only method', () { hb.when('GET').respond(202, 'c'); - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(202); expect(response).toBe('c'); }); @@ -151,8 +151,8 @@ void main() { hb.flush(); expect(callback.callCount).toBe(2); - expect(callback.argsForCall[0]).toEqual([201, 'second', '']); - expect(callback.argsForCall[1]).toEqual([200, 'first', '']); + expect(callback.calls[0].positionalArguments).toEqual([201, 'second', '']); + expect(callback.calls[1].positionalArguments).toEqual([200, 'first', '']); }); @@ -177,7 +177,7 @@ void main() { }); it('should default status code to 200', () { - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(200); expect(response).toBe('some-data'); }); @@ -202,8 +202,8 @@ void main() { hb.flush(); expect(callback.callCount).toBe(2); - expect(callback.argsForCall[0]).toEqual([200, 'first', '']); - expect(callback.argsForCall[1]).toEqual([200, 'second', '']); + expect(callback.calls[0].positionalArguments).toEqual([200, 'first', '']); + expect(callback.calls[1].positionalArguments).toEqual([200, 'second', '']); }); }); @@ -220,7 +220,7 @@ void main() { it('should have precedence over when()', () { - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(299); expect(response).toBe('expect'); }); @@ -257,7 +257,7 @@ void main() { it("should use when's respond() when no expect() respond is defined", () { - callback.andCallFake((status, response) { + callback.andCallFake((status, response, _) { expect(status).toBe(201); expect(response).toBe('data'); }); @@ -331,7 +331,7 @@ void main() { it('should abort requests when timeout promise resolves', () { hb.expect('GET', '/url1').respond(200); - var canceler, then = jasmine.createSpy('then').andCallFake((fn) { + var canceler, then = guinness.createSpy('then').andCallFake((fn) { canceler = fn; }); @@ -429,7 +429,7 @@ void main() { it('should remove all pending responses', () { - var cancelledClb = jasmine.createSpy('cancelled'); + var cancelledClb = guinness.createSpy('cancelled'); hb.expect('GET', '/url').respond(200, ''); hb('GET', '/url', null, cancelledClb); @@ -445,7 +445,7 @@ void main() { it('should not remove definitions', () { - var cancelledClb = jasmine.createSpy('cancelled'); + var cancelledClb = guinness.createSpy('cancelled'); hb.when('GET', '/url').respond(200, 'success'); hb('GET', '/url', null, cancelledClb); diff --git a/test/tools/html_extractor_spec.dart b/test/tools/html_extractor_spec.dart index 976e19442..da610dd20 100644 --- a/test/tools/html_extractor_spec.dart +++ b/test/tools/html_extractor_spec.dart @@ -2,9 +2,9 @@ library html_extractor_spec; import 'package:angular/tools/common.dart'; import 'package:angular/tools/html_extractor.dart'; -import 'package:unittest/unittest.dart'; -import '../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; import 'mock_io_service.dart'; void main() { diff --git a/test/tools/selector_spec.dart b/test/tools/selector_spec.dart index 38d69a0bb..bb074f87e 100644 --- a/test/tools/selector_spec.dart +++ b/test/tools/selector_spec.dart @@ -2,9 +2,9 @@ library angular.selector_spec; import 'package:angular/tools/selector.dart'; import 'package:html5lib/dom.dart'; -import 'package:unittest/unittest.dart'; -import '../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; void main() { describe('selector', () { diff --git a/test/tools/source_metadata_extractor_spec.dart b/test/tools/source_metadata_extractor_spec.dart index 4a4c6c5e8..09768043a 100644 --- a/test/tools/source_metadata_extractor_spec.dart +++ b/test/tools/source_metadata_extractor_spec.dart @@ -4,9 +4,9 @@ import 'package:analyzer/src/generated/ast.dart'; import 'package:angular/tools/common.dart'; import 'package:angular/tools/source_crawler.dart'; import 'package:angular/tools/source_metadata_extractor.dart'; -import 'package:unittest/unittest.dart'; -import '../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; void main() { describe('SourceMetadataExtractor', () { diff --git a/test/tools/symbol_inspector/symbol_inspector_spec.dart b/test/tools/symbol_inspector/symbol_inspector_spec.dart index 791ea5450..a052dcae2 100644 --- a/test/tools/symbol_inspector/symbol_inspector_spec.dart +++ b/test/tools/symbol_inspector/symbol_inspector_spec.dart @@ -1,10 +1,10 @@ library angular.tools.symbol_inspector; import 'package:angular/tools/symbol_inspector/symbol_inspector.dart'; -import 'package:unittest/unittest.dart'; import 'simple_library.dart'; -import '../../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; Symbol symbolForName(libraryInfo, String name) => libraryInfo.names.firstWhere( @@ -104,4 +104,4 @@ void main() => describe('symbol inspector', () { throwsA(contains("These whitelisted symbols are not used"))); }); }); -}); +}); \ No newline at end of file diff --git a/test/tools/transformer/expression_generator_spec.dart b/test/tools/transformer/expression_generator_spec.dart index 096e314c9..f7b9b3bb6 100644 --- a/test/tools/transformer/expression_generator_spec.dart +++ b/test/tools/transformer/expression_generator_spec.dart @@ -9,7 +9,8 @@ import 'package:barback/barback.dart'; import 'package:code_transformers/resolver.dart'; import 'package:code_transformers/tests.dart' as tests; -import '../../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; main() { describe('ExpressionGenerator', () { diff --git a/test/tools/transformer/metadata_generator_spec.dart b/test/tools/transformer/metadata_generator_spec.dart index 52b3b7890..1b515bcf4 100644 --- a/test/tools/transformer/metadata_generator_spec.dart +++ b/test/tools/transformer/metadata_generator_spec.dart @@ -8,7 +8,8 @@ import 'package:barback/barback.dart'; import 'package:code_transformers/resolver.dart'; import 'package:code_transformers/tests.dart' as tests; -import '../../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; main() { describe('MetadataGenerator', () { diff --git a/test/tools/transformer/static_angular_generator_spec.dart b/test/tools/transformer/static_angular_generator_spec.dart index 45d233704..8346c6a34 100644 --- a/test/tools/transformer/static_angular_generator_spec.dart +++ b/test/tools/transformer/static_angular_generator_spec.dart @@ -5,7 +5,8 @@ import 'package:angular/tools/transformer/static_angular_generator.dart'; import 'package:code_transformers/resolver.dart'; import 'package:code_transformers/tests.dart' as tests; -import '../../jasmine_syntax.dart'; +import 'package:unittest/unittest.dart' hide expect; +import 'package:guinness/guinness.dart'; main() { describe('StaticAngularGenerator', () {