Code coverage for Chrome Extension e2e testing - google-chrome-extension

I am using WebdriverIO / mocha for the e2e automation testing of Chrome Extension. So, I wonder is there any way to do a code coverage e.g. by instrumenting a code using nyc tool? If yes, what would be the proper way to do so given that my Chrome extension source code in ./src and it is built to a webpack bundle in /.dist folder (which is then loaded in Chrome browser). Is ./src or a ./dist folder should be instrumented in that case?
Thanks in advance for any hint :)
I have also tried the devtools service which is part of WebdriverIO, but its code coverage feature does not work at the moment, because of the known bug.

Related

Testing web extension in CI with cypress

I want to add E2E tests to my web extension, using cypress, and run them on a CI.
Is that even possible?
The tests pass locally on $ cypress open, but fail on $cypress run
The extension adds an element to the dom and cypress can't find it (the extension doesn't seem to get loaded in headless mode)
Here's a reproducible repo with the most simple one line test:
https://github.com/goldylucks/cypress-test-tiny

How do I generate code coverage for some Node.JS code without tests?

I have a build/ folder that gets autogenerated by a babel process in a package.json. It has several .js files, including in sub-folders. In the root is a file, main.js, which is something of a demo / testbed for the project, that instantiates various ES6 classes and tries out various functions. It currently runs without crashing.
Call it a poor man's end-2-end test. I'm trying to move quickly with what could be throw away code.
I don't have any formal tests. I don't want to write any formal tests for this codebase. But I am interested in knowing how much of the code in build/ is being touched currently by my demo, main.js.
How can I generate a code coverage report for this scenario, using nyc?
If that's not actually easy (all tutorials I see seem to involve instrumenting pre-existing unit tests from a mainstream testing framework), what nyc alternative would make this easy?
I tried
npm install nyc --save-dev
npx nyc node build/main.js
but it claimed 0 lines/files.
With thanks to What is instrumentation in nyc istanbul?, it was actually simple. From the root, where my package.json and build/ folder were:
npx nyc instrument build coverage
npx nyc --reporter=text --report-dir=./nyc_output node build/main.js
all necessary folders (coverage, nyc_output) were auto-created (though it made .nyc_output/ for some reason)

Setup jest multi projects with create-react-app and node

My projects uses a /server folder for my backend code and /react-ui for my client side code. There's a package.json in each folder. I can run test separately in the cmd line, but I would like to run both at the same time. I know about the multi projects feature of jest, but it doesn't seem to work with create-react-app. I'm trying to setup jest with babel as if I was not using create-react-app, but it seems like the wrong approach considering jest is already setup in CRA.
My current setup runs from the /server jest installation. With projects: ['<rootDir>', '<rootDir>/../react-ui']. The jest documentation isn't clear how I could direct it to run npm test in /react-ui
My only goal is to be able to watch both at the same time and I would like to not eject from CRA.
You can have (gulp) scripts on the main level that run each tests separately, but using same configs.

mocha sidebar is not showing tests

I'm developing a very simple typescript project and I added a very tiny test with mocha. I installed mocha sidebar on VS Code and all it's dependencies, but test are not showing in the left panel.
The strange is that when I press debug button, my test run without problem (?)
I want to distribute this package on NPM, and only distribute .js, .d.ts, js.map and d.ts.map files.
I think the problem is in my project.json, but I cannot figure what is it. The source code is here
The only change I needed was in the VS code workspace settings: Under extensions I pointed the 'mocha glob files'-setting to my test scripts
One thing that I notice from your repo is you have package.json, test folder and another src folder inside type-exception/src.
I can run the mocha sidebar plugin successfully.
My solution is to open the project in vscode from the type-exception/src folder not type-exception folder.
My file structure
My mocha sidebar
I also saw that you have correct vscode workspace settings that set mocha files to
{
"mocha.files.glob": "lib/test/**/*.js"
}
Hope it helps
I had the Testing view showing Jest tests and realised that for Mocha I needed to install another VSCode Extension called "Mocha Test Explorer": https://marketplace.visualstudio.com/items?itemName=hbenl.vscode-mocha-test-adapter
Once installed I created/edited a .vscode/settings.json file in my project folder and added the following clues to tell Mocha to find my tests under the tests folder:
{
"mochaExplorer.files": "tests/**/*.ts"
}

Sonarqube not detecting LCOV report generated using mocha

I have created a simple project using Node.js, mocha and generated the report for code coverage and unit testing as follows:
mocha -R lcov --ui tdd > coverage/coverage.lcov
mocha -R xunit --ui tdd > coverage/TEST-all.xml
The reports generated using the sonar runner does not reflect the coverage on Sonarqube. The sample test javascript project using LCOV that ships with the sonar-examples-master as well shows 0% code coverage in Sonarqube.
The sonar properties set are as follows:
sonar.language=js
sonar.sourceEncoding=UTF-8
sonar.tests=test
sonar.javascript.jstestdriver.reportsPath=coverage
sonar.javascript.lcov.reportPath=coverage/coverage.lcov
sonar.dynamicAnalysis=reuseReports
Looking forward for inputs on how to resolve this issue and enable the SonarQube to report the coverage on an existing LCOV report.
Thanks,
Neo
JS Test Driver was removed as part of the Sonar Javascript 1.5 release, http://jira.codehaus.org/browse/SONARPLUGINS-3408
So I switched back to the 1.4 plugin.
Regarding the LCOV, I had to match the paths in the LCOV with sonar.sources path.
So
sonar.sources=webapp/app
LCOV was like
SF:webapp/app/path/to/js.js
Hope that helps, I can correct anything I might have gotten wrong tomorrow when I'm at work again.

Resources