@@ -1886,17 +1886,26 @@ describe('modules/platform/azure/index', () => {
18861886 it ( 'returns file content' , async ( ) => {
18871887 const data = { foo : 'bar' } ;
18881888 azureApi . gitApi . mockImplementationOnce (
1889- ( ) =>
1890- ( {
1891- getItemContent : jest . fn ( ( ) =>
1892- Promise . resolve ( Readable . from ( JSON . stringify ( data ) ) ) ,
1893- ) ,
1894- } ) as any ,
1889+ jest . fn ( ) . mockImplementationOnce ( ( ) => ( {
1890+ getItem : jest . fn ( ( ) =>
1891+ Promise . resolve ( { content : JSON . stringify ( data ) } ) ,
1892+ ) ,
1893+ } ) ) ,
18951894 ) ;
18961895 const res = await azure . getJsonFile ( 'file.json' ) ;
18971896 expect ( res ) . toEqual ( data ) ;
18981897 } ) ;
18991898
1899+ it ( 'returns null when file not found' , async ( ) => {
1900+ azureApi . gitApi . mockImplementationOnce (
1901+ jest . fn ( ) . mockImplementationOnce ( ( ) => ( {
1902+ getItem : jest . fn ( ( ) => Promise . resolve ( null ) ) ,
1903+ } ) ) ,
1904+ ) ;
1905+ const res = await azure . getJsonFile ( 'file.json' ) ;
1906+ expect ( res ) . toBeNull ( ) ;
1907+ } ) ;
1908+
19001909 it ( 'returns file content in json5 format' , async ( ) => {
19011910 const json5Data = `
19021911 {
@@ -1905,71 +1914,65 @@ describe('modules/platform/azure/index', () => {
19051914 }
19061915 ` ;
19071916 azureApi . gitApi . mockImplementationOnce (
1908- ( ) =>
1909- ( {
1910- getItemContent : jest . fn ( ( ) =>
1911- Promise . resolve ( Readable . from ( json5Data ) ) ,
1912- ) ,
1913- } ) as any ,
1917+ jest . fn ( ) . mockImplementationOnce ( ( ) => ( {
1918+ getItem : jest . fn ( ( ) => Promise . resolve ( { content : json5Data } ) ) ,
1919+ } ) ) ,
19141920 ) ;
19151921 const res = await azure . getJsonFile ( 'file.json5' ) ;
19161922 expect ( res ) . toEqual ( { foo : 'bar' } ) ;
19171923 } ) ;
19181924
19191925 it ( 'returns file content from branch or tag' , async ( ) => {
19201926 const data = { foo : 'bar' } ;
1921- azureApi . gitApi . mockImplementationOnce (
1922- ( ) =>
1923- ( {
1924- getItemContent : jest . fn ( ( ) =>
1925- Promise . resolve ( Readable . from ( JSON . stringify ( data ) ) ) ,
1926- ) ,
1927- } ) as any ,
1927+ azureApi . gitApi . mockResolvedValueOnce (
1928+ partial < IGitApi > ( {
1929+ getItem : jest . fn ( ( ) =>
1930+ Promise . resolve ( { content : JSON . stringify ( data ) } ) ,
1931+ ) ,
1932+ } ) ,
19281933 ) ;
19291934 const res = await azure . getJsonFile ( 'file.json' , undefined , 'dev' ) ;
19301935 expect ( res ) . toEqual ( data ) ;
19311936 } ) ;
19321937
19331938 it ( 'throws on malformed JSON' , async ( ) => {
1934- azureApi . gitApi . mockImplementationOnce (
1935- ( ) =>
1936- ( {
1937- getItemContent : jest . fn ( ( ) =>
1938- Promise . resolve ( Readable . from ( '!@#' ) ) ,
1939- ) ,
1940- } ) as any ,
1939+ azureApi . gitApi . mockResolvedValueOnce (
1940+ partial < IGitApi > ( {
1941+ getItemContent : jest . fn ( ( ) => Promise . resolve ( Readable . from ( '!@#' ) ) ) ,
1942+ } ) ,
19411943 ) ;
19421944 await expect ( azure . getJsonFile ( 'file.json' ) ) . rejects . toThrow ( ) ;
19431945 } ) ;
19441946
19451947 it ( 'throws on errors' , async ( ) => {
1946- azureApi . gitApi . mockImplementationOnce (
1947- ( ) =>
1948- ( {
1949- getItemContent : jest . fn ( ( ) => {
1950- throw new Error ( 'some error' ) ;
1951- } ) ,
1952- } ) as any ,
1948+ azureApi . gitApi . mockResolvedValueOnce (
1949+ partial < IGitApi > ( {
1950+ getItemContent : jest . fn ( ( ) => {
1951+ throw new Error ( 'some error' ) ;
1952+ } ) ,
1953+ } ) ,
19531954 ) ;
19541955 await expect ( azure . getJsonFile ( 'file.json' ) ) . rejects . toThrow ( ) ;
19551956 } ) ;
19561957
19571958 it ( 'supports fetch from another repo' , async ( ) => {
19581959 const data = { foo : 'bar' } ;
1959- const gitApiMock = {
1960- getItemContent : jest . fn ( ( ) =>
1961- Promise . resolve ( Readable . from ( JSON . stringify ( data ) ) ) ,
1962- ) ,
1963- getRepositories : jest . fn ( ( ) =>
1964- Promise . resolve ( [
1965- { id : '123456' , name : 'bar' , project : { name : 'foo' } } ,
1966- ] ) ,
1967- ) ,
1968- } ;
1969- azureApi . gitApi . mockImplementationOnce ( ( ) => gitApiMock as any ) ;
1960+ const getItemFn = jest
1961+ . fn ( )
1962+ . mockResolvedValueOnce ( { content : JSON . stringify ( data ) } ) ;
1963+ azureApi . gitApi . mockResolvedValueOnce (
1964+ partial < IGitApi > ( {
1965+ getItem : getItemFn ,
1966+ getRepositories : jest
1967+ . fn ( )
1968+ . mockResolvedValue ( [
1969+ { id : '123456' , name : 'bar' , project : { name : 'foo' } } ,
1970+ ] ) ,
1971+ } ) ,
1972+ ) ;
19701973 const res = await azure . getJsonFile ( 'file.json' , 'foo/bar' ) ;
19711974 expect ( res ) . toEqual ( data ) ;
1972- expect ( gitApiMock . getItemContent . mock . calls ) . toMatchSnapshot ( ) ;
1975+ expect ( getItemFn . mock . calls ) . toMatchSnapshot ( ) ;
19731976 } ) ;
19741977
19751978 it ( 'returns null' , async ( ) => {
0 commit comments