make tests work

This commit is contained in:
Andrew
2015-03-29 10:53:19 -06:00
parent 91ff27a675
commit bedbe8b489
9 changed files with 31 additions and 173 deletions

View File

@@ -56,7 +56,7 @@ gulp.task('dependencies', function() {
})
gulp.task('ionic-js', function() {
return gulp.src(buildConfig.src.js)
return gulp.src(['src/**/*.js', '!src/**/test/*/**/*.js'])
.pipe(gulp.dest(buildConfig.distLib + '/ionic2'))
})

View File

@@ -5,7 +5,7 @@ module.exports = {
spec: ['src/**/test/*.spec.js'],
js: ['src/**/*.js', '!src/**/test/**/*.js'],
e2eTest: ['src/components/*/test/*/'],
e2e: ['src/components/*/test/**/*'],
e2e: ['src/components/*/test/*/**/*'],
html: 'src/**/*.html',
scss: 'src/components/**/*.scss',
},

View File

@@ -3,25 +3,16 @@ var buildConfig = require('../build/config');
module.exports = function(config) {
config.set({
singleRun: true,
basePath: '../..',
basePath: '../../dist/lib',
frameworks: ['jasmine'],
files: [
'node_modules/systemjs/dist/system.js',
'node_modules/es6-module-loader/dist/es6-module-loader.js',
'node_modules/traceur-runtime/index.js',
'node_modules/zone.js/zone.js',
'node_modules/zone.js/long-stack-trace-zone.js',
'dist/lib/angular2.js',
'jspm-config.js',
'scripts/test/test-main.js',
{pattern: 'src/**/*.spec.js', included: false},
],
files: buildConfig.scripts.concat([
{pattern: 'ionic2/**/*.js', included: false},
'../../scripts/test/test-main.js',
]),
exclude: [
'src/**/examples/**'
],
exclude: buildConfig.src.e2e,
logLevel: 'warn',

View File

@@ -1,20 +1,23 @@
// 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/';
// So that we can import packages like `core/foo`, instead of `core/src/foo`.
// System.paths = {
// '*': './*.js',
// 'transpiler/*': '../tools/transpiler/*.js'
// }
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(
Object.keys(window.__karma__.files) // All files served by Karma.
@@ -22,10 +25,10 @@ Promise.all(
.map(window.file2moduleName) // Normalize paths to module names.
.map(function(path) {
return System.import(path).then(function(module) {
if (module.hasOwnProperty('main')) {
module.main();
if (module.hasOwnProperty('run')) {
module.run();
} else {
throw new Error('Module ' + path + ' does not implement main() method.');
throw new Error('Module ' + path + ' does not implement run() method.');
}
});
}))
@@ -41,12 +44,12 @@ function onlySpecFiles(path) {
}
function file2moduleName(filePath) {
return filePath.replace(/\\/g, '/')
.replace(/^.*?\/dist\//, '')
.replace(/^.*?base\//, '')
// 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*$/, '');
.replace(/\.js$/, '');
}

View File

@@ -9,7 +9,7 @@ export let CheckboxConfig = new ComponentConfig('checkbox')
checked: 'checked'
},
events: {
'click': 'onClick()'
'^click': 'onClick()'
},
services: [CheckboxConfig]
})

View File

@@ -0,0 +1,2 @@
export function run() {
}

View File

View File

@@ -1,138 +0,0 @@
import {Config} from 'ionic2/config/component-config';
// TODO stop hardcoding platforms and media sizes
export function main() {
var rootConfig;
beforeEach(() => {
rootConfig = new Config();
});
it('should create a config one level down', () => {
var sub = rootConfig.platform('ios');
expect(sub._parent).toBe(rootConfig);
expect(sub._path).toEqual(['ios']);
expect(rootConfig._cases.ios).toBe(sub);
});
it('should create a config two levels down', () => {
var sub1 = rootConfig.platform('ios');
var sub2 = sub1.media('lg');
expect(sub2._parent).toBe(sub1);
expect(sub1._parent).toBe(rootConfig);
expect(rootConfig._cases['ios lg']).toBe(sub2);
expect(rootConfig._cases.ios).toBe(sub1);
});
it('set should be chainable', () => {
expect(rootConfig.set()).toBe(rootConfig);
});
it('should set values on the root', () => {
rootConfig.set({
letter: 'a'
});
expect(rootConfig.get('letter')).toBe('a');
});
it('should always return the same object for the same key', () => {
expect(rootConfig.platform('android')).toBe(rootConfig.platform('android'));
expect(rootConfig.platform('ios')).toBe(rootConfig.platform('ios'));
expect(rootConfig.media('lg')).toBe(rootConfig.media('lg'));
});
it('should return the same object when nesting in different order', () => {
var sub1 = rootConfig.platform('ios').media('sm');
var sub2 = rootConfig.media('sm').platform('ios');
expect(sub1).toBe(sub2);
});
it('should return the same object when nesting in different order for huge queries', () => {
var sub1 = rootConfig.platform('ios').media('sm').platform('android').media('lg');
var sub2 = rootConfig.media('sm').media('lg').platform('android').platform('ios');
expect(sub1).toBe(sub2);
});
it('should set values one level down and be chainable', () => {
rootConfig.set({ letter: 'a' });
var sub1 = rootConfig.platform('ios');
expect(sub1.get('letter')).toBe('a');
expect( sub1.set({ letter: 'b' }) ).toBe(sub1);
expect(sub1.get('letter')).toBe('b');
});
it('should set values two levels down and be chainable', () => {
rootConfig.set({ letter: 'a' });
var sub1 = rootConfig.platform('ios');
sub1.set({ letter: 'b' });
var sub2 = sub1.media('lg');
expect(sub2.get('letter')).toBe('b');
expect( sub2.set({ letter: 'c' }) ).toBe(sub2);
expect(sub2.get('letter')).toBe('c');
});
it('should use parent\'s value if its later set to undefined', () => {
rootConfig.set({ letter: 'a' });
var sub1 = rootConfig.platform('ios');
sub1.set({ letter: 'b' });
expect(sub1.get('letter')).toBe('b');
expect( sub1.unset('letter') ).toBe(sub1);
expect(sub1.get('letter')).toBe('a');
});
it('when() as alias for media()', () => {
expect(rootConfig.when('lg')).toBe(rootConfig.media('lg'));
expect(rootConfig.when('bad')).toBe(rootConfig);
expect(rootConfig.when('lg')).not.toBe(rootConfig.when('ios'));
});
it('when() as alias for platform()', () => {
expect(rootConfig.platform('ios')).toBe(rootConfig.when('ios'));
expect(rootConfig.when('bad')).toBe(rootConfig);
});
describe('invokeConfig', function() {
it('should invoke defaults', () => {
var obj = {};
rootConfig.set('foo', 'bar');
rootConfig.invoke(obj);
});
it('should invoke defaults in nested whens', () => {
var obj = {};
rootConfig.set({ a: 'root', b: 'root' });
rootConfig.when('ios').set({b: 'ios', c: 'ios'});
rootConfig.when('ios').when('lg').set({ c: 'ios-lg', d: 'ios-lg' });
rootConfig.invoke(obj);
expect(obj).toEqual({
a: 'root',
b: 'ios',
c: 'ios-lg',
d: 'ios-lg'
});
});
it('should run behaviors', () => {
var obj = {};
rootConfig.behavior(instance => {
instance.foo = 'bar';
});
rootConfig.invoke(obj);
expect(obj.foo).toBe('bar');
});
it('should invoke behaviors in nested whens', () => {
var obj = {};
rootConfig.when('ios')
.behavior(o => o.ios = true)
.when('lg')
.behavior(o => o.lg = true)
rootConfig.invoke(obj);
expect(obj).toEqual({
ios: true,
lg: true
});
});
});
}

View File

@@ -1,6 +1,6 @@
import * as util from 'ionic2/util';
export function main() {
export function run() {
describe('extend', function() {
it('should extend simple', () => {