-
Notifications
You must be signed in to change notification settings - Fork 23
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
Feature/replace karma-typescript by karma #2659
Feature/replace karma-typescript by karma #2659
Conversation
c60bd13
to
d1fe5a1
Compare
Hey @christophercr @nicanac I adapted the test logic in Stark to use karma config from angular and add our custom configuration. In the meanwhile, I copied Could you have a look ? 😊 |
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.
Nice job! Indeed, having a centralized testing logic compatible with NG CLI will always give us better compatibility with the NG ecosystem 😄
I just have some small thoughts about it... see my comments below.
starter/package.json
Outdated
@@ -127,8 +127,8 @@ | |||
"@angular/platform-server": "^8.2.0", | |||
"@angular/router": "^8.2.0", | |||
"@nationalbankbelgium/code-style": "^1.5.0", | |||
"@nationalbankbelgium/stark-core": "latest", | |||
"@nationalbankbelgium/stark-ui": "latest", | |||
"@nationalbankbelgium/stark-core": "file:../dist/packages-dist/stark-core/nationalbankbelgium-stark-core-10.2.0-71462b2f.tgz", |
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.
Shouldn't these changes be reverted? Normally the Starter should install the latest
from all Stark packages right?
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.
Indeed, you're right. This file should not be changed. Good catch! 👍
starter/package.json
Outdated
@@ -143,8 +143,8 @@ | |||
}, | |||
"devDependencies": { | |||
"@compodoc/compodoc": "~1.1.11", | |||
"@nationalbankbelgium/stark-build": "latest", | |||
"@nationalbankbelgium/stark-testing": "latest", | |||
"@nationalbankbelgium/stark-build": "file:../dist/packages-dist/stark-build/nationalbankbelgium-stark-build-10.2.0-71462b2f.tgz", |
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.
Shouldn't these changes be reverted? Normally the Starter should install the latest
from all Stark packages right?
@@ -1,7 +1,4 @@ | |||
{ | |||
"extends": "./tsconfig.json", | |||
"compilerOptions": { | |||
"module": "commonjs" |
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.
Don't remember exactly why we supported commonjs
libs in tests 🤔
// this ensures that Coveralls can show the list of packages correctly including their files | ||
for (const fileName of fileNames) { | ||
const packageName = fileName.match(/stark-\w*/)[0]; | ||
const replacements = [{ searchValue: /SF:(.*)(\r|\n)/, replaceValue: `SF:packages/${packageName}/$1$2` }]; |
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.
Are you sure that with ng test
the reports are split by package name? So that the coverage of all stark packages is shown in Coveralls correctly
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.
Actually, since we use ng test stark-core --code-coverage
from stark root folder instead of ng test
from "packages/stark-core" folder, the paths are correct.
ng test --code-coverage
from "packages/stark-core", lcov contains path "SF:src/common/error/error.ts"
ng test stark-core --code-coverage
from root, lcov contains path "SF:packages/stark-core/src/common/error/error.ts"
import "zone.js/dist/zone"; | ||
import "zone.js/dist/zone-testing"; |
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.
Ah nice! Is it really that simple now?
browserDisconnectTimeout: 30000, | ||
|
||
// Configuration for coverage-istanbul reporter | ||
coverageIstanbulReporter: { |
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.
Mmm are you sure that running code coverage also in non-ci environment is fast enough? As far as I remember, this was a bit slower than normal testing without coverage, that's why we did it only for CI...
Wait... I see that the script passes ng test --code-coverage
only for CI... so that is basically enabling code coverage only in CI right?
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.
Exactly! 😊
The configuration for coverageIstanbulReporter is there but to enable this reporter you need the --code-coverage
flag. It has no effect on ng test
without the flag.
package.json
Outdated
"cross-env": "^7.0.3", | ||
"cz-customizable": "^6.3.0", | ||
"hammerjs": "^2.0.8", | ||
"husky": "^4.3.8", | ||
"jasmine-core": "^3.6.0", | ||
"karma": "^5.2.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.
About moving all deps from stark-testing
to the root... could we try something else so we can avoid duplication?
What about just adding stark-testing
as DevDependency here and link it to the stark-testing folder (no need for a compiled tgz
I think because we don't compile anything in that package). That way the deps will be installed at the root... right? 🤔
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.
Ha ha, I didn't think to this since the dependencies are not well maintained after (doing npm i
from root after upgrading deps in stark-testing has no impact on installed deps in root).
However, since we are looking for a better solution in the future to manage our monorepo, I think it's better to use your solution and not copy deps from testing into root folder 👍
2e600fc
to
543e498
Compare
@christophercr I updated my PR based on your remarks. Could you have a look ? 😊 |
…cies in root folder Stark-Testing dependencies are now installed in Stark root folder instead of being installed in stark-testing folder
…r/devkit:build-angular` Increase test speed thanks to karma + stop use "commonjs" module during test. BREAKING CHANGE: Adapt angular.json, package.json and base.spec.ts files. Check test config in "angular.json": ``` // ... "test": { "builder": "@angular-builders/custom-webpack:karma", "options": { "main": "base.spec.ts", "karmaConfig": "./karma.conf.js", "tsConfig": "tsconfig.spec.json" } } ``` Check tests scripts in "package.json": ``` // BEFORE "test-fast": "karma start", "test-fast:ci": "karma start karma.conf.ci.js", // AFTER "test-fast": "npm run ng test", "test-fast:ci": "cross-env CI=1 npm run ng test --code-coverage", ``` Adapt "base.spec.ts" file as follows: ```typescript "use strict"; import "core-js/es"; import "core-js/proposals/reflect-metadata"; // IE polyfills // See https://developer.mozilla.org/en-US/docs/Web/API/Element/matches#Polyfill /* tslint:disable:no-unbound-method */ if (!Element.prototype.matches) { Element.prototype.matches = (<any>Element.prototype).msMatchesSelector || Element.prototype.webkitMatchesSelector; } /* tslint:enable:no-unbound-method */ // See: https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Polyfill if ((<any>window).NodeList && !NodeList.prototype.forEach) { (<any>NodeList.prototype).forEach = Array.prototype.forEach; } /* tslint:disable:no-import-side-effect */ import "zone.js/dist/zone"; import "zone.js/dist/zone-testing"; import "zone.js/dist/long-stack-trace-zone"; /* tslint:enable:no-import-side-effect */ // define global environment variable (used in some places in stark-core and stark-ui) global["ENV"] = "development"; import { getTestBed } from "@angular/core/testing"; import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from "@angular/platform-browser-dynamic/testing"; // tslint:disable:completed-docs bool-param-default declare const require: { context(path: string, deep?: boolean, filter?: RegExp): { keys(): string[]; <T>(id: string): T; }; }; getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); // Then we find all the tests. const context = require.context('./src', true, /\.spec\.ts$/); // And load the modules. context.keys().forEach(context); ```
+ Adapt GitHub Actions script to run starter tests
543e498
to
4e83f53
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@SuperITMan btw... where did the Coveralls checks go? |
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.
Looks great!
Just the remark about Coveralls checks missing 🤔
@christophercr It is now part of GitHub Actions: stark/.github/workflows/build.yml Lines 165 to 174 in fb6e448
EDIT: I didn't notice the check Coveralls is not present here. I'm having a look 👍 |
Ok, but what about the comment posted by Coveralls in the PRs to know whats the new coverage? |
Moreover, you can see in the Coveralls page (https://coveralls.io/github/NationalBankBelgium/stark) that the latest merge you did some minutes ago about the NGRX actions is not shown in that page 🤔 |
Alright!! Much better! 😋 |
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.
Seems really great, I just have a concern regarding the security issue -> snyk.
I'm not well informed about this security test, because when I'm not able to get the details and the reason why it fails.
Otherwise, testing are working well on my win10 pc and on my mac Os.
@nicanac |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Stark-testing is using karma-typescript.
Issue Number: #2653
What is the new behavior?
Using karma +
@angular-devkit/build-angular:karma
instead of karma-typescriptDoes this PR introduce a breaking change?
Other information