Skip to content

Commit

Permalink
initial script for jest to sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshshinde2012 committed May 12, 2024
1 parent 21e309f commit 989a771
Show file tree
Hide file tree
Showing 25 changed files with 5,562 additions and 1 deletion.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
project: './tsconfig.json',
},
plugins: ['@typescript-eslint', 'prettier'],
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
rules: {
'prettier/prettier': 'error',
'@typescript-eslint/explicit-module-boundary-types': 'off',
},
};
4 changes: 4 additions & 0 deletions .github/codeql/codeql-configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name : CodeQL Configuration

paths:
- './src'
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main

jobs:
CI:
strategy:
matrix:
node-version: [18.x]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up nodejs version ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Clean Cache
run: npm cache clean --force
- name: Install package
run: npm install
- name: Build
run: npm run build --if-present
- name: Test
run: npm run test
- name: Test & publish code coverage
uses: paambaati/codeclimate-action@v6.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
with:
coverageLocations: |
${{github.workspace}}/coverage/*.info:lcov
${{github.workspace}}/coverage/clover.xml:clover
debug: true
72 changes: 72 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ main ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
schedule:
- cron: '17 10 * * 2'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'javascript' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
config-file: ./.github/codeql/codeql-configuration.yml
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
42 changes: 42 additions & 0 deletions .github/workflows/njsscan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# This workflow integrates njsscan with GitHub's Code Scanning feature
# nodejsscan is a static security code scanner that finds insecure code patterns in your Node.js applications

name: njsscan sarif

on:
push:
branches: [ "main", "dev" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "main", "dev" ]
schedule:
- cron: '30 7 * * 0'

permissions:
contents: read

jobs:
njsscan:
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
runs-on: ubuntu-latest
name: njsscan code scanning
steps:
- name: Checkout the code
uses: actions/checkout@v4
- name: nodejsscan scan
id: njsscan
uses: ajinabraham/njsscan-action@d58d8b2f26322cd35a9efb8003baac517f226d81
with:
args: '. --sarif --output results.sarif || true'
- name: Upload njsscan report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif
20 changes: 20 additions & 0 deletions .github/workflows/snyk-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Snyk Scan
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Snyk Scan
uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
24 changes: 24 additions & 0 deletions .github/workflows/sonarcloud-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: SonarCloud Scan
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
with:
args: >
-Dsonar.javascript.lcov.reportPaths= ${{github.workspace}}/coverage/lcov.info
-Dsonar.testExecutionReportPaths= ${{github.workspace}}/test-report.xml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.idea/
.vscode/
node_modules/
build/
dist/
tmp/
temp/
logs
coverage/
coverage/lcov-report
coverage/coverage-final.json
coverage/clover.xml
/.nyc_output/
logs/
**/.DS_Store
test-report.xml
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm test
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run prepush
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore artifacts:
build
dist
coverage

# Ignore all HTML files:
*.html

.gitignore
.prettierignore
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"semi": true,
"useTabs": false,
"tabWidth": 2,
"printWidth": 120,
"trailingComma": "all",
"arrowParens": "always"
}
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Contributing

You can help this project by reporting bugs, asking for features, or sending in pull requests.

### Creating a pull request

1. Fork the repo on GitHub
2. Clone and make changes on your machine
3. Commit and Push the changes to your fork
4. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest change from "upstream" before making a pull request
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# jest-to-sonar
Convert the Jest test case report to a Sonar generic test execution report. 
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=santoshshinde2012_jest-to-sonar&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=santoshshinde2012_jest-to-sonar)![Github action workflow status](https://github.com/santoshshinde2012/jest-to-sonar/actions/workflows/node.js.yml/badge.svg?branch=main)![CodeQL](https://github.com/santoshshinde2012/jest-to-sonar/actions/workflows/codeql-analysis.yml/badge.svg?branch=main)![njsscan Analysis](https://github.com/santoshshinde2012/jest-to-sonar/actions/workflows/njsscan.yml/badge.svg?branch=main)![Maintainability](https://api.codeclimate.com/v1/badges/25a158be62f89833fcda/maintainability)![Test Coverage](https://api.codeclimate.com/v1/badges/25a158be62f89833fcda/test_coverage)

Convert the Jest test case report to a Sonar generic test execution report.

### Contribution

[Contribution guidelines for this project](CONTRIBUTING.md)

You can help this project by reporting bugs, asking for features, or sending in pull requests.

<hr/>

### Connect with me on
<div id="badges">
<a href="https://twitter.com/shindesan2012">
<img src="https://img.shields.io/badge/shindesan2012-black?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter Badge"/>
</a>
<a href="https://www.linkedin.com/in/shindesantosh/">
<img src="https://img.shields.io/badge/shindesantosh-blue?style=for-the-badge&logo=linkedin&logoColor=white" alt="LinkedIn Badge"/>
</a>
<a href="https://blog.santoshshinde.com/">
<img src="https://img.shields.io/badge/Blog-black?style=for-the-badge&logo=medium&logoColor=white" alt="Medium Badge"/>
</a>
<a href="https://www.buymeacoffee.com/santoshshin" target="_blank">
<img src="https://img.shields.io/badge/buymeacoffee-black?style=for-the-badge&logo=buymeacoffee&logoColor=white" alt="Buy Me A Coffee"/>
</a>
</div>
16 changes: 16 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
preset: 'ts-jest',
roots: ['./tests'],
coveragePathIgnorePatterns: ['/node_modules/', '/tests/'],
collectCoverage: true,
reporters: [
'default',
[
'./dist/index.js',
{
outputFile: 'test-report.xml',
},
],
],
testEnvironment: 'node',
};
Loading

0 comments on commit 989a771

Please sign in to comment.