Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1185)

Side by Side Diff: test/runner/loader_test.dart

Issue 983573002: Add support for running browser tests to the test runner. (Closed) Base URL: git@github.com:dart-lang/unittest@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:io'; 5 import 'dart:io';
6 6
7 import 'package:path/path.dart' as p; 7 import 'package:path/path.dart' as p;
8 import 'package:unittest/src/backend/state.dart'; 8 import 'package:unittest/src/backend/state.dart';
9 import 'package:unittest/src/runner/test_platform.dart';
9 import 'package:unittest/src/runner/loader.dart'; 10 import 'package:unittest/src/runner/loader.dart';
10 import 'package:unittest/unittest.dart'; 11 import 'package:unittest/unittest.dart';
11 12
12 import '../io.dart'; 13 import '../io.dart';
13 import '../utils.dart'; 14 import '../utils.dart';
14 15
15 Loader _loader; 16 Loader _loader;
16 String _sandbox; 17 String _sandbox;
17 18
18 final _tests = """ 19 final _tests = """
19 import 'dart:async'; 20 import 'dart:async';
20 21
21 import 'package:unittest/unittest.dart'; 22 import 'package:unittest/unittest.dart';
22 23
23 void main() { 24 void main() {
24 test("success", () {}); 25 test("success", () {});
25 test("failure", () => throw new TestFailure('oh no')); 26 test("failure", () => throw new TestFailure('oh no'));
26 test("error", () => throw 'oh no'); 27 test("error", () => throw 'oh no');
27 } 28 }
28 """; 29 """;
29 30
30 void main() { 31 void main() {
31 setUp(() { 32 setUp(() {
32 _loader = new Loader(packageRoot: p.join(packageDir, 'packages')); 33 _loader = new Loader([TestPlatform.vm],
34 packageRoot: p.join(packageDir, 'packages'));
33 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; 35 _sandbox = Directory.systemTemp.createTempSync('unittest_').path;
34 }); 36 });
35 37
36 tearDown(() { 38 tearDown(() {
37 new Directory(_sandbox).deleteSync(recursive: true); 39 new Directory(_sandbox).deleteSync(recursive: true);
38 return _loader.close(); 40 return _loader.close();
39 }); 41 });
40 42
41 group(".loadFile()", () { 43 group(".loadFile()", () {
42 var suite; 44 var suite;
43 setUp(() { 45 setUp(() {
44 /// TODO(nweiz): Use scheduled_test for this once it's compatible with 46 /// TODO(nweiz): Use scheduled_test for this once it's compatible with
45 /// this version of unittest. 47 /// this version of unittest.
46 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); 48 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests);
47 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')) 49 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).then((suites) {
48 .then((suite_) => suite = suite_); 50 expect(suites, hasLength(1));
51 suite = suites.first;
52 });
49 }); 53 });
50 54
51 test("returns a suite with a name matching the file path", () { 55 test("returns a suite with the file path and platform", () {
52 expect(suite.name, equals(p.join(_sandbox, 'a_test.dart'))); 56 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart')));
57 expect(suite.platform, equals('VM'));
53 }); 58 });
54 59
55 test("returns tests with the correct names", () { 60 test("returns tests with the correct names and platforms", () {
56 expect(suite.tests, hasLength(3)); 61 expect(suite.tests, hasLength(3));
57 expect(suite.tests[0].name, equals("success")); 62 expect(suite.tests[0].name, equals("success"));
58 expect(suite.tests[1].name, equals("failure")); 63 expect(suite.tests[1].name, equals("failure"));
59 expect(suite.tests[2].name, equals("error")); 64 expect(suite.tests[2].name, equals("error"));
60 }); 65 });
61 66
62 test("can load and run a successful test", () { 67 test("can load and run a successful test", () {
63 var liveTest = suite.tests[0].load(suite); 68 var liveTest = suite.tests[0].load(suite);
64 69
65 expectStates(liveTest, [ 70 expectStates(liveTest, [
66 const State(Status.running, Result.success), 71 const State(Status.running, Result.success),
67 const State(Status.complete, Result.success) 72 const State(Status.complete, Result.success)
68 ]); 73 ]);
69 expectErrors(liveTest, []); 74 expectErrors(liveTest, []);
70 75
71 return liveTest.run().whenComplete(() => liveTest.close()); 76 return liveTest.run().whenComplete(() => liveTest.close());
72 }); 77 });
73 78
74 test("can load and run a failing test", () { 79 test("can load and run a failing test", () {
75 var liveTest = suite.tests[1].load(suite); 80 var liveTest = suite.tests[1].load(suite);
76 expectSingleFailure(liveTest); 81 expectSingleFailure(liveTest);
77 return liveTest.run().whenComplete(() => liveTest.close()); 82 return liveTest.run().whenComplete(() => liveTest.close());
78 }); 83 });
79 84
80 test("throws a nice error if the package root doesn't exist", () { 85 test("throws a nice error if the package root doesn't exist", () {
81 var loader = new Loader(); 86 var loader = new Loader([TestPlatform.vm]);
82 expect(() { 87 expect(() {
83 try { 88 try {
84 loader.loadFile(p.join(_sandbox, 'a_test.dart')); 89 loader.loadFile(p.join(_sandbox, 'a_test.dart'));
85 } finally { 90 } finally {
86 loader.close(); 91 loader.close();
87 } 92 }
88 }, throwsA(isLoadException( 93 }, throwsA(isLoadException(
89 "Directory ${p.join(_sandbox, 'packages')} does not exist."))); 94 "Directory ${p.join(_sandbox, 'packages')} does not exist.")));
90 }); 95 });
91 }); 96 });
(...skipping 24 matching lines...) Expand all
116 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); 121 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests);
117 new File(p.join(_sandbox, 'another_test.dart')) 122 new File(p.join(_sandbox, 'another_test.dart'))
118 .writeAsStringSync(_tests); 123 .writeAsStringSync(_tests);
119 new Directory(p.join(_sandbox, 'dir')).createSync(); 124 new Directory(p.join(_sandbox, 'dir')).createSync();
120 new File(p.join(_sandbox, 'dir/sub_test.dart')) 125 new File(p.join(_sandbox, 'dir/sub_test.dart'))
121 .writeAsStringSync(_tests); 126 .writeAsStringSync(_tests);
122 127
123 return _loader.loadDir(_sandbox).then((suites_) => suites = suites_); 128 return _loader.loadDir(_sandbox).then((suites_) => suites = suites_);
124 }); 129 });
125 130
126 test("names those suites after their files", () { 131 test("gives those suites the correct paths", () {
127 expect(suites.map((suite) => suite.name), unorderedEquals([ 132 expect(suites.map((suite) => suite.path), unorderedEquals([
128 p.join(_sandbox, 'a_test.dart'), 133 p.join(_sandbox, 'a_test.dart'),
129 p.join(_sandbox, 'another_test.dart'), 134 p.join(_sandbox, 'another_test.dart'),
130 p.join(_sandbox, 'dir/sub_test.dart') 135 p.join(_sandbox, 'dir/sub_test.dart')
131 ])); 136 ]));
132 }); 137 });
133 138
134 test("can run tests in those suites", () { 139 test("can run tests in those suites", () {
135 var suite = suites.firstWhere((suite) => suite.name.contains("a_test")); 140 var suite = suites.firstWhere((suite) => suite.path.contains("a_test"));
136 var liveTest = suite.tests[1].load(suite); 141 var liveTest = suite.tests[1].load(suite);
137 expectSingleFailure(liveTest); 142 expectSingleFailure(liveTest);
138 return liveTest.run().whenComplete(() => liveTest.close()); 143 return liveTest.run().whenComplete(() => liveTest.close());
139 }); 144 });
140 }); 145 });
141 }); 146 });
142 } 147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698