|
| 1 | +import * as titaniumlib from 'titaniumlib'; |
| 2 | +import * as path from 'path'; |
| 3 | +import * as util from '../src/util'; |
| 4 | + |
1 | 5 | import execa from 'execa';
|
2 | 6 | import { appc, titanium, node, alloy, checkAllUpdates } from '../src/updates/';
|
3 |
| -import * as util from '../src/util'; |
4 | 7 |
|
5 |
| -import { expect } from 'chai'; |
| 8 | +import chai from 'chai'; |
| 9 | +import chaiAsPromised from 'chai-as-promised'; |
6 | 10 | import mockFS from 'mock-fs';
|
7 | 11 | import nock from 'nock';
|
8 | 12 | import os from 'os';
|
9 |
| -import * as path from 'path'; |
| 13 | +import sinon from 'sinon'; |
| 14 | +import sinonChai from 'sinon-chai'; |
| 15 | + |
10 | 16 | import { mockAppcCoreRequest, mockNpmRequest, mockSDKRequest, mockNodeRequest } from './fixtures/network/network-mocks';
|
11 | 17 | import { mockAppcCli, mockNode, mockNpmCli, mockNpmInstall, mockOS, mockSdk } from './util';
|
12 | 18 |
|
| 19 | +chai.use(chaiAsPromised); |
| 20 | +chai.use(sinonChai); |
| 21 | +const expect = chai.expect; |
| 22 | + |
13 | 23 | let fixProcessPlatform: () => void|undefined;
|
14 | 24 | describe('updates', () => {
|
15 | 25 |
|
@@ -57,6 +67,64 @@ describe('updates', () => {
|
57 | 67 | expect(update.hasUpdate).to.equal(false);
|
58 | 68 | });
|
59 | 69 |
|
| 70 | + it('install with titanium cli', async () => { |
| 71 | + |
| 72 | + global.sandbox |
| 73 | + .stub(titaniumlib.sdk, 'install') |
| 74 | + .resolves(''); |
| 75 | + |
| 76 | + const execStub: sinon.SinonStub = global.sandbox.stub(util, 'exec'); |
| 77 | + |
| 78 | + const selectStub = execStub |
| 79 | + .withArgs('ti', sinon.match.any, sinon.match.any) |
| 80 | + .resolves({ stdout: '{}' } as execa.ExecaReturnValue); |
| 81 | + |
| 82 | + mockNpmCli(execStub, 'titanium', '5.3.0'); |
| 83 | + |
| 84 | + await titanium.sdk.installUpdate('8.0.0.GA'); |
| 85 | + expect(selectStub).to.have.been.calledOnceWith('ti', [ 'sdk', 'select', '8.0.0.GA' ], { shell: true }); |
| 86 | + }); |
| 87 | + |
| 88 | + it('install with appc cli logged in', async () => { |
| 89 | + global.sandbox |
| 90 | + .stub(titaniumlib.sdk, 'install') |
| 91 | + .resolves(''); |
| 92 | + |
| 93 | + const execStub: sinon.SinonStub = global.sandbox.stub(util, 'exec'); |
| 94 | + |
| 95 | + const whoamiStub = execStub |
| 96 | + .withArgs('appc', [ 'whoami', '-o', 'json'], sinon.match.any) |
| 97 | + .resolves({ stdout: '{ "username": "bob" }' } as execa.ExecaReturnValue); |
| 98 | + |
| 99 | + const selectStub = execStub |
| 100 | + .withArgs('appc', [ 'ti', 'sdk', 'select', '8.0.0.GA' ], sinon.match.any) |
| 101 | + .resolves({ stdout: '' } as execa.ExecaReturnValue); |
| 102 | + |
| 103 | + mockNpmCli(execStub, 'titanium'); |
| 104 | + mockAppcCli(execStub, '6.6.6', '4.2.13'); |
| 105 | + |
| 106 | + await titanium.sdk.installUpdate('8.0.0.GA'); |
| 107 | + expect(whoamiStub).to.have.been.calledOnceWith('appc', [ 'whoami', '-o', 'json' ], { shell: true }); |
| 108 | + expect(selectStub).to.have.been.calledOnceWith('appc', [ 'ti', 'sdk', 'select', '8.0.0.GA' ], { shell: true }); |
| 109 | + }); |
| 110 | + |
| 111 | + it('install with appc cli logged out', async () => { |
| 112 | + global.sandbox |
| 113 | + .stub(titaniumlib.sdk, 'install') |
| 114 | + .resolves(''); |
| 115 | + |
| 116 | + const execStub: sinon.SinonStub = global.sandbox.stub(util, 'exec'); |
| 117 | + |
| 118 | + execStub |
| 119 | + .withArgs('appc', [ 'whoami', '-o', 'json'], sinon.match.any) |
| 120 | + .resolves({ stdout: '{}' } as execa.ExecaReturnValue); |
| 121 | + |
| 122 | + mockNpmCli(execStub, 'titanium'); |
| 123 | + mockAppcCli(execStub, '6.6.6', '4.2.13'); |
| 124 | + |
| 125 | + await expect(titanium.sdk.installUpdate('8.0.0.GA')).to.eventually.be.rejectedWith('Failed to select SDK as you are not logged in'); |
| 126 | + }); |
| 127 | + |
60 | 128 | it('getReleaseNotes()', () => {
|
61 | 129 | expect(titanium.sdk.getReleaseNotes('10.0.0.GA')).to.equal('https://titaniumsdk.com/guide/Titanium_SDK/Titanium_SDK_Release_Notes/Titanium_SDK_Release_Notes_10.x/Titanium_SDK_10.0.0.GA_Release_Note.html');
|
62 | 130 | });
|
@@ -121,6 +189,16 @@ describe('updates', () => {
|
121 | 189 | expect(update.hasUpdate).to.equal(false);
|
122 | 190 | });
|
123 | 191 |
|
| 192 | + it('installUpdate()', async () => { |
| 193 | + const stub = global.sandbox.stub(util, 'exec') |
| 194 | + .withArgs('npm', sinon.match.any, sinon.match.any) |
| 195 | + .resolves({ stdout: '' } as execa.ExecaReturnValue); |
| 196 | + |
| 197 | + await appc.install.installUpdate('6.6.6'); |
| 198 | + |
| 199 | + expect(stub).to.have.been.calledOnceWith('npm', [ 'install', '-g', '[email protected]', '--json' ], { shell: true }); |
| 200 | + }); |
| 201 | + |
124 | 202 | it('getReleaseNotes()', () => {
|
125 | 203 | expect(appc.install.getReleaseNotes()).to.equal('https://titaniumsdk.com/guide/Appcelerator_CLI/Appcelerator_CLI_Release_Notes/');
|
126 | 204 | });
|
@@ -184,6 +262,16 @@ describe('updates', () => {
|
184 | 262 | expect(update.hasUpdate).to.equal(true);
|
185 | 263 | });
|
186 | 264 |
|
| 265 | + it('installUpdate()', async () => { |
| 266 | + const stub = global.sandbox.stub(util, 'exec') |
| 267 | + .withArgs('appc', sinon.match.any, sinon.match.any) |
| 268 | + .resolves({ stdout: '' } as execa.ExecaReturnValue); |
| 269 | + |
| 270 | + await appc.core.installUpdate('6.6.6'); |
| 271 | + |
| 272 | + expect(stub).to.have.been.calledOnceWith('appc', [ 'use', '6.6.6' ], { shell: true }); |
| 273 | + }); |
| 274 | + |
187 | 275 | it('getReleaseNotes()', () => {
|
188 | 276 | expect(appc.core.getReleaseNotes('6.6.6')).to.equal('https://titaniumsdk.com/guide/Appcelerator_CLI/Appcelerator_CLI_Release_Notes/Appcelerator_CLI_Release_Notes_6.x/Appcelerator_CLI_6.6.6_GA_Release_Note.html');
|
189 | 277 | });
|
|
0 commit comments