@@ -2,22 +2,15 @@ import sinon from 'sinon';
22import { AndroidDriver } from '../../../lib/driver' ;
33import * as support from '@appium/support' ;
44import { ADB } from 'appium-adb' ;
5+ import { expect , use } from 'chai' ;
6+ import chaiAsPromised from 'chai-as-promised' ;
57
6- /** @type {AndroidDriver } */
7- let driver ;
8- let sandbox = sinon . createSandbox ( ) ;
8+ use ( chaiAsPromised ) ;
99
10- describe ( 'File Actions' , function ( ) {
11- let chai ;
12-
13- before ( async function ( ) {
14- chai = await import ( 'chai' ) ;
15- const chaiAsPromised = await import ( 'chai-as-promised' ) ;
16-
17- chai . should ( ) ;
18- chai . use ( chaiAsPromised . default ) ;
19- } ) ;
10+ let driver : AndroidDriver ;
11+ const sandbox = sinon . createSandbox ( ) ;
2012
13+ describe ( 'File Actions' , function ( ) {
2114 beforeEach ( function ( ) {
2215 driver = new AndroidDriver ( ) ;
2316 driver . adb = new ADB ( ) ;
@@ -28,104 +21,105 @@ describe('File Actions', function () {
2821
2922 describe ( 'pullFile' , function ( ) {
3023 it ( 'should be able to pull file from device' , async function ( ) {
31- let localFile = 'local/tmp_file' ;
24+ const localFile = 'local/tmp_file' ;
3225 sandbox . stub ( support . tempDir , 'path' ) . returns ( localFile ) ;
33- sandbox . stub ( driver . adb , 'pull' ) ;
26+ const pullStub1 = sandbox . stub ( driver . adb , 'pull' ) ;
3427 sandbox
3528 . stub ( support . util , 'toInMemoryBase64' )
3629 . withArgs ( localFile )
3730 . returns ( Buffer . from ( 'YXBwaXVt' , 'utf8' ) ) ;
3831 sandbox . stub ( support . fs , 'exists' ) . withArgs ( localFile ) . returns ( true ) ;
39- sandbox . stub ( support . fs , 'unlink' ) ;
40- await driver . pullFile ( 'remote_path' ) . should . become ( 'YXBwaXVt' ) ;
41- driver . adb . pull . calledWithExactly ( 'remote_path' , localFile ) . should . be . true ;
42- support . fs . unlink . calledWithExactly ( localFile ) . should . be . true ;
32+ const unlinkStub4 = sandbox . stub ( support . fs , 'unlink' ) ;
33+ await expect ( driver . pullFile ( 'remote_path' ) ) . to . become ( 'YXBwaXVt' ) ;
34+ expect ( pullStub1 . calledWithExactly ( 'remote_path' , localFile ) ) . to . be . true ;
35+ expect ( unlinkStub4 . calledWithExactly ( localFile ) ) . to . be . true ;
4336 } ) ;
4437
4538 it ( 'should be able to pull file located in application container from the device' , async function ( ) {
46- let localFile = 'local/tmp_file' ;
39+ const localFile = 'local/tmp_file' ;
4740 const packageId = 'com.myapp' ;
4841 const remotePath = 'path/in/container' ;
4942 const tmpPath = '/data/local/tmp/container' ;
5043 sandbox . stub ( support . tempDir , 'path' ) . returns ( localFile ) ;
51- sandbox . stub ( driver . adb , 'pull' ) ;
52- sandbox . stub ( driver . adb , 'shell' ) ;
44+ const pullStub = sandbox . stub ( driver . adb , 'pull' ) ;
45+ const shellStub2 = sandbox . stub ( driver . adb , 'shell' ) ;
5346 sandbox
5447 . stub ( support . util , 'toInMemoryBase64' )
5548 . withArgs ( localFile )
5649 . returns ( Buffer . from ( 'YXBwaXVt' , 'utf8' ) ) ;
5750 sandbox . stub ( support . fs , 'exists' ) . withArgs ( localFile ) . returns ( true ) ;
58- sandbox . stub ( support . fs , 'unlink' ) ;
59- await driver . pullFile ( `@${ packageId } /${ remotePath } ` ) . should . become ( 'YXBwaXVt' ) ;
60- driver . adb . pull . calledWithExactly ( tmpPath , localFile ) . should . be . true ;
61- driver . adb . shell . calledWithExactly ( [
51+ const unlinkStub3 = sandbox . stub ( support . fs , 'unlink' ) ;
52+ await expect ( driver . pullFile ( `@${ packageId } /${ remotePath } ` ) ) . to . become ( 'YXBwaXVt' ) ;
53+ expect ( pullStub . calledWithExactly ( tmpPath , localFile ) ) . to . be . true ;
54+ expect ( shellStub2 . calledWithExactly ( [
6255 'run-as' ,
6356 packageId ,
6457 `chmod 777 '/data/data/${ packageId } /${ remotePath } '` ,
65- ] ) . should . be . true ;
66- driver . adb . shell . calledWithExactly ( [
58+ ] ) ) . to . be . true ;
59+ expect ( shellStub2 . calledWithExactly ( [
6760 'run-as' ,
6861 packageId ,
6962 `cp -f '/data/data/${ packageId } /${ remotePath } ' '${ tmpPath } '` ,
70- ] ) . should . be . true ;
71- support . fs . unlink . calledWithExactly ( localFile ) . should . be . true ;
72- driver . adb . shell . calledWithExactly ( [ 'rm' , '-f' , tmpPath ] ) . should . be . true ;
63+ ] ) ) . to . be . true ;
64+ expect ( unlinkStub3 . calledWithExactly ( localFile ) ) . to . be . true ;
65+ expect ( shellStub2 . calledWithExactly ( [ 'rm' , '-f' , tmpPath ] ) ) . to . be . true ;
7366 } ) ;
7467 } ) ;
7568
7669 describe ( 'pushFile' , function ( ) {
7770 it ( 'should be able to push file to device' , async function ( ) {
78- let localFile = 'local/tmp_file' ;
79- let content = 'appium' ;
71+ const localFile = 'local/tmp_file' ;
72+ const content = 'appium' ;
8073 sandbox . stub ( support . tempDir , 'path' ) . returns ( localFile ) ;
81- sandbox . stub ( driver . adb , 'push' ) ;
74+ const pushStub1 = sandbox . stub ( driver . adb , 'push' ) ;
8275 sandbox . stub ( driver . adb , 'shell' ) ;
83- sandbox . stub ( support . fs , 'writeFile' ) ;
76+ const writeFileStub1 = sandbox . stub ( support . fs , 'writeFile' ) ;
8477 sandbox . stub ( support . fs , 'exists' ) . withArgs ( localFile ) . returns ( true ) ;
85- sandbox . stub ( support . fs , 'unlink' ) ;
78+ const unlinkStub1 = sandbox . stub ( support . fs , 'unlink' ) ;
8679 await driver . pushFile ( 'remote_path' , 'YXBwaXVt' ) ;
87- support . fs . writeFile . calledWithExactly ( localFile , content , 'binary' ) . should . be . true ;
88- support . fs . unlink . calledWithExactly ( localFile ) . should . be . true ;
89- driver . adb . push . calledWithExactly ( localFile , 'remote_path' ) . should . be . true ;
80+ expect ( writeFileStub1 . calledWithExactly ( localFile , content , 'binary' ) ) . to . be . true ;
81+ expect ( unlinkStub1 . calledWithExactly ( localFile ) ) . to . be . true ;
82+ expect ( pushStub1 . calledWithExactly ( localFile , 'remote_path' ) ) . to . be . true ;
9083 } ) ;
9184
9285 it ( 'should be able to push file located in application container to the device' , async function ( ) {
93- let localFile = 'local/tmp_file' ;
94- let content = 'appium' ;
86+ const localFile = 'local/tmp_file' ;
87+ const content = 'appium' ;
9588 const packageId = 'com.myapp' ;
9689 const remotePath = 'path/in/container' ;
9790 const tmpPath = '/data/local/tmp/container' ;
9891 sandbox . stub ( support . tempDir , 'path' ) . returns ( localFile ) ;
99- sandbox . stub ( driver . adb , 'push' ) ;
100- sandbox . stub ( driver . adb , 'shell' ) ;
101- sandbox . stub ( support . fs , 'writeFile' ) ;
92+ const pushStub2 = sandbox . stub ( driver . adb , 'push' ) ;
93+ const writeFileStub = sandbox . stub ( support . fs , 'writeFile' ) ;
10294 sandbox . stub ( support . fs , 'exists' ) . withArgs ( localFile ) . returns ( true ) ;
103- sandbox . stub ( support . fs , 'unlink' ) ;
95+ const unlinkStub2 = sandbox . stub ( support . fs , 'unlink' ) ;
96+ const shellStub = sandbox . stub ( driver . adb , 'shell' ) ;
10497 await driver . pushFile ( `@${ packageId } /${ remotePath } ` , 'YXBwaXVt' ) ;
105- support . fs . writeFile . calledWithExactly ( localFile , content , 'binary' ) . should . be . true ;
106- driver . adb . push . calledWithExactly ( localFile , tmpPath ) . should . be . true ;
107- driver . adb . shell . calledWithExactly ( [
98+ expect ( writeFileStub . calledWithExactly ( localFile , content , 'binary' ) ) . to . be . true ;
99+ expect ( pushStub2 . calledWithExactly ( localFile , tmpPath ) ) . to . be . true ;
100+ expect ( shellStub . calledWithExactly ( [
108101 'run-as' ,
109102 packageId ,
110103 `mkdir -p '/data/data/${ packageId } /path/in'` ,
111- ] ) . should . be . true ;
112- driver . adb . shell . calledWithExactly ( [
104+ ] ) ) . to . be . true ;
105+ expect ( shellStub . calledWithExactly ( [
113106 'run-as' ,
114107 packageId ,
115108 `touch '/data/data/${ packageId } /${ remotePath } '` ,
116- ] ) . should . be . true ;
117- driver . adb . shell . calledWithExactly ( [
109+ ] ) ) . to . be . true ;
110+ expect ( shellStub . calledWithExactly ( [
118111 'run-as' ,
119112 packageId ,
120113 `chmod 777 '/data/data/${ packageId } /${ remotePath } '` ,
121- ] ) . should . be . true ;
122- driver . adb . shell . calledWithExactly ( [
114+ ] ) ) . to . be . true ;
115+ expect ( shellStub . calledWithExactly ( [
123116 'run-as' ,
124117 packageId ,
125118 `cp -f '${ tmpPath } ' '/data/data/${ packageId } /${ remotePath } '` ,
126- ] ) . should . be . true ;
127- support . fs . unlink . calledWithExactly ( localFile ) . should . be . true ;
128- driver . adb . shell . calledWithExactly ( [ 'rm' , '-f' , tmpPath ] ) . should . be . true ;
119+ ] ) ) . to . be . true ;
120+ expect ( unlinkStub2 . calledWithExactly ( localFile ) ) . to . be . true ;
121+ expect ( shellStub . calledWithExactly ( [ 'rm' , '-f' , tmpPath ] ) ) . to . be . true ;
129122 } ) ;
130123 } ) ;
131124} ) ;
125+
0 commit comments