mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-18 16:02:53 +08:00
tests(): add basic tests (#1555)
This commit is contained in:
parent
e2acde5332
commit
749fd8af43
@ -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
|
||||
|
55
karma.conf.js
Normal file
55
karma.conf.js
Normal 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);
|
||||
|
||||
};
|
13
package.json
13
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": {
|
||||
|
67
src/@ionic-native/core/decorators.spec.ts
Normal file
67
src/@ionic-native/core/decorators.spec.ts
Normal 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');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user