Skip to content

CB-9597 Adds implementation for PlatformApiPoly class according to PlatformApi spec #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions cordova-lib/spec-cordova/compile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
*/
var cordova = require('../src/cordova/cordova'),
platforms = require('../src/platforms/platforms'),
path = require('path'),
HooksRunner = require('../src/hooks/HooksRunner'),
superspawn = require('../src/cordova/superspawn'),
util = require('../src/cordova/util'),
Q = require('q');

var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });


describe('compile command', function() {
var is_cordova, list_platforms, fire, result, cd_project_root;
var is_cordova, list_platforms, fire, result, cd_project_root, fail, platformApi, getPlatformApi;
var project_dir = '/some/path';

function wrapper(f, post) {
Expand All @@ -43,7 +41,9 @@ describe('compile command', function() {
cd_project_root = spyOn(util, 'cdProjectRoot').andReturn(project_dir);
list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
fire = spyOn(HooksRunner.prototype, 'fire').andReturn(Q());
spyOn(superspawn, 'spawn').andCallFake(function() { return Q(); });
platformApi = { build: jasmine.createSpy('build').andReturn(Q()) };
getPlatformApi = spyOn(platforms, 'getPlatformApi').andReturn(platformApi);
fail = function (err) { expect(err.stack).not.toBeDefined(); };
});
describe('failure', function() {
it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function() {
Expand All @@ -63,17 +63,21 @@ describe('compile command', function() {
describe('success', function() {
it('should run inside a Cordova-based project with at least one added platform and shell out to build', function(done) {
cordova.raw.compile(['android','ios']).then(function() {
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'build'), [], jasmine.any(Object));
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'build'), [], jasmine.any(Object));
done();
});
expect(getPlatformApi).toHaveBeenCalledWith('android');
expect(getPlatformApi).toHaveBeenCalledWith('ios');
expect(platformApi.build).toHaveBeenCalled();
})
.fail(fail)
.fin(done);
});

it('should pass down optional parameters', function (done) {
cordova.raw.compile({platforms:['blackberry10'], options:['--release']}).then(function () {
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'blackberry10', 'cordova', 'build'), ['--release'], jasmine.any(Object));
done();
});
cordova.raw.compile({platforms:['blackberry10'], options:{release: true}}).then(function () {
expect(getPlatformApi).toHaveBeenCalledWith('blackberry10');
expect(platformApi.build).toHaveBeenCalledWith({release: true});
})
.fail(fail)
.fin(done);
});
});

Expand All @@ -83,13 +87,17 @@ describe('compile command', function() {
cordova.raw.compile(['android', 'ios']).then(function() {
expect(fire).toHaveBeenCalledWith('before_compile', {verbose: false, platforms:['android', 'ios'], options: []});
done();
});
})
.fail(fail)
.fin(done);
});
it('should fire after hooks through the hooker module', function(done) {
cordova.raw.compile('android').then(function() {
expect(fire).toHaveBeenCalledWith('after_compile', {verbose: false, platforms:['android'], options: []});
done();
});
})
.fail(fail)
.fin(done);
});
});

Expand Down
48 changes: 27 additions & 21 deletions cordova-lib/spec-cordova/emulate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,16 @@
*/
var cordova = require('../src/cordova/cordova'),
platforms = require('../src/platforms/platforms'),
superspawn = require('../src/cordova/superspawn'),
path = require('path'),
HooksRunner = require('../src/hooks/HooksRunner'),
Q = require('q'),
util = require('../src/cordova/util');

var supported_platforms = Object.keys(platforms).filter(function(p) { return p != 'www'; });

describe('emulate command', function() {
var is_cordova, cd_project_root, list_platforms, fire, result;
var is_cordova, cd_project_root, list_platforms, fire, result, fail;
var project_dir = '/some/path';
var prepare_spy;
var prepare_spy, platformApi, getPlatformApi;

function wrapper(f, post) {
runs(function() {
Expand All @@ -45,7 +43,9 @@ describe('emulate command', function() {
list_platforms = spyOn(util, 'listPlatforms').andReturn(supported_platforms);
fire = spyOn(HooksRunner.prototype, 'fire').andReturn(Q());
prepare_spy = spyOn(cordova.raw, 'prepare').andReturn(Q());
spyOn(superspawn, 'spawn').andCallFake(Q);
fail = function (err) { expect(err.stack).not.toBeDefined(); };
platformApi = { run: jasmine.createSpy('run').andReturn(Q()) };
getPlatformApi = spyOn(platforms, 'getPlatformApi').andReturn(platformApi);
});
describe('failure', function() {
it('should not run inside a Cordova-based project with no added platforms by calling util.listPlatforms', function() {
Expand All @@ -66,35 +66,41 @@ describe('emulate command', function() {
it('should run inside a Cordova-based project with at least one added platform and call prepare and shell out to the emulate script', function(done) {
cordova.raw.emulate(['android','ios']).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['android', 'ios']);
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'android', 'cordova', 'run'), ['--emulator'], jasmine.any(Object));
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator'], jasmine.any(Object));

done();
});
expect(getPlatformApi).toHaveBeenCalledWith('android');
expect(getPlatformApi).toHaveBeenCalledWith('ios');
expect(platformApi.run).toHaveBeenCalled();
})
.fail(fail)
.fin(done);
});
it('should pass down options', function(done) {
cordova.raw.emulate({platforms: ['ios'], options:['--optionTastic']}).then(function(err) {
cordova.raw.emulate({platforms: ['ios'], options: {optionTastic: true }}).then(function(err) {
expect(prepare_spy).toHaveBeenCalledWith(['ios']);
expect(superspawn.spawn).toHaveBeenCalledWith(path.join(project_dir, 'platforms', 'ios', 'cordova', 'run'), ['--emulator', '--optionTastic'], jasmine.any(Object));

done();
});
expect(getPlatformApi).toHaveBeenCalledWith('ios');
expect(platformApi.run).toHaveBeenCalledWith({ device: false, emulator: true, optionTastic: true });
})
.fail(fail)
.fin(done);
});
});

describe('hooks', function() {
describe('when platforms are added', function() {
it('should fire before hooks through the hooker module', function(done) {
cordova.raw.emulate(['android', 'ios']).then(function() {
expect(fire).toHaveBeenCalledWith('before_emulate', {verbose: false, platforms:['android', 'ios'], options: []});
done();
});
expect(fire).toHaveBeenCalledWith('before_emulate',
jasmine.objectContaining({verbose: false, platforms:['android', 'ios'], options: jasmine.any(Object)}));
})
.fail(fail)
.fin(done);
});
it('should fire after hooks through the hooker module', function(done) {
cordova.raw.emulate('android').then(function() {
expect(fire).toHaveBeenCalledWith('after_emulate', {verbose: false, platforms:['android'], options: []});
done();
});
expect(fire).toHaveBeenCalledWith('after_emulate',
jasmine.objectContaining({verbose: false, platforms:['android'], options: jasmine.any(Object)}));
})
.fail(fail)
.fin(done);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" android:windowSoftInputMode="adjustPan" package="org.testing" xmlns:android="http://schemas.android.com/apk/res/android">
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/app_name" android:name="TestBase" android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"prepare_queue": {
"installed": [],
"uninstalled": []
},
"config_munge": {
"files": {}
},
"installed_plugins": {},
"dependent_plugins": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<name>Hello Cordova</name>
<description>
A sample Apache Cordova application that responds to the deviceready event.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<access origin="*" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
</widget>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function PlatformApi (argument) {
this.platform = 'windows';
};
12 changes: 6 additions & 6 deletions cordova-lib/spec-cordova/metadata/android_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* jshint boss:true */

var platforms = require('../../src/platforms/platforms'),
var androidParser = require('../../src/cordova/metadata/android_parser'),
util = require('../../src/cordova/util'),
path = require('path'),
shell = require('shelljs'),
Expand Down Expand Up @@ -65,24 +65,24 @@ describe('android project parser', function() {
it('should throw if provided directory does not contain an AndroidManifest.xml', function() {
exists.andReturn(false);
expect(function() {
new platforms.android.parser(android_proj);
new androidParser(android_proj);
}).toThrow();
});
it('should create an instance with path, strings, manifest and android_config properties', function() {
expect(function() {
var p = new platforms.android.parser(android_proj);
var p = new androidParser(android_proj);
expect(p.path).toEqual(android_proj);
expect(p.strings).toEqual(path.join(android_proj, 'res', 'values', 'strings.xml'));
expect(p.manifest).toEqual(path.join(android_proj, 'AndroidManifest.xml'));
expect(p.android_config).toEqual(path.join(android_proj, 'res', 'xml', 'config.xml'));
}).not.toThrow();
});
it('should be an instance of Parser', function() {
expect(new platforms.android.parser(android_proj) instanceof Parser).toBe(true);
expect(new androidParser(android_proj) instanceof Parser).toBe(true);
});
it('should call super with the correct arguments', function() {
var call = spyOn(Parser, 'call');
var p = new platforms.android.parser(android_proj);
var p = new androidParser(android_proj);
expect(call).toHaveBeenCalledWith(p, 'android', android_proj);
});
});
Expand All @@ -94,7 +94,7 @@ describe('android project parser', function() {
beforeEach(function() {
stringsRoot = null;
manifestRoot = null;
p = new platforms.android.parser(android_proj);
p = new androidParser(android_proj);
cp = spyOn(shell, 'cp');
rm = spyOn(shell, 'rm');
is_cordova = spyOn(util, 'isCordova').andReturn(android_proj);
Expand Down
12 changes: 6 additions & 6 deletions cordova-lib/spec-cordova/metadata/blackberry_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
under the License.
*/

var platforms = require('../../src/platforms/platforms'),
var blackberryParser = require('../../src/cordova/metadata/blackberry10_parser'),
util = require('../../src/cordova/util'),
path = require('path'),
shell = require('shelljs'),
Expand Down Expand Up @@ -76,22 +76,22 @@ describe('blackberry10 project parser', function() {
it('should throw an exception with a path that is not a native blackberry project', function() {
exists.andReturn(false);
expect(function() {
new platforms.blackberry10.parser(proj);
new blackberryParser(proj);
}).toThrow();
});
it('should accept a proper native blackberry project path as construction parameter', function() {
var project;
expect(function() {
project = new platforms.blackberry10.parser(proj);
project = new blackberryParser(proj);
}).not.toThrow();
expect(project).toBeDefined();
});
it('should be an instance of Parser', function() {
expect(new platforms.blackberry10.parser(proj) instanceof Parser).toBe(true);
expect(new blackberryParser(proj) instanceof Parser).toBe(true);
});
it('should call super with the correct arguments', function() {
var call = spyOn(Parser, 'call');
var p = new platforms.blackberry10.parser(proj);
var p = new blackberryParser(proj);
expect(call).toHaveBeenCalledWith(p, 'blackberry10', proj);
});
});
Expand All @@ -100,7 +100,7 @@ describe('blackberry10 project parser', function() {
var p, cp, rm, mkdir, is_cordova, write, read;
var bb_proj = path.join(proj, 'platforms', 'blackberry10');
beforeEach(function() {
p = new platforms.blackberry10.parser(bb_proj);
p = new blackberryParser(bb_proj);
cp = spyOn(shell, 'cp');
rm = spyOn(shell, 'rm');
mkdir = spyOn(shell, 'mkdir');
Expand Down
10 changes: 5 additions & 5 deletions cordova-lib/spec-cordova/metadata/browser_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
under the License.
*/

var platforms = require('../../src/platforms/platforms'),
var browserParser = require('../../src/cordova/metadata/browser_parser'),
util = require('../../src/cordova/util'),
path = require('path'),
shell = require('shelljs'),
Expand All @@ -35,16 +35,16 @@ describe('browser project parser', function() {
describe('constructions', function() {
it('should create an instance with a path', function() {
expect(function() {
var p = new platforms.browser.parser(proj);
var p = new browserParser(proj);
expect(p.path).toEqual(proj);
}).not.toThrow();
});
it('should be an instance of Parser', function() {
expect(new platforms.browser.parser(proj) instanceof Parser).toBe(true);
expect(new browserParser(proj) instanceof Parser).toBe(true);
});
it('should call super with the correct arguments', function() {
var call = spyOn(Parser, 'call');
var p = new platforms.browser.parser(proj);
var p = new browserParser(proj);
expect(call).toHaveBeenCalledWith(p, 'browser', proj);
});
});
Expand All @@ -54,7 +54,7 @@ describe('browser project parser', function() {
var browser_proj = path.join(proj, 'platforms', 'browser');

beforeEach(function() {
p = new platforms.browser.parser(browser_proj);
p = new browserParser(browser_proj);
cp = spyOn(shell, 'cp');
rm = spyOn(shell, 'rm');
mkdir = spyOn(shell, 'mkdir');
Expand Down
10 changes: 5 additions & 5 deletions cordova-lib/spec-cordova/metadata/firefoxos_parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* jshint boss:true */

var platforms = require('../../src/platforms/platforms'),
var firefoxosParser = require('../../src/cordova/metadata/firefoxos_parser'),
util = require('../../src/cordova/util'),
path = require('path'),
shell = require('shelljs'),
Expand Down Expand Up @@ -53,18 +53,18 @@ describe('firefoxos project parser', function() {
describe('constructions', function() {
it('should create an instance with a path', function() {
expect(function() {
var p = new platforms.firefoxos.parser(proj);
var p = new firefoxosParser(proj);
expect(p.path).toEqual(proj);
expect(p.config_path).toEqual(path.join(proj, 'config.xml'));
expect(p.manifest_path).toEqual(path.join(p.www_dir(), 'manifest.webapp'));
}).not.toThrow();
});
it('should be an instance of Parser', function() {
expect(new platforms.firefoxos.parser(proj) instanceof Parser).toBe(true);
expect(new firefoxosParser(proj) instanceof Parser).toBe(true);
});
it('should call super with the correct arguments', function() {
var call = spyOn(Parser, 'call');
var p = new platforms.firefoxos.parser(proj);
var p = new firefoxosParser(proj);
expect(call).toHaveBeenCalledWith(p, 'firefoxos', proj);
});
});
Expand All @@ -74,7 +74,7 @@ describe('firefoxos project parser', function() {
var ff_proj = path.join(proj, 'platforms', 'firefoxos');
var manifestJson = null;
beforeEach(function() {
p = new platforms.firefoxos.parser(ff_proj);
p = new firefoxosParser(ff_proj);
cp = spyOn(shell, 'cp');
rm = spyOn(shell, 'rm');
is_cordova = spyOn(util, 'isCordova').andReturn(proj);
Expand Down
Loading