@@ -11,37 +11,46 @@ import 'package:test/test.dart';
11
11
12
12
void main () {
13
13
group ('spawnHybridUri():' , () {
14
- test ('loads a file in a separate isolate connected via StreamChannel' ,
15
- () async {
16
- expect (spawnHybridUri ('util/emits_numbers.dart' ).stream.toList (),
17
- completion (equals ([1 , 2 , 3 ])));
18
- });
14
+ test (
15
+ 'loads a file in a separate isolate connected via StreamChannel' ,
16
+ () async {
17
+ expect (
18
+ spawnHybridUri ('util/emits_numbers.dart' ).stream.toList (),
19
+ completion (equals ([1 , 2 , 3 ])),
20
+ );
21
+ },
22
+ );
19
23
20
24
test ('resolves root-relative URIs relative to the package root' , () async {
21
- expect (spawnHybridUri ('/test/util/emits_numbers.dart' ).stream.toList (),
22
- completion (equals ([1 , 2 , 3 ])));
25
+ expect (
26
+ spawnHybridUri ('/test/util/emits_numbers.dart' ).stream.toList (),
27
+ completion (equals ([1 , 2 , 3 ])),
28
+ );
23
29
});
24
30
25
31
test ('supports Uri objects' , () async {
26
32
expect (
27
- spawnHybridUri (Uri .parse ('util/emits_numbers.dart' )).stream.toList (),
28
- completion (equals ([1 , 2 , 3 ])));
33
+ spawnHybridUri (Uri .parse ('util/emits_numbers.dart' )).stream.toList (),
34
+ completion (equals ([1 , 2 , 3 ])),
35
+ );
29
36
});
30
37
31
38
test ('supports package: uris referencing the root package' , () async {
32
39
expect (
33
- spawnHybridUri (Uri .parse ('package:spawn_hybrid/emits_numbers.dart' ))
34
- .stream
35
- .toList (),
36
- completion (equals ([1 , 2 , 3 ])));
40
+ spawnHybridUri (
41
+ Uri .parse ('package:spawn_hybrid/emits_numbers.dart' ),
42
+ ).stream.toList (),
43
+ completion (equals ([1 , 2 , 3 ])),
44
+ );
37
45
});
38
46
39
47
test ('supports package: uris referencing dependency packages' , () async {
40
48
expect (
41
- spawnHybridUri (Uri .parse ('package:other_package/emits_numbers.dart' ))
42
- .stream
43
- .toList (),
44
- completion (equals ([1 , 2 , 3 ])));
49
+ spawnHybridUri (
50
+ Uri .parse ('package:other_package/emits_numbers.dart' ),
51
+ ).stream.toList (),
52
+ completion (equals ([1 , 2 , 3 ])),
53
+ );
45
54
});
46
55
47
56
test ('rejects non-String, non-Uri objects' , () {
@@ -50,65 +59,83 @@ void main() {
50
59
51
60
test ('passes a message to the hybrid isolate' , () async {
52
61
expect (
53
- spawnHybridUri ('util/echos_message.dart' , message: 123 ).stream.first,
54
- completion (equals (123 )));
62
+ spawnHybridUri ('util/echos_message.dart' , message: 123 ).stream.first,
63
+ completion (equals (123 )),
64
+ );
55
65
expect (
56
- spawnHybridUri ('util/echos_message.dart' , message: 'wow' )
57
- .stream
58
- .first,
59
- completion (equals ('wow' )));
66
+ spawnHybridUri ('util/echos_message.dart' , message: 'wow' ).stream.first,
67
+ completion (equals ('wow' )),
68
+ );
60
69
});
61
70
62
- test ('emits an error from the stream channel if the isolate fails to load' ,
63
- () {
64
- expect (spawnHybridUri ('non existent file' ).stream.first,
65
- throwsA (isA <Exception >()));
66
- });
71
+ test (
72
+ 'emits an error from the stream channel if the isolate fails to load' ,
73
+ () {
74
+ expect (
75
+ spawnHybridUri ('non existent file' ).stream.first,
76
+ throwsA (isA <Exception >()),
77
+ );
78
+ },
79
+ );
67
80
});
68
81
69
82
group ('spawnHybridCode()' , () {
70
- test ('loads the code in a separate isolate connected via StreamChannel' ,
71
- () {
72
- expect (spawnHybridCode ('''
83
+ test (
84
+ 'loads the code in a separate isolate connected via StreamChannel' ,
85
+ () {
86
+ expect (
87
+ spawnHybridCode ('''
73
88
import "package:stream_channel/stream_channel.dart";
74
89
75
90
void hybridMain(StreamChannel channel) {
76
91
channel.sink..add(1)..add(2)..add(3)..close();
77
92
}
78
- ''' ).stream.toList (), completion (equals ([1 , 2 , 3 ])));
79
- });
93
+ ''' ).stream.toList (),
94
+ completion (equals ([1 , 2 , 3 ])),
95
+ );
96
+ },
97
+ );
80
98
81
99
test ('allows a first parameter with type StreamChannel<Object?>' , () {
82
- expect (spawnHybridCode ('''
100
+ expect (
101
+ spawnHybridCode ('''
83
102
import "package:stream_channel/stream_channel.dart";
84
103
85
104
void hybridMain(StreamChannel<Object?> channel) {
86
105
channel.sink..add(1)..add(2)..add(null)..close();
87
106
}
88
- ''' ).stream.toList (), completion (equals ([1 , 2 , null ])));
107
+ ''' ).stream.toList (),
108
+ completion (equals ([1 , 2 , null ])),
109
+ );
89
110
});
90
111
91
112
test ('gives a good error when the StreamChannel type is not supported' , () {
92
113
expect (
93
- spawnHybridCode ('''
114
+ spawnHybridCode ('''
94
115
import "package:stream_channel/stream_channel.dart";
95
116
96
117
void hybridMain(StreamChannel<Object> channel) {
97
118
channel.sink..add(1)..add(2)..add(3)..close();
98
119
}
99
120
''' ).stream,
100
- emitsError (isA <Exception >().having (
101
- (e) => e.toString (),
102
- 'toString' ,
103
- contains (
104
- 'The first parameter to the top-level hybridMain() must be a '
105
- 'StreamChannel<dynamic> or StreamChannel<Object?>. More specific '
106
- 'types such as StreamChannel<Object> are not supported.' ))));
121
+ emitsError (
122
+ isA <Exception >().having (
123
+ (e) => e.toString (),
124
+ 'toString' ,
125
+ contains (
126
+ 'The first parameter to the top-level hybridMain() must be a '
127
+ 'StreamChannel<dynamic> or StreamChannel<Object?>. More specific '
128
+ 'types such as StreamChannel<Object> are not supported.' ,
129
+ ),
130
+ ),
131
+ ),
132
+ );
107
133
});
108
134
109
135
test ('can use dart:io even when run from a browser' , () async {
110
136
var path = p.join ('test' , 'hybrid_test.dart' );
111
- expect (spawnHybridCode ("""
137
+ expect (
138
+ spawnHybridCode ("""
112
139
import 'dart:io';
113
140
114
141
import 'package:stream_channel/stream_channel.dart';
@@ -118,7 +145,9 @@ void main() {
118
145
..add(File(r"$path ").readAsStringSync())
119
146
..close();
120
147
}
121
- """ ).stream.first, completion (contains ('hybrid emits numbers' )));
148
+ """ ).stream.first,
149
+ completion (contains ('hybrid emits numbers' )),
150
+ );
122
151
}, testOn: 'browser' );
123
152
124
153
test ('forwards data from the test to the hybrid isolate' , () async {
@@ -147,15 +176,20 @@ void main() {
147
176
}
148
177
''' ;
149
178
150
- expect (spawnHybridCode (code, message: [1 , 2 , 3 ]).stream.first,
151
- completion (equals ([1 , 2 , 3 ])));
152
- expect (spawnHybridCode (code, message: {'a' : 'b' }).stream.first,
153
- completion (equals ({'a' : 'b' })));
179
+ expect (
180
+ spawnHybridCode (code, message: [1 , 2 , 3 ]).stream.first,
181
+ completion (equals ([1 , 2 , 3 ])),
182
+ );
183
+ expect (
184
+ spawnHybridCode (code, message: {'a' : 'b' }).stream.first,
185
+ completion (equals ({'a' : 'b' })),
186
+ );
154
187
});
155
188
156
- test ('allows the hybrid isolate to send errors across the stream channel' ,
157
- () {
158
- var channel = spawnHybridCode ('''
189
+ test (
190
+ 'allows the hybrid isolate to send errors across the stream channel' ,
191
+ () {
192
+ var channel = spawnHybridCode ('''
159
193
import "package:stack_trace/stack_trace.dart";
160
194
import "package:stream_channel/stream_channel.dart";
161
195
@@ -164,11 +198,15 @@ void main() {
164
198
}
165
199
''' );
166
200
167
- channel.stream.listen (null , onError: expectAsync2 ((error, stackTrace) {
168
- expect (error.toString (), equals ('oh no!' ));
169
- expect (stackTrace.toString (), contains ('hybridMain' ));
170
- }));
171
- });
201
+ channel.stream.listen (
202
+ null ,
203
+ onError: expectAsync2 ((error, stackTrace) {
204
+ expect (error.toString (), equals ('oh no!' ));
205
+ expect (stackTrace.toString (), contains ('hybridMain' ));
206
+ }),
207
+ );
208
+ },
209
+ );
172
210
173
211
test ('sends an unhandled synchronous error across the stream channel' , () {
174
212
var channel = spawnHybridCode ('''
@@ -179,10 +217,13 @@ void main() {
179
217
}
180
218
''' );
181
219
182
- channel.stream.listen (null , onError: expectAsync2 ((error, stackTrace) {
183
- expect (error.toString (), equals ('oh no!' ));
184
- expect (stackTrace.toString (), contains ('hybridMain' ));
185
- }));
220
+ channel.stream.listen (
221
+ null ,
222
+ onError: expectAsync2 ((error, stackTrace) {
223
+ expect (error.toString (), equals ('oh no!' ));
224
+ expect (stackTrace.toString (), contains ('hybridMain' ));
225
+ }),
226
+ );
186
227
});
187
228
188
229
test ('sends an unhandled asynchronous error across the stream channel' , () {
@@ -198,10 +239,13 @@ void main() {
198
239
}
199
240
''' );
200
241
201
- channel.stream.listen (null , onError: expectAsync2 ((error, stackTrace) {
202
- expect (error.toString (), equals ('oh no!' ));
203
- expect (stackTrace.toString (), contains ('hybridMain' ));
204
- }));
242
+ channel.stream.listen (
243
+ null ,
244
+ onError: expectAsync2 ((error, stackTrace) {
245
+ expect (error.toString (), equals ('oh no!' ));
246
+ expect (stackTrace.toString (), contains ('hybridMain' ));
247
+ }),
248
+ );
205
249
});
206
250
207
251
test ('deserializes TestFailures as TestFailures' , () {
@@ -228,31 +272,42 @@ void main() {
228
272
expect (() => channel.sink.add (< Object > [].iterator), throwsArgumentError);
229
273
});
230
274
231
- test ('gracefully handles an unserializable message in the browser' ,
232
- () async {
233
- var channel = spawnHybridCode ('''
275
+ test (
276
+ 'gracefully handles an unserializable message in the browser' ,
277
+ () async {
278
+ var channel = spawnHybridCode ('''
234
279
import 'package:stream_channel/stream_channel.dart';
235
280
236
281
void hybridMain(StreamChannel channel) {}
237
282
''' );
238
283
239
- expect (() => channel.sink.add (< Object > [].iterator), throwsArgumentError);
240
- }, testOn: 'browser' );
241
-
242
- test ('gracefully handles an unserializable message in the hybrid isolate' ,
243
- () {
244
- var channel = spawnHybridCode ('''
284
+ expect (
285
+ () => channel.sink.add (< Object > [].iterator),
286
+ throwsArgumentError,
287
+ );
288
+ },
289
+ testOn: 'browser' ,
290
+ );
291
+
292
+ test (
293
+ 'gracefully handles an unserializable message in the hybrid isolate' ,
294
+ () {
295
+ var channel = spawnHybridCode ('''
245
296
import "package:stream_channel/stream_channel.dart";
246
297
247
298
void hybridMain(StreamChannel channel) {
248
299
channel.sink.add([].iterator);
249
300
}
250
301
''' );
251
302
252
- channel.stream.listen (null , onError: expectAsync1 ((error) {
253
- expect (error.toString (), contains ("can't be JSON-encoded." ));
254
- }));
255
- });
303
+ channel.stream.listen (
304
+ null ,
305
+ onError: expectAsync1 ((error) {
306
+ expect (error.toString (), contains ("can't be JSON-encoded." ));
307
+ }),
308
+ );
309
+ },
310
+ );
256
311
257
312
test ('forwards prints from the hybrid isolate' , () {
258
313
expect (() async {
@@ -272,14 +327,17 @@ void main() {
272
327
// that's imported, URIs don't escape $ by default, and $ isn't allowed in
273
328
// imports.
274
329
test ('supports a dollar character in the hybrid code' , () {
275
- expect (spawnHybridCode (r'''
330
+ expect (
331
+ spawnHybridCode (r'''
276
332
import "package:stream_channel/stream_channel.dart";
277
333
278
334
void hybridMain(StreamChannel channel) {
279
335
var value = "bar";
280
336
channel.sink.add("foo${value}baz");
281
337
}
282
- ''' ).stream.first, completion ('foobarbaz' ));
338
+ ''' ).stream.first,
339
+ completion ('foobarbaz' ),
340
+ );
283
341
});
284
342
285
343
test ('closes the channel when the hybrid isolate exits' , () {
@@ -342,7 +400,8 @@ void main() {
342
400
});
343
401
344
402
test ('opts in to null safety by default' , () async {
345
- expect (spawnHybridCode ('''
403
+ expect (
404
+ spawnHybridCode ('''
346
405
import "package:stream_channel/stream_channel.dart";
347
406
348
407
// Use some null safety syntax
@@ -351,7 +410,9 @@ void main() {
351
410
void hybridMain(StreamChannel channel) {
352
411
channel.sink..add(1)..add(2)..add(3)..close();
353
412
}
354
- ''' ).stream.toList (), completion (equals ([1 , 2 , 3 ])));
413
+ ''' ).stream.toList (),
414
+ completion (equals ([1 , 2 , 3 ])),
415
+ );
355
416
});
356
417
});
357
418
}
0 commit comments