Skip to content

Commit

Permalink
Merge pull request #2717 from pnaik1/RHOAIENG-2500
Browse files Browse the repository at this point in the history
added Cypress test coverage
  • Loading branch information
openshift-merge-bot[bot] authored Apr 18, 2024
2 parents c5d5d2b + 8c911d4 commit 0f07306
Show file tree
Hide file tree
Showing 7 changed files with 355 additions and 163 deletions.
1 change: 0 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# testing
/coverage
/cypress-coverage
/jest-coverage
/test-results/
/public-cypress
Expand Down
6 changes: 6 additions & 0 deletions frontend/config/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ const DIST_DIR = process.env._ODH_DIST_DIR;
const OUTPUT_ONLY = process.env._ODH_OUTPUT_ONLY;
const ODH_FAVICON = process.env.ODH_FAVICON;
const ODH_PRODUCT_NAME = process.env.ODH_PRODUCT_NAME;
const COVERAGE = process.env.COVERAGE;

if (OUTPUT_ONLY !== true) {
console.info(
`\nPrepping files...\n SRC DIR: ${SRC_DIR}\n OUTPUT DIR: ${DIST_DIR}\n PUBLIC PATH: ${PUBLIC_PATH}\n`,
);
}

if (COVERAGE === 'true') {
console.info('\nAdding code coverage instrumentation.\n');
}

module.exports = (env) => {
return {
entry: {
Expand All @@ -32,6 +37,7 @@ module.exports = (env) => {
test: /\.(tsx|ts|jsx|js)?$/,
include: [SRC_DIR, COMMON_DIR],
use: [
COVERAGE === 'true' && '@jsdevtools/coverage-istanbul-loader',
{
loader: 'ts-loader',
options: {
Expand Down
495 changes: 334 additions & 161 deletions frontend/package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
"test:jest:coverage": "jest --coverage",
"test:unit": "npm run test:jest",
"test:cypress-ci": "npx concurrently -P -k -s first \"npm run cypress:server:build && npm run cypress:server\" \"npx wait-on tcp:127.0.0.1:9001 && npm run cypress:run:mock -- {@}\" -- ",
"coverage:merge": "istanbul-merge --out coverage/coverage-final.json jest-coverage/coverage-final.json cypress-coverage/coverage-final.json && nyc report --reporter html --reporter text -t coverage --report-dir coverage/report",
"coverage:merge": "istanbul-merge --out coverage/coverage-final.json jest-coverage/coverage-final.json src/__tests__/cypress/coverage/coverage-final.json && nyc report --reporter html --reporter text -t coverage --report-dir coverage/report",
"cypress:open": "cypress open --project src/__tests__/cypress",
"cypress:run": "cypress run -b chrome --project src/__tests__/cypress",
"cypress:open:mock": "MOCK=1 WS_PORT=9002 npm run cypress:open -- ",
"cypress:run:mock": "MOCK=1 WS_PORT=9002 npm run cypress:run -- ",
"cypress:run:mock:coverage": "rimraf src/__tests__/cypress/coverage src/__tests__/cypress/.nyc_output && COVERAGE=true npm run cypress:run:mock",
"cypress:open:record": "RECORD=1 npm run cypress:open",
"cypress:run:record": "RECORD=1 npm run cypress:run && npm run cypress:format",
"cypress:server:build": "ODH_DIST_DIR=./public-cypress POLL_INTERVAL=9999999 FAST_POLL_INTERVAL=9999999 WS_HOSTNAME=localhost:9002 npm run build",
"cypress:server:build:coverage": "COVERAGE=true npm run cypress:server:build",
"cypress:server": "serve ./public-cypress -p 9001 -s -L",
"cypress:server:dev": "POLL_INTERVAL=9999999 FAST_POLL_INTERVAL=9999999 ODH_PORT=9001 WS_HOSTNAME=localhost:9002 npm run start:dev",
"cypress:format": "prettier --write src/__tests__/**/*.snap.json"
Expand Down Expand Up @@ -87,6 +89,8 @@
},
"devDependencies": {
"@babel/core": "^7.21.0",
"@cypress/code-coverage": "^3.12.34",
"@jsdevtools/coverage-istanbul-loader": "^3.0.5",
"@testing-library/cypress": "^10.0.1",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "^6.3.0",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/__tests__/cypress/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
cypress/downloads
cypress/screenshots
coverage
.nyc_output
7 changes: 7 additions & 0 deletions frontend/src/__tests__/cypress/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'path';
import fs from 'fs';
import { defineConfig } from 'cypress';
import dotenv from 'dotenv';
import coverage from '@cypress/code-coverage/task';
import { interceptSnapshotFile } from '~/__tests__/cypress/cypress/utils/snapshotUtils';
import { setup as setupWebsockets } from '~/__tests__/cypress/cypress/support/websockets';

Expand All @@ -23,6 +24,10 @@ export default defineConfig({
PASSWORD: process.env.PASSWORD,
RECORD: !!process.env.RECORD,
WS_PORT: process.env.WS_PORT,
coverage: !!process.env.COVERAGE,
codeCoverage: {
exclude: [path.resolve(__dirname, '../../third_party/**')],
},
},
defaultCommandTimeout: 10000,
e2e: {
Expand All @@ -34,6 +39,7 @@ export default defineConfig({
: `cypress/e2e/**/*.(s)?cy.ts`,
experimentalInteractiveRunEvents: true,
setupNodeEvents(on, config) {
coverage(on, config);
setupWebsockets(on, config);
on('task', {
readJSON(filePath: string) {
Expand Down Expand Up @@ -75,6 +81,7 @@ export default defineConfig({
}
});
}
return config;
},
},
});
1 change: 1 addition & 0 deletions frontend/src/__tests__/cypress/cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { mockDashboardConfig, mockStatus } from '~/__mocks__';
import { ODHDashboardConfigModel } from '~/__tests__/cypress/cypress/utils/models';
import './commands';
import { addCommands as webSocketsAddCommands } from './websockets';
import '@cypress/code-coverage/support';

chai.use(chaiSubset);

Expand Down

0 comments on commit 0f07306

Please sign in to comment.