OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 import 'dart:io'; |
| 6 |
| 7 import 'package:path/path.dart' as p; |
| 8 import 'package:unittest/src/backend/state.dart'; |
| 9 import 'package:unittest/src/runner/test_platform.dart'; |
| 10 import 'package:unittest/src/runner/loader.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 |
| 13 import '../../io.dart'; |
| 14 import '../../utils.dart'; |
| 15 |
| 16 Loader _loader; |
| 17 String _sandbox; |
| 18 |
| 19 final _tests = """ |
| 20 import 'dart:async'; |
| 21 |
| 22 import 'package:unittest/unittest.dart'; |
| 23 |
| 24 void main() { |
| 25 test("success", () {}); |
| 26 test("failure", () => throw new TestFailure('oh no')); |
| 27 test("error", () => throw 'oh no'); |
| 28 } |
| 29 """; |
| 30 |
| 31 void main() { |
| 32 setUp(() { |
| 33 _loader = new Loader([TestPlatform.chrome], |
| 34 packageRoot: p.join(packageDir, 'packages')); |
| 35 _sandbox = Directory.systemTemp.createTempSync('unittest_').path; |
| 36 /// TODO(nweiz): Use scheduled_test for this once it's compatible with this |
| 37 /// version of unittest. |
| 38 new File(p.join(_sandbox, 'a_test.dart')).writeAsStringSync(_tests); |
| 39 }); |
| 40 |
| 41 tearDown(() { |
| 42 new Directory(_sandbox).deleteSync(recursive: true); |
| 43 return _loader.close(); |
| 44 }); |
| 45 |
| 46 group(".loadFile()", () { |
| 47 var suite; |
| 48 setUp(() { |
| 49 return _loader.loadFile(p.join(_sandbox, 'a_test.dart')).then((suites) { |
| 50 expect(suites, hasLength(1)); |
| 51 suite = suites.first; |
| 52 }); |
| 53 }); |
| 54 |
| 55 test("returns a suite with the file path and platform", () { |
| 56 expect(suite.path, equals(p.join(_sandbox, 'a_test.dart'))); |
| 57 expect(suite.platform, equals('Chrome')); |
| 58 }); |
| 59 |
| 60 test("returns tests with the correct names", () { |
| 61 expect(suite.tests, hasLength(3)); |
| 62 expect(suite.tests[0].name, equals("success")); |
| 63 expect(suite.tests[1].name, equals("failure")); |
| 64 expect(suite.tests[2].name, equals("error")); |
| 65 }); |
| 66 |
| 67 test("can load and run a successful test", () { |
| 68 var liveTest = suite.tests[0].load(suite); |
| 69 |
| 70 expectStates(liveTest, [ |
| 71 const State(Status.running, Result.success), |
| 72 const State(Status.complete, Result.success) |
| 73 ]); |
| 74 expectErrors(liveTest, []); |
| 75 |
| 76 return liveTest.run().whenComplete(() => liveTest.close()); |
| 77 }); |
| 78 |
| 79 test("can load and run a failing test", () { |
| 80 var liveTest = suite.tests[1].load(suite); |
| 81 expectSingleFailure(liveTest); |
| 82 return liveTest.run().whenComplete(() => liveTest.close()); |
| 83 }); |
| 84 }); |
| 85 |
| 86 test("throws a nice error if the package root doesn't exist", () { |
| 87 var loader = new Loader([TestPlatform.chrome]); |
| 88 expect( |
| 89 loader.loadFile(p.join(_sandbox, 'a_test.dart')) |
| 90 .whenComplete(loader.close), |
| 91 throwsA(isLoadException( |
| 92 "Directory ${p.join(_sandbox, 'packages')} does not exist."))); |
| 93 }); |
| 94 |
| 95 test("loads a suite both in the browser and the VM", () { |
| 96 var loader = new Loader([TestPlatform.vm, TestPlatform.chrome], |
| 97 packageRoot: p.join(packageDir, 'packages')); |
| 98 var path = p.join(_sandbox, 'a_test.dart'); |
| 99 return loader.loadFile(path).then((suites) { |
| 100 expect(suites[0].platform, equals('VM')); |
| 101 expect(suites[0].path, equals(path)); |
| 102 expect(suites[1].platform, equals('Chrome')); |
| 103 expect(suites[1].path, equals(path)); |
| 104 |
| 105 for (var suite in suites) { |
| 106 expect(suite.tests, hasLength(3)); |
| 107 expect(suite.tests[0].name, equals("success")); |
| 108 expect(suite.tests[1].name, equals("failure")); |
| 109 expect(suite.tests[2].name, equals("error")); |
| 110 } |
| 111 }).whenComplete(loader.close); |
| 112 }); |
| 113 } |
OLD | NEW |