Skip to content

Commit 28a7811

Browse files
author
Tim Blasi
committed
refactor(dart/transform): Migrates tests to use package:test
Our transformer unit tests currently use package:guinness, which uses package:unittest under the covers. package:unittest has been updated and renamed package:test, so for simplicity migrate test to use package:test syntax.
1 parent eeb594c commit 28a7811

6 files changed

Lines changed: 194 additions & 179 deletions

File tree

modules_dart/transform/test/transform/common/async_string_writer_tests.dart

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,78 @@
11
library angular2.test.transform.common.async_string_writer;
22

33
import 'dart:async';
4+
5+
import 'package:test/test.dart';
6+
47
import 'package:angular2/src/transform/common/async_string_writer.dart';
5-
import 'package:guinness/guinness.dart';
68

79
void allTests() {
8-
it('should function as a basic Writer without async calls.', () {
10+
test('should function as a basic Writer without async calls.', () {
911
var writer = new AsyncStringWriter();
1012
writer.print('hello');
11-
expect('$writer').toEqual('hello');
13+
expect('$writer', equals('hello'));
1214
writer.println(', world');
13-
expect('$writer').toEqual('hello, world\n');
15+
expect('$writer', equals('hello, world\n'));
1416
});
1517

16-
it('should concatenate futures added with `asyncPrint`.', () async {
18+
test('should concatenate futures added with `asyncPrint`.', () async {
1719
var writer = new AsyncStringWriter();
1820
writer.print('hello');
19-
expect('$writer').toEqual('hello');
21+
expect('$writer', equals('hello'));
2022
writer.asyncPrint(new Future.value(', world.'));
2123
writer.print(' It is a beautiful day.');
22-
expect(await writer.asyncToString())
23-
.toEqual('hello, world. It is a beautiful day.');
24+
expect(await writer.asyncToString(),
25+
equals('hello, world. It is a beautiful day.'));
2426
});
2527

26-
it('should concatenate multiple futures regardless of order.', () async {
28+
test('should concatenate multiple futures regardless of order.', () async {
2729
var completer1 = new Completer<String>();
2830
var completer2 = new Completer<String>();
2931

3032
var writer = new AsyncStringWriter();
3133
writer.print('hello');
32-
expect('$writer').toEqual('hello');
34+
expect('$writer', equals('hello'));
3335
writer.asyncPrint(completer1.future);
3436
writer.asyncPrint(completer2.future);
3537

3638
completer2.complete(' It is a beautiful day.');
3739
completer1.complete(', world.');
3840

39-
expect(await writer.asyncToString())
40-
.toEqual('hello, world. It is a beautiful day.');
41+
expect(await writer.asyncToString(),
42+
equals('hello, world. It is a beautiful day.'));
4143
});
4244

43-
it('should allow multiple "rounds" of `asyncPrint`.', () async {
45+
test('should allow multiple "rounds" of `asyncPrint`.', () async {
4446
var writer = new AsyncStringWriter();
4547
writer.print('hello');
46-
expect('$writer').toEqual('hello');
48+
expect('$writer', equals('hello'));
4749
writer.asyncPrint(new Future.value(', world.'));
48-
expect(await writer.asyncToString()).toEqual('hello, world.');
50+
expect(await writer.asyncToString(), equals('hello, world.'));
4951

5052
writer.asyncPrint(new Future.value(' It is '));
5153
writer.asyncPrint(new Future.value('a beautiful '));
5254
writer.asyncPrint(new Future.value('day.'));
5355

54-
expect(await writer.asyncToString())
55-
.toEqual('hello, world. It is a beautiful day.');
56+
expect(await writer.asyncToString(),
57+
equals('hello, world. It is a beautiful day.'));
5658
});
5759

58-
it('should handle calls to async methods while waiting.', () {
60+
test('should handle calls to async methods while waiting.', () {
5961
var completer1 = new Completer<String>();
6062
var completer2 = new Completer<String>();
6163

6264
var writer = new AsyncStringWriter();
6365
writer.print('hello');
64-
expect('$writer').toEqual('hello');
66+
expect('$writer', equals('hello'));
6567

6668
writer.asyncPrint(completer1.future);
6769
var f1 = writer.asyncToString().then((result) {
68-
expect(result).toEqual('hello, world.');
70+
expect(result, equals('hello, world.'));
6971
});
7072

7173
writer.asyncPrint(completer2.future);
7274
var f2 = writer.asyncToString().then((result) {
73-
expect(result).toEqual('hello, world. It is a beautiful day.');
75+
expect(result, equals('hello, world. It is a beautiful day.'));
7476
});
7577

7678
completer1.complete(', world.');
@@ -79,24 +81,24 @@ void allTests() {
7981
return Future.wait([f1, f2]);
8082
});
8183

82-
it(
84+
test(
8385
'should handle calls to async methods that complete in reverse '
8486
'order while waiting.', () {
8587
var completer1 = new Completer<String>();
8688
var completer2 = new Completer<String>();
8789

8890
var writer = new AsyncStringWriter();
8991
writer.print('hello');
90-
expect('$writer').toEqual('hello');
92+
expect('$writer', equals('hello'));
9193

9294
writer.asyncPrint(completer1.future);
9395
var f1 = writer.asyncToString().then((result) {
94-
expect(result).toEqual('hello, world.');
96+
expect(result, equals('hello, world.'));
9597
});
9698

9799
writer.asyncPrint(completer2.future);
98100
var f2 = writer.asyncToString().then((result) {
99-
expect(result).toEqual('hello, world. It is a beautiful day.');
101+
expect(result, equals('hello, world. It is a beautiful day.'));
100102
});
101103

102104
completer2.complete(' It is a beautiful day.');

modules_dart/transform/test/transform/common/code/ng_deps_code_tests.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
library angular2.test.transform.common.code.ng_deps_code_tests;
22

33
import 'package:analyzer/analyzer.dart';
4+
import 'package:test/test.dart';
5+
46
import 'package:angular2/src/transform/common/code/ng_deps_code.dart';
57
import 'package:angular2/src/transform/common/model/import_export_model.pb.dart';
68
import 'package:angular2/src/transform/common/model/ng_deps_model.pb.dart';
7-
import 'package:guinness/guinness.dart';
89

910
main() => allTests();
1011

1112
void allTests() {
12-
describe('writeNgDepsModel', () {
13-
it('should output parsable code', () async {
13+
group('writeNgDepsModel', () {
14+
test('should output parsable code', () async {
1415
final ngDeps = new NgDepsModel()
1516
..libraryUri = 'test.foo'
1617
..imports.add(new ImportModel()
@@ -23,12 +24,12 @@ void allTests() {
2324

2425
var compilationUnit = parseCompilationUnit(buf.toString());
2526

26-
expect(compilationUnit).toBeNotNull();
27-
expect(compilationUnit.declarations).toBeNotNull();
28-
expect(compilationUnit.declarations.length > 0).toBeTrue();
27+
expect(compilationUnit, isNotNull);
28+
expect(compilationUnit.declarations, isNotNull);
29+
expect(compilationUnit.declarations.length > 0, isTrue);
2930
});
3031

31-
it('should output parsable code with deferred imports', () async {
32+
test('should output parsable code with deferred imports', () async {
3233
// Regression test for i/4587.
3334
final ngDeps = new NgDepsModel()
3435
..libraryUri = 'test.foo'
@@ -43,9 +44,9 @@ void allTests() {
4344

4445
var compilationUnit = parseCompilationUnit(buf.toString());
4546

46-
expect(compilationUnit).toBeNotNull();
47-
expect(compilationUnit.declarations).toBeNotNull();
48-
expect(compilationUnit.declarations.length > 0).toBeTrue();
47+
expect(compilationUnit, isNotNull);
48+
expect(compilationUnit.declarations, isNotNull);
49+
expect(compilationUnit.declarations.length > 0, isTrue);
4950
});
5051
});
5152
}
Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
library angular2.test.transform.common.annotation_matcher_test;
22

3+
import 'package:test/test.dart';
4+
35
import 'package:angular2/src/core/render/api.dart';
46
import 'package:angular2/src/compiler/directive_metadata.dart';
57
import 'package:angular2/src/transform/common/ng_meta.dart';
6-
import 'package:guinness/guinness.dart';
78

89
main() => allTests();
910

@@ -15,18 +16,18 @@ void allTests() {
1516
CompileDirectiveMetadata.create(type: new CompileTypeMetadata(name: 'N4'))
1617
];
1718

18-
it('should allow empty data.', () {
19+
test('should allow empty data.', () {
1920
var ngMeta = new NgMeta.empty();
20-
expect(ngMeta.isEmpty).toBeTrue();
21+
expect(ngMeta.isEmpty, isTrue);
2122
});
2223

23-
describe('serialization', () {
24-
it('should parse empty data correctly.', () {
24+
group('serialization', () {
25+
test('should parse empty data correctly.', () {
2526
var ngMeta = new NgMeta.fromJson({});
26-
expect(ngMeta.isEmpty).toBeTrue();
27+
expect(ngMeta.isEmpty, isTrue);
2728
});
2829

29-
it('should be lossless', () {
30+
test('should be lossless', () {
3031
var a = new NgMeta.empty();
3132
a.identifiers['T0'] = mockDirMetadata[0];
3233
a.identifiers['T1'] = mockDirMetadata[1];
@@ -42,8 +43,8 @@ void allTests() {
4243
});
4344
});
4445

45-
describe('flatten', () {
46-
it('should include recursive aliases.', () {
46+
group('flatten', () {
47+
test('should include recursive aliases.', () {
4748
var a = new NgMeta.empty();
4849
a.identifiers['T0'] = mockDirMetadata[0];
4950
a.identifiers['T1'] = mockDirMetadata[1];
@@ -54,62 +55,62 @@ void allTests() {
5455
a.aliases['a3'] = ['T3', 'a2'];
5556
a.aliases['a4'] = ['a3', 'T0'];
5657

57-
expect(a.flatten('a4')).toEqual([mockDirMetadata[3], mockDirMetadata[1], mockDirMetadata[0]]);
58+
expect(a.flatten('a4'), equals([mockDirMetadata[3], mockDirMetadata[1], mockDirMetadata[0]]));
5859
});
5960

60-
it('should detect cycles.', () {
61+
test('should detect cycles.', () {
6162
var a = new NgMeta.empty();
6263
a.identifiers['T0'] = mockDirMetadata[0];
6364
a.aliases['a1'] = ['T0', 'a2'];
6465
a.aliases['a2'] = ['a1'];
6566

66-
expect(() => a.flatten('a1')).toThrowWith(message: new RegExp('Cycle: a1 -> a2 -> a1.'));
67+
expect(() => a.flatten('a1'), throwsA(predicate((ex) => new RegExp('Cycle: a1 -> a2 -> a1.').hasMatch(ex.message))));
6768
});
6869

69-
it('should allow duplicates.', () {
70+
test('should allow duplicates.', () {
7071
var a = new NgMeta.empty();
7172
a.identifiers['T0'] = mockDirMetadata[0];
7273
a.aliases['a1'] = ['T0', 'a2'];
7374
a.aliases['a2'] = ['T0'];
7475

75-
expect(() => a.flatten('a1')).not.toThrow();
76+
expect(() => a.flatten('a1'), returnsNormally);
7677
});
7778
});
7879

79-
describe('merge', () {
80-
it('should merge all identifiers on addAll', () {
80+
group('merge', () {
81+
test('should merge all identifiers on addAll', () {
8182
var a = new NgMeta.empty();
8283
var b = new NgMeta.empty();
8384
a.identifiers['T0'] = mockDirMetadata[0];
8485
b.identifiers['T1'] = mockDirMetadata[1];
8586
a.addAll(b);
86-
expect(a.identifiers).toContain('T1');
87-
expect(a.identifiers['T1']).toEqual(mockDirMetadata[1]);
87+
expect(a.identifiers, contains('T1'));
88+
expect(a.identifiers['T1'], equals(mockDirMetadata[1]));
8889
});
8990

90-
it('should merge all aliases on addAll', () {
91+
test('should merge all aliases on addAll', () {
9192
var a = new NgMeta.empty();
9293
var b = new NgMeta.empty();
9394
a.aliases['a'] = ['x'];
9495
b.aliases['b'] = ['y'];
9596
a.addAll(b);
96-
expect(a.aliases).toContain('b');
97-
expect(a.aliases['b']).toEqual(['y']);
97+
expect(a.aliases, contains('b'));
98+
expect(a.aliases['b'], equals(['y']));
9899
});
99100
});
100101
}
101102

102103
_checkSimilar(NgMeta a, NgMeta b) {
103-
expect(a.identifiers.length).toEqual(b.identifiers.length);
104-
expect(a.aliases.length).toEqual(b.aliases.length);
104+
expect(a.identifiers.length, equals(b.identifiers.length));
105+
expect(a.aliases.length, equals(b.aliases.length));
105106
for (var k in a.identifiers.keys) {
106-
expect(b.identifiers).toContain(k);
107+
expect(b.identifiers, contains(k));
107108
var at = a.identifiers[k];
108109
var bt = b.identifiers[k];
109-
expect(at.type.name).toEqual(bt.type.name);
110+
expect(at.type.name, equals(bt.type.name));
110111
}
111112
for (var k in a.aliases.keys) {
112-
expect(b.aliases).toContain(k);
113-
expect(b.aliases[k]).toEqual(a.aliases[k]);
113+
expect(b.aliases, contains(k));
114+
expect(b.aliases[k], equals(a.aliases[k]));
114115
}
115116
}

0 commit comments

Comments
 (0)