Upgrade karma for ng2-alfresco-search, disable broken coverage

This commit is contained in:
Denys Vuika 2016-09-22 17:07:47 +01:00
parent e44ae2cae4
commit 993c72b9a1
2 changed files with 137 additions and 93 deletions

View File

@ -5,105 +5,122 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
__karma__.loaded = function() {}; __karma__.loaded = function() {};
var builtPath = '/base/dist/';
function isJsFile(path) {
return path.slice(-3) == '.js';
}
function isSpecFile(path) {
return /\.spec\.(.*\.)?js$/.test(path);
}
function isBuiltFile(path) {
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
}
var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isBuiltFile);
var paths = {
// paths serve as alias
'npm:': 'base/node_modules/'
};
var map = { var map = {
'app': 'base/dist', 'app': 'base/dist',
'rxjs': 'base/node_modules/rxjs', // angular bundles
'@angular': 'base/node_modules/@angular', '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
// testing
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
'@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
'@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',
'@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js',
'ng2-alfresco-core': '/base/node_modules/ng2-alfresco-core/dist', // other libraries
'ng2-translate' : '/base/node_modules/ng2-translate' 'rxjs': 'npm:rxjs',
'ng2-translate': 'npm:ng2-translate',
'alfresco-js-api': 'npm:alfresco-js-api/dist',
'ng2-activiti-form': 'npm:ng2-activiti-form/dist',
'ng2-activiti-processlist': 'npm:ng2-activiti-processlist/dist',
'ng2-activiti-tasklist': 'npm:ng2-activiti-tasklist/dist',
'ng2-alfresco-core': 'npm:ng2-alfresco-core/dist',
'ng2-alfresco-datatable': 'npm:ng2-alfresco-datatable/dist',
'ng2-alfresco-documentlist': 'npm:ng2-alfresco-documentlist/dist',
'ng2-alfresco-login': 'npm:ng2-alfresco-login/dist',
//'ng2-alfresco-search': 'npm:ng2-alfresco-search/dist',
'ng2-alfresco-tag': 'npm:ng2-alfresco-tag/dist',
'ng2-alfresco-upload': 'npm:ng2-alfresco-upload/dist',
'ng2-alfresco-viewer': 'npm:ng2-alfresco-viewer/dist',
'ng2-alfresco-webscript': 'npm:ng2-alfresco-webscript/dist'
}; };
var packages = { var packages = {
'app': { main: 'main.js', defaultExtension: 'js' }, 'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' }, 'rxjs': { defaultExtension: 'js' },
'ng2-translate': { defaultExtension: 'js' },
'ng2-alfresco-core': { main: 'index.js', defaultExtension: 'js' }, 'alfresco-js-api': { main: './alfresco-js-api.js', defaultExtension: 'js'},
'ng2-translate': { defaultExtension: 'js' } 'ng2-activiti-form': { main: './index.js', defaultExtension: 'js'},
}; 'ng2-activiti-processlist': { main: './index.js', defaultExtension: 'js'},
'ng2-activiti-tasklist': { main: './index.js', defaultExtension: 'js'},
var packageNames = [ 'ng2-alfresco-core': { main: './index.js', defaultExtension: 'js'},
'@angular/common', 'ng2-alfresco-datatable': { main: './index.js', defaultExtension: 'js'},
'@angular/compiler', 'ng2-alfresco-documentlist': { main: './index.js', defaultExtension: 'js'},
'@angular/core', 'ng2-alfresco-login': { main: './index.js', defaultExtension: 'js'},
'@angular/http', //'ng2-alfresco-search': { main: './index.js', defaultExtension: 'js'},
'@angular/platform-browser', 'ng2-alfresco-tag': { main: './index.js', defaultExtension: 'js'},
'@angular/platform-browser-dynamic', 'ng2-alfresco-upload': { main: './index.js', defaultExtension: 'js'},
'@angular/router', 'ng2-alfresco-viewer': { main: './index.js', defaultExtension: 'js'},
'@angular/router-deprecated', 'ng2-alfresco-webscript': { main: './index.js', defaultExtension: 'js'}
'@angular/testing',
'@angular/upgrade'
];
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
packages['base/dist'] = {
defaultExtension: 'js',
format: 'register',
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
}; };
var config = { var config = {
paths: paths,
map: map, map: map,
packages: packages packages: packages
}; };
System.config(config); System.config(config);
System.import('@angular/platform-browser/src/browser/browser_adapter') System.import('@angular/core/testing')
.then(function(browser_adapter) { browser_adapter.BrowserDomAdapter.makeCurrent(); }) .then(initTestBed)
.then(function () { .then(initTesting);
function initTestBed(){
return Promise.all([ return Promise.all([
System.import('@angular/core/testing'), System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing') System.import('@angular/platform-browser-dynamic/testing')
]) ])
})
.then(function (providers) { .then(function (providers) {
var testing = providers[0]; var coreTesting = providers[0];
var testingBrowser = providers[1]; var browserTesting = providers[1];
testing.setBaseTestProviders(
testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS,
testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS);
coreTesting.TestBed.initTestEnvironment(
browserTesting.BrowserDynamicTestingModule,
browserTesting.platformBrowserDynamicTesting());
}) })
.then(function() { return Promise.all(resolveTestFiles()); })
.then(
function() {
__karma__.start();
},
function(error) {
if(typeof __karma__.error == 'function') {
__karma__.error(error.stack || error);
}else{
console.error(error);
}
}
);
function createPathRecords(pathsMapping, appPath) {
var pathParts = appPath.split('/');
var moduleName = './' + pathParts.slice(Math.max(pathParts.length - 2, 1)).join('/');
moduleName = moduleName.replace(/\.js$/, '');
pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath];
return pathsMapping;
} }
function onlyAppFiles(filePath) { // Import all spec files and start karma
return /\/base\/dist\/(?!.*\.spec\.js$).*\.js$/.test(filePath); function initTesting () {
} return Promise.all(
allSpecFiles.map(function (moduleName) {
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); return System.import(moduleName);
}); })
)
.then(__karma__.start, __karma__.error);
} }

View File

@ -7,27 +7,56 @@ module.exports = function (config) {
frameworks: ['jasmine-ajax', 'jasmine'], frameworks: ['jasmine-ajax', 'jasmine'],
files: [ files: [
// paths loaded by Karma // System.js for module loading
{pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true}, 'node_modules/systemjs/dist/system.src.js',
{pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false},
{pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true}, // Polyfills
'node_modules/core-js/client/shim.js',
'node_modules/reflect-metadata/Reflect.js',
// zone.js
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.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',
// RxJs
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false }, { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },
// Paths loaded via module imports:
// Angular itself
{pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false},
{pattern: 'node_modules/@angular/**/*.map', included: false, watched: false}, {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false},
{pattern: 'node_modules/material-design-lite/material.min.js', included: true, watched: false}, 'node_modules/alfresco-js-api/dist/alfresco-js-api.js',
{pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false}, {pattern: 'node_modules/ng2-translate/**/*.js', included: false, watched: false},
{pattern: 'node_modules/ng2-translate/**/*.js.map', included: false, watched: false},
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false}, 'karma-test-shim.js',
{pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false},
{pattern: 'karma-test-shim.js', included: true, watched: true},
// paths loaded via module imports // paths loaded via module imports
{pattern: 'dist/**/*.js', included: false, watched: true}, {pattern: 'dist/**/*.js', included: false, watched: true},
{pattern: 'dist/**/*.html', included: true, served: true, watched: true}, {pattern: 'dist/**/*.html', included: true, served: true, watched: true},
{pattern: 'dist/**/*.css', included: true, served: true, watched: true}, {pattern: 'dist/**/*.css', included: true, served: true, watched: true},
// ng2-components
{ pattern: 'node_modules/ng2-activiti-form/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-activiti-processlist/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-activiti-tasklist/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-datatable/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-documentlist/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-login/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-search/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-tag/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-upload/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-viewer/dist/**/*.js', included: false, served: true, watched: false },
{ pattern: 'node_modules/ng2-alfresco-webscript/dist/**/*.js', included: false, served: true, watched: false },
// paths to support debugging with source maps in dev tools // paths to support debugging with source maps in dev tools
{pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'src/**/*.ts', included: false, watched: false},
{pattern: 'dist/**/*.js.map', included: false, watched: false} {pattern: 'dist/**/*.js.map', included: false, watched: false}
@ -62,7 +91,6 @@ module.exports = function (config) {
} }
}, },
// Karma plugins loaded // Karma plugins loaded
plugins: [ plugins: [
'karma-jasmine', 'karma-jasmine',
@ -79,7 +107,7 @@ module.exports = function (config) {
// Source files that you wanna generate coverage for. // Source files that you wanna generate coverage for.
// Do not include tests or libraries (these files will be instrumented by Istanbul) // Do not include tests or libraries (these files will be instrumented by Istanbul)
preprocessors: { preprocessors: {
'dist/**/!(*spec).js': ['coverage'] //'dist/**/!(*spec).js': ['coverage']
}, },
coverageReporter: { coverageReporter: {
@ -87,7 +115,6 @@ module.exports = function (config) {
subdir: 'report', subdir: 'report',
reporters: [ reporters: [
{type: 'text'}, {type: 'text'},
{type: 'text-summary'},
{type: 'json', file: 'coverage-final.json'}, {type: 'json', file: 'coverage-final.json'},
{type: 'html'}, {type: 'html'},
{type: 'lcov'} {type: 'lcov'}