11import fs from 'fs' ;
22import * as path from 'path' ;
33import * as utils from '../src/utils' ;
4+ import * as fetchModule from '../src/fetch' ;
45
56/**
67 * Mock @actions/core
@@ -12,15 +13,6 @@ jest.mock('@actions/core', () => ({
1213 info : jest . fn ( )
1314} ) ) ;
1415
15- /**
16- * Mock fetch.ts
17- */
18- jest . mock ( '../src/fetch' , ( ) => ( {
19- fetch : jest . fn ( ) . mockImplementation ( ( ) => {
20- return { data : '{ "latest": "8.1", "5.x": "5.6" }' } ;
21- } )
22- } ) ) ;
23-
2416describe ( 'Utils tests' , ( ) => {
2517 it ( 'checking readEnv' , async ( ) => {
2618 process . env [ 'test' ] = 'setup-php' ;
@@ -43,15 +35,27 @@ describe('Utils tests', () => {
4335 } ) ;
4436
4537 it ( 'checking getManifestURL' , async ( ) => {
46- expect ( await utils . getManifestURL ( ) ) . toContain ( 'php-versions.json' ) ;
38+ for ( const url of await utils . getManifestURLS ( ) ) {
39+ expect ( url ) . toContain ( 'php-versions.json' ) ;
40+ }
4741 } ) ;
4842
4943 it ( 'checking parseVersion' , async ( ) => {
44+ const fetchSpy = jest
45+ . spyOn ( fetchModule , 'fetch' )
46+ . mockResolvedValue ( { data : '{ "latest": "8.1", "5.x": "5.6" }' } ) ;
5047 expect ( await utils . parseVersion ( 'latest' ) ) . toBe ( '8.1' ) ;
5148 expect ( await utils . parseVersion ( '7' ) ) . toBe ( '7.0' ) ;
5249 expect ( await utils . parseVersion ( '7.4' ) ) . toBe ( '7.4' ) ;
5350 expect ( await utils . parseVersion ( '5.x' ) ) . toBe ( '5.6' ) ;
5451 expect ( await utils . parseVersion ( '4.x' ) ) . toBe ( undefined ) ;
52+
53+ fetchSpy . mockReset ( ) ;
54+ fetchSpy . mockResolvedValueOnce ( { } ) . mockResolvedValueOnce ( { } ) ;
55+ await expect ( utils . parseVersion ( 'latest' ) ) . rejects . toThrow (
56+ 'Could not fetch the PHP version manifest.'
57+ ) ;
58+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 2 ) ;
5559 } ) ;
5660
5761 it ( 'checking parseIniFile' , async ( ) => {
0 commit comments