diff --git a/circle.yml b/circle.yml index 9f6c757da..bbeb054a2 100644 --- a/circle.yml +++ b/circle.yml @@ -33,6 +33,9 @@ jobs: - run: name: Build changed plugins command: node scripts/ci-tests.js + - run: + name: Run tests + command: npm test - add_ssh_keys - deploy: name: Update docs diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 000000000..eb10d4d9c --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,55 @@ +"use strict"; + +module.exports = config => { + + const conf = { + frameworks: [ + 'jasmine', + 'karma-typescript' + ], + + plugins: [ + 'karma-typescript', + 'karma-jasmine', + 'karma-phantomjs-launcher' + ], + + preprocessors: { + 'src/**/*.ts': ['karma-typescript'] + }, + + karmaTypescriptConfig: { + bundlerOptions: { + entrypoints: /\.spec\.ts$/, + transforms: [ + require("karma-typescript-es6-transform")() + ] + }, + compilerOptions: { + lib: ['es2015', 'dom'], + paths: { + "@ionic-native/core": ["./src/@ionic-native/core"] + }, + baseUrl: '.' + } + }, + + files: [ + { pattern: 'src/**/*.ts', included: true, watched: true } + ], + + reporters: ['progress'], + + port: 9876, + colors: true, + logLevel: config.INFO, + autoWatch: true, + browsers: [ + 'PhantomJS' + ], + singleRun: false + }; + + config.set(conf); + +}; diff --git a/package.json b/package.json index 4a4ad947f..b5d95b104 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,8 @@ "@angular/compiler-cli": "4.1.2", "@angular/core": "4.1.2", "@types/cordova": "0.0.34", + "@types/jasmine": "^2.5.47", + "@types/node": "^7.0.18", "canonical-path": "0.0.2", "child-process-promise": "2.2.0", "conventional-changelog-cli": "1.2.0", @@ -22,6 +24,13 @@ "gulp-rename": "1.2.2", "gulp-replace": "0.5.4", "gulp-tslint": "6.1.2", + "jasmine-core": "^2.6.1", + "karma": "^1.7.0", + "karma-cli": "^1.0.1", + "karma-jasmine": "^1.1.0", + "karma-phantomjs-launcher": "^1.0.4", + "karma-typescript": "^3.0.1", + "karma-typescript-es6-transform": "^1.0.0", "lodash": "4.17.4", "minimist": "1.1.3", "node-html-encoder": "0.0.2", @@ -45,7 +54,9 @@ "shipit": "npm run build && gulp readmes && npm run npmpub", "npmpub": "node scripts/build/publish.js", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", - "postchangelog": "git commit -am \"chore(): update changelog\"" + "postchangelog": "git commit -am \"chore(): update changelog\"", + "test": "karma start karma.conf.js --single-run", + "test:watch": "karma start karma.conf.js" }, "config": { "commitizen": { diff --git a/src/@ionic-native/core/decorators.spec.ts b/src/@ionic-native/core/decorators.spec.ts new file mode 100644 index 000000000..242e52784 --- /dev/null +++ b/src/@ionic-native/core/decorators.spec.ts @@ -0,0 +1,67 @@ +import { Plugin, Cordova, CordovaProperty } from './decorators'; +import { IonicNativePlugin } from './ionic-native-plugin'; + +declare const window: any; + +window['myPlugin'] = { + + hello: () => 'world', + key: 'value' + +}; + +describe('Decorators', () => { + + @Plugin({ + pluginName: 'MyPlugin', + pluginRef: 'myPlugin', + repo: '', + plugin: 'cordova-plugin-my-plugin' + }) + class MyPlugin extends IonicNativePlugin { + + @CordovaProperty + key: string; + + @Cordova({ sync: true }) + hello(): string { return; } + + } + + let instance: MyPlugin; + + beforeEach(() => { + instance = new MyPlugin(); + }); + + describe('Plugin', () => { + + it('should set class properties', () => { + expect(MyPlugin.getPluginName()).toEqual('MyPlugin'); + expect(MyPlugin.getPluginRef()).toEqual('myPlugin'); + }); + + }); + + describe('Cordova', () => { + + it('should do a sync function', () => { + expect(instance.hello()).toEqual('world'); + }); + + }); + + describe('CordovaProperty', () => { + + it('should return property value', () => { + expect(instance.key).toEqual('value'); + }); + + it('should set property value', () => { + instance.key = 'value2'; + expect(instance.key).toEqual('value2'); + }); + + }); + +});