diff --git a/angular-cli.json b/angular-cli.json new file mode 100644 index 000000000..02abf1177 --- /dev/null +++ b/angular-cli.json @@ -0,0 +1,53 @@ +{ + "project": { + "version": "1.0.0-beta.22-1", + "name": "ionic2-tdd" + }, + "apps": [ + { + "root": "src", + "outDir": "dist", + "assets": [ + "assets" + ], + "index": "index.html", + "main": "app/main.ts", + "test": "test.ts", + "tsconfig": "tsconfig.test.json", + "prefix": "app", + "mobile": false, + "styles": [ + "styles.css" + ], + "scripts": [], + "environmentSource": "environments/environment.ts", + "environments": { + "dev": "environments/environment.ts", + "prod": "environments/environment.prod.ts" + } + } + ], + "addons": [], + "packages": [], + "test": { + "karma": { + "config": "./karma.conf.js" + } + }, + "defaults": { + "styleExt": "css", + "prefixInterfaces": false, + "inline": { + "style": false, + "template": false + }, + "spec": { + "class": false, + "component": true, + "directive": true, + "module": false, + "pipe": true, + "service": true + } + } +} \ No newline at end of file diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..f6234ad7a --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,88 @@ +// Karma configuration +// Generated on Thu Jul 27 2017 11:22:22 GMT-0300 (ART) + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['jasmine', '@angular/cli'], + + + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-remap-istanbul'), + require('karma-mocha-reporter'), + require('@angular/cli/plugins/karma'), + ], + + // list of files / patterns to load in the browser + files: [ + { pattern: './src/test.ts', watched: false } + ], + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + './src/test.ts': ['@angular/cli'] + }, + + mime: { + 'text/x-typescript': ['ts', 'tsx'] + }, + + remapIstanbulReporter: { + reports: { + html: 'coverage', + lcovonly: './coverage/coverage.lcov' + } + }, + angularCli: { + config: './angular-cli.json', + environment: 'dev' + }, + reporters: config.angularCli && config.angularCli.codeCoverage + ? ['mocha', 'karma-remap-istanbul'] + : ['mocha'], + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['Chrome'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }) +} diff --git a/package.json b/package.json index c7c2b706f..0a6f17e24 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "private": true, "scripts": { "clean": "ionic-app-scripts clean", + "test": "ng test", "build": "ionic-app-scripts build", "lint": "ionic-app-scripts lint", "ionic:build": "ionic-app-scripts build", @@ -29,6 +30,7 @@ "ionic-angular": "3.5.3", "ionicons": "3.0.0", "lodash": "^4.17.4", + "pre-commit": "^1.2.2", "rxjs": "5.4.0", "sw-toolbox": "3.6.0", "zone.js": "0.8.12" @@ -38,7 +40,23 @@ "@ionic/cli-plugin-cordova": "1.4.1", "@ionic/cli-plugin-ionic-angular": "1.3.2", "ionic": "3.6.0", - "typescript": "2.3.4" + "typescript": "2.3.4", + "@angular/cli": "^1.2.5", + "@angular/compiler": "^4.3.1", + "@angular/compiler-cli": "^4.3.1", + "@types/jasmine": "^2.5.53", + "@types/node": "^8.0.17", + "codecov": "^2.2.0", + "jasmine-core": "^2.6.4", + "jasmine-spec-reporter": "^4.1.1", + "karma": "^1.7.0", + "karma-chrome-launcher": "^2.2.0", + "karma-jasmine": "^1.1.0", + "karma-mocha-reporter": "^2.2.3", + "karma-remap-istanbul": "^0.6.0", + "ts-node": "^3.3.0", + "tslint": "^5.5.0", + "tslint-eslint-rules": "^4.1.1" }, "description": "Copay Bitcoin Wallet" } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts new file mode 100644 index 000000000..2ff6f8c87 --- /dev/null +++ b/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment: any = { + production: true, +}; \ No newline at end of file diff --git a/src/environments/environment.ts b/src/environments/environment.ts new file mode 100644 index 000000000..0d1ff5f60 --- /dev/null +++ b/src/environments/environment.ts @@ -0,0 +1,8 @@ +// The file contents for the current environment will overwrite these during build. +// The build system defaults to the dev environment which uses `environment.ts`, but if you do +// `ng build --env=prod` then `environment.prod.ts` will be used instead. +// The list of which env maps to which file can be found in `angular-cli.json`. + +export const environment: any = { + production: false, +}; \ No newline at end of file diff --git a/src/mocks.ts b/src/mocks.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/polyfills.ts b/src/polyfills.ts new file mode 100644 index 000000000..d199f7883 --- /dev/null +++ b/src/polyfills.ts @@ -0,0 +1,19 @@ +// This file includes polyfills needed by Angular 2 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'; +import 'core-js/es6/function'; +import 'core-js/es6/parse-int'; +import 'core-js/es6/parse-float'; +import 'core-js/es6/number'; +import 'core-js/es6/math'; +import 'core-js/es6/string'; +import 'core-js/es6/date'; +import 'core-js/es6/array'; +import 'core-js/es6/regexp'; +import 'core-js/es6/map'; +import 'core-js/es6/set'; +import 'core-js/es6/reflect'; + +import 'core-js/es7/reflect'; +import 'zone.js/dist/zone'; \ No newline at end of file diff --git a/src/providers/storage-service/storage-service.spec.ts b/src/providers/storage-service/storage-service.spec.ts new file mode 100644 index 000000000..2d3e5964f --- /dev/null +++ b/src/providers/storage-service/storage-service.spec.ts @@ -0,0 +1,11 @@ +import { StorageService } from './storage-service'; + +describe('Storage Service', () => { + it('should do nothing', () => { + expect(true).toBeTruthy(); + }); + it('should get', () => { + var storage = new StorageService(); + expect(storage.get('myKey')).toEqual('myKey'); + }); +}); \ No newline at end of file diff --git a/src/providers/storage-service/storage-service.ts b/src/providers/storage-service/storage-service.ts index 9d4149db0..0de495537 100644 --- a/src/providers/storage-service/storage-service.ts +++ b/src/providers/storage-service/storage-service.ts @@ -7,4 +7,7 @@ export class StorageService { console.log('Hello StorageService Provider'); } + public get(key:string):string { + return key; + } } diff --git a/src/test.ts b/src/test.ts new file mode 100644 index 000000000..711d8c8bb --- /dev/null +++ b/src/test.ts @@ -0,0 +1,38 @@ +import './polyfills.ts'; + +import 'zone.js/dist/long-stack-trace-zone'; +import 'zone.js/dist/proxy.js'; +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 { 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'; + +// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. +declare var __karma__: any; +declare var require: any; + +// Prevent Karma from running prematurely. +__karma__.loaded = function (): void { + // noop +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting(), +); + +// Then we find all the tests. +let context: any = require.context('./', true, /\.spec\.ts/); + +// And load the modules. +context.keys().map(context); + +// Finally, start Karma to run the tests. +__karma__.start(); \ No newline at end of file diff --git a/src/tsconfig.test.json b/src/tsconfig.test.json new file mode 100644 index 000000000..cdfdbdcd9 --- /dev/null +++ b/src/tsconfig.test.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "baseUrl": "", + "declaration": false, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "lib": ["es6", "dom"], + "mapRoot": "./", + "module": "es6", + "moduleResolution": "node", + "outDir": "../dist/out-tsc", + "sourceMap": true, + "target": "es5", + "typeRoots": [ + "../node_modules/@types" + ] + } +} \ No newline at end of file