mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-20 14:41:28 +01:00
Merge pull request #9203 from zhoumeina/add_unit_test
Karma test refactor to support test in portal and coverage report
This commit is contained in:
commit
dfa9d61ef3
@ -171,7 +171,29 @@
|
|||||||
"main": "lib/src/test.ts",
|
"main": "lib/src/test.ts",
|
||||||
"tsConfig": "lib/tsconfig.lib.json",
|
"tsConfig": "lib/tsconfig.lib.json",
|
||||||
"karmaConfig": "lib/karma.conf.js"
|
"karmaConfig": "lib/karma.conf.js"
|
||||||
}
|
},
|
||||||
|
"scripts": [
|
||||||
|
"node_modules/core-js/client/shim.min.js",
|
||||||
|
"node_modules/mutationobserver-shim/dist/mutationobserver.min.js",
|
||||||
|
"node_modules/@webcomponents/custom-elements/custom-elements.min.js",
|
||||||
|
"node_modules/@clr/icons/clr-icons.min.js",
|
||||||
|
"node_modules/web-animations-js/web-animations.min.js",
|
||||||
|
"node_modules/marked/lib/marked.js",
|
||||||
|
"node_modules/prismjs/prism.js",
|
||||||
|
"node_modules/prismjs/components/prism-yaml.min.js"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"node_modules/@clr/icons/clr-icons.min.css",
|
||||||
|
"node_modules/@clr/ui/clr-ui.min.css",
|
||||||
|
"node_modules/prismjs/themes/prism-solarizedlight.css",
|
||||||
|
"src/styles.css"
|
||||||
|
],
|
||||||
|
"assets": [
|
||||||
|
"src/images",
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/setting.json",
|
||||||
|
"src/i18n"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"lint": {
|
"lint": {
|
||||||
"builder": "@angular-devkit/build-angular:tslint",
|
"builder": "@angular-devkit/build-angular:tslint",
|
||||||
|
@ -1,47 +1,87 @@
|
|||||||
// Karma configuration file, see link for more information
|
// Karma configuration file, see link for more information
|
||||||
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
config.set({
|
config.set({
|
||||||
basePath: '/',
|
basePath: '',
|
||||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||||
plugins: [
|
plugins: [
|
||||||
require('karma-jasmine'),
|
require('karma-jasmine'),
|
||||||
require('karma-chrome-launcher'),
|
require('karma-chrome-launcher'),
|
||||||
require('karma-mocha-reporter'),
|
require('karma-mocha-reporter'),
|
||||||
require('karma-remap-istanbul'),
|
require('karma-coverage-istanbul-reporter'),
|
||||||
require('@angular-devkit/build-angular/plugins/karma')
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
],
|
],
|
||||||
files: [
|
client: {
|
||||||
{pattern: './src/test.ts', watched: false}
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
],
|
},
|
||||||
preprocessors: {
|
coverageIstanbulReporter: {
|
||||||
|
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib
|
||||||
|
reports: ['html', 'lcovonly', 'text-summary'],
|
||||||
|
|
||||||
},
|
// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
|
||||||
mime: {
|
dir: path.join(__dirname, 'coverage'),
|
||||||
'text/x-typescript': ['ts', 'tsx']
|
|
||||||
},
|
// Combines coverage information from multiple browsers into one report rather than outputting a report
|
||||||
remapIstanbulReporter: {
|
// for each browser.
|
||||||
dir: require('path').join(__dirname, 'coverage'), reports: {
|
combineBrowserReports: true,
|
||||||
html: 'coverage',
|
|
||||||
lcovonly: './coverage/coverage.lcov'
|
// if using webpack and pre-loaders, work around webpack breaking the source path
|
||||||
|
fixWebpackSourcePaths: true,
|
||||||
|
|
||||||
|
// Omit files with no statements, no functions and no branches from the report
|
||||||
|
skipFilesWithNoCoverage: true,
|
||||||
|
|
||||||
|
// Most reporters accept additional config options. You can pass these through the `report-config` option
|
||||||
|
'report-config': {
|
||||||
|
// all options available at: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/html/index.js#L135-L137
|
||||||
|
html: {
|
||||||
|
// outputs the report in ./coverage/html
|
||||||
|
subdir: 'html'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
reporters: config.angularCli && config.angularCli.codeCoverage
|
// enforce percentage thresholds
|
||||||
? ['mocha', 'karma-remap-istanbul']
|
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
|
||||||
: ['mocha'],
|
thresholds: {
|
||||||
|
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
|
||||||
|
// thresholds for all files
|
||||||
|
global: {
|
||||||
|
statements: 10,
|
||||||
|
lines: 10,
|
||||||
|
branches: 0,
|
||||||
|
functions: 10
|
||||||
|
},
|
||||||
|
// thresholds per file
|
||||||
|
each: {
|
||||||
|
statements: 0,
|
||||||
|
lines: 0,
|
||||||
|
branches: 0,
|
||||||
|
functions: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
reporters: ['progress', 'mocha','coverage-istanbul'],
|
||||||
|
mochaReporter: {
|
||||||
|
output: 'minimal'
|
||||||
|
},
|
||||||
|
reportSlowerThan: 100,
|
||||||
port: 9876,
|
port: 9876,
|
||||||
colors: true,
|
colors: true,
|
||||||
logLevel: config.LOG_INFO,
|
logLevel: config.LOG_INFO,
|
||||||
autoWatch: true,
|
autoWatch: true,
|
||||||
|
singleRun: true,
|
||||||
browsers: ['ChromeHeadlessNoSandbox'],
|
browsers: ['ChromeHeadlessNoSandbox'],
|
||||||
|
browserDisconnectTolerance: 2,
|
||||||
|
browserNoActivityTimeout: 50000,
|
||||||
customLaunchers: {
|
customLaunchers: {
|
||||||
ChromeHeadlessNoSandbox: {
|
ChromeHeadlessNoSandbox: {
|
||||||
base: 'ChromeHeadless',
|
base: 'ChromeHeadless',
|
||||||
flags: ['--no-sandbox']
|
flags: ['--no-sandbox']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
singleRun: true
|
restartOnFileChange: true
|
||||||
});
|
});
|
||||||
};
|
};
|
87
src/portal/lib/karma.conf.js
Normal file
87
src/portal/lib/karma.conf.js
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// Karma configuration file, see link for more information
|
||||||
|
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
module.exports = function (config) {
|
||||||
|
config.set({
|
||||||
|
basePath: '',
|
||||||
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||||
|
plugins: [
|
||||||
|
require('karma-jasmine'),
|
||||||
|
require('karma-chrome-launcher'),
|
||||||
|
require('karma-mocha-reporter'),
|
||||||
|
require('karma-coverage-istanbul-reporter'),
|
||||||
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
|
],
|
||||||
|
client: {
|
||||||
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
|
},
|
||||||
|
coverageIstanbulReporter: {
|
||||||
|
// reports can be any that are listed here: https://github.com/istanbuljs/istanbuljs/tree/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib
|
||||||
|
reports: ['html', 'lcovonly', 'text-summary'],
|
||||||
|
|
||||||
|
// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
|
||||||
|
dir: path.join(__dirname, 'coverage'),
|
||||||
|
|
||||||
|
// Combines coverage information from multiple browsers into one report rather than outputting a report
|
||||||
|
// for each browser.
|
||||||
|
combineBrowserReports: true,
|
||||||
|
|
||||||
|
// if using webpack and pre-loaders, work around webpack breaking the source path
|
||||||
|
fixWebpackSourcePaths: true,
|
||||||
|
|
||||||
|
// Omit files with no statements, no functions and no branches from the report
|
||||||
|
skipFilesWithNoCoverage: true,
|
||||||
|
|
||||||
|
// Most reporters accept additional config options. You can pass these through the `report-config` option
|
||||||
|
'report-config': {
|
||||||
|
// all options available at: https://github.com/istanbuljs/istanbuljs/blob/aae256fb8b9a3d19414dcf069c592e88712c32c6/packages/istanbul-reports/lib/html/index.js#L135-L137
|
||||||
|
html: {
|
||||||
|
// outputs the report in ./coverage/html
|
||||||
|
subdir: 'html'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// enforce percentage thresholds
|
||||||
|
// anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode
|
||||||
|
thresholds: {
|
||||||
|
emitWarning: false, // set to `true` to not fail the test command when thresholds are not met
|
||||||
|
// thresholds for all files
|
||||||
|
global: {
|
||||||
|
statements: 10,
|
||||||
|
lines: 10,
|
||||||
|
branches: 0,
|
||||||
|
functions: 10
|
||||||
|
},
|
||||||
|
// thresholds per file
|
||||||
|
each: {
|
||||||
|
statements: 0,
|
||||||
|
lines: 0,
|
||||||
|
branches: 0,
|
||||||
|
functions: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
reporters: ['progress', 'mocha','coverage-istanbul'],
|
||||||
|
mochaReporter: {
|
||||||
|
output: 'minimal'
|
||||||
|
},
|
||||||
|
reportSlowerThan: 100,
|
||||||
|
port: 9876,
|
||||||
|
colors: true,
|
||||||
|
logLevel: config.LOG_INFO,
|
||||||
|
autoWatch: true,
|
||||||
|
singleRun: true,
|
||||||
|
browsers: ['ChromeHeadlessNoSandbox'],
|
||||||
|
browserDisconnectTolerance: 2,
|
||||||
|
browserNoActivityTimeout: 50000,
|
||||||
|
customLaunchers: {
|
||||||
|
ChromeHeadlessNoSandbox: {
|
||||||
|
base: 'ChromeHeadless',
|
||||||
|
flags: ['--no-sandbox']
|
||||||
|
}
|
||||||
|
},
|
||||||
|
restartOnFileChange: true
|
||||||
|
});
|
||||||
|
};
|
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"extends": "../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "../out-tsc/lib",
|
"outDir": "../out-tsc/lib",
|
||||||
"target": "es2015",
|
"target": "es2015",
|
||||||
@ -11,13 +10,22 @@
|
|||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"typeRoots": ["node_modules/@types"],
|
"baseUrl": "./",
|
||||||
|
"typeRoots": [
|
||||||
|
"../node_modules/@types"
|
||||||
|
],
|
||||||
"lib": [
|
"lib": [
|
||||||
"dom",
|
"dom",
|
||||||
"es2015"
|
"es2015"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@angular/*": [ "../node_modules/@angular/*"]
|
"lib": [
|
||||||
|
"dist/lib"
|
||||||
|
],
|
||||||
|
"lib/*": [
|
||||||
|
"dist/lib/*"
|
||||||
|
],
|
||||||
|
"@angular/*": [ "./node_modules/@angular/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
@ -30,7 +38,5 @@
|
|||||||
"flatModuleOutFile": "AUTOGENERATED"
|
"flatModuleOutFile": "AUTOGENERATED"
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"src/test.ts",
|
|
||||||
"**/*.spec.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
1291
src/portal/package-lock.json
generated
1291
src/portal/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,12 @@
|
|||||||
"start": "ng serve --ssl true --ssl-key ssl/server.key --ssl-cert ssl/server.crt --host 0.0.0.0 --proxy-config proxy.config.json",
|
"start": "ng serve --ssl true --ssl-key ssl/server.key --ssl-cert ssl/server.crt --host 0.0.0.0 --proxy-config proxy.config.json",
|
||||||
"lint": "tslint \"src/**/*.ts\"",
|
"lint": "tslint \"src/**/*.ts\"",
|
||||||
"lint:lib": "tslint \"lib/**/*.ts\" -e \"lib/dist/**/*\" ",
|
"lint:lib": "tslint \"lib/**/*.ts\" -e \"lib/dist/**/*\" ",
|
||||||
"test": "ng test harbor-portal",
|
"test": "ng test --code-coverage",
|
||||||
|
"test:watch": "ng test --code-coverage --watch",
|
||||||
|
"test:debug": "ng test --code-coverage --source-map false",
|
||||||
|
"test:chrome": "ng test --code-coverage --browsers Chrome",
|
||||||
|
"test:headless": "ng test --watch=false --no-progress --code-coverage --browsers=ChromeNoSandboxHeadless",
|
||||||
|
"test:chrome-debug": "ng test --code-coverage --browsers Chrome --watch",
|
||||||
"pree2e": "webdriver-manager update",
|
"pree2e": "webdriver-manager update",
|
||||||
"e2e": "protractor",
|
"e2e": "protractor",
|
||||||
"build": "ng build --aot",
|
"build": "ng build --aot",
|
||||||
@ -71,9 +76,10 @@
|
|||||||
"codelyzer": "~5.0.0",
|
"codelyzer": "~5.0.0",
|
||||||
"enhanced-resolve": "^3.0.0",
|
"enhanced-resolve": "^3.0.0",
|
||||||
"jasmine-spec-reporter": "~4.2.1",
|
"jasmine-spec-reporter": "~4.2.1",
|
||||||
"karma": "~1.7.1",
|
"karma": "^1.7.1",
|
||||||
"karma-chrome-launcher": "~2.2.0",
|
"karma-chrome-launcher": "~2.2.0",
|
||||||
"karma-cli": "^1.0.1",
|
"karma-cli": "^1.0.1",
|
||||||
|
"karma-coverage": "^2.0.1",
|
||||||
"karma-coverage-istanbul-reporter": "~2.0.0",
|
"karma-coverage-istanbul-reporter": "~2.0.0",
|
||||||
"karma-jasmine": "^2.0.0",
|
"karma-jasmine": "^2.0.0",
|
||||||
"karma-jasmine-html-reporter": "^0.2.2",
|
"karma-jasmine-html-reporter": "^0.2.2",
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||||
import { LicenseComponent } from './license.component';
|
import { LicenseComponent } from './license.component';
|
||||||
|
|
||||||
describe('LicenseComponent', () => {
|
fdescribe('LicenseComponent', () => {
|
||||||
let component: LicenseComponent;
|
let component: LicenseComponent;
|
||||||
let fixture: ComponentFixture<LicenseComponent>;
|
let fixture: ComponentFixture<LicenseComponent>;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ LicenseComponent ]
|
declarations: [LicenseComponent],
|
||||||
|
imports: [
|
||||||
|
HttpClientTestingModule
|
||||||
|
]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@ -38,7 +38,7 @@ getTestBed().initTestEnvironment(
|
|||||||
platformBrowserDynamicTesting()
|
platformBrowserDynamicTesting()
|
||||||
);
|
);
|
||||||
// Then we find all the tests.
|
// Then we find all the tests.
|
||||||
let context = require.context('../lib', true, /\.spec\.ts/);
|
let context = require.context('./', true, /\.spec\.ts/);
|
||||||
// And load the modules.
|
// And load the modules.
|
||||||
context.keys().map(context);
|
context.keys().map(context);
|
||||||
// Finally, start Karma to run the tests.
|
// Finally, start Karma to run the tests.
|
||||||
|
Loading…
Reference in New Issue
Block a user