Line data Source code
1 : // Copyright (c) 2016, 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 'package:stream_channel/stream_channel.dart'; 6 : // ignore: deprecated_member_use 7 : import 'package:test_api/backend.dart' 8 : show RemoteListener, StackTraceFormatter, StackTraceMapper; 9 : 10 : /// Returns a channel that will emit a serialized representation of the tests 11 : /// defined in [getMain]. 12 : /// 13 : /// This channel is used to control the tests. Platform plugins should forward 14 : /// it `deserializeSuite`. It's guaranteed to communicate using only 15 : /// JSON-serializable values. 16 : /// 17 : /// Any errors thrown within [getMain], synchronously or not, will be forwarded 18 : /// to the load test for this suite. Prints will similarly be forwarded to that 19 : /// test's print stream. 20 : /// 21 : /// If [hidePrints] is `true` (the default), calls to `print()` within this 22 : /// suite will not be forwarded to the parent zone's print handler. However, the 23 : /// caller may want them to be forwarded in (for example) a browser context 24 : /// where they'll be visible in the development console. 25 : /// 26 : /// If [beforeLoad] is passed, it's called before the tests have been declared 27 : /// for this worker. 28 11 : StreamChannel<Object?> serializeSuite(Function Function() getMain, 29 : {bool hidePrints = true, 30 : Future Function( 31 : StreamChannel<Object?> Function(String name) suiteChannel)? 32 : beforeLoad}) => 33 11 : RemoteListener.start( 34 : getMain, 35 : hidePrints: hidePrints, 36 : beforeLoad: beforeLoad, 37 : ); 38 : 39 : /// Sets the stack trace mapper for the current test suite. 40 : /// 41 : /// This is used to convert JavaScript stack traces into their Dart equivalents 42 : /// using source maps. It should be set before any tests run, usually in the 43 : /// `onLoad()` callback to [serializeSuite]. 44 0 : void setStackTraceMapper(StackTraceMapper mapper) { 45 0 : var formatter = StackTraceFormatter.current; 46 : if (formatter == null) { 47 0 : throw StateError( 48 : 'setStackTraceMapper() may only be called within a test worker.'); 49 : } 50 : 51 0 : formatter.configure(mapper: mapper); 52 : }