mercredi 27 septembre 2017

How to get the code coverage in Angular Dart?

I've tried using package coverage to get the code coverage from my Angular Dart 4.0 project.

The following steps are my working flow:

  1. run pub serve test --port=8081
  2. run pub run test --pub-serve=8081 --pause-after-load
  3. waiting for test runner print the observatory URL (e.g. http://127.0.0.1:12345)
  4. run pub global run coverage:collect_coverage --port=12345 -o coverage.json
  5. press Enter to resume test runner
  6. run pub global run coverage:format_coverage --packages=.packages-c -i coverage.json -o coverage.report

After step 5, I will get a coverage.json file which contans some data, but I don't know why the coverage report always shows each code is uncovered.

Am I using a wrong flow for getting code coverage? Or have any better way to do it?

Thanks !


There are my experiment code:

experiment_component.dart

import 'package:angular/angular.dart';

@Component(
  selector: 'experiment_component',
  template: '<h1></h1>'
)
class ExperimentComponent {

  String greeting = '';

  void greet() {
    greeting = 'Hello';
  }

}

experiment_component_test.dart

@TestOn('browser')
@Tags(const ['aot'])
import 'package:angular/angular.dart';
import 'package:angular4_test/src/experiment_component.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';

NgTestBed<ExperimentComponent> testBed;
NgTestFixture<ExperimentComponent> testFixture;

@AngularEntrypoint()
void main() {

  tearDown(disposeAnyRunningTest);

  setUp(() async {
    testBed = new NgTestBed<ExperimentComponent>();
    testFixture = await testBed.create();
  });

  test('should render Hello', () async {
    await testFixture.update((comp)=> comp.greet());
    expect(testFixture.text, contains('Hello'));
  });

}

.packages-c

angular4_test:lib/

coverage.report

 |import 'package:angular/angular.dart';
 |
 |@Component(
 |  selector: 'experiment_component',
 |  template: '<h1></h1>'
 |)
 |class ExperimentComponent {
 |
 |  String greeting = '';
 |
 |  void greet() {
0|    greeting = 'Hello';
 |  }
 |
 |}

Aucun commentaire:

Enregistrer un commentaire