OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 /// A unit test library for running groups of tests in a browser, instead of the | 5 /// A unit test library for running groups of tests in a browser, instead of the |
6 /// entire test file. This is especially used for large tests files that have | 6 /// entire test file. This is especially used for large tests files that have |
7 /// many subtests, so we can mark groups as failing at a finer granularity than | 7 /// many subtests, so we can mark groups as failing at a finer granularity than |
8 /// the entire test file. | 8 /// the entire test file. |
9 /// | 9 /// |
10 /// To use, import this file, and call [useHtmlIndividualConfiguration] at the | 10 /// To use, import this file, and call [useHtmlIndividualConfiguration] at the |
11 /// start of your set sequence. Important constraint: your group descriptions | 11 /// start of your set sequence. Important constraint: your group descriptions |
12 /// MUST NOT contain spaces. | 12 /// MUST NOT contain spaces. |
13 library unittest.html_individual_config; | 13 library unittest.html_individual_config; |
14 | 14 |
15 import 'dart:html'; | 15 import 'dart:html'; |
16 import 'unittest.dart' as unittest; | 16 import 'unittest.dart' as unittest; |
17 import 'html_config.dart' as htmlconfig; | 17 import 'html_config.dart' as htmlconfig; |
18 | 18 |
19 class HtmlIndividualConfiguration extends htmlconfig.HtmlConfiguration { | 19 class HtmlIndividualConfiguration extends htmlconfig.HtmlConfiguration { |
20 HtmlIndividualConfiguration(bool isLayoutTest): super(isLayoutTest); | 20 HtmlIndividualConfiguration(bool isLayoutTest) : super(isLayoutTest); |
21 | 21 |
22 void onStart() { | 22 void onStart() { |
23 var search = window.location.search; | 23 var search = window.location.search; |
24 if (search != '') { | 24 if (search != '') { |
25 var groups = search.substring(1).split('&') | 25 var groups = search |
| 26 .substring(1) |
| 27 .split('&') |
26 .where((p) => p.startsWith('group=')) | 28 .where((p) => p.startsWith('group=')) |
27 .toList(); | 29 .toList(); |
28 | 30 |
29 if (!groups.isEmpty) { | 31 if (!groups.isEmpty) { |
30 if (groups.length > 1) { | 32 if (groups.length > 1) { |
31 throw new ArgumentError('More than one "group" parameter provided.'); | 33 throw new ArgumentError('More than one "group" parameter provided.'); |
32 } | 34 } |
33 | 35 |
34 var testGroupName = groups.single.split('=')[1]; | 36 var testGroupName = groups.single.split('=')[1]; |
35 var startsWith = "$testGroupName${unittest.groupSep}"; | 37 var startsWith = "$testGroupName${unittest.groupSep}"; |
36 unittest.filterTests((unittest.TestCase tc) => | 38 unittest.filterTests( |
37 tc.description.startsWith(startsWith)); | 39 (unittest.TestCase tc) => tc.description.startsWith(startsWith)); |
38 } | 40 } |
39 } | 41 } |
40 super.onStart(); | 42 super.onStart(); |
41 } | 43 } |
42 } | 44 } |
43 | 45 |
44 void useHtmlIndividualConfiguration([bool isLayoutTest = false]) { | 46 void useHtmlIndividualConfiguration([bool isLayoutTest = false]) { |
45 unittest.unittestConfiguration = isLayoutTest ? _singletonLayout : _singletonN
otLayout; | 47 unittest.unittestConfiguration = |
| 48 isLayoutTest ? _singletonLayout : _singletonNotLayout; |
46 } | 49 } |
47 | 50 |
48 final _singletonLayout = new HtmlIndividualConfiguration(true); | 51 final _singletonLayout = new HtmlIndividualConfiguration(true); |
49 final _singletonNotLayout = new HtmlIndividualConfiguration(false); | 52 final _singletonNotLayout = new HtmlIndividualConfiguration(false); |
OLD | NEW |