@@ -10,15 +10,14 @@ import {
1010} from '../packages/gcs/src' ;
1111import { authRequest , deepClone , metafile , storageOptions , testfile } from './shared' ;
1212
13- const mockFetch = jest . fn ( ) ;
14- global . fetch = mockFetch ;
15-
1613const mockAuthRequest = jest . fn ( ) ;
1714jest . mock ( 'google-auth-library' , ( ) => ( {
1815 GoogleAuth : jest . fn ( ( ) => ( { request : mockAuthRequest } ) )
1916} ) ) ;
2017
2118describe ( 'GCStorage' , ( ) => {
19+ const mockFetch = jest . fn ( ) ;
20+ const originalFetch = global . fetch ;
2221 jest . useFakeTimers ( ) . setSystemTime ( new Date ( '2022-02-02' ) ) ;
2322 let storage : GCStorage ;
2423 const uri = 'http://api.com?upload_id=123456789' ;
@@ -30,10 +29,16 @@ describe('GCStorage', () => {
3029
3130 beforeEach ( async ( ) => {
3231 jest . clearAllMocks ( ) ;
32+ global . fetch = mockFetch ;
3333 mockAuthRequest . mockResolvedValueOnce ( { bucket : 'ok' } ) ;
3434 storage = new GCStorage ( { ...storageOptions , bucket : 'test-bucket' } ) ;
3535 } ) ;
3636
37+ afterAll ( ( ) => {
38+ jest . useRealTimers ( ) ;
39+ global . fetch = originalFetch ;
40+ } ) ;
41+
3742 describe ( 'initialization' , ( ) => {
3843 it ( 'should set defaults' , ( ) => {
3944 mockAuthRequest . mockResolvedValueOnce ( { bucket : 'ok' } ) ;
@@ -46,9 +51,7 @@ describe('GCStorage', () => {
4651 describe ( '.create()' , ( ) => {
4752 it ( 'should request api and set status and uri' , async ( ) => {
4853 mockAuthRequest . mockRejectedValueOnce ( { code : 404 , detail : 'meta not found' } ) ; // getMeta
49- mockAuthRequest . mockResolvedValueOnce ( {
50- headers : new Headers ( { location : uri } )
51- } ) ; //
54+ mockAuthRequest . mockResolvedValueOnce ( { headers : new Headers ( { location : uri } ) } ) ;
5255 mockAuthRequest . mockResolvedValueOnce ( '_saveOk' ) ;
5356 const gcsFile = await storage . create ( req , metafile ) ;
5457 expect ( gcsFile ) . toMatchSnapshot ( ) ;
0 commit comments