diff --git a/canvas_modules/harness/.gitignore b/canvas_modules/harness/.gitignore index 6a8ba6303d..c0bba62f85 100644 --- a/canvas_modules/harness/.gitignore +++ b/canvas_modules/harness/.gitignore @@ -54,3 +54,6 @@ fingerprints.json # Pen test related pen-test/temp.json pen-test/cookies + +.nyc_output +instrumented \ No newline at end of file diff --git a/canvas_modules/harness/.nycrc b/canvas_modules/harness/.nycrc new file mode 100644 index 0000000000..7045f8a1aa --- /dev/null +++ b/canvas_modules/harness/.nycrc @@ -0,0 +1,25 @@ +{ + "extends": "@istanbuljs/nyc-config-babel", + "all": true, + "reporter": [ + "html", + "text-summary", + "l-cov" + ], + "include": [ + "src/**/*.js", + "../common-canvas/src" + ], + "instrument": true, + "sourceMap": true, + "require": [ + "./scripts/babel/babelOptions.js" + ], + "webpack": { + "config": [ + "./webpack.config.dev.js", + "./webpack.config.prod.js" + ] + } + +} \ No newline at end of file diff --git a/canvas_modules/harness/cypress.config.js b/canvas_modules/harness/cypress.config.js index 8ff0627a94..7a95ce16a0 100644 --- a/canvas_modules/harness/cypress.config.js +++ b/canvas_modules/harness/cypress.config.js @@ -12,13 +12,17 @@ module.exports = defineConfig({ e2e: { setupNodeEvents(on, config) { // `cy.log()` command's output can be seen on the screen along with test steps + require("@cypress/code-coverage/task")(on, config) on("task", { log(message) { console.log(message); /* eslint no-console: "off" */ return null; } }); + return config; }, baseUrl: "http://localhost:3001", + specPattern: "cypress/e2e/**/*.cy.{js,jsx,ts,tsx}", + supportFile: "cypress/support/e2e.js", }, }); diff --git a/canvas_modules/harness/cypress/support/e2e.js b/canvas_modules/harness/cypress/support/e2e.js index 654e4a86c0..8bf62c8d2c 100644 --- a/canvas_modules/harness/cypress/support/e2e.js +++ b/canvas_modules/harness/cypress/support/e2e.js @@ -31,6 +31,7 @@ import "./canvas/utils-cmds"; import "./canvas/verification-cmds"; import "./canvas/operation-cmds"; import "./canvas/palette-cmds"; +import "@cypress/code-coverage/support"; // turn off screenshots when running in headless mode. Cypress.Screenshot.defaults({ diff --git a/canvas_modules/harness/package.json b/canvas_modules/harness/package.json index 99e087eed3..d7d8b4434d 100644 --- a/canvas_modules/harness/package.json +++ b/canvas_modules/harness/package.json @@ -7,6 +7,7 @@ "start": "NODE_ENV=development node index.js", "build": "npx stylelint 'src/**/*.scss' 'assets/**/*.scss' && grunt", "test": "npx cypress open", + "coverage": "npx cypress run && npx nyc report --reporter=html --reporter=text-summary", "bundle-report": "NODE_ENV=production BUNDLE_REPORT=true grunt", "start-prod": "NODE_ENV=production node index.js", "build-prod": "npx stylelint 'src/**/*.scss' 'assets/**/*.scss' && NODE_ENV=production grunt --max-old-space-size=8192" @@ -36,12 +37,15 @@ "@babel/preset-react": "7.24.1", "@carbon/charts": "1.15.3", "@carbon/charts-react": "1.15.3", - "@carbon/react": "^1.52.0", + "@carbon/react": "1.52.0", + "@cypress/code-coverage": "3.12.39", "@elyra/canvas": "file:../common-canvas", + "@istanbuljs/nyc-config-babel": "3.0.0", "@pmmmwh/react-refresh-webpack-plugin": "0.5.11", "ajv": "8.12.0", "autoprefixer": "10.4.19", "babel-loader": "9.1.3", + "babel-plugin-istanbul": "6.1.1", "babel-plugin-lodash": "3.3.4", "css-loader": "6.10.0", "cypress": "13.7.3", @@ -63,6 +67,7 @@ "html-webpack-plugin": "5.6.0", "ibm-design-icons": "2.1.4", "mini-css-extract-plugin": "2.8.1", + "nyc": "17.0.0", "object-assign": "4.1.1", "path": "0.12.7", "postcss": "8.4.38", @@ -90,4 +95,4 @@ "webpack-hot-middleware": "2.26.1", "webpack-manifest-plugin": "5.0.0" } -} +} \ No newline at end of file diff --git a/canvas_modules/harness/scripts/babel/babelOptions.js b/canvas_modules/harness/scripts/babel/babelOptions.js index 00b8897550..8e96afece3 100644 --- a/canvas_modules/harness/scripts/babel/babelOptions.js +++ b/canvas_modules/harness/scripts/babel/babelOptions.js @@ -18,7 +18,7 @@ const babelOptions = { babelrc: false, // required so webpack ignores the .babelrc file used for testing in root of project presets: ["@babel/preset-react", "@babel/preset-env"], - plugins: ["lodash", "@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime"], + plugins: ["lodash", "@babel/plugin-proposal-class-properties", "@babel/plugin-transform-runtime", "istanbul"] }; exports.babelOptions = babelOptions; diff --git a/canvas_modules/harness/webpack.config.dev.js b/canvas_modules/harness/webpack.config.dev.js index 50bd1aaff7..4136e663d9 100644 --- a/canvas_modules/harness/webpack.config.dev.js +++ b/canvas_modules/harness/webpack.config.dev.js @@ -141,4 +141,4 @@ module.exports = { rules: rules }, plugins: plugins -}; +}; \ No newline at end of file diff --git a/canvas_modules/harness/webpack.config.prod.js b/canvas_modules/harness/webpack.config.prod.js index 279b8aefe6..15e3b28e78 100644 --- a/canvas_modules/harness/webpack.config.prod.js +++ b/canvas_modules/harness/webpack.config.prod.js @@ -131,4 +131,4 @@ module.exports = { rules: rules }, plugins: plugins -}; +}; \ No newline at end of file