#60 coverage and tets for core component

This commit is contained in:
Mario Romano
2016-05-16 19:17:22 +01:00
parent fbb94189e7
commit 874b6c0a31
9 changed files with 228 additions and 208 deletions

View File

@@ -10,3 +10,36 @@
Core library for other ng2-alfresco components.
This should be added as a dependency for any project using the components.
## Install
```sh
npm install --save ng2-alfresco-core
```
## Build from sources
Alternatively you can build component from sources with the following commands:
```sh
npm install
npm run build
```
## Running unit tests
```sh
npm test
```
This task rebuilds all the code, runs tslint, license checks and other quality check tools
before performing unit testing.
## Code coverage
```sh
npm run coverage
```

View File

@@ -0,0 +1,74 @@
// Tun on full stack traces in errors to help debugging
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
// // Cancel Karma's synchronous start,
// // we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {};
System.config({
packages: {
'base/dist': {
defaultExtension: 'js',
format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
},
'ng2-translate': {
defaultExtension: 'js',
format: 'register'
}
},
map: {
'ng2-translate': '/base/node_modules/ng2-translate/bundles'
}
});
System.import('angular2/src/platform/browser/browser_adapter')
.then(function(browser_adapter) { browser_adapter.BrowserDomAdapter.makeCurrent(); })
.then(function() { return Promise.all(resolveTestFiles()); })
.then(
function() {
__karma__.start();
},
function(error) {
__karma__.error(error.stack || error);
}
);
function createPathRecords(pathsMapping, appPath) {
// creates local module name mapping to global path with karma's fingerprint in path, e.g.:
// './vg-player/vg-player':
// '/base/dist/vg-player/vg-player.js?f4523daf879cfb7310ef6242682ccf10b2041b3e'
var moduleName = './' + resolveKeyPathForMapping('base/dist/', appPath);
moduleName = moduleName.replace(/\.js$/, '');
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
return pathsMapping;
}
function onlyAppFiles(filePath) {
return /\/base\/dist\/(?!.*\.spec\.js$).*\.js$/.test(filePath);
}
function onlySpecFiles(path) {
return /\.spec\.js$/.test(path);
}
function resolveTestFiles() {
return Object.keys(window.__karma__.files) // All files served by Karma.
.filter(onlySpecFiles)
.map(function(moduleName) {
// loads all spec files via their global module names (e.g.
// 'base/dist/vg-player/vg-player.spec')
return System.import(moduleName);
});
}
function resolveKeyPathForMapping(basePathWhereToStart, appPath) {
var location = appPath.indexOf(basePathWhereToStart);
if (location > -1) {
return appPath.substring(basePathWhereToStart.length + 1);
} else {
return appPath;
}
}

View File

@@ -1,128 +1,78 @@
// Karma configuration
// Generated on Wed Jul 15 2015 09:44:02 GMT+0200 (Romance Daylight Time)
'use strict';
var argv = require('yargs').argv;
module.exports = function(config) {
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './',
basePath: '.',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
// list of files / patterns to load in the browser
files: [
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
'node_modules/es6-module-loader/dist/es6-module-loader.js',
'node_modules/traceur/bin/traceur-runtime.js', // Required by PhantomJS2, otherwise it shouts ReferenceError: Can't find variable: require
'node_modules/traceur/bin/traceur.js',
'node_modules/systemjs/dist/system.src.js',
'node_modules/reflect-metadata/Reflect.js',
'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js',
{ pattern: 'node_modules/ng2-translate/**/*.js', included: false, watched: false }, // source files
{ pattern: 'node_modules/angular2/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'dist/**/*.js', included: false, watched: true },
{ pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false }, // PhantomJS2 (and possibly others) might require it
// paths loaded by Karma
{pattern: 'node_modules/angular2/bundles/angular2-polyfills.js', included: true, watched: false},
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/rxjs/bundles/Rx.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/angular2.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/testing.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: false},
{pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: false},
{pattern: 'node_modules/ng2-translate/bundles/ng2-translate.js', included: true, watched: false},
// suppress annoying 404 warnings for resources, images, etc.
//{ pattern: 'dist/src/assets/**/*', watched: false, included: false, served: true },
{pattern: 'karma-test-shim.js', included: true, watched: true},
'test-main.js'
// paths loaded via module imports
{pattern: 'dist/**/*.js', included: false, watched: true},
// paths to support debugging with source maps in dev tools
{pattern: 'services/**/*.ts', included: false, watched: false},
{pattern: 'material/**/*.ts', included: false, watched: false},
{pattern: 'dist/**/*.js.map', included: false, watched: false}
],
// must go along with above, suppress annoying 404 warnings.
// proxied base paths
proxies: {
'/assets/': '/base/dist/dev/assets/'
// required for component assets fetched by Angular's compiler
'/src/': '/base/src/'
},
// list of files to exclude
exclude: [
'node_modules/angular2/**/*spec.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'dist/**/!(*spec).js': ['coverage']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha', 'coverage'],
// web server port
port: 9876,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
colors: true,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
browsers: ['Chrome'],
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'PhantomJS',
'Chrome'
// Karma plugins loaded
plugins: [
'karma-jasmine',
'karma-coverage',
'karma-chrome-launcher',
'karma-mocha-reporter'
],
// Coverage reporter generates the coverage
reporters: ['mocha', 'coverage'],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
// Source files that you wanna generate coverage for.
// Do not include tests or libraries (these files will be instrumented by Istanbul)
preprocessors: {
'dist/**/!(*spec).js': ['coverage']
},
coverageReporter: {
dir: 'coverage/',
reporters: [
{ type: 'text-summary' },
{ type: 'json', subdir: '.', file: 'coverage-final.json' },
{ type: 'html' }
{type: 'text-summary'},
{type: 'json', subdir: '.', file: 'coverage-final.json'},
{type: 'html'}
]
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Passing command line arguments to tests
client: {
files: argv.files
}
});
if (process.env.APPVEYOR) {
config.browsers = ['IE'];
config.singleRun = true;
config.browserNoActivityTimeout = 90000; // Note: default value (10000) is not enough
}
if (process.env.TRAVIS || process.env.CIRCLECI) {
config.browsers = ['Chrome_travis_ci'];
config.singleRun = true;
}
singleRun: true
})
};

View File

@@ -4,15 +4,23 @@
"version": "0.1.0",
"author": "Alfresco Software, Ltd.",
"scripts": {
"build": "npm run tslint-test && npm run tslint-src && npm run tslint-root && typings install && rm -rf dist && tsc && license-check",
"postinstall": "npm run typings",
"typings": "typings install",
"start": "npm run test && http-server -c-1 -o -p 8875 .",
"build": "npm run tslint && typings install && rm -rf dist && tsc && npm run copytemplates && license-check",
"tslint": "npm run tslint-test && npm run tslint-src && npm run tslint-root",
"tslint-test": "tslint -c tslint.json test/**/*.ts",
"tslint-src": "tslint -c tslint.json src/**/*.ts",
"tslint-root": "tslint -c tslint.json *.ts",
"copytemplates": "npm run copy-html && npm run copy-css",
"copy-html": "copyfiles './src/**/*.html' dist",
"copy-css": "copyfiles './src/**/*.css' dist",
"licensecheck": "license-check",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"test": "karma start karma.conf.js"
"pretest": "npm run build",
"test": "karma start karma.conf.js",
"posttest": "node_modules/.bin/remap-istanbul -i coverage/coverage-final.json -o coverage -t html",
"coverage": "http-server -c-1 -o -p 9875 ./coverage"
},
"repository": {
"type": "git",
@@ -52,23 +60,22 @@
"angular2": "2.0.0-beta.15"
},
"devDependencies": {
"typescript": "^1.8.10",
"typings": "^0.7.12",
"jasmine-spec-reporter": "^2.4.0",
"copyfiles": "^0.2.1",
"coveralls": "^2.11.9",
"http-server": "0.8.5",
"jasmine-ajax": "^3.2.0",
"jasmine-core": "2.4.1",
"karma": "~0.13.22",
"karma-chrome-launcher": "~1.0.1",
"karma-coverage": "^1.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-jasmine": "~1.0.2",
"karma-mocha-reporter": "^2.0.3",
"karma-phantomjs-launcher": "^1.0.0",
"traceur": "^0.0.91",
"license-check": "^1.0.4",
"remap-istanbul": "^0.6.3",
"phantomjs-prebuilt": "^2.1.7",
"coveralls": "^2.11.9",
"jasmine-ajax": "^3.2.0",
"jasmine-core": "2.4.1",
"license-check": "^1.0.4"
"traceur": "^0.0.91",
"tslint": "^3.8.1",
"typescript": "^1.8.10",
"typings": "^0.7.12"
},
"license-check-config": {
"src": [

View File

@@ -27,7 +27,7 @@ export default {
AlfrescoSettingsService,
AlfrescoTranslationLoader
]
}
};
export const ALFRESCO_CORE_PROVIDERS: [any] = [
AlfrescoSettingsService,

View File

@@ -1,78 +0,0 @@
if (!Object.hasOwnProperty('name')) {
Object.defineProperty(Function.prototype, 'name', {
get: function() {
var matches = this.toString().match(/^\s*function\s*(\S*)\s*\(/);
var name = matches && matches.length > 1 ? matches[1] : "";
Object.defineProperty(this, 'name', {value: name});
return name;
}
});
}
// Turn on full stack traces in errors to help debugging
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
// Cancel Karma's synchronous start,
// we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {};
System.config({
baseURL: '/base/',
defaultJSExtensions: true,
paths: {
'angular2/*': 'node_modules/angular2/*.js',
'rxjs/*': 'node_modules/rxjs/*.js',
'ng2-translate/*':'node_modules/ng2-translate/*.js'
}
});
Promise.all([
System.import('angular2/src/platform/browser/browser_adapter'),
System.import('angular2/platform/testing/browser'),
System.import('angular2/testing')
]).then(function (modules) {
var browser_adapter = modules[0];
var providers = modules[1];
var testing = modules[2];
testing.setBaseTestProviders(providers.TEST_BROWSER_PLATFORM_PROVIDERS,
providers.TEST_BROWSER_APPLICATION_PROVIDERS);
browser_adapter.BrowserDomAdapter.makeCurrent();
}).then(function() {
return Promise.all(
Object.keys(window.__karma__.files) // All files served by Karma.
.filter(onlySpecFiles)
.map(file2moduleName)
.map(function(path) {
return System.import(path).then(function(module) {
if (module.hasOwnProperty('main')) {
module.main();
} else {
throw new Error('Module ' + path + ' does not implement main() method.');
}
});
}));
})
.then(function() {
__karma__.start();
}, function(error) {
// console.error(error.stack || error);
__karma__.start();
});
function onlySpecFiles(path) {
// check for individual files, if not given, always matches to all
var patternMatched = __karma__.config.files ?
path.match(new RegExp(__karma__.config.files)) : true;
return patternMatched && /[\.|_]spec\.js$/.test(path);
}
// Normalize paths to module names.
function file2moduleName(filePath) {
return filePath.replace(/\\/g, '/')
.replace(/^\/base\//, '')
.replace(/\.js$/, '');
}

View File

@@ -1,27 +1,26 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"removeComments": true,
"noLib": false,
"module": "system",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"removeComments": true,
"declaration": true,
"noLib": false,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": false,
"noImplicitReturns": true,
"noImplicitReturns": false,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"outDir": "dist"
},
"exclude": [
"demo",
"node_modules",
"dist",
"typings/browser.d.ts",
"typings/browser",
"demo"
],
"compileOnSave": false
"typings/main",
"typings/main.d.ts"
]
}

View File

@@ -8,6 +8,23 @@
</a>
</p>
## Install
```sh
npm install --save ng2-alfresco-login
```
## Build from sources
Alternatively you can build component from sources with the following commands:
```sh
npm install
npm run build
```
Components included:
* Alfresco Login Component
@@ -37,17 +54,6 @@ export class MyLoginComponent {
}
```
### Build
```sh
npm install
npm npm run build
```
### Test
```sh
npm test
```
### Demo
## Configuring development environment
@@ -82,3 +88,18 @@ cd demo
npm install
npm start
```
## Running unit tests
```sh
npm test
```
This task rebuilds all the code, runs tslint, license checks and other quality check tools
before performing unit testing.
## Code coverage
```sh
npm run coverage
```

View File

@@ -16,7 +16,6 @@ npm install --save ng2-alfresco-upload
```
## Build from sources
Alternatively you can build component from sources with the following commands:
@@ -64,3 +63,18 @@ This component, provide a drag and drop are to upload files to alfresco.
#### Options
**showDialogUpload**: {boolean} optional) default true. Hide/show upload dialog.<br />
## Running unit tests
```sh
npm test
```
This task rebuilds all the code, runs tslint, license checks and other quality check tools
before performing unit testing.
## Code coverage
```sh
npm run coverage
```