|
1 | 1 | var td = require('testdouble');
|
2 | 2 | var path = require('path');
|
3 | 3 | var BashTask = require('../../../../../lib/tasks/bash');
|
4 |
| -var OpenAppTask = require('../../../../../lib/targets/cordova/tasks/open-app'); |
| 4 | +var fsUtils = require('../../../../../lib/utils/fs-utils'); |
5 | 5 | var expect = require('../../../../helpers/expect');
|
6 | 6 | var openCommand = require('../../../../../lib/utils/open-app-command');
|
7 | 7 | var mockProject = require('../../../../fixtures/corber-mock/project');
|
8 | 8 | var _merge = require('lodash').merge;
|
9 | 9 | var isObject = td.matchers.isA(Object);
|
10 | 10 |
|
| 11 | +var setupOpenTask = function() { |
| 12 | + var OpenAppTask = require('../../../../../lib/targets/cordova/tasks/open-app'); |
| 13 | + return new OpenAppTask(_merge(mockProject, { platform: 'ios' })); |
| 14 | +}; |
| 15 | + |
11 | 16 | describe('Cordova Open App Task', function() {
|
12 |
| - var bashDouble, openApp, cdvPath; |
| 17 | + var cdvPath; |
13 | 18 |
|
14 | 19 | beforeEach(function() {
|
15 |
| - bashDouble = td.replace(BashTask.prototype, 'runCommand'); |
16 | 20 | cdvPath = path.resolve(
|
17 | 21 | __dirname, '../../../../',
|
18 | 22 | 'fixtures',
|
19 | 23 | 'corber-mock/corber/cordova'
|
20 | 24 | );
|
21 |
| - |
22 |
| - openApp = new OpenAppTask(_merge(mockProject, { platform: 'ios' })); |
23 | 25 | });
|
24 | 26 |
|
25 | 27 | afterEach(function() {
|
26 | 28 | td.reset();
|
27 | 29 | });
|
28 | 30 |
|
29 |
| - it('runs open command for ios', function() { |
30 |
| - openApp.run(); |
31 |
| - var expectedPath = cdvPath + '/platforms/ios/*.xcodeproj'; |
32 |
| - var expectedCmd = openCommand(expectedPath); |
33 |
| - td.verify(bashDouble(expectedCmd, isObject)); |
| 31 | + it('runs openApp with the path from getProjectPath', function() { |
| 32 | + var bashDouble = td.replace(BashTask.prototype, 'runCommand'); |
| 33 | + |
| 34 | + var openApp = setupOpenTask(); |
| 35 | + return openApp.run().then(function() { |
| 36 | + var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcodeproj'; |
| 37 | + var expectedCmd = openCommand(expectedPath); |
| 38 | + td.verify(bashDouble(expectedCmd, isObject)); |
| 39 | + }); |
34 | 40 | });
|
35 | 41 |
|
36 |
| - it('runs open command for Android', function() { |
37 |
| - openApp.platform = 'android'; |
38 |
| - openApp.run(); |
39 | 42 |
|
40 |
| - var expectedPath = cdvPath + '/platforms/android/'; |
41 |
| - var expectedCmd = openCommand(expectedPath); |
42 |
| - td.verify(bashDouble(expectedCmd, isObject)); |
43 |
| - }), |
| 43 | + context('getProjectPath', function() { |
| 44 | + it('ios returns xcworkspace if it exists', function() { |
| 45 | + td.replace(fsUtils, 'existsSync', function() { |
| 46 | + return true; |
| 47 | + }); |
44 | 48 |
|
45 |
| - it('outputs an error if no platform is specified', function() { |
46 |
| - openApp.platform = 'invalidPlatform'; |
| 49 | + var openApp = setupOpenTask(); |
| 50 | + return openApp.getProjectPath('ios', mockProject.project).then(function(projectPath) { |
| 51 | + var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcworkspace'; |
| 52 | + expect(projectPath).to.equal(expectedPath); |
| 53 | + }); |
| 54 | + }); |
47 | 55 |
|
48 |
| - return expect(openApp.run()).to.eventually.be.rejectedWith( |
49 |
| - /platform is not supported/ |
50 |
| - ); |
| 56 | + it('ios returns xcodeproj if workspace does not exist', function() { |
| 57 | + td.replace(fsUtils, 'existsSync', function() { |
| 58 | + return false; |
| 59 | + }); |
| 60 | + |
| 61 | + var openApp = setupOpenTask(); |
| 62 | + return openApp.getProjectPath('ios', mockProject.project).then(function(projectPath) { |
| 63 | + var expectedPath = cdvPath + '/platforms/ios/emberCordovaDummyApp.xcodeproj'; |
| 64 | + expect(projectPath).to.equal(expectedPath); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + it('rejects for android', function() { |
| 69 | + var openApp = setupOpenTask(); |
| 70 | + openApp.platform = 'android'; |
| 71 | + |
| 72 | + return expect(openApp.run()).to.eventually.be.rejectedWith( |
| 73 | + /is not supported for android/ |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + it('rejects if an invalid platform is specified', function() { |
| 78 | + var openApp = setupOpenTask(); |
| 79 | + openApp.platform = 'invalidPlatform'; |
| 80 | + |
| 81 | + return expect(openApp.run()).to.eventually.be.rejectedWith( |
| 82 | + /is not supported/ |
| 83 | + ); |
| 84 | + }); |
51 | 85 | });
|
52 | 86 | });
|
0 commit comments