From 1f80fc9c31d512f004460e86eb57932ec2305a77 Mon Sep 17 00:00:00 2001 From: Pierre Smeyers <pierre.smeyers@gmail.com> Date: Sun, 2 Oct 2022 16:04:47 +0200 Subject: [PATCH] feat: normalize reports --- README.md | 31 ++++++++++++++++--------------- kicker.json | 6 ------ templates/gitlab-ci-angular.yml | 18 +++++++----------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index d478d59..ed73594 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,6 @@ Those stage are bound to the `build` stage, and uses the following variable: |-----------------|------------------------------------------------------------|------------------------------------------| | `NG_TEST_ARGS` | Angular [ng test](https://angular.io/cli/test) arguments | `test --code-coverage --reporters progress,junit` | | `NG_BUILD_ARGS` | Angular [ng build](https://angular.io/cli/build) arguments | `build --prod` | -| `NG_JUNIT_TEST_REPORT_PATH` | Path to JUnit report | `reports/junit_test_report.xml` | The next chapters presents some requirements related to your unit tests (using Karma). @@ -76,15 +75,16 @@ Add the config section: ```js // [to be continuous]: karma-coverage configuration (needs 'text-summary' to let GitLab grab coverage from stdout) coverageReporter: { - dir: require("path").resolve("reports"), - subdir: ".", + dir: 'reports', + subdir: '.', + file: 'ng-coverage.lcov.info', reporters: [{ type: "lcovonly" }, { type: "text-summary" }], }, ``` #### JUnit report -In order to be able to [integrate your test reports to GitLab](https://docs.gitlab.com/ee/ci/junit_test_reports.html), +In order to be able to [integrate your test reports to GitLab](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsjunit), the Angular template expects the following in your `karma.conf.js`. Add the [karma-junit-reporter](https://github.com/karma-runner/karma-junit-reporter) package as dev dependency: @@ -102,10 +102,10 @@ In your `karma.conf.js`, add the plugin: Add the config section: ```js - // [to be continuous]: karma-junit-reporter configuration (report needs to be in 'reports/junit_test_report.xml') + // [to be continuous]: karma-junit-reporter configuration (report needs to be in 'reports/ng-test.xunit.xml') junitReporter: { - outputDir: require('path').resolve('reports'), - outputFile: 'junit_test_report.xml', + outputDir: 'reports', + outputFile: 'ng-test.xunit.xml', useBrowserName: false, ... } @@ -131,9 +131,10 @@ In your `karma.conf.js`, add the plugin: Add the config section: ```js + // [to be continuous]: karma-sonarqube-execution-reporter configuration (report needs to be in 'reports/ng-test.sonar.xml') sonarQubeExecutionReporter: { - outputDir: require('path').resolve('reports'), - outputFile: 'sonar_test_report.xml', + outputDir: 'reports', + outputFile: 'ng-test.sonar.xml', ... } ``` @@ -152,8 +153,7 @@ This stage is bound to the `test` stage and uses the following variables : | Name | description | default value | |----------------------|------------------------------------------------------------|------------------------------------------| | `NG_E2E_ARGS` | Angular [ng e2e](https://angular.io/cli/e2e) arguments | `e2e` | -| `NG_E2E_REPORT_PATH` | path where e2e reports are stored | `reports/e2e` | -| `NG_E2E_ENABLED` | set to `true`to enable the e2e tests execution | *none (disabled by default)* | +| `NG_E2E_ENABLED` | set to `true`to enable the e2e tests execution | *none (disabled by default)* | Implementation rely on the official [Angular CLI](https://cli.angular.io/) tool (`ng build` and `ng test` commands). @@ -167,7 +167,8 @@ exports.config = { onPrepare() { jasmine.getEnv().addReporter(new JUnitXmlReporter({ consolidateAll: true, - savePath: 'reports/e2e' + savePath: 'reports', + filePrefix: 'ng-e2e.xunit' })); } ... @@ -237,12 +238,12 @@ sonar.test.inclusions=**/*.spec.ts # tests report: generic format # set the path configured with karma-sonarqube-execution-reporter -sonar.testExecutionReportPaths=reports/sonar_test_report.xml +sonar.testExecutionReportPaths=reports/ng-test.sonar.xml # lint report: TSLint JSON -sonar.typescript.tslint.reportPaths=reports/tslint-report.json +sonar.typescript.tslint.reportPaths=reports/ng-lint.tslint.json # coverage report: LCOV format # set the path configured with karma-coverage-istanbul-reporter -sonar.typescript.lcov.reportPaths=reports/lcov.info +sonar.typescript.lcov.reportPaths=reports/ng-coverage.lcov.info ``` More info: diff --git a/kicker.json b/kicker.json index 4d0c7d2..f4e409f 100644 --- a/kicker.json +++ b/kicker.json @@ -94,12 +94,6 @@ "description": "ng [e2e](https://angular.io/cli/e2e) arguments", "default": "e2e", "advanced": true - }, - { - "name": "NG_E2E_REPORT_PATH", - "description": "path where e2e reports are stored", - "default": "reports/e2e", - "advanced": true } ] } diff --git a/templates/gitlab-ci-angular.yml b/templates/gitlab-ci-angular.yml index f92ba5d..755305c 100644 --- a/templates/gitlab-ci-angular.yml +++ b/templates/gitlab-ci-angular.yml @@ -50,10 +50,6 @@ variables: # Default Docker image for ANGULAR CLI (can be overridden) NG_CLI_IMAGE: trion/ng-cli-karma:latest - # JUnit test report - NG_JUNIT_TEST_REPORT_PATH: "reports/junit_test_report.xml" - NG_E2E_REPORT_PATH: "reports/e2e" - # Angular lint NG_LINT_ARGS: "lint" @@ -133,10 +129,10 @@ stages: function sonar_lint_report() { if [[ -n "$SONAR_URL" ]] then - mkdir -p reports + mkdir -p -m 777 reports # generate ts lint report in json for SONARqube # shellcheck disable=SC2086 - ng $NG_LINT_ARGS --format=json --force > reports/tslint-report.json + ng $NG_LINT_ARGS --format=json --force > reports/ng-lint.tslint.json fi } @@ -474,13 +470,13 @@ ng-build: coverage: '/^Statements\s*:\s*([^%]+)/' artifacts: reports: - junit: $NG_WORKSPACE_DIR/$NG_JUNIT_TEST_REPORT_PATH + junit: + - "$NG_WORKSPACE_DIR/reports/ng-test.xunit.xml" when: always # save artifact even if test failed name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" paths: - - $NG_WORKSPACE_DIR/coverage - $NG_WORKSPACE_DIR/dist - - $NG_WORKSPACE_DIR/reports + - $NG_WORKSPACE_DIR/reports/ng-*" expire_in: 1 day ############################################################################################### @@ -494,11 +490,11 @@ ng-e2e: - ng $NG_E2E_ARGS artifacts: reports: - junit: $NG_WORKSPACE_DIR/$NG_E2E_REPORT_PATH/junit*.xml + junit: $NG_WORKSPACE_DIR/reports/ng-e2e.xunit.xml when: always # save artifact even if test failed name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG" paths: - - $NG_WORKSPACE_DIR/$NG_E2E_REPORT_PATH + - $NG_WORKSPACE_DIR/reports/ng-e2e.* expire_in: 1 day rules: # only run if feature is enabled -- GitLab