CEC-1167 ota admin portal (#127)
* Add test coverage script * Remove unnecessary check * CEC-1167 unit test and code coverage * included sonar job * updated the workflow * updated sonar properties * updated sonar properties * updated sonar properties * updated sonar properties * updated sonar properties * updated sonar properties * updated sonar properties * updated sonar properties Co-authored-by: jwu-fisker <jwu@fiskerinc.com>
This commit is contained in:
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@@ -1,6 +1,7 @@
|
|||||||
name: Node.js CI
|
name: Node.js CI
|
||||||
|
|
||||||
on: [pull_request]
|
on: push
|
||||||
|
# [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
@@ -8,6 +9,9 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v2
|
uses: actions/setup-node@v2
|
||||||
with:
|
with:
|
||||||
@@ -15,6 +19,12 @@ jobs:
|
|||||||
cache: "npm"
|
cache: "npm"
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run build --if-present
|
- run: npm run build --if-present
|
||||||
- run: npm test
|
- run: npm test -- --coverage --coverageDirectory='coverage' --watchAll=false
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
|
- name: SonarCloud Scan
|
||||||
|
uses: sonarsource/sonarcloud-github-action@master
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -33,6 +33,7 @@
|
|||||||
"build:local": "env-cmd -f .env.local react-scripts build",
|
"build:local": "env-cmd -f .env.local react-scripts build",
|
||||||
"test": "env-cmd -f .env.local react-scripts test",
|
"test": "env-cmd -f .env.local react-scripts test",
|
||||||
"test:debug": "react-scripts --inspect-brk test --runInBand --no-cache",
|
"test:debug": "react-scripts --inspect-brk test --runInBand --no-cache",
|
||||||
|
"test:coverage": "npm test -- --coverage --watchAll=false --no-cache",
|
||||||
"eject": "react-scripts eject"
|
"eject": "react-scripts eject"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
@@ -53,6 +54,15 @@
|
|||||||
"react-test-renderer": "^17.0.2"
|
"react-test-renderer": "^17.0.2"
|
||||||
},
|
},
|
||||||
"jest": {
|
"jest": {
|
||||||
"globalSetup": "./testEnv.js"
|
"globalSetup": "./testEnv.js",
|
||||||
|
"collectCoverageFrom": [
|
||||||
|
"src/**/*.{js,jsx,ts,tsx}"
|
||||||
|
],
|
||||||
|
"coverageReporters": [
|
||||||
|
"html",
|
||||||
|
"json",
|
||||||
|
"lcov",
|
||||||
|
"cobertura"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
6
sonar-project.properties
Normal file
6
sonar-project.properties
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
sonar.projectKey=Fisker-Inc_ota-admin-portal
|
||||||
|
sonar.organization=fisker-inc
|
||||||
|
sonar.sourceEncoding=UTF-8
|
||||||
|
sonar.javascript.coveragePlugin=lcov
|
||||||
|
sonar.javascript.lcov.reportPaths=coverage/lcov.info
|
||||||
|
sonar.sources=src
|
||||||
@@ -3,11 +3,8 @@ import { TEST_TOKEN } from "./testing";
|
|||||||
|
|
||||||
describe("JWT Helper", () => {
|
describe("JWT Helper", () => {
|
||||||
it("Should decode", () => {
|
it("Should decode", () => {
|
||||||
const start = Date.now()
|
|
||||||
const v = parsePayload(TEST_TOKEN);
|
const v = parsePayload(TEST_TOKEN);
|
||||||
const diff = Date.now() - start;
|
|
||||||
|
|
||||||
expect(diff < 2).toBeTruthy();
|
|
||||||
expect(typeof v).toEqual("object");
|
expect(typeof v).toEqual("object");
|
||||||
expect(v.exp).toBeTruthy();
|
expect(v.exp).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user