Skip to content
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

Merged
merged 1 commit into from
Apr 24, 2020
Merged

Conversation

alacambre-yseop
Copy link
Collaborator

@alacambre-yseop alacambre-yseop commented Jul 10, 2019

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 found jest. jest provides code coverage very easily with just some nice dev dependencies and has a wonderful integration with VSCode. So, I started to migrate from mocha to jest.
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:
image
image

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.

@alacambre-yseop
Copy link
Collaborator Author

I'm progressing!
image

@alacambre-yseop alacambre-yseop force-pushed the feature/sonarqube branch 5 times, most recently from 954cc8b to 1ca3c7a Compare September 6, 2019 19:55
@alacambre-yseop alacambre-yseop changed the title chore: try to use sonarqube build: enable sonarcloud checks Sep 6, 2019
@alacambre-yseop alacambre-yseop self-assigned this Sep 6, 2019
@alacambre-yseop alacambre-yseop marked this pull request as ready for review September 6, 2019 20:20
Copy link
Contributor

@mminot-yseop mminot-yseop left a 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.

assert.notStrictEqual(languages.length, 0);
assert.notStrictEqual(languages.indexOf('yml'), -1);
expect(languages).not.toBeNull();
expect(languages.length).not.toBe(0);
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nonono, it’s OK.

import { runCLI } from 'jest-cli';
import path = require('path');

const jestTestRunnerForVSCodeE2E: ITestRunner = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E2E?

Copy link
Contributor

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.

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 ?

##
## Duplications
##
# Increase minimum lines for code duplications triggering (default = 10)
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

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.

@Harukero
Copy link
Contributor

Harukero commented Sep 6, 2019

I will try to give a try to microsoft/vscode-test#37.

babel.config.js Outdated
node: "current",
},
}],
+"@babel/preset-typescript",

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 ?

},
"dependencies": {
"@types/jest": "^24.0.18",

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

"glob": "^7.1.4",
"mocha": "^5.2.0",
"jest-cli": "^24.9.0",

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 Show resolved Hide resolved
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();

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

ymlExtension
.activate()
.then(() => {
assert.strictEqual(ymlExtension.isActive, true);
expect(ymlExtension.isActive).toBeTruthy();

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();
})

Jenkinsfile Show resolved Hide resolved
client/src/test/extension.test.ts Outdated Show resolved Hide resolved
# sonar.typescript.tslint.reportPaths=target/lint/tslint-report.json

# Stylelint report
# sonar.css.stylelint.reportPaths=target/lint/stylelint-report.json

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"

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.

Jenkinsfile Show resolved Hide resolved
import { runCLI } from 'jest-cli';
import path = require('path');

const jestTestRunnerForVSCodeE2E: ITestRunner = {

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",

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.

Copy link
Contributor

@mminot-yseop mminot-yseop left a 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. 😅

jest.config.js Show resolved Hide resolved
@alacambre-yseop alacambre-yseop removed the request for review from eborel-yseop April 24, 2020 07:51
@alacambre-yseop alacambre-yseop force-pushed the feature/sonarqube branch 2 times, most recently from ce8a97c to ebba558 Compare April 24, 2020 08:33
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Contributor

@mminot-yseop mminot-yseop left a 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)

@alacambre-yseop
Copy link
Collaborator Author

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).

@alacambre-yseop alacambre-yseop merged commit 969ba93 into develop Apr 24, 2020
@alacambre-yseop alacambre-yseop deleted the feature/sonarqube branch April 24, 2020 08:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants