Commit fc24665e authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

feat: normalize reports

parent 1c3a1593
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ This job is bound to the `build` stage, and uses the following variables:
| `NODE_BUILD_ARGS`             | npm [run script](https://docs.npmjs.com/cli/v8/commands/npm-run-script) arguments <br/> yarn [run script](https://classic.yarnpkg.com/en/docs/cli/run) arguments  | `run build --prod`    |
| `NODE_TEST_ARGS`              | npm [test](https://docs.npmjs.com/cli/v8/commands/npm-test) arguments <br/> yarn [test](https://classic.yarnpkg.com/en/docs/cli/test) arguments                   | `test -- --coverage`  |

The job generates a unit test report that you will find here: `NODE_PROJECT_DIR/reports/unit_test_report.xml`.
The job generates a unit test report that you will find here: `NODE_PROJECT_DIR/reports/node-test.xunit.xml`.

#### Unit testing with Jest

@@ -79,9 +79,9 @@ For coverage, Jest comes built-in with **Istanbul** package. So no need for extr
},
```

##### Junit Report
##### JUnit Report

By default Jest doesn't generate any test report supported by GitLab. To do so you need to use the [jest-junit](https://www.npmjs.com/package/jest-junit) package.
By default Jest doesn't generate any test report supported by GitLab. To do so, you need to use the [jest-junit](https://www.npmjs.com/package/jest-junit) package.

Add the package as a development dependency:

@@ -100,7 +100,7 @@ Then update your `jest.config.js` or `package.json` as follows:
            "jest-junit",
            {
                "outputDirectory": "reports",
                "outputName": "unit_test_report.xml"
                "outputName": "node-test.xunit.xml"
            }
        ]
    ]
@@ -108,9 +108,9 @@ Then update your `jest.config.js` or `package.json` as follows:
},
```

##### Sonar report
##### SonarQube report

By default Jest doesn't generate any test report supported by Sonar. To do so you need to use the [jest-sonar](https://www.npmjs.com/package/jest-sonar) package.
By default Jest doesn't generate any test report supported by SonarQube. To do so, you need to use the [jest-sonar](https://www.npmjs.com/package/jest-sonar) package.

Add the package as a development dependency:

@@ -129,14 +129,14 @@ Then update your `jest.config.js` or `package.json` as follows:
            "jest-junit",
            {
                "outputDirectory": "reports",
                "outputName": "unit_test_report.xml"
                "outputName": "node-test.xunit.xml"
            }
        ],
        [
            "jest-sonar",
            {
                "outputDirectory": "reports",
                "outputName": "sonar_test_report.xml"
                "outputName": "node-test.sonar.xml"
            }
        ]
    ],
@@ -168,7 +168,7 @@ Then update your `package.json` as follows:
}
```

##### Junit report
##### JUnit report

By default Mocha doesn't generate any test report supported by GitLab. To do so you need to use the [mocha-junit-reporter](https://www.npmjs.com/package/mocha-junit-reporter) package.

@@ -183,11 +183,11 @@ Then update your `package.json` as follows:
```js
"scripts": {
  "test": "npm run mocha",
  "mocha": "nyc mocha app/tests/*.test.js --reporter spec --reporter mocha-junit-reporter --reporter-options mochaFile=./reports/unit_test_report.xml",
  "mocha": "nyc mocha app/tests/*.test.js --reporter spec --reporter mocha-junit-reporter --reporter-options mochaFile=./reports/node-test.xunit.xml",
}
```

##### Sonar report
##### SonarQube report

Mocha provides XUnit reporter which is compatible with SonarQube. So no need for extra dependency, just add this parameter `--reporter-option`

@@ -196,7 +196,7 @@ Then update your `package.json` as follows:
```js
"scripts": {
  "test": "npm run mocha",
  "mocha": "nyc mocha app/tests/*.test.js --reporter-option output=./reports/sonar_test_report.xml",
  "mocha": "nyc mocha app/tests/*.test.js --reporter-option output=./reports/node-test.sonar.xml",
}
```

@@ -223,9 +223,9 @@ sonar.tests=.
sonar.test.inclusions=**/*.test.js

# tests report: generic format
sonar.testExecutionReportPaths=reports/sonar_test_report.xml
sonar.testExecutionReportPaths=reports/node-test.sonar.xml
# lint report: ESLint JSON
sonar.eslint.reportPaths=reports/eslint-report.json
sonar.eslint.reportPaths=reports/node-lint.xslint.json
# coverage report: LCOV format
sonar.javascript.lcov.reportPaths=reports/lcov.info
```
@@ -244,9 +244,9 @@ sonar.tests=src
sonar.test.inclusions=**/*.spec.ts

# tests report: generic format
sonar.testExecutionReportPaths=reports/sonar_test_report.xml
sonar.testExecutionReportPaths=reports/node-test.sonar.xml
# lint report: TSLint JSON
sonar.typescript.tslint.reportPaths=reports/tslint-report.json
sonar.typescript.tslint.reportPaths=reports/node-lint.xslint.json
# coverage report: LCOV format
sonar.typescript.lcov.reportPaths=reports/lcov.info
```
+16 −40
Original line number Diff line number Diff line
@@ -102,16 +102,6 @@ stages:
    fi
  }

  function sonar_lint_report() {
    if [[ -n "$SONAR_URL" ]]
    then
      mkdir -p -m 777 reports
      # generate eslint report in json for SonarQube
      # shellcheck disable=SC2086
      $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/eslint-report.json
    fi
  }

  function install_ca_certs() {
    certs=$1
    if [[ -z "$certs" ]]
@@ -271,6 +261,15 @@ stages:
    fi
  }

  function sonar_lint_report() {
    if [[ -n "$SONAR_URL" ]]
    then
      mkdir -p -m 777 reports
      # generate eslint report in json for SonarQube
      # shellcheck disable=SC2086
      $NODE_MANAGER $NODE_LINT_ARGS -- --format=json --output-file=reports/node-lint.xslint.json
    fi
  }

  unscope_variables

@@ -310,7 +309,6 @@ stages:
      ;;
      esac


node-build:
  extends: .node-base
  stage: build
@@ -321,12 +319,14 @@ node-build:
  coverage: '/^All files\s*\|\s*(\d+(?:\.\d+)?)/'
  artifacts:
    reports:
      junit: $NODE_PROJECT_DIR/reports/unit_test_report.xml
      junit: $NODE_PROJECT_DIR/reports/node-test.xunit.xml
    when: always
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    paths:
      - $NODE_PROJECT_DIR/$NODE_BUILD_DIR
      - $NODE_PROJECT_DIR/reports/
      - $NODE_PROJECT_DIR/reports/node-test.*
      - $NODE_PROJECT_DIR/reports/node-coverage.*
      - $NODE_PROJECT_DIR/reports/lcov.info
    expire_in: 1 day
  rules:
    # always if $NODE_BUILD_DISABLED not set
@@ -345,7 +345,7 @@ node-lint:
    when: always # store artifact even if test Failed
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    paths:
      - $NODE_PROJECT_DIR/reports/
      - $NODE_PROJECT_DIR/reports/node-lint.xslint.json
    expire_in: 1 day
  rules:
    # exclude if $NODE_LINT_ENABLED unset
@@ -363,19 +363,7 @@ node-audit:
  extends: .node-base
  stage: test
  script:
    - mkdir -p -m 777 reports
    - |
      if ! $NODE_MANAGER audit $NODE_AUDIT_ARGS
      then
        # failed: also generate JSON report
        $NODE_MANAGER audit --json $NODE_AUDIT_ARGS > reports/audit-report.json
      fi
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
    when: always
    paths:
      - $NODE_PROJECT_DIR/reports/
    - $NODE_MANAGER audit $NODE_AUDIT_ARGS
  rules:
    # exclude if $NODE_AUDIT_DISABLED set
    - if: '$NODE_AUDIT_DISABLED == "true"'
@@ -387,19 +375,7 @@ node-outdated:
  extends: .node-base
  stage: test
  script:
    - mkdir -p -m 777 reports
    - |
      if ! $NODE_MANAGER outdated $NODE_OUTDATED_ARGS
      then
        # failed: also generate JSON report
        $NODE_MANAGER outdated --json $NODE_OUTDATED_ARGS > reports/outdated-report.json
      fi
  artifacts:
    name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
    expire_in: 1 day
    when: always
    paths:
      - $NODE_PROJECT_DIR/reports/
    - $NODE_MANAGER outdated $NODE_OUTDATED_ARGS
  rules:
    # exclude if $NODE_OUTDATED_DISABLED set
    - if: '$NODE_OUTDATED_DISABLED == "true"'