Comments (5)
Ran into this problem myself today. I think that the issue is really with the JsTestDriverSensor.java implementation from the sonar-javascript-plugin v2.8. That class has a method to get the test file names (AKA the "spec" file names). The method implementation cannot work when you have dots in the file name because it replaces all dots with "/". It does this because it assumes you are using dots as directory delimiters and that your file naming strategy is compatible with Java, (which doesn't allow dots in class names). Here is the method implementation I'm speaking of:
protected String getUnitTestFileName(String className) {
// For JsTestDriver assume notation com.company.MyJsTest that maps to com/company/MyJsTest.js
String fileName = getUnitTestClassName(className);
fileName = fileName.replace('.', File.separatorChar);
fileName = fileName + ".js";
return fileName;
}
from karma-junit-reporter.
Spent some time on this, found a way to make it work w/ john papa's guidelines.
In sonar-project.properties
, pull in the tests using the jstest
option, not the jstestdriver
:
# tell sonar our tests and source are intermingled
sonar.sources=src
sonar.tests=src
# spec.js files aren't "source"
sonar.exclusions=**/*.spec.js
# tests are spec.js files
sonar.test.inclusions=**/*.spec.js
# use the jstest sensor, look in the "tests" folder for results
sonar.javascript.jstest.reportsPath=tests/
jstest
doesn't do any transformations to the test name (see https://github.com/SonarCommunity/sonar-javascript/blob/master/sonar-javascript-plugin/src/main/java/org/sonar/plugins/javascript/unittest/jstest/JsTestSensor.java)
Then, in your tests, the first describe block has to match the path and filename exactly; so dir/subdir/avengers.controller.spec.js needs to start with describe('dir/subdir/avengers.controller.spec.js', ...)
Then, in your karma.conf.js, configure the junit reporter:
junitReporter: {
useBrowserName: false,
outputDir: 'tests',
outputFile: 'TESTS-results.xml' // sonarqube is looking for TESTS-*.xml
}
When you run tests, karma-junit-reporter will write a tests/TESTS-results.xml
file with XML that looks like:
<testcase name="does things" time="0.014" classname="dir/subdir/avengers.controller.spec.js"/>
With those in place, sonar-runner can read the xml, use the classname to find the path to the test, combines that with the sonar.tests
setting to produce the full path to test file, and then be happy.
from karma-junit-reporter.
thanks @ryepup. I ended up writing my own sonar plugin to handle the test report xml. My plugin does not require that the describe block have any particular name. I found it too restrictive and brittle to limit what developers could name the describe blocks. For anyone interested, see the free plugin I wrote here: https://github.com/acwatson/sonar-karma-test-report-plugin
from karma-junit-reporter.
Thank you @ryepup! I was trying to do this for a long time!
from karma-junit-reporter.
I see that sonar will use a new schema (see bug #78). I think that this problem should dissapear as soon as this new schema is implemented.
Is my analysis correct and of any help?
from karma-junit-reporter.
Related Issues (20)
- Question about CLA and License HOT 4
- License of XSD file HOT 1
- Project Lifetime HOT 2
- Readme should say to add module as a plugin in karma.conf.js HOT 1
- Where does 2.0.0 come from? HOT 1
- Testcase name must be escaped HOT 2
- Text string with emoji crashes the karma HOT 3
- npm audit vulnerability with xmlbuilder package HOT 1
- Please consider releasing a new version. HOT 1
- Suite (package) name is not prepended to the classname attribute in the testcase element
- How to give custom test suite name using karma junit reporter? HOT 2
- Replacement of Path-is-absolute dependency HOT 1
- Windows machines not reporting browser and OS HOT 2
- Warnings HOT 2
- false positive failure with junit on skipped tests
- Any word on 2.0.2
- sometimes junit-reported just doesn't generate reports HOT 11
- link at bottom of readme should point to .io
- Reestablish CI/CD with GitHub Actions
- Is the project still maintained? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-junit-reporter.