diff --git a/gulpfile.js b/gulpfile.js index b92a8cb94e..6c8416282c 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -11,28 +11,12 @@ var rename = require('gulp-rename'); var traceur = require('gulp-traceur'); var lazypipe = require('lazypipe'); var sass = require('gulp-sass'); - -var config = { - 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' - ] -}; +var config = require('./scripts/build/config'); +var karma = require('karma').server; gulp.task('default', ['js', 'html', 'sass', 'libs', 'playgroundJs', 'playgroundFiles']); -gulp.task('watch', ['default'], function () { +gulp.task('watch', ['default'], function() { var http = require('http'); var connect = require('connect'); var serveStatic = require('serve-static'); @@ -50,6 +34,13 @@ gulp.task('watch', ['default'], function () { 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.watch('src/**/*.scss', ['sass']); }); diff --git a/package.json b/package.json index 9a4bc277fd..03530b0923 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "gulp-rename": "~1.2.0", "gulp-sass": "^1.3.3", "gulp-traceur": "0.16.*", + "karma": "^0.12.31", "lazypipe": "^0.2.2", "open": "0.0.5", "serve-static": "~1.8.1", @@ -20,7 +21,11 @@ "angular2": "2.0.0-alpha.13", "es6-module-loader": "~0.11.0", "hammerjs": "^2.0.4", + "jasmine-core": "^2.2.0", + "karma-chrome-launcher": "^0.1.7", + "karma-jasmine": "^0.3.5", "systemjs": "~0.11.0", + "traceur": "0.0.87", "zone.js": "0.4.1" } } diff --git a/scripts/build/config.js b/scripts/build/config.js new file mode 100644 index 0000000000..639c2bc9a7 --- /dev/null +++ b/scripts/build/config.js @@ -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' + ] +}; diff --git a/scripts/test/karma-watch.conf.js b/scripts/test/karma-watch.conf.js new file mode 100644 index 0000000000..063ab1405b --- /dev/null +++ b/scripts/test/karma-watch.conf.js @@ -0,0 +1,8 @@ +module.exports = function(config) { + require('./karma.conf.js')(config); + config.set({ + singleRun: false, + }); +}; + + diff --git a/scripts/test/karma.conf.js b/scripts/test/karma.conf.js new file mode 100644 index 0000000000..fbbc5fdf75 --- /dev/null +++ b/scripts/test/karma.conf.js @@ -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 + }); +}; + + diff --git a/scripts/test/placeholder b/scripts/test/placeholder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/scripts/test/test-main.js b/scripts/test/test-main.js new file mode 100644 index 0000000000..71b002914e --- /dev/null +++ b/scripts/test/test-main.js @@ -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*$/, ''); +} diff --git a/src/components/app/app_spec.js b/src/components/app/app_spec.js new file mode 100644 index 0000000000..716ba30a12 --- /dev/null +++ b/src/components/app/app_spec.js @@ -0,0 +1,7 @@ +import {Ion} from '../ion'; + +export function main() { + it('should be true', () => { + expect(false).toBe(true); + }); +}