diff --git a/ng2-components/ng2-alfresco-search/karma-test-shim.js b/ng2-components/ng2-alfresco-search/karma-test-shim.js index 45a2f4f180..f43c3634b0 100644 --- a/ng2-components/ng2-alfresco-search/karma-test-shim.js +++ b/ng2-components/ng2-alfresco-search/karma-test-shim.js @@ -5,105 +5,122 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; __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 = { 'app': 'base/dist', - 'rxjs': 'base/node_modules/rxjs', - '@angular': 'base/node_modules/@angular', + // angular bundles + '@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', - 'ng2-translate' : '/base/node_modules/ng2-translate' + // other libraries + '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 = { 'app': { main: 'main.js', defaultExtension: 'js' }, - 'rxjs': { defaultExtension: 'js' }, + 'rxjs': { defaultExtension: 'js' }, + 'ng2-translate': { defaultExtension: 'js' }, - 'ng2-alfresco-core': { main: 'index.js', defaultExtension: 'js' }, - 'ng2-translate': { defaultExtension: 'js' } -}; - -var packageNames = [ - '@angular/common', - '@angular/compiler', - '@angular/core', - '@angular/http', - '@angular/platform-browser', - '@angular/platform-browser-dynamic', - '@angular/router', - '@angular/router-deprecated', - '@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, {}) + 'alfresco-js-api': { main: './alfresco-js-api.js', 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'}, + 'ng2-alfresco-core': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-datatable': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-documentlist': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-login': { main: './index.js', defaultExtension: 'js'}, + //'ng2-alfresco-search': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-tag': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-upload': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-viewer': { main: './index.js', defaultExtension: 'js'}, + 'ng2-alfresco-webscript': { main: './index.js', defaultExtension: 'js'} }; var config = { + paths: paths, map: map, packages: packages }; System.config(config); -System.import('@angular/platform-browser/src/browser/browser_adapter') - .then(function(browser_adapter) { browser_adapter.BrowserDomAdapter.makeCurrent(); }) - .then(function () { - return Promise.all([ - System.import('@angular/core/testing'), - System.import('@angular/platform-browser-dynamic/testing') - ]) - }) +System.import('@angular/core/testing') + .then(initTestBed) + .then(initTesting); + +function initTestBed(){ + return Promise.all([ + System.import('@angular/core/testing'), + System.import('@angular/platform-browser-dynamic/testing') + ]) .then(function (providers) { - var testing = providers[0]; - var testingBrowser = providers[1]; - - testing.setBaseTestProviders( - testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, - testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); + var coreTesting = providers[0]; + var browserTesting = providers[1]; + 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) { - 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') +// Import all spec files and start karma +function initTesting () { + return Promise.all( + allSpecFiles.map(function (moduleName) { return System.import(moduleName); - }); + }) + ) + .then(__karma__.start, __karma__.error); } diff --git a/ng2-components/ng2-alfresco-search/karma.conf.js b/ng2-components/ng2-alfresco-search/karma.conf.js index 20f4f6bb74..97303d3231 100644 --- a/ng2-components/ng2-alfresco-search/karma.conf.js +++ b/ng2-components/ng2-alfresco-search/karma.conf.js @@ -7,27 +7,56 @@ module.exports = function (config) { frameworks: ['jasmine-ajax', 'jasmine'], files: [ - // paths loaded by Karma - {pattern: 'node_modules/reflect-metadata/Reflect.js', included: true, watched: true}, - {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: false}, - {pattern: 'node_modules/zone.js/dist/zone.js', included: true, watched: true}, - {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false}, + // System.js for module loading + 'node_modules/systemjs/dist/system.src.js', + + // 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.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/**/*.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}, - {pattern: 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', included: true, watched: false}, + 'node_modules/alfresco-js-api/dist/alfresco-js-api.js', + {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}, - {pattern: 'node_modules/ng2-translate/**/*.js', included: false, served: true, watched: false}, - - {pattern: 'karma-test-shim.js', included: true, watched: true}, + 'karma-test-shim.js', // paths loaded via module imports {pattern: 'dist/**/*.js', included: false, watched: true}, {pattern: 'dist/**/*.html', 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 {pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'dist/**/*.js.map', included: false, watched: false} @@ -62,7 +91,6 @@ module.exports = function (config) { } }, - // Karma plugins loaded plugins: [ 'karma-jasmine', @@ -79,7 +107,7 @@ module.exports = function (config) { // 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'] + //'dist/**/!(*spec).js': ['coverage'] }, coverageReporter: { @@ -87,7 +115,6 @@ module.exports = function (config) { subdir: 'report', reporters: [ {type: 'text'}, - {type: 'text-summary'}, {type: 'json', file: 'coverage-final.json'}, {type: 'html'}, {type: 'lcov'}