Skip to content

Commit

Permalink
[ACS-4865] setup and enable code coverage for all projects (#3074)
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysVuika authored Mar 20, 2023
1 parent 86c0bbb commit 9609393
Show file tree
Hide file tree
Showing 37 changed files with 1,297 additions and 405 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ npm start content-ce -- --configuration=adf

Changing the ADF code results in the recompilation and hot-reloading of the ACA application.

## Unit Tests

Use standard Angular CLI commands to test the projects:

```sh
ng test <project>
```

### Code Coverage

The projects are already configured to produce code coverage reports in console and HTML output.

You can view HTML reports in the `./coverage/<project>` folder.

When working with unit testing and code coverage improvement, you can run unit tests in the "live reload" mode:

```sh
ng test <project> --watch
```

Upon changing unit tests code, you can track the coverage results either in the console output, or by reloading the HTML report in the browser.

## Triggering the build to use specific branch of ADF with CI flags

You can create commits with the intention of running the build pipeline using a specific branch of ADF. To achieve this, you need to add a specific CI flag in your commit message:
Expand Down
7 changes: 7 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/adf-office-services-ext/src/test.ts",
"tsConfig": "projects/adf-office-services-ext/tsconfig.spec.json",
"karmaConfig": "projects/adf-office-services-ext/karma.conf.js"
Expand Down Expand Up @@ -413,6 +414,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-shared/test.ts",
"tsConfig": "projects/aca-shared/tsconfig.spec.json",
"karmaConfig": "projects/aca-shared/karma.conf.js"
Expand Down Expand Up @@ -465,6 +467,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-about/src/test.ts",
"tsConfig": "projects/aca-about/tsconfig.spec.json",
"karmaConfig": "projects/aca-about/karma.conf.js"
Expand Down Expand Up @@ -506,6 +509,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-folder-rules/src/test.ts",
"tsConfig": "projects/aca-folder-rules/tsconfig.spec.json",
"karmaConfig": "projects/aca-folder-rules/karma.conf.js"
Expand Down Expand Up @@ -554,6 +558,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-content/src/test.ts",
"tsConfig": "projects/aca-content/tsconfig.spec.json",
"karmaConfig": "projects/aca-content/karma.conf.js",
Expand Down Expand Up @@ -605,6 +610,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-viewer/src/test.ts",
"tsConfig": "projects/aca-viewer/tsconfig.spec.json",
"karmaConfig": "projects/aca-viewer/karma.conf.js"
Expand Down Expand Up @@ -648,6 +654,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"codeCoverage": true,
"main": "projects/aca-preview/src/test.ts",
"tsConfig": "projects/aca-preview/tsconfig.spec.json",
"karmaConfig": "projects/aca-preview/karma.conf.js"
Expand Down
55 changes: 33 additions & 22 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
// process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(config) {
config.set({
const { join } = require('path');
const { constants } = require('karma');

module.exports = () => {
return {
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-coverage'),
require('karma-mocha-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
files: [
{
pattern:
'./node_modules/@angular/material/prebuilt-themes/indigo-pink.css',
watched: false
},
{
pattern:
'./node_modules/@alfresco/adf-core/bundles/assets/adf-core/i18n/en.json',
Expand All @@ -46,38 +43,52 @@ module.exports = function(config) {
'/base/node_modules/@alfresco/adf-content-services/bundles/assets/adf-content-services/i18n/en.json'
},
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
jasmine: {
// you can add configuration options for Jasmine here
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
// for example, you can disable the random execution with `random: false`
// or set a specific seed with `seed: 4321`
},
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
jasmineHtmlReporter: {
suppressAll: true, // removes the duplicated traces
},

coverageReporter: {
dir: join(__dirname, './coverage'),
subdir: '.',
reporters: [{ type: 'html' }, { type: 'text-summary' }],
check: {
global: {
statements: 75,
branches: 67,
functions: 73,
lines: 75
}
}
},

reporters: ['mocha', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
logLevel: constants.LOG_INFO,
autoWatch: true,
browsers: ['ChromeHeadless'],
customLaunchers: {
ChromeHeadless: {
base: 'Chrome',
flags: [
'--no-sandbox',
// '--headless',
'--headless',
'--disable-gpu',
'--remote-debugging-port=9222'
]
}
},
singleRun: true,
captureTimeout: 180000,
browserDisconnectTimeout: 180000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 300000,

restartOnFileChange: true,
// workaround for alfresco-js-api builds
webpack: { node: { fs: 'empty' } }
});
};
};
58 changes: 58 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"build.release": "npm run build -- --configuration=production,release",
"build-libs": "ng build aca-shared && ng build adf-office-services-ext && ng build aca-about && ng build aca-viewer && ng build aca-preview && ng build aca-folder-rules && ng build aca-content",
"test": "ng test",
"test:ci": "ng test adf-office-services-ext && ng test content-ce --code-coverage",
"lint": "NODE_OPTIONS=--max_old_space_size=4096 ng lint",
"update-webdriver": "./scripts/update-webdriver.sh",
"e2e": "npm run update-webdriver && protractor $SUITE",
Expand Down Expand Up @@ -102,6 +101,7 @@
"jasmine-spec-reporter": "~5.0.0",
"karma": "^6.4.1",
"karma-chrome-launcher": "~3.1.1",
"karma-coverage": "^2.2.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "~5.1.0",
"karma-jasmine-html-reporter": "^2.0.0",
Expand Down
31 changes: 7 additions & 24 deletions projects/aca-about/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const { join } = require('path');
const getBaseKarmaConfig = require('../../karma.conf');

module.exports = function (config) {
const baseConfig = getBaseKarmaConfig();
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
...baseConfig,
coverageReporter: {
...baseConfig.coverageReporter,
dir: join(__dirname, '../../coverage/aca-about'),
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/aca-about'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
restartOnFileChange: true
});
};
31 changes: 7 additions & 24 deletions projects/aca-content/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const { join } = require('path');
const getBaseKarmaConfig = require('../../karma.conf');

module.exports = function (config) {
const baseConfig = getBaseKarmaConfig();
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
...baseConfig,
coverageReporter: {
...baseConfig.coverageReporter,
dir: join(__dirname, '../../coverage/aca-content'),
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/aca-content'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: true,
restartOnFileChange: true
});
};
5 changes: 2 additions & 3 deletions projects/aca-content/src/lib/testing/app-testing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

import { NgModule } from '@angular/core';
import { TranslateService, TranslatePipe } from '@ngx-translate/core';
import { TranslatePipe, TranslateModule } from '@ngx-translate/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import {
TranslationService,
Expand All @@ -44,7 +44,6 @@ import { EffectsModule } from '@ngrx/effects';
import { MaterialModule } from '../material.module';
import { INITIAL_STATE } from '../store/initial-state';
import { TranslatePipeMock } from './translate-pipe.directive';
import { TranslateServiceMock } from '@alfresco/aca-shared';
import { BehaviorSubject, Observable, of } from 'rxjs';

@NgModule({
Expand All @@ -53,6 +52,7 @@ import { BehaviorSubject, Observable, of } from 'rxjs';
HttpClientModule,
RouterTestingModule,
MaterialModule,
TranslateModule.forRoot(),
StoreModule.forRoot(
{ app: appReducer },
{
Expand All @@ -71,7 +71,6 @@ import { BehaviorSubject, Observable, of } from 'rxjs';
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{ provide: TranslationService, useClass: TranslationMock },
{ provide: TranslateService, useClass: TranslateServiceMock },
{ provide: TranslatePipe, useClass: TranslatePipeMock },
{
provide: DiscoveryApiService,
Expand Down
Loading

0 comments on commit 9609393

Please sign in to comment.