Skip to content

Commit b75941a

Browse files
committed
tests(get-platform): test for getPlatform and subsequent changes
1 parent b1e8b37 commit b75941a

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

lib/commands/open.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
var OpenAppTask = require('../tasks/open-app');
3+
var OpenAppTask = require('../tasks/open-app');
4+
var getPlatform = require('../utils/get-platform');
45

56
module.exports = {
67
name: 'cordova:open',
@@ -15,9 +16,11 @@ module.exports = {
1516
],
1617

1718
run: function(options) {
19+
var platform = getPlatform(this.project.config(), options);
20+
1821
var open = new OpenAppTask({
1922
application: options.application,
20-
platform: options.platform,
23+
platform: platform,
2124
project: this.project,
2225
ui: this.ui
2326
});

lib/utils/get-platform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = function getPlatform(config, options) {
22
var platform, defaultPlatform;
3-
defaultPlatform = config.cordova && config.cordova.platform;
4-
defaultPlatform? platform = defaultPlatform : platform = options.platform;
3+
defaultPlatform = config && config.cordova && config.cordova.platform;
4+
defaultPlatform ? platform = defaultPlatform : platform = options.platform;
55

66
return platform;
77
}

node-tests/fixtures/ember-cordova-mock/project.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ module.exports = {
77
env: 'development',
88
id: 'ember-cordova-mock',
99
name: 'ember-cordova-mock',
10-
platform: 'ios',
10+
cordova: {
11+
platform: 'ios'
12+
},
1113

1214
project: {
1315
root: path.resolve(__dirname, '..', '..', 'fixtures', 'ember-cordova-mock')
1416
},
17+
18+
config: function() {},
19+
1520
ui: new MockUI()
1621
}

node-tests/unit/commands/build-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ describe('Build Command', () => {
8989
it('passes platform to cordova build task', () => {
9090
let passedPlatform = 'ios';
9191

92-
runBuild({
92+
return runBuild({
9393
platform: passedPlatform
94+
}).then(function() {
95+
expect(cordovaPlatform).to.equal(passedPlatform);
9496
});
95-
96-
expect(cordovaPlatform).to.equal(passedPlatform);
9797
});
9898
});
9999

node-tests/unit/tasks/open-app-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ const OpenAppTask = require('../../../lib/tasks/open-app');
77
const expect = require('../../helpers/expect');
88
const openCommand = require('../../../lib/utils/open-app-command');
99

10-
1110
const mockProject = require('../../fixtures/ember-cordova-mock/project');
11+
const _merge = require('lodash').merge;
1212
const isObject = td.matchers.isA(Object);
1313

1414
describe('Open App Task', () => {
@@ -22,7 +22,7 @@ describe('Open App Task', () => {
2222
'ember-cordova-mock/ember-cordova/cordova'
2323
);
2424

25-
openApp = new OpenAppTask(mockProject);
25+
openApp = new OpenAppTask(_merge(mockProject, { platform: 'ios' }));
2626
});
2727

2828
afterEach(() => {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
const expect = require('../../helpers/expect');
4+
const getPlatform = require('../../../lib/utils/get-platform');
5+
const mockProject = require('../../fixtures/ember-cordova-mock/project');
6+
7+
describe('Get Platform Util', () => {
8+
it('returns the default platform if one is set', function() {
9+
expect(
10+
getPlatform(mockProject)
11+
).to.equal('ios');
12+
});
13+
14+
it('returns the cflag platform is there is no default', function() {
15+
expect(
16+
getPlatform({}, {platform: 'android'})
17+
).to.equal('android');
18+
});
19+
});
20+

0 commit comments

Comments
 (0)