Skip to content

Commit

Permalink
test: add checking the coverage report (stakwork#350)
Browse files Browse the repository at this point in the history
* test: add checking the coverage report

* fix: add timeout

* test: add an action for coverage report

* fix: add a name to the task

* test: add version of the action to actions

* fix: fix action

* test: test coverage script

* fix: test actions

* fix: change action run for instrument the code for code coverage

* fix: update gitignore

* fix: reinstall deps

* fix: eslint

---------

Co-authored-by: Github Actions <[email protected]>
  • Loading branch information
maradondt and Github Actions authored Jul 26, 2023
1 parent 053fd1c commit 76f98ae
Show file tree
Hide file tree
Showing 13 changed files with 919 additions and 412 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
with:
install-command: yarn --immutable
browser: chrome
start: yarn run build-preview-e2e
start: yarn run start-e2e
wait-on: 'http://localhost:3000' # Waits for above
wait-on-timeout: 120 # Waits for 2 minutes
# Records to Cypress Dashboard
Expand All @@ -37,3 +37,6 @@ jobs:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# created by the GH Action automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check the coverage value
run: yarn test-coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/coverage
/cypress/videos
/cypress/screenshots
/.nyc_output

# production
build/
Expand Down
288 changes: 144 additions & 144 deletions build/assets/index-9e3ca490.js → build/assets/index-c9cf93ba.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Second Brain</title>
<script type="module" crossorigin src="/assets/index-9e3ca490.js"></script>
<script type="module" crossorigin src="/assets/index-c9cf93ba.js"></script>
<link rel="stylesheet" href="/assets/index-43d18007.css">
</head>
<body style="background: #000">
Expand Down
12 changes: 11 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
import { defineConfig } from 'cypress'

export default defineConfig({
env: {
codeCoverage: {
exclude: "cypress/**/*.*",
},
},
e2e: {
baseUrl: 'http://localhost:3000',
defaultCommandTimeout: 10000,
pageLoadTimeout: 90000,
requestTimeout: 60000,
responseTimeout: 60000,
setupNodeEvents(on, config) {
// implement node event listeners here
require('@cypress/code-coverage/task')(on, config)
// include any other plugin code...

// It's IMPORTANT to return the config object
// with any changed environment variables
return config
},
viewportHeight: 900,
viewportWidth: 1440,
Expand Down
63 changes: 63 additions & 0 deletions cypress/coverageTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable no-throw-literal */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable no-console */
const { exec } = require('child_process')
const { readFileSync } = require('fs')
const path = require('path')

const getPackageJSON = () => {
const packageJSONPath = path.join(__dirname, '../package.json')
const packageJsonFile = readFileSync(packageJSONPath)
const data = JSON.parse(packageJsonFile)

return data
}

const getCoverageReportValue = () =>
new Promise((res, rej) => {
exec('npx nyc report --reporter=text-summary', (err, stdout, stderr) => {
if (err) {
rej(stderr || err)
}

try {
const summaryRegexp = /\d{2}.\d{1}/
const coverageReportValueString = stdout.match(summaryRegexp)?.[0]
const coverageValueNumber = parseFloat(coverageReportValueString)

if (!coverageValueNumber) {
console.error('coverageValueNumber was parsed incorrectly')
process.exit(1)
}

res(coverageValueNumber)
} catch (e) {
rej(e)
}
})
})

;(async () => {
const data = getPackageJSON()
const minCoverageValue = data.coverage.min

console.log('🚀 required coverage', minCoverageValue)

if (!minCoverageValue) {
console.error('minCoverageValue from package.json was parsed incorrectly')
process.exit(1)
}

const valueReportValue = await getCoverageReportValue()

console.log('🚀 coverage report value', valueReportValue)

if (valueReportValue < minCoverageValue) {
console.error('Project test coverage less then required')
process.exit(1)
}

console.log('Coverage is good')
})()

process.on('exit', (code) => console.error(`exiting the code ${code}`))
1 change: 1 addition & 0 deletions cypress/e2e/graph/searchAndRender.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('Search and render / Home interactions', () => {
},
{
fixture: 'search.json',
delay: 1000,
},
).as('search')

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/sourcesTable/sourcesTable.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('Sources Table / Home interactions', () => {
},
).as('radar')

cy.wait(5000)
cy.get(actionMenu).click({ waitForAnimations: false })
cy.get(openSourceBtn).click({ waitForAnimations: false })
cy.wait('@radar')
Expand Down
5 changes: 4 additions & 1 deletion cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
// require('./commands')

// coverage
import '@cypress/code-coverage/support'
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"build-preview-e2e": "VITE_APP_IS_E2E=true yarn run build && vite preview --port 3000",
"test": "NODE_ENV=test yarn jest",
"test-start": "yarn jest --watch",
"test-coverage": "node ./cypress/coverageTest.js",
"cy-open": "cypress open",
"cy-run": "cypress run",
"format": "prettier --write --config prettier.config.js ./src",
Expand Down Expand Up @@ -131,6 +132,7 @@
"@babel/preset-typescript": "^7.21.5",
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
"@cypress/code-coverage": "^3.11.0",
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand All @@ -149,7 +151,7 @@
"@typescript-eslint/parser": "^5.27.1",
"@vitejs/plugin-react": "^4.0.0",
"babel-plugin-transform-vite-meta-env": "^1.0.3",
"cypress": "^12.2.0",
"cypress": "12.16.0",
"eslint": "^8.41.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -173,12 +175,21 @@
"vite": "^4.3.9",
"vite-compatible-readable-stream": "^3.6.1",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-istanbul": "^4.1.0",
"vite-plugin-node-polyfills": "^0.8.2",
"vite-plugin-svgr": "^3.2.0",
"vite-tsconfig-paths": "^4.2.0"
},
"packageManager": "[email protected]",
"engines": {
"node": ">=16.0.0"
},
"nyc": {
"reporter": [
"html"
]
},
"coverage": {
"min": 65
}
}
2 changes: 1 addition & 1 deletion src/components/App/Helper/AskQuestion/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const AskQuestion = () => {
</Flex>
<ResponsesWrapper>
{askedQuestions?.map((item, index) => (
<Flex key={`${item}`} className="response" py={12}>
<Flex key={item} className="response" py={12}>
<Text kind="medium">{item}</Text>
<Flex py={12}>
{askedQuestionsAnswers?.[index] !== undefined ? (
Expand Down
18 changes: 17 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfil
import react from '@vitejs/plugin-react'
import { isArray, mergeWith } from 'lodash'
import rollupNodePolyFill from 'rollup-plugin-node-polyfills'
import istanbul from 'vite-plugin-istanbul'

import builtins from 'rollup-plugin-node-builtins'
import { UserConfigExport, defineConfig, loadEnv } from 'vite'
import { defineConfig, loadEnv, UserConfigExport } from 'vite'
import eslint from 'vite-plugin-eslint'
import svgrPlugin from 'vite-plugin-svgr'
import viteTsconfigPaths from 'vite-tsconfig-paths'
Expand All @@ -19,6 +20,8 @@ const commonConfigOptions = ({ mode }: { mode: Mode }): UserConfigExport => {
crypto: 'crypto-browserify',
},
},
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
plugins: [react(), viteTsconfigPaths(), svgrPlugin(), eslint(), builtins({ crypto: false })],
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
Expand Down Expand Up @@ -50,6 +53,19 @@ const devConfigOptions: UserConfigExport = {
server: {
open: true,
},
plugins: [
...(process.env.VITE_APP_IS_E2E
? [
istanbul({
include: 'src/*',
exclude: ['node_modules', 'test/'],
extension: ['.js', '.ts', '.jsx', '.tsx'],
requireEnv: false,
cypress: true,
}),
]
: []),
],
},
customizer,
),
Expand Down
Loading

0 comments on commit 76f98ae

Please sign in to comment.