Skip to content

Commit

Permalink
Update unit test with coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Sep 8, 2024
1 parent 08a24ac commit 532ea49
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 46 deletions.
15 changes: 13 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,21 @@ jobs:
run: npm ci

- name: Build project
run: npm run build # Assumes you have a build script in package.json
run: npm run build

- name: Test
run: npm test
run: |
npm test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info # cSpell: ignore lcov
#token: ${{ secrets.CODECOV_TOKEN }}
flags: unittests # cSpell: ignore unittests
name: relabeler-tests
verbose: true
fail_ci_if_error: true

- name: Create artifact
run: |
Expand Down
90 changes: 48 additions & 42 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,53 @@ pr:
- main

pool:
vmImage: 'ubuntu-latest'
vmImage: "ubuntu-latest"

steps:
- task: NodeTool@0
inputs:
versionSpec: '18.x'
displayName: 'Install Node.js'

- script: |
npm install
displayName: 'npm install'

- script: |
npm run build
displayName: 'npm build'

- script: |
npm test
displayName: 'npm test'

- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/TEST-*.xml'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'Cobertura' # cSpell: ignore Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/*coverage.xml'

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)/build'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true

- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'
- task: NodeTool@0
inputs:
versionSpec: "18.x"
displayName: "Install Node.js"

- script: |
npm install
displayName: "npm install"
- script: |
npm run build
displayName: "npm build"
- script: |
npm test
displayName: "npm test and coverage"
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: "JUnit"
testResultsFiles: "**/TEST-*.xml"

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: "Cobertura" # cSpell: ignore Cobertura
summaryFileLocation: "$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml"

- task: PublishPipelineArtifact@1
inputs:
targetPath: "$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml"
artifact: "coverage-report"
publishLocation: "pipeline"

- task: ArchiveFiles@2
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)/dist"
includeRootFolder: false
archiveType: "zip"
archiveFile: "$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip"
replaceExistingArchive: true

- task: PublishPipelineArtifact@1
inputs:
targetPath: "$(Build.ArtifactStagingDirectory)"
artifact: "build-artifact"
publishLocation: "pipeline"
36 changes: 36 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
coverage:
status:
project:
default:
# Thresholds for overall project coverage
target: 80% # Set your desired coverage target
threshold: 1% # Allowable drop in coverage
patch:
default:
# Thresholds for coverage of new changes
target: 80% # Set your desired coverage target for new changes
threshold: 5% # Allowable drop in coverage for new changes

comment:
layout: "reach, diff, flags, files"
behavior: default
require_changes: false

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

flags:
unittests:
paths:
- "src/"

# Exclude specific files or directories from coverage
ignore:
- "__tests__/"
- "node_modules/"
- "dist/"
4 changes: 2 additions & 2 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ export default {
},
collectCoverage: true,
coverageDirectory: 'coverage',
coverageReporters: ['cobertura', 'text'] // cSpell: ignore cobertura
};
coverageReporters: ['lcov', 'text', 'cobertura'], // Generates both LCOV and Cobertura reports
}; // cSpell: ignore lcov cobertura

0 comments on commit 532ea49

Please sign in to comment.