Skip to content

Commit

Permalink
Removing 404 for app.html
Browse files Browse the repository at this point in the history
  • Loading branch information
lathonez committed Feb 18, 2016
1 parent 14d379a commit 5af7958
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
16 changes: 15 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var config = require('./ionic.config');
var ts = require('gulp-typescript');
var tslint = require('gulp-tslint');
var karma = require('karma').Server;
var mkdirp = require('mkdirp');

// typescript files are compiled individually and saved to www/build/test/ - delete them here
gulp.task('test.clean', function() {
Expand All @@ -24,6 +25,18 @@ gulp.task('test.lint', function () {
.pipe(tslint.report('verbose'));
});

gulp.task('test.copyHTML', ['test.clean'], function() {
// need to manually make a directoy for admin atm as there is no *.ts inside
mkdirp(config.paths.test.dest + '/admin', function(err) {
if (err) {
console.log(err);
throw err;
}
gulp.src(config.paths.html.src)
.pipe(gulp.dest(config.paths.test.dest));
});
});

// compile typescript into indivudal files, project directoy structure is replicated under www/build/test
gulp.task('test.compile', ['test.clean'], function () {
// tsconfig options basically copy pasta from tsconfig.json
Expand Down Expand Up @@ -52,7 +65,8 @@ gulp.task('test.compile', ['test.clean'], function () {
});

// run jasmine unit tests using karma - lint and compile are run in parallel
gulp.task('test', ['test.lint', 'test.compile'], function() {
gulp.task('test', ['test.lint', 'test.compile', 'test.copyHTML'], function() {

karma.start({
configFile: __dirname + '/' + config.paths.test.config,
}, function(karmaExitCode) {
Expand Down
13 changes: 13 additions & 0 deletions test/app.stub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Stub out the @App decorator provided by Ionic
// This allows us to test app.ts (thus providing a full coverage report as app.ts must include everything)
// which otherwise blows up in the browser on "ion-app selector cannot be found"
//
// https://www.sitepen.com/blog/2015/10/20/typescript-decorators/
//
export function App<TFunction extends Function>(target: TFunction): TFunction {
let newConstructor = function () {
// no-op
};

return <any> newConstructor;
}
9 changes: 6 additions & 3 deletions test/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function(config) {
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false }, // PhantomJS2 (and possibly others) might require it
{ pattern: 'www/build/test/**/*.js', included: false, watched: true },
// { pattern: 'www/test/stub.html', included: false, served: true },
{ pattern: 'www/build/test/**/*.html', included: false, served: true},

'test/test-main.js'
],
Expand All @@ -39,7 +39,8 @@ module.exports = function(config) {
// list of files to exclude
exclude: [
'node_modules/angular2/**/*_spec.js',
'node_modules/ionic-framework/**/*spec*'
'node_modules/ionic-framework/**/*spec*',
'node_modules/ionic-framework/decorators/app.js'
],

// preprocess matching files before serving them to the browser
Expand Down Expand Up @@ -73,7 +74,9 @@ module.exports = function(config) {
// Also any files you want to serve need to be in the files array above with serverd: true
proxies: {
// allows us to keep test code separate from app code and still have the references work
'/base/www/build/app': '/base/www/build/test'
'/base/node_modules/ionic-framework/decorators/app.js': '/base/www/build/test/app.stub.js', // stub out Ionic's @App decorator
'/base/www/build/app': '/base/www/build/test',
'/build': '/base/www/build/test'
},

// level of logging
Expand Down
15 changes: 15 additions & 0 deletions test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

export class TestUtils {

// http://stackoverflow.com/questions/2705583/how-to-simulate-a-click-with-javascript
public static eventFire(el: any, etype: string): void {
if (el.fireEvent) {
el.fireEvent('on' + etype);
} else {
let evObj: any = document.createEvent('Events');
evObj.initEvent(etype, true, false);
el.dispatchEvent(evObj);
}
}
}

0 comments on commit 5af7958

Please sign in to comment.