make tests es6 modules

This commit is contained in:
Tim Lancina
2015-07-13 17:07:08 -05:00
parent 5a7f1951d1
commit a126b9abb5
7 changed files with 32 additions and 127 deletions

View File

@ -123,6 +123,20 @@ var exampleBabelOptions = {
} }
}; };
var testBabelOptions = {
optional: ['es7.decorators'],
/*plugins: [
'./transformers/disable-define',
'angular2-annotations',
'type-assertion:after'
],*/
modules: "system",
moduleIds: true,
getModuleId: function(name) {
return "dist/tests/" + name.split('/test').join('');
}
};
var tscOptions = { var tscOptions = {
target: 'ES6', target: 'ES6',
// Don't use the version of typescript that gulp-typescript depends on, we need 1.5 // Don't use the version of typescript that gulp-typescript depends on, we need 1.5
@ -192,7 +206,7 @@ gulp.task('bundle.js', function() {
gulp.task('tests', function() { gulp.task('tests', function() {
return gulp.src('ionic/components/*/test/*/**/*.spec.ts') return gulp.src('ionic/components/*/test/*/**/*.spec.ts')
.pipe(tsc(tscOptions, null, tscReporter)) .pipe(tsc(tscOptions, null, tscReporter))
.pipe(babel()) .pipe(babel(testBabelOptions))
.pipe(rename(function(file) { .pipe(rename(function(file) {
file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep) file.dirname = file.dirname.replace(path.sep + 'test' + path.sep, path.sep)
})) }))
@ -273,8 +287,8 @@ gulp.task('vendor', function() {
require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig); require('./scripts/snapshot/snapshot.task')(gulp, argv, buildConfig);
gulp.task('karma', function() { gulp.task('karma', function() {
//return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' }) return karma.start({ configFile: __dirname + '/scripts/test/karma.conf.js' })
return karma.start({ configFile: __dirname + '/karma.conf.js' }) //return karma.start({ configFile: __dirname + '/karma.conf.js' })
}); });
gulp.task('karma-watch', function() { gulp.task('karma-watch', function() {

View File

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

View File

@ -1,68 +0,0 @@
// Karma configuration
// Generated on Mon Jul 13 2015 15:16:50 GMT-0500 (CDT)
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: [
{pattern: 'dist/js/es5/ionic/**/*.js', included: false},
{pattern: 'dist/tests/**/*.spec.js', included: true},
'test-main.js'
],
// list of files to exclude
exclude: [
'ionic/components/*/test/*/**/*'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],
// 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_DEBUG,
// 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: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}

View File

@ -3,7 +3,7 @@ module.exports = {
distLib: 'dist/lib', distLib: 'dist/lib',
src: { src: {
spec: ['ionic/**/test/*.spec.js'], spec: ['ionic/**/test/*.spec.js'],
js: ['ionic/**/*.js', '!src/**/test/**/*.js'], js: ['ionic/**/*.js'],
// Get all the non-js files and main.js // Get all the non-js files and main.js
e2e: ['ionic/components/*/test/*/**/*'], e2e: ['ionic/components/*/test/*/**/*'],
@ -12,40 +12,15 @@ module.exports = {
}, },
scripts: [ scripts: [
{ 'scripts/resources/traceur-runtime.js',
from: 'node_modules/gulp-traceur/node_modules/traceur/bin/traceur.js', { pattern: 'jspm_packages/es6-module-loader.js', included: false },
to: 'traceur.js', 'jspm_packages/system.src.js',
}, { 'config.js',
from: 'node_modules/es6-module-loader/dist/es6-module-loader.src.js', 'scripts/resources/angular2.dev.js',
to: 'es6-module-loader.src.js' 'dist/js/ionic.bundle.js',
}, { 'dist/vendor/web-animations-js/web-animations.min.js'
from: 'node_modules/systemjs/dist/system.src.js',
to: 'system.src.js'
}, {
from: 'scripts/e2e/system-init.js',
to: 'system-init.js'
}, {
from: 'node_modules/angular2/node_modules/zone.js/zone.js',
to: 'zone.js'
}, {
from: 'node_modules/angular2/node_modules/zone.js/long-stack-trace-zone.js',
to: 'long-stack-trace-zone.js'
},
'angular2.js',
'angular2-di.js',
'ionic2.js',
// 'https://cdn.firebase.com/js/client/2.2.4/firebase.js'
// 'https://cdn.firebase.com/js/client/2.2.4/firebase-debug.js'
], ],
traceurOptions: {
sourceMaps: true,
annotations: true,
types: true,
memberVariables: true,
modules: 'instantiate',
},
protractorPort: 8876, protractorPort: 8876,
autoprefixer: { autoprefixer: {

View File

@ -2,14 +2,15 @@ var buildConfig = require('../build/config');
module.exports = function(config) { module.exports = function(config) {
config.set({ config.set({
singleRun: true, //singleRun: true,
basePath: '../..', basePath: '../../',
frameworks: ['jasmine'], frameworks: ['jasmine'],
files: buildConfig.scripts.concat([ files: buildConfig.scripts.concat([
{pattern: 'ionic2/**/*.js', included: false}, 'dist/js/es5/ionic/**/*.js',
'../../scripts/test/test-main.js', 'dist/tests/**/*.spec.js',
'scripts/test/test-main.js'
]), ]),
exclude: buildConfig.src.e2e, exclude: buildConfig.src.e2e,
@ -17,7 +18,6 @@ module.exports = function(config) {
logLevel: 'warn', logLevel: 'warn',
preprocessors: { preprocessors: {
'modules/**/*.js': ['traceur']
}, },
browsers: ['Chrome'], browsers: ['Chrome'],

View File

@ -4,26 +4,12 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 50;
// we will call `__karma__.start()` later, once all the specs are loaded. // we will call `__karma__.start()` later, once all the specs are loaded.
__karma__.loaded = function() {}; __karma__.loaded = function() {};
System.config({
baseURL: 'http://localhost:9876/base',
traceurOptions: {
'sourceMaps': true,
'annotations': true,
'types': true,
'script': false,
'memberVariables': true,
'modules': 'instantiate'
},
map: {
'rx/dist/rx.all': 'rx.all',
}
})
Promise.all( Promise.all(
Object.keys(window.__karma__.files) // All files served by Karma. Object.keys(window.__karma__.files) // All files served by Karma.
.filter(onlySpecFiles) .filter(onlySpecFiles)
.map(window.file2moduleName) // Normalize paths to module names. .map(window.file2moduleName) // Normalize paths to module names.
.map(function(path) { .map(function(path) {
debugger;
return System.import(path).then(function(module) { return System.import(path).then(function(module) {
if (module.hasOwnProperty('run')) { if (module.hasOwnProperty('run')) {
module.run(); module.run();

View File

@ -1,2 +0,0 @@
__karma__.start();