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

Commit 5c6a18e

Browse files
vsavkinmhevery
authored andcommitted
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 Closes #994
1 parent db04ce3 commit 5c6a18e

24 files changed

+132
-481
lines changed

benchmark/dom/_perf.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import '../../test/_specs.dart' as perf;
2-
import '../../test/jasmine_syntax.dart' as jasmine;
32
import '../_perf.dart' hide xtime, time;
43
import 'package:angular/mock/module.dart';
54

@@ -17,6 +16,5 @@ time(name, body, {verify:_noop, cleanUp:_noop}) {
1716
}
1817

1918
main() {
20-
jasmine.main();
2119
perf.main();
2220
}

karma-perf.conf.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = function(config) {
1010
files: [
1111
'benchmark/dom/*.dart',
1212
'benchmark/*_perf.dart',
13-
'test/config/filter_tests.dart',
13+
'test/config/init_guinness.dart',
1414
{pattern: '**/*.dart', watched: true, included: false, served: true},
1515
'packages/browser/dart.js',
1616
'packages/browser/interop.js'
@@ -29,6 +29,10 @@ module.exports = function(config) {
2929
'../../../karma-parser-getter-setter'
3030
],
3131

32+
karmaDartImports: {
33+
guinness: 'package:guinness/guinness_html.dart'
34+
},
35+
3236
preprocessors: {
3337
'test/core/parser/generated_getter_setter.dart': ['parser-getter-setter']
3438
},

karma.conf.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ module.exports = function(config) {
88
// all tests must be 'included', but all other libraries must be 'served' and
99
// optionally 'watched' only.
1010
files: [
11-
'test/jasmine_syntax.dart',
1211
'test/*.dart',
1312
'test/**/*_spec.dart',
14-
'test/config/filter_tests.dart',
13+
'test/config/init_guinness.dart',
1514
{pattern: '**/*.dart', watched: true, included: false, served: true},
1615
'packages/browser/dart.js',
1716
'packages/browser/interop.js',
@@ -40,6 +39,10 @@ module.exports = function(config) {
4039
'../../../karma-parser-getter-setter'
4140
],
4241

42+
karmaDartImports: {
43+
guinness: 'package:guinness/guinness_html.dart'
44+
},
45+
4346
customLaunchers: {
4447
ChromeNoSandbox: { base: 'Chrome', flags: ['--no-sandbox'] }
4548
},

pubspec.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ packages:
3333
description: di
3434
source: hosted
3535
version: "0.0.40"
36+
guinness:
37+
description: guinness
38+
source: hosted
39+
version: "0.1.1"
3640
html5lib:
3741
description: html5lib
3842
source: hosted

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ dev_dependencies:
2929
benchmark_harness: '>=1.0.0'
3030
unittest: '>=0.10.1 <0.12.0'
3131
mock: '>=0.10.0 <0.12.0'
32+
guinness: '>=0.1.1 <0.2.0'

test/_specs.dart

Lines changed: 49 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import 'dart:html' hide Animation;
44

55
import 'package:angular/angular.dart';
66
import 'package:angular/mock/module.dart';
7-
import 'package:unittest/unittest.dart' as unit;
87

9-
import 'jasmine_syntax.dart' as jasmine_syntax;
8+
import 'package:guinness/guinness_html.dart' as gns;
109

1110
export 'dart:html' hide Animation;
12-
export 'package:unittest/unittest.dart';
11+
12+
export 'package:unittest/unittest.dart' hide expect;
13+
export 'package:guinness/guinness_html.dart';
14+
1315
export 'package:mock/mock.dart';
1416
export 'package:di/di.dart';
1517
export 'package:di/dynamic_injector.dart';
@@ -37,194 +39,42 @@ es(String html) {
3739

3840
e(String html) => es(html).first;
3941

40-
Expect expect(actual, [unit.Matcher matcher = null]) {
41-
if (matcher != null) unit.expect(actual, matcher);
42-
return new Expect(actual);
43-
}
44-
45-
class Expect {
46-
var actual;
47-
NotExpect not;
48-
49-
Expect(this.actual) {
50-
not = new NotExpect(this);
51-
}
5242

53-
toEqual(expected) => unit.expect(actual, unit.equals(expected));
54-
toContain(expected) => unit.expect(actual, unit.contains(expected));
55-
toBe(expected) => unit.expect(actual,
56-
unit.predicate((actual) => identical(expected, actual), '$expected'));
57-
toThrow([exception]) => unit.expect(actual, exception == null ?
58-
unit.throws:
59-
unit.throwsA(new ExceptionContains(exception)));
60-
toBeFalsy() => unit.expect(actual, _isFalsy,
61-
reason: '"$actual" is not Falsy');
62-
toBeTruthy() => unit.expect(actual, (v) => !_isFalsy(v),
63-
reason: '"$actual" is not Truthy');
64-
toBeDefined() => unit.expect(actual, unit.isNotNull);
65-
toBeNull() => unit.expect(actual, unit.isNull);
66-
toBeNotNull() => unit.expect(actual, unit.isNotNull);
67-
68-
toHaveHtml(expected) => unit.expect(_toHtml(actual), unit.equals(expected));
69-
toHaveText(expected) =>
70-
unit.expect(_elementText(actual), unit.equals(expected));
71-
72-
toHaveBeenCalled() =>
73-
unit.expect(actual.called, true, reason: 'method not called');
74-
toHaveBeenCalledOnce() => unit.expect(actual.count, 1,
75-
reason: 'method invoked ${actual.count} expected once');
76-
toHaveBeenCalledWith([a,b,c,d,e,f]) =>
77-
unit.expect(actual.firstArgsMatch(a,b,c,d,e,f), true,
78-
reason: 'method invoked with correct arguments');
79-
toHaveBeenCalledOnceWith([a,b,c,d,e,f]) =>
80-
unit.expect(actual.count == 1 && actual.firstArgsMatch(a,b,c,d,e,f),
81-
true,
82-
reason: 'method invoked once with correct arguments. '
83-
'(Called ${actual.count} times)');
84-
85-
toHaveClass(cls) => unit.expect(actual.classes.contains(cls), true,
86-
reason: ' Expected ${actual} to have css class ${cls}');
87-
88-
toHaveAttribute(name, [value = null]) {
89-
unit.expect(actual.attributes.containsKey(name), true,
90-
reason: 'Epxected $actual to have attribute $name');
91-
if (value != null) {
92-
unit.expect(actual.attributes[name], value,
93-
reason: 'Epxected $actual attribute "$name" to be "$value"');
94-
}
43+
Expect expect(actual, [matcher]) {
44+
final expect = new Expect(actual);
45+
if (matcher != null) {
46+
expect.to(matcher);
9547
}
48+
return expect;
49+
}
9650

97-
toEqualSelect(options) {
98-
var actualOptions = [];
51+
class Expect extends gns.Expect {
52+
Expect(actual) : super(actual);
9953

100-
for (var option in actual.querySelectorAll('option')) {
101-
actualOptions.add(option.selected ? [option.value] : option.value);
102-
}
103-
return unit.expect(actualOptions, options);
104-
}
54+
NotExpect get not => new NotExpect(actual);
10555

106-
toBeValid() => unit.expect(actual.valid && !actual.invalid, true,
56+
toBeValid() => _expect(actual.valid && !actual.invalid, true,
10757
reason: 'Form is not valid');
108-
toBePristine() =>
109-
unit.expect(actual.pristine && !actual.dirty, true,
110-
reason: 'Form is dirty');
111-
112-
_isFalsy(v) => v == null ? true: v is bool ? v == false : false;
113-
114-
_toHtml(node, [bool outer = false]) {
115-
if (node is Comment) {
116-
return '<!--${node.text}-->';
117-
} else if (node is DocumentFragment) {
118-
var acc = '';
119-
node.childNodes.forEach((n) { acc += _toHtml(n, true); });
120-
return acc;
121-
} else if (node is List) {
122-
var acc = '';
123-
node.forEach((n) { acc += _toHtml(n); });
124-
return acc;
125-
} else if (node is Element) {
126-
// Remove all the "ng-binding" internal classes
127-
node = node.clone(true) as Element;
128-
node.classes.remove('ng-binding');
129-
node.querySelectorAll(".ng-binding").forEach((Element e) {
130-
e.classes.remove('ng-binding');
131-
});
132-
var htmlString = outer ? node.outerHtml : node.innerHtml;
133-
// Strip out empty class attributes. This seems like a Dart bug...
134-
return htmlString.replaceAll(' class=""', '').trim();
135-
} else if (node is Text) {
136-
return node.text;
137-
} else {
138-
throw "JQuery._toHtml not implemented for node type [${node.nodeType}]";
139-
}
140-
}
14158

142-
_elementText(n, [bool notShadow = false]) {
143-
if (n is Iterable) {
144-
return n.map((nn) => _elementText(nn)).join("");
145-
}
146-
147-
if (n is Comment) return '';
148-
149-
if (!notShadow && n is Element && n.shadowRoot != null) {
150-
var cShadows = n.shadowRoot.nodes.map((n) => n.clone(true)).toList();
151-
for (var i = 0, ii = cShadows.length; i < ii; i++) {
152-
var n = cShadows[i];
153-
if (n is Element) {
154-
var updateElement = (e) {
155-
var text = new Text('SHADOW-CONTENT');
156-
if (e.parent == null) {
157-
cShadows[i] = text;
158-
} else {
159-
e.parent.insertBefore(text, e);
160-
}
161-
e.nodes = [];
162-
};
163-
if (n is ContentElement) { updateElement(n); }
164-
n.querySelectorAll('content').forEach(updateElement);
165-
}
166-
};
167-
var shadowText = _elementText(cShadows, true);
168-
var domText = _elementText(n, true);
169-
170-
return shadowText.replaceFirst("SHADOW-CONTENT", domText);
171-
}
172-
173-
if (n.nodes == null || n.nodes.length == 0) return n.text;
174-
175-
return n.nodes.map((cn) => _elementText(cn)).join("");
176-
}
177-
}
59+
toBePristine() => _expect(actual.pristine && !actual.dirty, true,
60+
reason: 'Form is dirty');
17861

179-
class NotExpect {
180-
Expect _expect;
181-
get actual => _expect.actual;
182-
183-
NotExpect(this._expect);
184-
185-
toHaveBeenCalled() =>
186-
unit.expect(actual.called, false, reason: 'method called');
187-
toThrow() => actual();
188-
189-
toHaveClass(cls) => unit.expect(actual.classes.contains(cls), false,
190-
reason: ' Expected ${actual} to not have css class ${cls}');
191-
toHaveAttribute(name) => unit.expect(actual.attributes.containsKey(name),
192-
false, reason: ' Expected $actual to not have attribute "$name"');
193-
toBe(expected) => unit.expect(actual,
194-
unit.predicate((actual) => !identical(expected, actual), 'not $expected'));
195-
toEqual(expected) => unit.expect(actual,
196-
unit.predicate((actual) => expected != actual, 'not $expected'));
197-
toContain(expected) => unit.expect(actual,
198-
unit.predicate((actual) => !actual.contains(expected), 'not $expected'));
199-
toBePristine() => unit.expect(actual.pristine && !actual.dirty, false,
200-
reason: 'Form is pristine');
201-
toBeValid() => unit.expect(actual.valid && !actual.invalid, false,
202-
reason: 'Form is valid');
62+
get _expect => gns.guinness.matchers.expect;
20363
}
20464

205-
class ExceptionContains extends unit.Matcher {
206-
207-
final _expected;
208-
209-
const ExceptionContains(this._expected);
65+
class NotExpect extends gns.NotExpect {
66+
NotExpect(actual) : super(actual);
21067

211-
bool matches(item, Map matchState) {
212-
if (item is String) {
213-
return item.indexOf(_expected) >= 0;
214-
}
215-
return matches('$item', matchState);
216-
}
68+
toBeValid() => _expect(actual.valid && !actual.invalid, false,
69+
reason: 'Form is valid');
21770

218-
unit.Description describe(unit.Description description) =>
219-
description.add('exception contains ').addDescriptionOf(_expected);
71+
toBePristine() => _expect(actual.pristine && !actual.dirty, false,
72+
reason: 'Form is pristine');
22073

221-
unit.Description describeMismatch(item, unit.Description mismatchDescription,
222-
Map matchState, bool verbose) {
223-
return super.describeMismatch('$item', mismatchDescription, matchState,
224-
verbose);
225-
}
74+
get _expect => gns.guinness.matchers.expect;
22675
}
22776

77+
22878
_injectify(fn) {
22979
// The function does two things:
23080
// First: if the it() passed a function, we wrap it in
@@ -236,20 +86,29 @@ _injectify(fn) {
23686
return fn.outer(inject(fn.inner));
23787
}
23888

239-
// Jasmine syntax
240-
beforeEachModule(fn) => jasmine_syntax.beforeEach(module(fn), priority:1);
241-
beforeEach(fn) => jasmine_syntax.beforeEach(_injectify(fn));
242-
afterEach(fn) => jasmine_syntax.afterEach(_injectify(fn));
243-
it(name, fn) => jasmine_syntax.it(name, _injectify(fn));
244-
iit(name, fn) => jasmine_syntax.iit(name, _injectify(fn));
245-
xit(name, fn) => jasmine_syntax.xit(name, fn);
246-
xdescribe(name, fn) => jasmine_syntax.xdescribe(name, fn);
247-
ddescribe(name, fn) => jasmine_syntax.ddescribe(name, fn);
248-
describe(name, fn) => jasmine_syntax.describe(name, fn);
249-
250-
var jasmine = jasmine_syntax.jasmine;
89+
// Replace guinness syntax elements to inject dependencies.
90+
beforeEachModule(fn) => gns.beforeEach(module(fn), priority:1);
91+
beforeEach(fn) => gns.beforeEach(_injectify(fn));
92+
afterEach(fn) => gns.afterEach(_injectify(fn));
93+
it(name, fn) => gns.it(name, _injectify(fn));
94+
iit(name, fn) => gns.iit(name, _injectify(fn));
95+
96+
_removeNgBinding(node) {
97+
if (node is Element) {
98+
node = node.clone(true) as Element;
99+
node.classes.remove('ng-binding');
100+
node.querySelectorAll(".ng-binding").forEach((Element e) {
101+
e.classes.remove('ng-binding');
102+
});
103+
return node;
104+
}
105+
return node;
106+
}
251107

252108
main() {
253-
jasmine_syntax.beforeEach(setUpInjector, priority:3);
254-
jasmine_syntax.afterEach(tearDownInjector);
109+
gns.beforeEach(setUpInjector, priority:3);
110+
gns.afterEach(tearDownInjector);
111+
112+
gns.guinnessEnableHtmlMatchers();
113+
gns.guinness.matchers.config.preprocessHtml = _removeNgBinding;
255114
}

test/config/filter_tests.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/config/init_guinness.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import 'package:guinness/guinness.dart';
2+
import 'package:unittest/unittest.dart' as unit;
3+
4+
main() {
5+
unit.filterStacks = true;
6+
unit.formatStacks = false;
7+
guinness.initSpecs();
8+
}

test/core/scope_spec.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ void main() {
11671167

11681168
it(r'should return a function that allows listeners to be unregistered', inject(
11691169
(RootScope rootScope) {
1170-
var listener = jasmine.createSpy('watch listener');
1170+
var listener = guinness.createSpy('watch listener');
11711171
var watch;
11721172

11731173
watch = rootScope.watch('foo', listener);
@@ -1248,7 +1248,7 @@ void main() {
12481248
..watch('numberValue', logger)
12491249
..digest();
12501250

1251-
expect(log.removeAt(0).isNaN).toEqual(true); //jasmine's toBe and toEqual don't work well with NaNs
1251+
expect(log.removeAt(0).isNaN).toEqual(true); //guinness's toBe and toEqual don't work well with NaNs
12521252
expect(log).toEqual([null, '', false, 23]);
12531253
log = [];
12541254
rootScope.digest();

0 commit comments

Comments
 (0)