Skip to content

Commit b904e69

Browse files
committed
add tests + update changelog
1 parent 7992863 commit b904e69

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

pkgs/test/test/runner/coverage_test.dart

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ dev_dependencies:
167167
workingDirectory: pkgDir,
168168
);
169169
await validateTest(test);
170-
expect(File(lcovFile).readAsStringSync(), '''
170+
expect(
171+
File(lcovFile).readAsStringSync(),
172+
contains('''
171173
SF:${p.join(pkgDir, 'lib', 'calculate.dart')}
172174
DA:1,1
173175
DA:2,2
@@ -176,7 +178,8 @@ DA:5,0
176178
LF:4
177179
LH:3
178180
end_of_record
179-
''');
181+
'''),
182+
);
180183
});
181184

182185
test('gathers coverage for tests in multiple packages', () async {
@@ -271,7 +274,9 @@ dev_dependencies:
271274
workingDirectory: pkgDir,
272275
);
273276
await validateTest(test);
274-
expect(File(lcovFile).readAsStringSync(), '''
277+
expect(
278+
File(lcovFile).readAsStringSync(),
279+
contains('''
275280
SF:${p.join(pkgDir, 'lib', 'calculate.dart')}
276281
DA:1,1
277282
DA:2,2
@@ -280,7 +285,83 @@ DA:5,0
280285
LF:4
281286
LH:3
282287
end_of_record
283-
''');
288+
'''),
289+
);
290+
});
291+
292+
test('gathers coverage for code outside of lib (dart_frog)', () async {
293+
await d.dir(d.sandbox, [
294+
d.dir('dart_frog_sample', [
295+
d.file('pubspec.yaml', '''
296+
name: dart_frog_sample
297+
version: 1.0.0
298+
environment:
299+
sdk: ^3.5.0
300+
dependencies:
301+
dart_frog: ^1.0.0
302+
dev_dependencies:
303+
mocktail: ^1.0.0
304+
test: ^1.26.2
305+
'''),
306+
d.dir('routes', [
307+
d.file('index.dart', '''
308+
import 'package:dart_frog/dart_frog.dart';
309+
Response onRequest(RequestContext context) {
310+
return Response(body: 'Welcome to Dart Frog!');
311+
}
312+
'''),
313+
]),
314+
d.dir('test', [
315+
d.dir('routes', [
316+
d.file('index_test.dart', '''
317+
import 'dart:io';
318+
import 'package:dart_frog/dart_frog.dart';
319+
import 'package:mocktail/mocktail.dart';
320+
import 'package:test/test.dart';
321+
322+
import '../../routes/index.dart' as route;
323+
324+
class _MockRequestContext extends Mock implements RequestContext {}
325+
326+
void main() {
327+
group('GET /', () {
328+
test('responds with a 200 and "Welcome to Dart Frog!".', () {
329+
final context = _MockRequestContext();
330+
final response = route.onRequest(context);
331+
expect(response.statusCode, equals(HttpStatus.ok));
332+
expect(
333+
response.body(),
334+
completion(equals('Welcome to Dart Frog!')),
335+
);
336+
});
337+
});
338+
}
339+
'''),
340+
]),
341+
]),
342+
]),
343+
]).create();
344+
345+
final pkgDir = p.join(d.sandbox, 'dart_frog_sample');
346+
await (await runPub(['get'], workingDirectory: pkgDir)).shouldExit(0);
347+
final lcovFile = p.join(coverageDirectory.path, 'lcov.info');
348+
var test = await runTest(
349+
['--coverage-path', lcovFile, 'test/routes/index_test.dart'],
350+
packageConfig: p.join(pkgDir, '.dart_tool/package_config.json'),
351+
workingDirectory: pkgDir,
352+
);
353+
await validateTest(test);
354+
expect(
355+
File(lcovFile).readAsStringSync(),
356+
contains('''
357+
SF:${p.join(pkgDir, 'routes', 'index.dart')}
358+
DA:2,1
359+
DA:3,1
360+
LF:2
361+
LH:2
362+
end_of_record
363+
'''),
364+
);
284365
});
285366

286367
test('gathers coverage for Chrome tests', () async {

pkgs/test_core/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 0.6.16-wip
22

3+
* Fix default coverage reporting to include all collected coverage.
34
* Add `SuiteConfiguration.suiteLoadTimeout` to configure the timeout for loading a test suite.
45
* Removed hard-coded timeout of 12m for loading a test suite and set default to `none`.
56

0 commit comments

Comments
 (0)