unit tests!

This commit is contained in:
Andrew
2015-03-19 14:34:48 -05:00
parent 85908b00c9
commit 71125622fa
8 changed files with 134 additions and 19 deletions

View File

@ -11,28 +11,12 @@ var rename = require('gulp-rename');
var traceur = require('gulp-traceur'); var traceur = require('gulp-traceur');
var lazypipe = require('lazypipe'); var lazypipe = require('lazypipe');
var sass = require('gulp-sass'); var sass = require('gulp-sass');
var config = require('./scripts/build/config');
var config = { var karma = require('karma').server;
dist: 'dist',
src: {
js: ['src/**/*.js', '!src/**/*.spec.js'],
html: 'src/**/*.html',
scss: 'src/components/**/*.scss',
playgroundJs: 'playground/**/*.js',
playgroundFiles: ['playground/**/*', '!playground/**/*.js'],
},
lib: [
'node_modules/gulp-traceur/node_modules/traceur/bin/traceur-runtime.js',
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/angular2/node_modules/zone.js/zone.js',
'node_modules/hammerjs/hammer.js'
]
};
gulp.task('default', ['js', 'html', 'sass', 'libs', 'playgroundJs', 'playgroundFiles']); gulp.task('default', ['js', 'html', 'sass', 'libs', 'playgroundJs', 'playgroundFiles']);
gulp.task('watch', ['default'], function () { gulp.task('watch', ['default'], function() {
var http = require('http'); var http = require('http');
var connect = require('connect'); var connect = require('connect');
var serveStatic = require('serve-static'); var serveStatic = require('serve-static');
@ -50,6 +34,13 @@ gulp.task('watch', ['default'], function () {
console.log('Serving `dist` on http://localhost:' + port); console.log('Serving `dist` on http://localhost:' + port);
}); });
gulp.task('karma', function() {
return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' });
});
gulp.task('karma-watch', function() {
return karma.start({ configFile: __dirname + '/scripts/test/karma-watch.conf.js' });
});
gulp.task('sass-watch', ['sass'], function () { gulp.task('sass-watch', ['sass'], function () {
gulp.watch('src/**/*.scss', ['sass']); gulp.watch('src/**/*.scss', ['sass']);
}); });

View File

@ -11,6 +11,7 @@
"gulp-rename": "~1.2.0", "gulp-rename": "~1.2.0",
"gulp-sass": "^1.3.3", "gulp-sass": "^1.3.3",
"gulp-traceur": "0.16.*", "gulp-traceur": "0.16.*",
"karma": "^0.12.31",
"lazypipe": "^0.2.2", "lazypipe": "^0.2.2",
"open": "0.0.5", "open": "0.0.5",
"serve-static": "~1.8.1", "serve-static": "~1.8.1",
@ -20,7 +21,11 @@
"angular2": "2.0.0-alpha.13", "angular2": "2.0.0-alpha.13",
"es6-module-loader": "~0.11.0", "es6-module-loader": "~0.11.0",
"hammerjs": "^2.0.4", "hammerjs": "^2.0.4",
"jasmine-core": "^2.2.0",
"karma-chrome-launcher": "^0.1.7",
"karma-jasmine": "^0.3.5",
"systemjs": "~0.11.0", "systemjs": "~0.11.0",
"traceur": "0.0.87",
"zone.js": "0.4.1" "zone.js": "0.4.1"
} }
} }

19
scripts/build/config.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
dist: 'dist',
src: {
js: ['src/**/*.js', '!src/**/examples/**'],
test: ['src/**/*.spec.js'],
examples: ['src/**/examples/**'],
html: 'src/**/*.html',
scss: 'src/components/**/*.scss',
playgroundJs: 'playground/**/*.js',
playgroundFiles: ['playground/**/*', '!playground/**/*.js'],
},
lib: [
'node_modules/gulp-traceur/node_modules/traceur/bin/traceur-runtime.js',
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
'node_modules/systemjs/lib/extension-register.js',
'node_modules/angular2/node_modules/zone.js/zone.js',
'node_modules/hammerjs/hammer.js'
]
};

View File

@ -0,0 +1,8 @@
module.exports = function(config) {
require('./karma.conf.js')(config);
config.set({
singleRun: false,
});
};

View File

@ -0,0 +1,33 @@
var buildConfig = require('../build/config');
module.exports = function(config) {
config.set({
singleRun: true,
basePath: '../..',
frameworks: ['jasmine'],
files: [
// Sources and specs.
// Loaded through the es6-module-loader, in `test-main.js`.
{pattern: 'dist/ionic/**/*.js', included: false},
]
.concat(buildConfig.lib)
.concat('scripts/test/test-main.js'),
exclude: [
'src/**/examples/**'
],
logLevel: 'warn',
preprocessors: {
'modules/**/*.js': ['traceur']
},
browsers: ['Chrome'],
port: 9876
});
};

52
scripts/test/test-main.js Normal file
View File

@ -0,0 +1,52 @@
// Use "register" extension from systemjs.
// That's what Traceur outputs: `System.register()`.
register(System);
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50;
// Cancel Karma's synchronous start,
// we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {};
System.baseURL = 'http://localhost:9876/base/dist/';
// So that we can import packages like `core/foo`, instead of `core/src/foo`.
// System.paths = {
// '*': './*.js',
// 'transpiler/*': '../tools/transpiler/*.js'
// }
Promise.all(
Object.keys(window.__karma__.files) // All files served by Karma.
.filter(onlySpecFiles)
.map(window.file2moduleName) // Normalize paths to module names.
.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) {
return /_spec\.js$/.test(path);
}
function file2moduleName(filePath) {
return filePath.replace(/\\/g, '/')
.replace(/^.*?\/dist\//, '')
// module name should be relative to `modules` and `tools` folder
// .replace(/.*\/modules\//, '')
// .replace(/.*\/tools\//, '')
// module name should not include `lib`, `web` folders
// module name should not have a suffix
// .split('.').pop().join('');
.replace(/\.\w*$/, '');
}

View File

@ -0,0 +1,7 @@
import {Ion} from '../ion';
export function main() {
it('should be true', () => {
expect(false).toBe(true);
});
}