2019-11-27 23:04:02 +00:00
|
|
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
2019-06-27 18:17:58 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-01-27 23:17:53 +00:00
|
|
|
// @dart = 2.8
|
|
|
|
|
2019-06-27 18:17:58 +00:00
|
|
|
import 'package:flutter_tools/src/test/coverage_collector.dart';
|
2021-04-19 21:59:04 +00:00
|
|
|
import 'package:vm_service/vm_service.dart';
|
2019-06-27 18:17:58 +00:00
|
|
|
|
2019-07-13 18:51:44 +00:00
|
|
|
import '../src/common.dart';
|
2021-04-07 05:55:03 +00:00
|
|
|
import '../src/fake_vm_services.dart';
|
2019-06-27 18:17:58 +00:00
|
|
|
|
|
|
|
void main() {
|
2020-04-29 18:52:46 +00:00
|
|
|
testWithoutContext('Coverage collector Can handle coverage SentinelException', () async {
|
|
|
|
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
|
|
|
requests: <VmServiceExpectation>[
|
|
|
|
FakeVmServiceRequest(
|
|
|
|
method: 'getVM',
|
2021-04-19 21:59:04 +00:00
|
|
|
jsonResponse: (VM.parse(<String, Object>{})
|
|
|
|
..isolates = <IsolateRef>[
|
|
|
|
IsolateRef.parse(<String, Object>{
|
2020-04-29 18:52:46 +00:00
|
|
|
'id': '1'
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
).toJson(),
|
|
|
|
),
|
|
|
|
const FakeVmServiceRequest(
|
|
|
|
method: 'getScripts',
|
|
|
|
args: <String, Object>{
|
|
|
|
'isolateId': '1',
|
|
|
|
},
|
|
|
|
jsonResponse: <String, Object>{
|
|
|
|
'type': 'Sentinel'
|
|
|
|
}
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
final Map<String, Object> result = await collect(
|
|
|
|
null,
|
|
|
|
(String predicate) => true,
|
|
|
|
connector: (Uri uri) async {
|
|
|
|
return fakeVmServiceHost.vmService;
|
|
|
|
},
|
|
|
|
);
|
2019-06-27 18:17:58 +00:00
|
|
|
|
|
|
|
expect(result, <String, Object>{'type': 'CodeCoverage', 'coverage': <Object>[]});
|
2020-04-29 18:52:46 +00:00
|
|
|
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
2019-06-27 18:17:58 +00:00
|
|
|
});
|
2021-04-19 21:59:04 +00:00
|
|
|
|
|
|
|
testWithoutContext('Coverage collector processes coverage and script data', () async {
|
|
|
|
final FakeVmServiceHost fakeVmServiceHost = FakeVmServiceHost(
|
|
|
|
requests: <VmServiceExpectation>[
|
|
|
|
FakeVmServiceRequest(
|
|
|
|
method: 'getVM',
|
|
|
|
jsonResponse: (VM.parse(<String, Object>{})
|
|
|
|
..isolates = <IsolateRef>[
|
|
|
|
IsolateRef.parse(<String, Object>{
|
|
|
|
'id': '1'
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
).toJson(),
|
|
|
|
),
|
|
|
|
FakeVmServiceRequest(
|
|
|
|
method: 'getScripts',
|
|
|
|
args: <String, Object>{
|
|
|
|
'isolateId': '1',
|
|
|
|
},
|
|
|
|
jsonResponse: ScriptList(scripts: <ScriptRef>[
|
|
|
|
ScriptRef(uri: 'foo.dart', id: '1'),
|
|
|
|
]).toJson(),
|
|
|
|
),
|
|
|
|
FakeVmServiceRequest(
|
|
|
|
method: 'getSourceReport',
|
|
|
|
args: <String, Object>{
|
|
|
|
'isolateId': '1',
|
|
|
|
'reports': <Object>['Coverage'],
|
|
|
|
'scriptId': '1',
|
|
|
|
'forceCompile': true,
|
|
|
|
},
|
|
|
|
jsonResponse: SourceReport(
|
|
|
|
ranges: <SourceReportRange>[
|
|
|
|
SourceReportRange(
|
|
|
|
scriptIndex: 0,
|
|
|
|
startPos: 0,
|
|
|
|
endPos: 0,
|
|
|
|
compiled: true,
|
|
|
|
coverage: SourceReportCoverage(
|
|
|
|
hits: <int>[],
|
|
|
|
misses: <int>[],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
scripts: <ScriptRef>[
|
|
|
|
ScriptRef(
|
|
|
|
uri: 'foo.dart',
|
|
|
|
id: '1',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
).toJson(),
|
|
|
|
),
|
|
|
|
FakeVmServiceRequest(
|
|
|
|
method: 'getObject',
|
|
|
|
args: <String, Object>{
|
|
|
|
'isolateId': '1',
|
|
|
|
'objectId': '1',
|
|
|
|
},
|
|
|
|
jsonResponse: Script(
|
|
|
|
uri: 'foo.dart',
|
|
|
|
id: '1',
|
|
|
|
library: LibraryRef(name: '', id: '1111', uri: 'foo.dart'),
|
|
|
|
tokenPosTable: <List<int>>[],
|
|
|
|
).toJson(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
|
|
|
|
final Map<String, Object> result = await collect(
|
|
|
|
null,
|
|
|
|
(String predicate) => true,
|
|
|
|
connector: (Uri uri) async {
|
|
|
|
return fakeVmServiceHost.vmService;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(result, <String, Object>{'type': 'CodeCoverage', 'coverage': <Object>[
|
|
|
|
<String, Object>{
|
|
|
|
'source': 'foo.dart',
|
|
|
|
'script': <String, Object>{
|
|
|
|
'type': '@Script',
|
|
|
|
'fixedId': true,
|
|
|
|
'id': 'libraries/1/scripts/foo.dart',
|
|
|
|
'uri': 'foo.dart',
|
|
|
|
'_kind': 'library',
|
|
|
|
},
|
|
|
|
'hits': <Object>[],
|
|
|
|
},
|
|
|
|
]});
|
|
|
|
expect(fakeVmServiceHost.hasRemainingExpectations, false);
|
|
|
|
});
|
2019-06-27 18:17:58 +00:00
|
|
|
}
|