-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code coverage for cypress testing #2031
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Prince Sanchez <[email protected]>
Signed-off-by: Prince Sanchez <[email protected]>
@@ -0,0 +1,24 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.nycrc file is needed to configure NYC which generates code coverage reports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more details on this? For example how does webpack get used and is there any documentation on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this file and it doesn't seem to make a different in the result.
Signed-off-by: Prince Sanchez <[email protected]>
@@ -141,4 +141,4 @@ module.exports = { | |||
rules: rules | |||
}, | |||
plugins: plugins | |||
}; | |||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these files changed? Looks like an addition line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the webpack.config.dev.js and webpack.config.prod.js, I reverted them to their original state because I believe I added a comma in the previous commit last Thursday.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are still showing up as changed though.
Signed-off-by: Prince Sanchez <[email protected]>
… into cypress-fvt-testing
@@ -0,0 +1,24 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give more details on this? For example how does webpack get used and is there any documentation on this?
canvas_modules/harness/package.json
Outdated
"build": "npx stylelint 'src/**/*.scss' 'assets/**/*.scss' && grunt", | ||
"test": "npx cypress open", | ||
"test": "npx cypress open && npx cypress run", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially added the script to see if Cypress would open and run in the terminal simultaneously, but unfortunately, it didn't work as expected. I intended to revert the changes but it seems I have forgot to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not able to comment on your question above, but I did some more research and the .nycrc file configures NYC (Istanbul's CLI) for code coverage, specifying which files to include, exclude, and the reporting format. Webpack is used with Babel to instrument the code via babel-plugin-istanbul before bundling it. Here was the documentation for NYC https://github.com/istanbuljs/nyc, it can also be found on the cypress docs.
canvas_modules/harness/package.json
Outdated
"@pmmmwh/react-refresh-webpack-plugin": "0.5.11", | ||
"ajv": "8.12.0", | ||
"autoprefixer": "10.4.19", | ||
"babel-core": "6.26.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some research on both babel-core and @babel/register and found that they primarily ensure the code runs correctly in environments that don't natively support the latest JavaScript features. Since I was still able to generate code coverage without them, I went ahead and removed these dependencies from the project.
canvas_modules/harness/package.json
Outdated
@@ -34,14 +36,19 @@ | |||
"@babel/polyfill": "7.12.1", | |||
"@babel/preset-env": "7.24.3", | |||
"@babel/preset-react": "7.24.1", | |||
"@babel/register": "7.24.6", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
Signed-off-by: Prince Sanchez <[email protected]>
canvas_modules/harness/package.json
Outdated
@@ -5,8 +5,10 @@ | |||
"license": "Apache-2.0", | |||
"scripts": { | |||
"start": "NODE_ENV=development node index.js", | |||
"cypress:run": "cypress open", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we add this? We already run a similar cmd under test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was an extra script, so I went ahead and removed it to eliminate redundancy.
canvas_modules/harness/package.json
Outdated
@@ -62,7 +67,10 @@ | |||
"grunt-yamllint": "0.3.0", | |||
"html-webpack-plugin": "5.6.0", | |||
"ibm-design-icons": "2.1.4", | |||
"istanbul": "0.4.5", | |||
"istanbul-instrumenter-loader": "3.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that actually used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was still able to generate a coverage report without these, so I removed them
canvas_modules/harness/package.json
Outdated
@@ -62,7 +67,10 @@ | |||
"grunt-yamllint": "0.3.0", | |||
"html-webpack-plugin": "5.6.0", | |||
"ibm-design-icons": "2.1.4", | |||
"istanbul": "0.4.5", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this module. It says it's no longer maintained and shouldn't be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding your comment on generating a coverage report, I updated the 'coverage' script to: "coverage": "npx cypress run && npx nyc --reporter=html --reporter=text-summary". This way, when you run npm run coverage, it will execute all the tests. Once all 43 tests are finished, you can open coverage/index.html to view the report in the browser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work? I tried running npm run coverage
but that errors out.
If I want to see coverage reports what steps are needed?
Signed-off-by: Prince Sanchez <[email protected]>
… into cypress-fvt-testing
@@ -12,13 +12,17 @@ module.exports = defineConfig({ | |||
e2e: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add this file to be checked in linting. It should have flagged the new code since we don't use single quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is working as expected. This is giving code coverage for the test harness but what we really want is code coverage for common-canvas.
@@ -31,6 +31,7 @@ import "./canvas/utils-cmds"; | |||
import "./canvas/verification-cmds"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add the entire cypress directory. It should have flagged this well in the build.
@@ -0,0 +1,24 @@ | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this file and it doesn't seem to make a different in the result.
Signed-off-by: Prince Sanchez <[email protected]>
… into cypress-fvt-testing
Signed-off-by: Prince Sanchez <[email protected]>
Quality Gate passedIssues Measures |
Developer's Certificate of Origin 1.1