Skip to content

Commit

Permalink
Update to ionic rc5 and ng-cli beta25-5
Browse files Browse the repository at this point in the history
  • Loading branch information
lathonez committed Jan 17, 2017
1 parent 0231b9c commit 7328aad
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 107 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
<a name="2.6.0"></a>
# 2.6.0 (2017-01-18)

### Features

* **Update**: Update to Ionic RC5 ([](https://github.com/lathonez/clicker/commit/))

The above update includes creating a mock for Ionic's platform class and using it as a provider in test.ts. I have not attempted to mock out the whole class, what is there is sufficient for clicker. If anything is missing for your app, you can add easily by referencing the signature in node_modules/ionic-angular/platform/platform.d.ts.

<a name="2.5.3"></a>
# 2.5.3 (2016-01-03)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ See the changelog [here](https://github.com/lathonez/clicker/blob/master/CHANGEL
## Dependencies

* **@Angular:** 2.2.1
* **angular-cli**: 1.0.0-beta.24
* **Ionic:** 2.0.0-rc.4
* **angular-cli**: 1.0.0-beta.25-5
* **Ionic:** 2.0.0-rc.5
2 changes: 1 addition & 1 deletion angular-cli.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"project": {
"version": "1.0.0-beta.22-1",
"version": "1.0.0-beta.25-5",
"name": "clicker"
},
"apps": [
Expand Down
10 changes: 5 additions & 5 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
<feature name="StatusBar">
<param name="ios-package" onload="true" value="CDVStatusBar"/>
</feature>
<plugin name="cordova-plugin-device" spec="~1.1.4"/>
<plugin name="cordova-plugin-console" spec="~1.0.5"/>
<plugin name="cordova-plugin-whitelist" spec="~1.3.1"/>
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/>
<plugin name="cordova-plugin-statusbar" spec="~2.2.1"/>
<plugin name="ionic-plugin-keyboard" spec="~2.2.1"/>
<plugin name="cordova-plugin-whitelist" spec="1.3.1"/>
<plugin name="cordova-plugin-console" spec="1.0.5"/>
<plugin name="cordova-plugin-statusbar" spec="2.2.1"/>
<plugin name="cordova-plugin-device" spec="1.1.4"/>
<plugin name="cordova-plugin-splashscreen" spec="~4.0.1"/>
</widget>
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@
"test": "ng test",
"test-coverage": "ng test --code-coverage"
},
"version": "2.5.3",
"version": "2.6.0",
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/storage": "1.1.6",
"ionic-angular": "2.0.0-rc.4",
"@ionic/storage": "1.1.7",
"ionic-angular": "2.0.0-rc.5",
"ionic-native": "2.2.11",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
"zone.js": "0.6.26",
"sw-toolbox": "3.4.0"
},
"devDependencies": {
"@ionic/app-scripts": "0.0.47",
"@angular/compiler-cli": "2.2.1",
"@ionic/app-scripts": "1.0.0",
"@types/jasmine": "2.5.38",
"@types/node": "6.0.42",
"angular-cli": "1.0.0-beta.24",
"angular-cli": "1.0.0-beta.25.5",
"codecov": "1.0.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.7.0",
Expand All @@ -51,19 +52,19 @@
"tslint-eslint-rules": "3.2.0",
"typescript": "2.0.10"
},
"description": "Clicker: An Ionic project",
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-console",
"cordova-plugin-statusbar",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"repository": {
"type": "git",
"url": "https://github.com/lathonez/clicker.git"
},
"license": "MIT"
"license": "MIT",
"description": "Clicker: An Ionic project"
}
2 changes: 1 addition & 1 deletion protractor.conf.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/docs/referenceConf.js
// https://github.com/angular/protractor/blob/master/lib/config.ts

/*global jasmine */
var SpecReporter = require('jasmine-spec-reporter');
Expand Down
34 changes: 30 additions & 4 deletions src/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

/* tslint:disable */
// IONIC:

export class ConfigMock {
Expand Down Expand Up @@ -50,11 +50,35 @@ export class NavMock {
}

export class PlatformMock {
public ready(): any {
return new Promise((resolve: Function) => {
resolve();
public ready(): Promise<{String}> {
return new Promise((resolve) => {
resolve('READY');
});
}

public registerBackButtonAction(fn: Function, priority?: number): Function {
return (() => true);
}

public hasFocus(ele: HTMLElement): boolean {
return true;
}

public doc(): HTMLDocument {
return document;
}

public registerListener(ele: any, eventName: string, callback: any): Function {
return (() => true);
}

public win(): Window {
return window;
}

public raf(callback: any): number {
return 1;
}
}

export class MenuMock {
Expand All @@ -64,3 +88,5 @@ export class MenuMock {
});
}
}

/* tslint:enable */
5 changes: 3 additions & 2 deletions src/pages/page2/page2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { App, Config, Form, IonicModule, Keyboard, DomController, MenuController, NavController, Platform } from 'ionic-angular';
import { ConfigMock } from '../../mocks';
import { ConfigMock, PlatformMock } from '../../mocks';
import { Page2 } from './page2';

let fixture: ComponentFixture<Page2> = null;
Expand All @@ -15,8 +15,9 @@ describe('Pages: Page2', () => {
TestBed.configureTestingModule({
declarations: [Page2],
providers: [
App, DomController, Form, Keyboard, MenuController, NavController, Platform,
App, DomController, Form, Keyboard, MenuController, NavController,
{provide: Config, useClass: ConfigMock},
{provide: Platform, useClass: PlatformMock},
],
imports: [
FormsModule,
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// This file includes polyfills needed by Angular 2 and is loaded before
// This file includes polyfills needed by Angular and is loaded before
// the app. You can add your own extra polyfills to this file.
import 'core-js/es6/symbol';
import 'core-js/es6/object';
Expand Down
102 changes: 26 additions & 76 deletions src/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,30 @@
// tick this to make the cache invalidate and update
const CACHE_VERSION = 1;
const CURRENT_CACHES = {
'read-through': 'read-through-cache-v' + CACHE_VERSION
};

self.addEventListener('activate', (event) => {
// Delete all caches that aren't named in CURRENT_CACHES.
// While there is only one cache in this example, the same logic will handle the case where
// there are multiple versioned caches.
const expectedCacheNames = Object.keys(CURRENT_CACHES).map((key) => {
return CURRENT_CACHES[key];
});

event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (expectedCacheNames.indexOf(cacheName) === -1) {
// If this cache name isn't present in the array of "expected" cache names, then delete it.
console.log('Deleting out of date cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
);
});

// This sample illustrates an aggressive approach to caching, in which every valid response is
// cached and every request is first checked against the cache.
// This may not be an appropriate approach if your web application makes requests for
// arbitrary URLs as part of its normal operation (e.g. a RSS client or a news aggregator),
// as the cache could end up containing large responses that might not end up ever being accessed.
// Other approaches, like selectively caching based on response headers or only caching
// responses served from a specific domain, might be more appropriate for those use cases.
self.addEventListener('fetch', (event) => {
/**
* Check out https://googlechrome.github.io/sw-toolbox/docs/master/index.html for
* more info on how to use sw-toolbox to custom configure your service worker.
*/

event.respondWith(
caches.open(CURRENT_CACHES['read-through']).then((cache) => {
return cache.match(event.request).then((response) => {
if (response) {
// If there is an entry in the cache for event.request, then response will be defined
// and we can just return it.

return response;
}
'use strict';
importScripts('./build/sw-toolbox.js');

// Otherwise, if there is no entry in the cache for event.request, response will be
// undefined, and we need to fetch() the resource.
console.log(' No response for %s found in cache. ' +
'About to fetch from network...', event.request.url);

// We call .clone() on the request since we might use it in the call to cache.put() later on.
// Both fetch() and cache.put() "consume" the request, so we need to make a copy.
// (see https://fetch.spec.whatwg.org/#dom-request-clone)
return fetch(event.request.clone()).then((response) => {

// Optional: add in extra conditions here, e.g. response.type == 'basic' to only cache
// responses from the same domain. See https://fetch.spec.whatwg.org/#concept-response-type
if (response.status < 400 && response.type === 'basic') {
// We need to call .clone() on the response object to save a copy of it to the cache.
// (https://fetch.spec.whatwg.org/#dom-request-clone)
cache.put(event.request, response.clone());
}

// Return the original response object, which will be used to fulfill the resource request.
return response;
});
}).catch((error) => {
// This catch() will handle exceptions that arise from the match() or fetch() operations.
// Note that a HTTP error response (e.g. 404) will NOT trigger an exception.
// It will return a normal response object that has the appropriate error code set.
console.error(' Read-through caching failed:', error);
self.toolbox.options.cache = {
name: 'ionic-cache'
};

throw error;
});
})
);
});
// pre-cache our key assets
self.toolbox.precache(
[
'./build/main.js',
'./build/main.css',
'./build/polyfills.js',
'index.html',
'manifest.json'
]
);

// dynamically cache any other local assets
self.toolbox.router.any('/*', self.toolbox.cacheFirst);

// for any other requests go to the network, cache,
// and then only use that cached resource if your user goes offline
self.toolbox.router.default = self.toolbox.networkFirst;
7 changes: 4 additions & 3 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { getTestBed, TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
import { App, Config, Form, IonicModule, Keyboard, DomController, MenuController, NavController, Platform } from 'ionic-angular';
import { ConfigMock } from './mocks';
import { ConfigMock, PlatformMock } from './mocks';
import { ClickersServiceMock } from './services/clickers.mock';
import { ClickersService } from './services';

Expand All @@ -30,7 +30,7 @@ getTestBed().initTestEnvironment(
platformBrowserDynamicTesting(),
);
// Then we find all the tests.
let context: any = require.context('./', true, /\.spec\.ts/);
const context: any = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
Expand All @@ -55,7 +55,8 @@ export class TestUtils {
...components,
],
providers: [
App, Platform, Form, Keyboard, DomController, MenuController, NavController,
App, Form, Keyboard, DomController, MenuController, NavController,
{provide: Platform, useClass: PlatformMock},
{provide: Config, useClass: ConfigMock},
{provide: ClickersService, useClass: ClickersServiceMock},
],
Expand Down

0 comments on commit 7328aad

Please sign in to comment.