-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(): add initial test suite (#523)
- Loading branch information
1 parent
d5513db
commit 1facde3
Showing
11 changed files
with
735 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"globalDevDependencies": { | ||
"jasmine": "registry:dt/jasmine#2.2.0+20160621224255" | ||
} | ||
} |
Oops, something went wrong.