Skip to content

Commit ddc701e

Browse files
authored
Merge branch 'master' into single-run
2 parents 299a69e + d0a743f commit ddc701e

File tree

9 files changed

+123
-6
lines changed

9 files changed

+123
-6
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ Based on the awesome [unit testing example](https://github.com/roblouie/unit-tes
55

66
Clone repo, run `npm install`.
77

8+
Unit Tests
9+
----------
10+
811
To run the tests, run `npm test`.
912

1013
See the example test in `src/app/app.component.spec.ts` for an example of a component test.
14+
15+
End-To-End Tests (Browser-Only)
16+
-------------------------------
17+
18+
To serve the app, run `ionic serve`.
19+
20+
To run the end-to-end tests, run (while the app is being served) `npm run e2e`.
21+
22+
See the example end-to-end test in `e2e/app.e2e-spec.ts`.

e2e/app.e2e-spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Page } from './app.po';
2+
3+
describe('App', function() {
4+
let page: Page;
5+
6+
beforeEach(() => {
7+
page = new Page();
8+
});
9+
10+
describe('default screen', () => {
11+
beforeEach(() => {
12+
page.navigateTo('/');
13+
});
14+
15+
it('should have a title saying Page One', () => {
16+
page.getTitle().then(title => {
17+
expect(title).toEqual('Page One');
18+
});
19+
});
20+
})
21+
});

e2e/app.po.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { browser } from 'protractor';
2+
3+
export class Page {
4+
5+
navigateTo(destination) {
6+
return browser.get(destination);
7+
}
8+
9+
getTitle() {
10+
return browser.getTitle();
11+
}
12+
13+
}

e2e/tsconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compileOnSave": false,
3+
"compilerOptions": {
4+
"declaration": false,
5+
"emitDecoratorMetadata": true,
6+
"experimentalDecorators": true,
7+
"module": "commonjs",
8+
"moduleResolution": "node",
9+
"outDir": "../dist/out-tsc-e2e",
10+
"sourceMap": true,
11+
"target": "es5",
12+
"typeRoots": [
13+
"../node_modules/@types"
14+
]
15+
}
16+
}

ionic.config.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
2-
"name": "test-test",
2+
"name": "ionic-unit-testing-example",
33
"app_id": "",
4-
"projectTypeId": "ionic-angular"
5-
}
4+
"projectTypeId": "ionic-angular",
5+
"v2": true,
6+
"typescript": true
7+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"ionic:serve": "ionic-app-scripts serve",
1111
"test": "karma start ./test-config/karma.conf.js",
1212
"test-ci": "karma start ./test-config/karma.conf.js --single-run"
13+
"e2e": "webdriver-manager update --standalone false --gecko false; protractor ./test-config/protractor.conf.js"
1314
},
1415
"dependencies": {
1516
"@angular/common": "2.4.8",
@@ -40,15 +41,18 @@
4041
"angular2-template-loader": "^0.6.2",
4142
"html-loader": "^0.4.5",
4243
"jasmine": "^2.5.3",
44+
"jasmine-spec-reporter": "^3.2.0",
4345
"karma": "^1.5.0",
4446
"karma-chrome-launcher": "^2.0.0",
4547
"karma-jasmine": "^1.1.0",
4648
"karma-jasmine-html-reporter": "^0.2.2",
4749
"karma-sourcemap-loader": "^0.3.7",
4850
"karma-webpack": "^2.0.3",
4951
"null-loader": "^0.1.1",
52+
"protractor": "^5.1.1",
5053
"ts-loader": "^2.0.3",
51-
"typescript": "2.0.9"
54+
"ts-node": "^3.0.2",
55+
"typescript": "2.1.6"
5256
},
5357
"version": "0.0.1",
5458
"description": "An Ionic project"

src/app/app.html

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
<ion-nav [root]="rootPage"></ion-nav>
1+
<ion-menu [content]="content">
2+
<ion-header>
3+
<ion-toolbar>
4+
<ion-title>Menu</ion-title>
5+
</ion-toolbar>
6+
</ion-header>
7+
8+
<ion-content>
9+
<ion-list>
10+
<button menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)">
11+
{{p.title}}
12+
</button>
13+
</ion-list>
14+
</ion-content>
15+
16+
</ion-menu>
17+
18+
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>

test-config/protractor.conf.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Protractor configuration file, see link for more information
2+
// https://github.com/angular/protractor/blob/master/lib/config.ts
3+
4+
/*global jasmine */
5+
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
6+
7+
exports.config = {
8+
allScriptsTimeout: 11000,
9+
specs: [
10+
'../e2e/**/*.e2e-spec.ts'
11+
],
12+
capabilities: {
13+
'browserName': 'chrome'
14+
},
15+
directConnect: true,
16+
baseUrl: 'http://localhost:8100/',
17+
framework: 'jasmine',
18+
jasmineNodeOpts: {
19+
showColors: true,
20+
defaultTimeoutInterval: 30000,
21+
print: function() {}
22+
},
23+
useAllAngular2AppRoots: true,
24+
beforeLaunch: function() {
25+
require('ts-node').register({
26+
project: 'e2e'
27+
});
28+
},
29+
onPrepare: function() {
30+
jasmine.getEnv().addReporter(new SpecReporter());
31+
}
32+
};

test-config/webpack.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
},
2121
{
2222
test: /\.html$/,
23-
loader: 'html-loader'
23+
loader: 'html-loader?attrs=false'
2424
},
2525
{
2626
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,

0 commit comments

Comments
 (0)