tests(): add basic tests (#1555)

This commit is contained in:
Ibby Hadeed 2017-05-14 03:25:33 -04:00 committed by GitHub
parent e2acde5332
commit 749fd8af43
4 changed files with 137 additions and 1 deletions

View File

@ -33,6 +33,9 @@ jobs:
- run: - run:
name: Build changed plugins name: Build changed plugins
command: node scripts/ci-tests.js command: node scripts/ci-tests.js
- run:
name: Run tests
command: npm test
- add_ssh_keys - add_ssh_keys
- deploy: - deploy:
name: Update docs name: Update docs

55
karma.conf.js Normal file
View File

@ -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);
};

View File

@ -8,6 +8,8 @@
"@angular/compiler-cli": "4.1.2", "@angular/compiler-cli": "4.1.2",
"@angular/core": "4.1.2", "@angular/core": "4.1.2",
"@types/cordova": "0.0.34", "@types/cordova": "0.0.34",
"@types/jasmine": "^2.5.47",
"@types/node": "^7.0.18",
"canonical-path": "0.0.2", "canonical-path": "0.0.2",
"child-process-promise": "2.2.0", "child-process-promise": "2.2.0",
"conventional-changelog-cli": "1.2.0", "conventional-changelog-cli": "1.2.0",
@ -22,6 +24,13 @@
"gulp-rename": "1.2.2", "gulp-rename": "1.2.2",
"gulp-replace": "0.5.4", "gulp-replace": "0.5.4",
"gulp-tslint": "6.1.2", "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", "lodash": "4.17.4",
"minimist": "1.1.3", "minimist": "1.1.3",
"node-html-encoder": "0.0.2", "node-html-encoder": "0.0.2",
@ -45,7 +54,9 @@
"shipit": "npm run build && gulp readmes && npm run npmpub", "shipit": "npm run build && gulp readmes && npm run npmpub",
"npmpub": "node scripts/build/publish.js", "npmpub": "node scripts/build/publish.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", "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": { "config": {
"commitizen": { "commitizen": {

View File

@ -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');
});
});
});