Merge pull request #63 from Alfresco/dev-mromano-tests-karma

#62 add coverage and tests
This commit is contained in:
Maurizio Vitale 2016-05-13 11:17:35 +01:00
commit caebc8c8e4
11 changed files with 246 additions and 114 deletions

View File

@ -0,0 +1,128 @@
// 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) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
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
// suppress annoying 404 warnings for resources, images, etc.
//{ pattern: 'dist/src/assets/**/*', watched: false, included: false, served: true },
'test-main.js'
],
// must go along with above, suppress annoying 404 warnings.
proxies: {
'/assets/': '/base/dist/dev/assets/'
},
// 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,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: [
'PhantomJS',
'Chrome'
],
customLaunchers: {
Chrome_travis_ci: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
coverageReporter: {
dir: 'coverage/',
reporters: [
{ 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;
}
};

View File

@ -12,8 +12,7 @@
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings",
"test": "live-server --open=index.html --entry-file=test/ --mount=/ng2-alfresco-core:../ng2-alfresco-core",
"test:w": "concurrently \"npm run tsc:w\" \"npm run test\" "
"test": "karma start karma.conf.js"
},
"repository": {
"type": "git",
@ -43,9 +42,10 @@
"angular2": "2.0.0-beta.15",
"systemjs": "0.19.26",
"es6-shim": "^0.35.0",
"es6-module-loader": "^0.17.8",
"reflect-metadata": "0.1.2",
"rxjs": "5.0.0-beta.2",
"zone.js": "0.6.10",
"zone.js": "^0.6.12",
"ng2-translate": "^1.11.2"
},
"peerDependencies": {
@ -59,7 +59,18 @@
"typings": "^0.7.12",
"license-check": "^1.0.4",
"tslint": "^3.8.1",
"concurrently": "^2.0.0"
"concurrently": "^2.0.0",
"jasmine-spec-reporter": "^2.4.0",
"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",
"remap-istanbul": "^0.6.3",
"phantomjs-prebuilt": "^2.1.7"
},
"license-check-config": {
"src": [

View File

@ -0,0 +1,78 @@
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,3 +0,0 @@
*.js
*.js.map
*.d.ts

View File

@ -1,65 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/">
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Alfresco Login component Tests</title>
<link rel="stylesheet" href="../node_modules/jasmine-core/lib/jasmine-core/jasmine.css">
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/jasmine-html.js"></script>
<script src="../node_modules/jasmine-core/lib/jasmine-core/boot.js"></script>
<!-- #1. add the system.js library -->
<script src="../node_modules/es6-shim/es6-shim.min.js"></script>
<script src="../node_modules/systemjs/dist/system-polyfills.js"></script>
<script src="../node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/rxjs/bundles/Rx.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/http.dev.js"></script>
<script src="../node_modules/angular2/bundles/router.dev.js"></script>
<script src="../node_modules/angular2/bundles/testing.dev.js"></script>
<script>
// #2. Configure systemjs to use the .js extension
// for imports from the app folder
System.config({
packages: {
'test': {defaultExtension: 'js'},
'src': {defaultExtension: 'js'},
'ng2-translate': {
defaultExtension: 'js'
},
'rxjs': {
defaultExtension: 'js'
}
},
map: {
'ng2-translate': '../node_modules/ng2-translate',
'rxjs': '../node_modules/rxjs'
}
});
// #3. Import the spec file explicitly
Promise.all([
System.import('test/services/alfresco-authentication.spec'),
System.import('test/components/alfresco-login.spec')
])
// #4. wait for all imports to load ...
// then re-execute `window.onload` which
// triggers the Jasmine test-runner start
// or explain what went wrong.
.then(window.onload)
.catch(console.error.bind(console));
</script>
</head>
<body>
<!-- Unit Testing Chapter #1: Proof of life. -->
<script>
</script>
</body>
</html>

View File

@ -1,16 +0,0 @@
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false,
"declaration": false,
"outDir": "../dist"
},
"exclude": [
]
}

View File

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