-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from ihadeed/master
removed dependencies made everything a dev dependency to make things simpler added NgModule ( closes #25 ) added .editorconfig file removed typings and added @types compiling with ngc instead of tsc to produce needed files for AoT compilation added tests fix linting add circleci instructions
- Loading branch information
Showing
16 changed files
with
402 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
# We recommend you to keep these unchanged | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
# Created by .ignore support plugin (hsz.mobi) | ||
/.idea | ||
.vscode/ | ||
# Node generated files | ||
node_modules | ||
npm-debug.log | ||
# OS generated files | ||
Thumbs.db | ||
.DS_Store | ||
# Ignored files | ||
*.js | ||
*.map | ||
*.d.ts | ||
typings | ||
.idea | ||
dist | ||
aot |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
working_directory: ~/ionic-cache/ | ||
docker: | ||
- image: node:7 | ||
steps: | ||
- checkout | ||
- restore_cache: | ||
key: node_modules_{{ checksum "package.json" }} | ||
- run: npm install | ||
- save_cache: | ||
key: node_modules_{{ checksum "package.json" }} | ||
paths: | ||
- ~/ionic-cache/node_modules/ | ||
- run: | ||
name: Lint | ||
command: npm run lint | ||
- run: | ||
name: Test | ||
command: npm test | ||
- run: | ||
name: Build | ||
command: npm run build |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"use strict"; | ||
|
||
module.exports = config => { | ||
|
||
const conf = { | ||
frameworks: [ | ||
'jasmine', | ||
'karma-typescript' | ||
], | ||
|
||
plugins: [ | ||
'karma-typescript', | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
'karma-chrome-launcher' | ||
], | ||
|
||
preprocessors: { | ||
'src/**/*.ts': ['karma-typescript'] | ||
}, | ||
|
||
karmaTypescriptConfig: { | ||
bundlerOptions: { | ||
entrypoints: /\.spec\.ts$/, | ||
transforms: [ | ||
require("karma-typescript-angular2-transform") | ||
] | ||
}, | ||
compilerOptions: { | ||
lib: ['es2015', 'dom'] | ||
} | ||
}, | ||
|
||
files: [ | ||
{ pattern: 'src/**/*', included: true, watched: true }, | ||
], | ||
|
||
reporters: ['progress'], | ||
|
||
port: 9876, | ||
colors: true, | ||
logLevel: config.INFO, | ||
autoWatch: true, | ||
browsers: [ | ||
'Chrome', | ||
// 'PhantomJS' | ||
], | ||
singleRun: false | ||
}; | ||
|
||
if (process.env.CIRCLECI) { | ||
conf.browsers = ['PhantomJS']; | ||
} | ||
|
||
config.set(conf); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { NgModule, ModuleWithProviders } from '@angular/core'; | ||
import { CacheService } from './cache.service'; | ||
|
||
@NgModule() | ||
export class CacheModule { | ||
static forRoot(): ModuleWithProviders { | ||
return { | ||
ngModule: CacheModule, | ||
providers: [ | ||
CacheService | ||
] | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import 'core-js'; | ||
import 'zone.js/dist/zone'; | ||
import 'zone.js/dist/long-stack-trace-zone'; | ||
import 'zone.js/dist/proxy'; | ||
import 'zone.js/dist/sync-test'; | ||
import 'zone.js/dist/jasmine-patch'; | ||
import 'zone.js/dist/async-test'; | ||
import 'zone.js/dist/fake-async-test'; | ||
import { CacheService, MESSAGES } from './cache.service'; | ||
import { async, TestBed } from '@angular/core/testing'; | ||
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing'; | ||
import { Observable } from 'rxjs/Observable'; | ||
import 'rxjs/add/observable/of'; | ||
|
||
TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); | ||
|
||
describe('CacheService', () => { | ||
|
||
let service: CacheService; | ||
|
||
beforeAll(() => { | ||
service = new CacheService(); | ||
}); | ||
|
||
afterAll(async(() => { | ||
service.clearAll(); | ||
})); | ||
|
||
it('should create an instance of the service', () => expect(service).toBeDefined()); | ||
|
||
it('should save item to storage (async)', async(() => { | ||
service.saveItem('name', 'ibby') | ||
.then(() => expect(true).toBeTruthy()) | ||
.catch(() => expect(false).toBeTruthy()); | ||
})); | ||
|
||
it('should get previously stored value (async)', async(() => { | ||
service.getItem('name') | ||
.then(value => expect(value).toEqual('ibby')) | ||
.catch(() => expect(false).toBeTruthy()); | ||
})); | ||
|
||
it('should disable cache', () => { | ||
service.enableCache(false); | ||
expect((<any> service).cacheEnabled === false).toBeTruthy(); | ||
}); | ||
|
||
it('should throw an error when getting item and cache is disabled', async(() => { | ||
service.getItem('name') | ||
.then(() => expect(false).toBeTruthy()) | ||
.catch((e) => expect(e).toEqual(MESSAGES[1])); | ||
})); | ||
|
||
it('should enable cache', () => { | ||
service.enableCache(true); | ||
expect((<any> service).cacheEnabled === true).toBeTruthy(); | ||
}); | ||
|
||
}); | ||
|
||
describe('Observable Caching', () => { | ||
|
||
const key: string = 'http_cache_test'; | ||
|
||
let mockData: any = { | ||
hello: 'world' | ||
}; | ||
|
||
let observable = Observable.of(mockData); | ||
|
||
let service: CacheService; | ||
|
||
beforeAll(() => { | ||
service = new CacheService(); | ||
}); | ||
|
||
beforeEach(() => { | ||
spyOn(observable, 'subscribe').and.callThrough(); | ||
}); | ||
|
||
afterAll(function(done) { | ||
service.clearAll() | ||
.then(() => done()) | ||
.catch(() => done()); | ||
}); | ||
|
||
it('should create an instance of the service', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
// it('', inject([XHRBackend, CacheService], (mockBackend: XHRBackend, cache: CacheService) => { })) | ||
|
||
it('should return data from observable (async)', function(done) { | ||
service.loadFromObservable(key, observable) | ||
.subscribe(res => { | ||
expect(res).toBeDefined(); | ||
expect(observable.subscribe).toHaveBeenCalled(); | ||
expect(res).toEqual(mockData); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return cached observable data (async)', function(done) { | ||
service.loadFromObservable(key, observable) | ||
.subscribe(res => { | ||
expect(observable.subscribe).not.toHaveBeenCalled(); | ||
expect(res).toEqual(mockData); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.