@@ -3,6 +3,8 @@ import { Yok } from "../../../yok";
33
44import { EventEmitter } from "events" ;
55import { assert , use } from "chai" ;
6+ import * as util from "util" ;
7+
68let chaiAsPromised = require ( 'chai-as-promised' ) ;
79use ( chaiAsPromised ) ;
810
@@ -41,6 +43,11 @@ class IOSSimulatorDiscoveryStub extends EventEmitter {
4143 }
4244}
4345
46+ function getErrorMessage ( injector : IInjector , message : string , ...args : string [ ] ) : string {
47+ return util . format ( injector . resolve ( "messages" ) . Devices [ message ] ,
48+ ..._ . concat ( args , injector . resolve ( "staticConfig" ) . CLIENT_NAME . toLowerCase ( ) ) ) ;
49+ }
50+
4451let androidDeviceDiscovery : EventEmitter ,
4552 iOSDeviceDiscovery : EventEmitter ,
4653 iOSSimulatorDiscovery : EventEmitter ,
@@ -168,7 +175,7 @@ function resetDefaultSetInterval(): void {
168175 global . setInterval = originalSetInterval ;
169176}
170177
171- describe ( "devicesService" , ( ) => {
178+ describe . only ( "devicesService" , ( ) => {
172179 let counter = 0 ,
173180 iOSDevice = {
174181 deviceInfo : {
@@ -334,7 +341,9 @@ describe("devicesService", () => {
334341 it ( "throws error when invalid identifier is passed" , async ( ) => {
335342 let results = devicesService . isAppInstalledOnDevices ( [ "invalidDeviceId" , iOSDevice . deviceInfo . identifier ] , "com.telerik.unitTest1" , "cordova" ) ;
336343
337- await assert . isRejected ( Promise . all ( results ) ) ;
344+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIdentifierErrorMessageWithIdentifier" , "invalidDeviceId" ) ;
345+
346+ await assert . isRejected ( Promise . all ( results ) , expectedErrorMessage ) ;
338347
339348 _ . each ( await getPromisesResults ( results ) , promiseResult => {
340349 let error = promiseResult . error ;
@@ -400,11 +409,13 @@ describe("devicesService", () => {
400409 } ) ;
401410
402411 it ( "fails when deviceId is invalid index (less than 0)" , async ( ) => {
403- await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : "-1" } ) ) ;
412+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIndexErrorMessage" , "-2" ) ;
413+ await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : "-1" } ) , expectedErrorMessage ) ;
404414 } ) ;
405415
406416 it ( "fails when deviceId is invalid index (more than currently connected devices)" , async ( ) => {
407- await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : "100" } ) ) ;
417+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIndexErrorMessage" , "99" ) ;
418+ await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : "100" } ) , expectedErrorMessage ) ;
408419 } ) ;
409420
410421 it ( "does not fail when iOSDeviceDiscovery startLookingForDevices fails" , async ( ) => {
@@ -432,21 +443,23 @@ describe("devicesService", () => {
432443
433444 it ( "when initialize is called with platform and deviceId and such device cannot be found" , async ( ) => {
434445 assert . isFalse ( devicesService . hasDevices , "Initially devicesService hasDevices must be false." ) ;
435- await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : androidDevice . deviceInfo . identifier } ) ) ;
446+
447+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIdentifierErrorMessage" ) ;
448+ await assert . isRejected ( devicesService . initialize ( { platform : "android" , deviceId : androidDevice . deviceInfo . identifier } ) , expectedErrorMessage ) ;
436449 } ) ;
437450
438451 it ( "when initialize is called with deviceId and invalid platform" , async ( ) => {
439452 assert . isFalse ( devicesService . hasDevices , "Initially devicesService hasDevices must be false." ) ;
440453 iOSDeviceDiscovery . emit ( "deviceFound" , iOSDevice ) ;
441454 androidDeviceDiscovery . emit ( "deviceFound" , androidDevice ) ;
442- await assert . isRejected ( devicesService . initialize ( { platform : "invalidPlatform" , deviceId : androidDevice . deviceInfo . identifier } ) ) ;
455+ await assert . isRejected ( devicesService . initialize ( { platform : "invalidPlatform" , deviceId : androidDevice . deviceInfo . identifier } ) , "Deploying to %s connected devices is not supported. Build the app using the `build` command and deploy the package manually." ) ;
443456 } ) ;
444457
445458 it ( "when initialize is called with platform and deviceId and device's platform is different" , async ( ) => {
446459 assert . isFalse ( devicesService . hasDevices , "Initially devicesService hasDevices must be false." ) ;
447460 iOSDeviceDiscovery . emit ( "deviceFound" , iOSDevice ) ;
448461 androidDeviceDiscovery . emit ( "deviceFound" , androidDevice ) ;
449- await assert . isRejected ( devicesService . initialize ( { platform : "ios" , deviceId : androidDevice . deviceInfo . identifier } ) ) ;
462+ await assert . isRejected ( devicesService . initialize ( { platform : "ios" , deviceId : androidDevice . deviceInfo . identifier } ) , "Cannot resolve the specified connected device. The provided platform does not match the provided index or identifier.To list currently connected devices and verify that the specified pair of platform and index or identifier exists, run \'device\'." ) ;
450463 } ) ;
451464
452465 describe ( "when only deviceIdentifier is passed" , ( ) => {
@@ -492,11 +505,13 @@ describe("devicesService", () => {
492505 } ) ;
493506
494507 it ( "fails when deviceId is invalid index (less than 0)" , async ( ) => {
495- await assert . isRejected ( devicesService . initialize ( { deviceId : "-1" } ) ) ;
508+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIndexErrorMessage" , "-2" ) ;
509+ await assert . isRejected ( devicesService . initialize ( { deviceId : "-1" } ) , expectedErrorMessage ) ;
496510 } ) ;
497511
498512 it ( "fails when deviceId is invalid index (more than currently connected devices)" , async ( ) => {
499- await assert . isRejected ( devicesService . initialize ( { deviceId : "100" } ) ) ;
513+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIndexErrorMessage" , "99" ) ;
514+ await assert . isRejected ( devicesService . initialize ( { deviceId : "100" } ) , expectedErrorMessage ) ;
500515 } ) ;
501516
502517 it ( "does not fail when iOSDeviceDiscovery startLookingForDevices fails" , async ( ) => {
@@ -618,7 +633,7 @@ describe("devicesService", () => {
618633 androidDeviceDiscovery . emit ( "deviceLost" , tempDevice ) ;
619634 iOSDeviceDiscovery . emit ( "deviceLost" , iOSDevice ) ;
620635 counter = 0 ;
621- await assert . isRejected ( devicesService . execute ( ( ) => { counter ++ ; return Promise . resolve ( ) ; } , ( ) => true ) ) ;
636+ await assert . isRejected ( devicesService . execute ( ( ) => { counter ++ ; return Promise . resolve ( ) ; } , ( ) => true ) , "Unable to detect platform for which to start emulator." ) ;
622637 counter = 0 ;
623638 devicesService . execute ( ( ) => { counter ++ ; return Promise . resolve ( ) ; } , ( ) => true , { allowNoDevices : true } ) ;
624639 assert . deepEqual ( counter , 0 , "The action must not be executed when there are no devices." ) ;
@@ -662,7 +677,7 @@ describe("devicesService", () => {
662677 assert . isFalse ( devicesService . hasDevices , "Initially devicesService hasDevices must be false." ) ;
663678 androidDeviceDiscovery . emit ( "deviceFound" , androidDevice ) ;
664679 iOSDeviceDiscovery . emit ( "deviceFound" , iOSDevice ) ;
665- await assert . isRejected ( devicesService . initialize ( ) ) ;
680+ await assert . isRejected ( devicesService . initialize ( ) , "Multiple device platforms detected (android and ios). Specify platform or device on command line." ) ;
666681 } ) ;
667682
668683 it ( "when parameters are not passed and devices with invalid platforms are detected initialize should work with correct devices only" , async ( ) => {
@@ -688,7 +703,7 @@ describe("devicesService", () => {
688703 platform : "invalid-platform"
689704 }
690705 } ) ;
691- await assert . isRejected ( devicesService . initialize ( ) ) ;
706+ await assert . isRejected ( devicesService . initialize ( ) , "{ formatStr: \'Cannot find connected devices. Reconnect any connected devices, verify that your system recognizes them, and run this command again.\',\n suppressCommandHelp: true }" ) ;
692707 } ) ;
693708
694709 it ( "caches execution result and does not execute next time when called" , async ( ) => {
@@ -840,7 +855,8 @@ describe("devicesService", () => {
840855
841856 it ( "throws error when invalid identifier is passed" , async ( ) => {
842857 let results = devicesService . deployOnDevices ( [ "invalidDeviceId" , iOSDevice . deviceInfo . identifier ] , "path" , "packageName" , "cordova" ) ;
843- await assert . isRejected ( Promise . all ( results ) ) ;
858+ let expectedErrorMessage = getErrorMessage ( testInjector , "NotFoundDeviceByIdentifierErrorMessageWithIdentifier" , "invalidDeviceId" ) ;
859+ await assert . isRejected ( Promise . all ( results ) , expectedErrorMessage ) ;
844860 let realResults = await getPromisesResults ( results ) ;
845861 _ . each ( realResults , singlePromiseResult => {
846862 let error = singlePromiseResult . error ;
0 commit comments