-
Notifications
You must be signed in to change notification settings - Fork 2
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
build: enable sonarcloud checks #109
Conversation
756738a
to
29a0c22
Compare
29a0c22
to
3add9a1
Compare
954cc8b
to
1ca3c7a
Compare
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.
Wow must have been tedious.
client/src/test/extension.test.ts
Outdated
assert.notStrictEqual(languages.length, 0); | ||
assert.notStrictEqual(languages.indexOf('yml'), -1); | ||
expect(languages).not.toBeNull(); | ||
expect(languages.length).not.toBe(0); |
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.
Nothing like expect(x).toBeEmpty()
? Just asking xD
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.
It seems it doesn't exist. Maybe I can use is([])
instead?
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.
Nonono, it’s OK.
client/src/test/index.ts
Outdated
import { runCLI } from 'jest-cli'; | ||
import path = require('path'); | ||
|
||
const jestTestRunnerForVSCodeE2E: ITestRunner = { |
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.
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.
E2E → End to End; You can check this article for more information. It's the one from the first comment.
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 know what are recommendations for vscode extensions' testing.
This file seems to be the main input to launch tests, but isn't it possible to directly provide the jest command as a TestRunner ?
sonar-project.properties
Outdated
## | ||
## Duplications | ||
## | ||
# Increase minimum lines for code duplications triggering (default = 10) |
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.
Reason for the increase? 20 seems a bit much.
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.
No good reason for the increase. Just a copy-paste.
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.
Try to reset (if not done already) and see if it puts us in dire straits or not. The default value – or even something lower xD – would be nice.
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.
It was a need to allow specific patterns on AA; default values are sufficient I think.
I will try to give a try to microsoft/vscode-test#37. |
babel.config.js
Outdated
node: "current", | ||
}, | ||
}], | ||
+"@babel/preset-typescript", |
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.
Isn't the +
weird, right ?
client/package.json
Outdated
}, | ||
"dependencies": { | ||
"@types/jest": "^24.0.18", |
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.
You can move it to devDependencies
client/package.json
Outdated
"glob": "^7.1.4", | ||
"mocha": "^5.2.0", | ||
"jest-cli": "^24.9.0", |
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.
You can directly use the jest
dep which simply wraps the jest-cli
client/src/test/extension.test.ts
Outdated
const ymlExtension = vscode.extensions.all.find((extension) => { | ||
return extension.id === YML_EXTENSION_ID; | ||
}); | ||
assert.notStrictEqual(ymlExtension, null); | ||
assert.strictEqual(ymlExtension.isActive, false); | ||
expect(ymlExtension).not.toBeNull(); |
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.
you can do something like expect(ymlExtension).toBeDefined();
to also check undefined values
client/src/test/extension.test.ts
Outdated
ymlExtension | ||
.activate() | ||
.then(() => { | ||
assert.strictEqual(ymlExtension.isActive, true); | ||
expect(ymlExtension.isActive).toBeTruthy(); |
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.
you can do the done()
just after this expect()
myPromise.then(() => {
expect(ymlExtension.isActive).toBeTruthy();
done();
})
and jest also supports promises as returned type.
It allows to avoid using the done
mechanism.
return myPromise.then(() => {
expect(ymlExtension.isActive).toBeTruthy();
})
sonar-project.properties
Outdated
# sonar.typescript.tslint.reportPaths=target/lint/tslint-report.json | ||
|
||
# Stylelint report | ||
# sonar.css.stylelint.reportPaths=target/lint/stylelint-report.json |
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 stylelint will be used one day in this project.
Jenkinsfile
Outdated
@@ -23,7 +25,7 @@ pipeline { | |||
ansiColor('xterm') { | |||
sh "npm install --unsafe-perm" |
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.
You could use npm ci
to install packages without updating them.
client/src/test/index.ts
Outdated
import { runCLI } from 'jest-cli'; | ||
import path = require('path'); | ||
|
||
const jestTestRunnerForVSCodeE2E: ITestRunner = { |
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 know what are recommendations for vscode extensions' testing.
This file seems to be the main input to launch tests, but isn't it possible to directly provide the jest command as a TestRunner ?
package.json
Outdated
"rimraf": "^2.6.3", | ||
"sonar-scanner": "^3.1.0", |
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.
If you use the Sonar CLI provided by Jenkins, this dep is not used.
38b43ca
to
c403321
Compare
4594148
to
48c1a47
Compare
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 had quite a lot of “Changed since last view” but could not make out much from them. 😅
9ecfc52
to
ae69cdc
Compare
ce8a97c
to
ebba558
Compare
ebba558
to
b4ae898
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
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 you fix your issue regarding the config file that seemed to be ignored? (cf. what you said on Slack while asking for help)
It seems so (I hope). |
I'm sorry because this PR is a little bit tricky and has some downsides. Let me explain.
I started to update the Jenkinsfile and add a simple configuration for sonar. This explains the picture in the first comment.
Then I tried to have code coverage too.
The thing is that in this project we were using a test framework named
mocha
. When I searched in the repositories I know, I foundjest
.jest
provides code coverage very easily with just some nice dev dependencies and has a wonderful integration with VSCode. So, I started to migrate frommocha
tojest
.While everything went fine for the server-side code, client-side tests don't work anymore.
This is because we try to launch tests over an instance of VSCode that will bring its dependencies at a weird moment. Jest tries the code, says something like “
vscode
dependency doesn't exist.”, then fails miserably.It tried this method, but it is based on an older version of VSCode and doesn't work with modern projects.
Every new file or change in the
client/
directory are for that, but I disabled the tests because they are not working (yet).Server-side tests work fine and code coverage on this part is very nice as you can see:
While writing this comment, I discovered this tool that probably allows to use
mocha
. while still having code coverage.I still prefere
jest
now, even for test writing.Since our client-tests aren't quite good or very relevant, I propose to keep them disabled until I found a way to enable them later. I know that having fewer tests, even dumb ones, isn't nice, but I believe that code coverage and bug smell detection is better.