Skip to content

Commit

Permalink
Remove app.stub.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lathonez committed Apr 20, 2016
1 parent a9af049 commit 5de5e5d
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 109 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,10 @@
<a name="1.1.0"></a>
# 1.1.0 (2016-04-??)

### Features

* **Build**: Remove the need for app.stub.js [#79](https://github.com/lathonez/clicker/issues/79) ([???????](https://github.com/lathonez/clicker/commit/???????))

<a name="1.0.0"></a>
# 1.0.0 (2016-04-20)

Expand Down
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -21,8 +21,8 @@ npm test # run unit tests

## Debug Unit tests
```bash
npm run watch # in one window - build all the tests and start watching for changes
npm run karma # start karma in debug mode: mutli run Chrome, hit `debug` to get going
npm run watch # in one window - build all the tests and start watching for changes
npm run karma # start karma in debug mode: mutli run Chrome, hit `debug` to get going
```

## Run E2E
Expand Down Expand Up @@ -61,7 +61,6 @@ External dependencies are listed here to justify their inclusion and to enable t

* codecov.io: sending unit test coverage reports to codecov.io
* gulp-load-plugins: helper to load other gulp plugins easily
* gulp-rename: rename a file in gulp, used to patch Ionic's app decorator
* gulp-tslint: access tslint from gulp
* gulp-typescript: transpile typescript in gulp
* gulp-util: logging in gulp
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -15,7 +15,6 @@
"del": "2.2.0",
"gulp": "3.9.1",
"gulp-load-plugins": "1.2.0",
"gulp-rename": "^1.2.2",
"gulp-tslint": "4.3.5",
"gulp-typescript": "^2.12.1",
"gulp-util": "^3.0.7",
Expand Down Expand Up @@ -46,7 +45,7 @@
"typings": "0.7.12"
},
"name": "clicker",
"version": "1.0.0",
"version": "1.1.0",
"description": "clicker: An Ionic project",
"cordovaPlugins": [
"cordova-sqlite-storage",
Expand Down
68 changes: 0 additions & 68 deletions test/app.stub.js

This file was deleted.

38 changes: 2 additions & 36 deletions test/gulpfile.ts
Expand Up @@ -45,13 +45,10 @@ gulp.task('build-e2e', () => {
});

// transpile unit tests into test.bundle.js, output sourcemaps
gulp.task('build-unit', ['clean-test', 'html', 'lint', 'patch-app'], (done: Function) => {
gulp.task('build-unit', ['clean-test', 'html', 'lint'], (done: Function) => {

let browserify: any = require('ionic-gulp-browserify-typescript');
let specs: any = glob.sync('**/*.spec.ts');
let doneFn: Function = (() => {
runSequence('restore-app', (<any>done));
});

browserify(
{
Expand All @@ -65,7 +62,7 @@ gulp.task('build-unit', ['clean-test', 'html', 'lint', 'patch-app'], (done: Func
debug: true,
},
}
).on('end', doneFn);
).on('end', done);
});

// delete everything used in our test cycle here
Expand Down Expand Up @@ -115,25 +112,6 @@ gulp.task('lint', () => {
}));
});

// patch Ionic's app decorator with one that doesn't break tests, see https://github.com/lathonez/clicker/issues/79
gulp.task('patch-app', () => {

let appSrc: string = 'node_modules/ionic-angular/decorators/';
let stubSrc: string = 'test/app.stub.js';

gulp.src(join(appSrc, 'app.js'))
.pipe(plugins.rename('app.backup'))
.pipe(gulp.dest(appSrc));

plugins.util.log(join(appSrc, 'app.js') + ' has been backed up to ' + join(appSrc, 'app.backup'));

gulp.src(stubSrc)
.pipe(plugins.rename('app.js'))
.pipe(gulp.dest(appSrc));

plugins.util.log(join(appSrc, 'app.js') + ' has been patched with ' + stubSrc);
});

// remapped coverage (see remap-coverage) contains everything from the test bundle (including node modules)
// this task removes everything we don't care about from the remapped istanbul JSON
gulp.task('prune-coverage', () => {
Expand Down Expand Up @@ -178,18 +156,6 @@ gulp.task('report-coverage', (done: Function) => {
reporter.write(collector, false, done);
});

// restore Ionic's app decorator after patching, see https://github.com/lathonez/clicker/issues/79
gulp.task('restore-app', () => {

let appSrc: string = 'node_modules/ionic-angular/decorators/';

gulp.src(join(appSrc, 'app.backup'))
.pipe(plugins.rename('app.js'))
.pipe(gulp.dest(appSrc));

plugins.util.log(join(appSrc, 'app.backup') + ' has been restored to ' + join(appSrc, 'app.js'));
});

// build unit tests, run unit tests, remap and report coverage
gulp.task('unit-test', (done: Function) => {
runSequence(
Expand Down
4 changes: 4 additions & 0 deletions test/karma.config.js
Expand Up @@ -21,6 +21,10 @@ module.exports = function(config) {
{pattern: 'www/build/**/*.html', included: false},
],

// we need <ion-app> in our Karma runner's html
customContextFile: 'test/karma.context.html',
customDebugFile: 'test/karma.debug.html',

// list of files to exclude
exclude: [
'node_modules/angular2/**/*_spec.js',
Expand Down
37 changes: 37 additions & 0 deletions test/karma.context.html
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<!--
This is the execution context.
Loaded within the iframe.
Reloaded before every execution run.
-->
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
</head>
<body>
<!-- The scripts need to be in the body DOM element, as some test running frameworks need the body
to have already been created so they can insert their magic into it. For example, if loaded
before body, Angular Scenario test framework fails to find the body and crashes and burns in
an epic manner. -->
<script type="text/javascript">
// sets window.__karma__ and overrides console and error handling
// Use window.opener if this was opened by someone else - in a new window
if (window.opener) {
window.opener.karma.setupContext(window);
} else {
window.parent.karma.setupContext(window);
}

// All served files with the latest timestamps
%MAPPINGS%
</script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script type="text/javascript">
window.__karma__.loaded();
</script>
<ion-app></ion-app>
</body>
</html>
59 changes: 59 additions & 0 deletions test/karma.debug.html
@@ -0,0 +1,59 @@
<!doctype html>
<!--
This file is almost the same as context.html - loads all source files,
but its purpose is to be loaded in the main frame (not within an iframe),
just for immediate execution, without reporting to Karma server.
-->
<html>
<head>
%X_UA_COMPATIBLE%
<title>Karma DEBUG RUNNER</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
</head>
<body>
<!-- The scripts need to be at the end of body, so that some test running frameworks
(Angular Scenario, for example) need the body to be loaded so that it can insert its magic
into it. If it is before body, then it fails to find the body and crashes and burns in an epic
manner. -->
<script type="text/javascript">
window.__karma__ = {
info: function(info) {
if (info.dump && window.console) window.console.log(info.dump);
},
complete: function() {
if (window.console) window.console.log('Skipped ' + this.skipped + ' tests');
},
store: function() {},
skipped: 0,
result: window.console ? function(result) {
if (result.skipped) {
this.skipped++;
return;
}
var msg = result.success ? 'SUCCESS ' : 'FAILED ';
window.console.log(msg + result.suite.join(' ') + ' ' + result.description);

for (var i = 0; i < result.log.length; i++) {
window.console.error(result.log[i]);
}
} : function() {},
loaded: function() {
this.start();
}
};

%CLIENT_CONFIG%

// All served files with the latest timestamps
%MAPPINGS%
</script>
<!-- Dynamically replaced with <script> tags -->
%SCRIPTS%
<script type="text/javascript">
window.__karma__.loaded();
</script>
<ion-app></ion-app>
</body>
</html>

0 comments on commit 5de5e5d

Please sign in to comment.