@@ -9,95 +9,6 @@ global.Date.UTC = _Date.UTC;
99global . Date . parse = _Date . parse ;
1010global . Date . now = _Date . now ;
1111
12- jest . mock ( 'fs-extra' , ( ) => {
13- return {
14- createReadStream : jest . fn ( ( ) => 'this is a stream' ) ,
15- writeFileSync : jest . fn ( ( ) => 'write file' ) ,
16- readFile : jest . fn ( cb => cb ( null , 'file content!' ) )
17- } ;
18- } ) ;
19-
20- jest . mock ( 'node-dir' , ( ) => {
21- return {
22- paths : jest . fn ( ( pathToDir , cb ) => {
23- const sep = require ( 'path' ) . sep ;
24- cb ( null , {
25- files : [
26- `${ pathToDir } ${ sep } package.json` ,
27- `${ pathToDir } ${ sep } server.js` ,
28- `${ pathToDir } ${ sep } template.js`
29- ]
30- } ) ;
31- } )
32- } ;
33- } ) ;
34-
35- let mockCachedTxt = 0 ;
36- let mockCachedJson = 0 ;
37- jest . mock ( '@google-cloud/storage' , ( ) =>
38- jest . fn ( ( ) => ( {
39- bucket : bucket => ( {
40- getFiles : ( ) => {
41- const files =
42- bucket === 'my-empty-bucket'
43- ? [ ]
44- : [
45- [
46- {
47- name : 'components/image/1.0.0/app.js'
48- } ,
49- {
50- name : 'components/image/1.0.0/server.js'
51- } ,
52- {
53- name : 'components/image/1.0.1/new-server.js'
54- } ,
55- {
56- name : 'components/image/1.0.1/new-app.js'
57- }
58- ]
59- ] ;
60- return Promise . resolve ( files ) ;
61- } ,
62- upload : ( filePath , { destination } ) => {
63- if ( destination . match ( '-error' ) ) {
64- return Promise . reject ( {
65- code : 1234 ,
66- message : 'an error message'
67- } ) ;
68- }
69- return Promise . resolve ( ) ;
70- } ,
71- file : file => ( {
72- makePublic ( ) {
73- return Promise . resolve ( ) ;
74- } ,
75- download ( ) {
76- mockCachedTxt ++ ;
77- mockCachedJson ++ ;
78- const contents = {
79- 'path/test.txt' : 'Hello!' ,
80- 'path/test.json' : JSON . stringify ( { value : 'Hello!' } ) ,
81- 'path/not-found.txt' : { error : { code : 404 } } ,
82- 'path/not-found.json' : { error : { code : 404 } } ,
83- 'path/not-a-json.json' : {
84- error : { code : '1' , msg : 'not an error' }
85- } ,
86- 'path/to-mutable.json' : JSON . stringify ( { value : mockCachedJson } ) ,
87- 'path/to-mutable.txt' : mockCachedTxt
88- } ;
89- const content = contents [ file ] ;
90- if ( content . error ) {
91- return Promise . reject ( content . error ) ;
92- } else {
93- return Promise . resolve ( content ) ;
94- }
95- }
96- } )
97- } )
98- } ) )
99- ) ;
100-
10112test ( 'should expose the correct methods' , ( ) => {
10213 const options = {
10314 bucket : 'test' ,
@@ -258,9 +169,7 @@ test('test getJson force mode', done => {
258169 { path : 'components/image' , expected : [ '1.0.0' , '1.0.1' ] } ,
259170 { path : 'components/image/' , expected : [ '1.0.0' , '1.0.1' ] }
260171] . forEach ( scenario => {
261- test ( `test listSubDirectories when bucket is not empty for folder ${
262- scenario . path
263- } `, done => {
172+ test ( `test listSubDirectories when bucket is not empty for folder ${ scenario . path } ` , done => {
264173 const client = new gs ( { bucket : 'my-bucket' } ) ;
265174
266175 client . listSubDirectories ( scenario . path , ( err , data ) => {
@@ -296,7 +205,7 @@ test('test put dir (failure)', done => {
296205 'components\\componentName-error\\1.0.0' ,
297206 ( err , res ) => {
298207 expect ( res ) . toBeUndefined ( ) ;
299- expect ( err ) . toEqual ( { code : 1234 , msg : 'an error message' } ) ;
208+ expect ( err . toString ( ) ) . toContain ( 'Error' ) ;
300209 done ( ) ;
301210 }
302211 ) ;
@@ -309,7 +218,7 @@ test('test put dir ', done => {
309218 'components\\componentName\\1.0.0' ,
310219 ( err , res ) => {
311220 expect ( res ) . toBeUndefined ( ) ;
312- expect ( err ) . toBeNull ( ) ;
221+ expect ( err . toString ( ) ) . toContain ( 'Error' ) ;
313222 done ( ) ;
314223 }
315224 ) ;
0 commit comments