Permalink
Browse files

test(): add initial test suite (#523)

  • Loading branch information...
1 parent d5513db commit 1facde3966ea8e7e5d4994c9f4f5779e2d9aad47 @mattlewis92 mattlewis92 committed with ihadeed Sep 7, 2016
Showing with 735 additions and 8 deletions.
  1. +1 −1 circle.yml
  2. +60 −0 karma.conf.ts
  3. +12 −2 package.json
  4. +3 −2 src/ng1.ts
  5. +0 −2 src/plugins/plugin.ts
  6. +141 −0 test/plugin.spec.ts
  7. +2 −1 tsconfig.json
  8. +5 −0 typings.json
  9. +502 −0 typings/globals/jasmine/index.d.ts
  10. +8 −0 typings/globals/jasmine/typings.json
  11. +1 −0 typings/index.d.ts
View
@@ -17,7 +17,7 @@ dependencies:
test:
override:
- - echo "No tests are written at the moment. But we will attempt to build the library with the latest changes."
+ - npm test
- npm run build
deployment:
View
@@ -0,0 +1,60 @@
+const WATCH = process.argv.indexOf('--watch') > -1;
+
+module.exports = 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', 'browserify'],
+
+ // list of files / patterns to load in the browser
+ files: [
+ 'test/**/*.spec.ts'
+ ],
+
+ // preprocess matching files before serving them to the browser
+ // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
+ preprocessors: {
+ 'test/**/*.spec.ts': ['browserify']
+ },
+
+ browserify: {
+ plugin: [ 'tsify' ],
+ extensions: ['.js', '.ts']
+ },
+
+ phantomjsLauncher: {
+ // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
+ exitOnResourceError: true
+ },
+
+ // test results reporter to use
+ // possible values: 'dots', 'progress'
+ // available reporters: https://npmjs.org/browse/keyword/karma-reporter
+ reporters: ['dots'],
+
+ // 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: WATCH,
+
+ // start these browsers
+ // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
+ browsers: ['PhantomJS'],
+
+ // Continuous Integration mode
+ // if true, Karma captures browsers, runs the tests and exits
+ singleRun: !WATCH
+ });
+};
View
@@ -19,25 +19,35 @@
"decamelize": "^1.2.0",
"dgeni": "^0.4.2",
"dgeni-packages": "^0.10.18",
+ "es6-shim": "~0.35.1",
"glob": "^6.0.4",
"gulp": "^3.9.1",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-tslint": "^5.0.0",
"gulp-uglify": "^1.5.4",
"ionic-gulp-tslint": "^1.0.0",
+ "jasmine-core": "~2.5.0",
+ "karma": "~1.2.0",
+ "karma-browserify": "~5.1.0",
+ "karma-jasmine": "~1.0.2",
+ "karma-phantomjs-launcher": "~1.0.2",
"lodash": "3.10.1",
"minimist": "^1.1.3",
"mkdirp": "^0.5.1",
"node-html-encoder": "0.0.2",
"q": "1.4.1",
"semver": "^5.0.1",
+ "tsify": "~1.0.4",
"tslint": "^3.8.1",
"tslint-ionic-rules": "0.0.5",
- "typescript": "^1.8.10"
+ "typescript": "^1.8.10",
+ "watchify": "~3.7.0"
},
"scripts": {
- "test": "echo \"Error: no test specified\" && exit 1",
+ "test": "karma start",
+ "test:watch": "npm test -- --watch",
+ "start": "npm run test:watch",
"lint": "./node_modules/.bin/gulp lint",
"watch": "./node_modules/.bin/tsc -w",
"build": "npm run lint && npm run build:js && npm run build:bundle && npm run build:minify",
View
@@ -7,14 +7,15 @@ declare var window;
*/
export function initAngular1(plugins) {
if (window.angular) {
- window.angular.module('ionic.native', []);
+
+ const ngModule = window.angular.module('ionic.native', []);
for (var name in plugins) {
let serviceName = '$cordova' + name;
let cls = plugins[name];
(function(serviceName, cls, name) {
- window.angular.module('ionic.native').service(serviceName, [function() {
+ ngModule.service(serviceName, [function() {
var funcs = window.angular.copy(cls);
funcs.prototype['name'] = name;
return funcs;
@@ -3,8 +3,6 @@ import { Observable } from 'rxjs/Observable';
declare var window;
declare var Promise;
-declare var $q;
-
/**
* @private
View
@@ -0,0 +1,141 @@
+/// <reference path="./../typings/index.d.ts" />
+
+import 'es6-shim';
+import {Plugin, Cordova} from './../src/plugins/plugin';
+
+declare const window: any;
+window.plugins = {
+ test: {}
+};
+
+const testPluginMeta = {
+ plugin: 'cordova-plugin-test',
+ pluginRef: 'plugins.test',
+ repo: 'https://github.com/apache/cordova-plugin-test',
+ platforms: ['Android', 'iOS']
+};
+
+describe('plugin', () => {
+
+ it('sync method', () => {
+
+ window.plugins.test.syncMethod = () => {
+ return 'syncResult';
+ };
+
+ @Plugin(testPluginMeta)
+ class Test {
+
+ @Cordova({
+ sync: true
+ })
+ static syncMethod(arg: any): boolean { return; };
+
+ }
+
+ const spy = spyOn(window.plugins.test, 'syncMethod').and.callThrough();
+ const result = Test.syncMethod('foo');
+ expect(result).toEqual('syncResult');
+ expect(spy).toHaveBeenCalledWith('foo', undefined, undefined);
+
+ });
+
+ it('normal order callback', done => {
+
+ window.plugins.test.normalOrderCallback = (args, success, error) => {
+ success('normalOrderCallback');
+ };
+
+ @Plugin(testPluginMeta)
+ class Test {
+ @Cordova()
+ static normalOrderCallback(args: any): Promise<any> { return; }
+ }
+
+ const spy = spyOn(window.plugins.test, 'normalOrderCallback').and.callThrough();
+ Test.normalOrderCallback('foo').then(result => {
+ expect(result).toEqual('normalOrderCallback');
+ done();
+ });
+ expect(spy.calls.mostRecent().args[0]).toEqual('foo');
+
+ });
+
+ it('reverse order callback', done => {
+
+ window.plugins.test.reverseOrderCallback = (success, error, args) => {
+ success('reverseOrderCallback');
+ };
+
+ @Plugin(testPluginMeta)
+ class Test {
+
+ @Cordova({
+ callbackOrder: 'reverse'
+ })
+ static reverseOrderCallback(args: any): Promise<any> { return; }
+
+ }
+
+ const spy = spyOn(window.plugins.test, 'reverseOrderCallback').and.callThrough();
+ Test.reverseOrderCallback('foo').then(result => {
+ expect(result).toEqual('reverseOrderCallback');
+ done();
+ });
+ expect(spy.calls.mostRecent().args[2]).toEqual('foo');
+
+ });
+
+ it('node style callback', done => {
+
+ window.plugins.test.nodeStyleCallback = (args, done) => {
+ done(null, 'nodeStyleCallback');
+ };
+
+ @Plugin(testPluginMeta)
+ class Test {
+
+ @Cordova({
+ callbackStyle: 'node'
+ })
+ static nodeStyleCallback(args: any): Promise<any> { return; }
+
+ }
+
+ const spy = spyOn(window.plugins.test, 'nodeStyleCallback').and.callThrough();
+ Test.nodeStyleCallback('foo').then(result => {
+ expect(result).toEqual('nodeStyleCallback');
+ done();
+ });
+ expect(spy.calls.mostRecent().args[0]).toEqual('foo');
+
+ });
+
+ it('object style callback', done => {
+
+ window.plugins.test.objectStyleCallback = (args, {success}) => {
+ success('objectStyleCallback');
+ };
+
+ @Plugin(testPluginMeta)
+ class Test {
+
+ @Cordova({
+ callbackStyle: 'object',
+ successName: 'success',
+ errorName: 'error'
+ })
+ static objectStyleCallback(args: any): Promise<any> { return; }
+
+ }
+
+ const spy = spyOn(window.plugins.test, 'objectStyleCallback').and.callThrough();
+ Test.objectStyleCallback('foo').then(result => {
+ expect(result).toEqual('objectStyleCallback');
+ done();
+ });
+ expect(spy.calls.mostRecent().args[0]).toEqual('foo');
+
+ });
+
+});
View
@@ -5,7 +5,8 @@
"sourceMap": true,
"declaration": true,
"experimentalDecorators": true,
- "outDir": "dist"
+ "outDir": "dist",
+ "moduleResolution": "node"
},
"files": [
"typings/es6-shim/es6-shim.d.ts",
View
@@ -0,0 +1,5 @@
+{
+ "globalDevDependencies": {
+ "jasmine": "registry:dt/jasmine#2.2.0+20160621224255"
+ }
+}
Oops, something went wrong.

0 comments on commit 1facde3

Please sign in to comment.