| OLD | NEW |
| (Empty) | |
| 1 # Hacking Observatory |
| 2 |
| 3 These instructions will guide you through the Observatory development and |
| 4 testing workflow. |
| 5 |
| 6 ## SDK Setup & Build |
| 7 Getting ready to start. |
| 8 |
| 9 Before you start to hack on Observatory, follow the [instructions][build_sdk] to |
| 10 have a working environment in which you are able to build and test the Dart SDK. |
| 11 |
| 12 ### Develop with Dartium ~ Suggested |
| 13 If you want to avoid triggering a new compilation to JavaScript for each edit |
| 14 you do, you can use a modified version of Chromium named Dartium that will |
| 15 interpret you dart code directly. |
| 16 |
| 17 You can obtain Dartium in two different ways: |
| 18 1. [Download][download_dartium] the binaries |
| 19 2. [Build][build_dartium] Dartium from the source code |
| 20 |
| 21 |
| 22 ## Run existing tests |
| 23 Before hacking Observatory let's run the existing Observatory tests. |
| 24 We suggest to run all the test in __debug__ mode. |
| 25 |
| 26 First build the sdk in debug mode |
| 27 ``` |
| 28 $ ./tools/build.py --mode debug create_sdk |
| 29 ``` |
| 30 |
| 31 From the root of the sdk repository run: |
| 32 ``` |
| 33 $ ./tools/test.py -mdebug service |
| 34 ``` |
| 35 |
| 36 ## Serve Observatory |
| 37 Observatory is built as part of building the sdk, but when working on |
| 38 Observatory we recommend that you use __pub serve__ so you can avoid the |
| 39 overhead of building the sdk for each change. |
| 40 |
| 41 Use __pub__ to __serve__ Observatory: |
| 42 ``` |
| 43 [...]/runtime/observatory$ pub serve |
| 44 ``` |
| 45 |
| 46 ## Open Observatory |
| 47 You can open the development version of Observatory from |
| 48 Chrome/Chromium/__Dartium__ by navigating to [localhost:8080][open_observatory] |
| 49 |
| 50 Every change you make to the Observatory source code will be visible by simply |
| 51 __refreshing__ the page in the browser. |
| 52 |
| 53 ## Connect to a VM |
| 54 Start a Dart VM with the ``--observe`` flag (as explained in the |
| 55 [get started guide][observatory_get_started]) and connect your Observatory |
| 56 instance to that VM. |
| 57 |
| 58 Example script (file name ```clock.dart```): |
| 59 ```dart |
| 60 import 'dart:async' show Timer, Duration; |
| 61 |
| 62 main() { |
| 63 bool tick = true; |
| 64 new Timer.periodic(const Duration(seconds: 1), (Timer t) { |
| 65 print(tick ? 'tick' : 'tock'); |
| 66 tick = !tick; |
| 67 }); |
| 68 } |
| 69 ``` |
| 70 Start the script: |
| 71 ``` |
| 72 $ dart --observe clock.dart |
| 73 ``` |
| 74 |
| 75 ## Code Reviews |
| 76 The development workflow of Dart (and Observatory) is based on code reviews. |
| 77 |
| 78 Follow the code review [instructions][code_review] to be able to successfully |
| 79 submit your code. |
| 80 |
| 81 The main reviewers for Observatory related CLs are: |
| 82 - turnidge |
| 83 - johnmccutchan |
| 84 - rmacnak |
| 85 |
| 86 ## Write a new service test |
| 87 All the service tests are located in the ```tests/service``` folder. |
| 88 Test file names follow the convention ```<description>_test.dart``` |
| 89 (e.g. ```a_brief_description_test.dart```). |
| 90 |
| 91 The test is generally structured in the following way. |
| 92 ```dart |
| 93 import 'package:test/test.dart'; |
| 94 |
| 95 main() { |
| 96 // Some code that you need to test. |
| 97 var a = 1 + 2; |
| 98 |
| 99 // Some assertions to check the results. |
| 100 expect(a, equal(3)); |
| 101 } |
| 102 ``` |
| 103 See the official [test library][test_library] instructions; |
| 104 |
| 105 The ```test_helper.dart``` file expose some functions that allow to run a part |
| 106 of the code into another __VM__. |
| 107 |
| 108 To test synchronous operations: |
| 109 ```dart |
| 110 import 'test_helper.dart'; |
| 111 |
| 112 code() { |
| 113 // Write the code you want to be execute into another VM. |
| 114 } |
| 115 |
| 116 var tests = [ |
| 117 // A series of tests that you want to run against the above code. |
| 118 (Isolate isolate) async { |
| 119 await isolate.reload(); |
| 120 // Use the isolate to communicate to the VM. |
| 121 } |
| 122 ]; |
| 123 |
| 124 main(args) => runIsolateTestsSynchronous(args, |
| 125 tests, |
| 126 testeeConcurrent: code); |
| 127 ``` |
| 128 |
| 129 In order to test asynchronous operations: |
| 130 ```dart |
| 131 import 'test_helper.dart'; |
| 132 |
| 133 code() async { |
| 134 // Write the asynchronous code you want to be execute into another VM. |
| 135 } |
| 136 |
| 137 var tests = [ |
| 138 // A series of tests that you want to run against the above code. |
| 139 (Isolate isolate) async { |
| 140 await isolate.reload(); |
| 141 // Use the isolate to communicate to the VM. |
| 142 } |
| 143 ]; |
| 144 |
| 145 main(args) async => runIsolateTests(args, |
| 146 tests, |
| 147 testeeConcurrent: code); |
| 148 ``` |
| 149 |
| 150 Both ```runIsolateTests``` and ```runIsolateTestsSynchronous``` have the |
| 151 following named parameters: |
| 152 - __testeeBefore__ (void()) a function that is going to be executed before |
| 153 the test |
| 154 - __testeeConcurrent__ (void()) test that is going to be executed |
| 155 - __pause_on_start__ (bool, default: false) pause the Isolate before the first |
| 156 instruction |
| 157 - __pause_on_exit__ (bool, default: false) pause the Isolate after the last |
| 158 instruction |
| 159 - __pause_on_unhandled_exceptions__ (bool, default: false) pause the Isolate at |
| 160 an unhandled exception |
| 161 - __trace_service__ (bool, default: false) trace VM service requests |
| 162 - __trace_compiler__ (bool, default: false) trace compiler operations |
| 163 - __verbose_vm__ (bool, default: false) verbose logging |
| 164 |
| 165 |
| 166 Some common and reusable test are available from ```service_test_common.dart```: |
| 167 - hasPausedFor |
| 168 - hasStoppedAtBreakpoint |
| 169 - hasStoppedWithUnhandledException |
| 170 - hasStoppedAtExit |
| 171 - hasPausedAtStartcode_review |
| 172 and utility functions: |
| 173 - subscribeToStream |
| 174 - cancelStreamSubscription |
| 175 - asyncStepOver |
| 176 - setBreakpointAtLine |
| 177 - resumeIsolate |
| 178 - resumeAndAwaitEvent |
| 179 - resumeIsolateAndAwaitEvent |
| 180 - stepOver |
| 181 - getClassFromRootLib |
| 182 - rootLibraryFieldValue |
| 183 |
| 184 ## Run your tests |
| 185 See: __Run existing tests__ |
| 186 |
| 187 [build_sdk]: https://github.com/dart-lang/sdk/wiki/Building "Building the Dart S
DK" |
| 188 [download_dartium]: https://www.dartlang.org/tools/dartium/ "Download Dartium" |
| 189 [build_dartium]: https://github.com/dart-lang/sdk/wiki/Building-Dartium "Build D
artium" |
| 190 [open_observatory]: http://localhost:8080/ "Open Observatory" |
| 191 [observatory_get_started]: https://dart-lang.github.io/observatory/get-started.h
tml "Observatory get started" |
| 192 [code_review]: https://github.com/dart-lang/sdk/wiki/Code-review-workflow-with-G
itHub-and-reitveld "Code Review" |
| 193 [test_library]: https://pub.dartlang.org/packages/test "Test Library" |
| OLD | NEW |