@@ -8,6 +8,7 @@ import { resolveLicenseContent } from "../../../src/lib/internal/resolveLicenseC
8
8
import { when } from "jest-when" ;
9
9
import { doesFileExist , readFile } from "../../../src/lib/utils/file.utils" ;
10
10
import { PackageJson } from "../../../src/lib/utils/packageJson.utils" ;
11
+ import logger from "../../../src/lib/utils/console.utils" ;
11
12
import { join } from "path" ;
12
13
import { Dependency , LicenseContent } from "../../../src/lib/internal/resolveLicenses" ;
13
14
@@ -17,6 +18,7 @@ jest.mock("../../../src/lib/utils/pnpmCli.utils", () => ({
17
18
} ) ) ;
18
19
19
20
jest . mock ( "../../../src/lib/utils/file.utils" ) ;
21
+ jest . mock ( "../../../src/lib/utils/console.utils" ) ;
20
22
21
23
jest . mock ( "../../../src/lib/internal/resolveLicenseContent" , ( ) => ( {
22
24
resolveLicenseContent : jest . fn ( ) ,
@@ -39,8 +41,8 @@ describe("resolveDependenciesForPnpmProject", () => {
39
41
name : "dependency3" ,
40
42
paths : [ "/some/path/dependency3" ] ,
41
43
} ;
42
- const dependency3LicenseContent = null as unknown as string ;
43
44
45
+ const mockedLogger = jest . mocked ( logger ) ;
44
46
const mockedReadFile = jest . mocked ( readFile ) ;
45
47
const mockedDoesFileExist = jest . mocked ( doesFileExist ) ;
46
48
const mockedGetPnpmVersion = jest . mocked ( getPnpmVersion ) ;
@@ -67,7 +69,9 @@ describe("resolveDependenciesForPnpmProject", () => {
67
69
68
70
when ( mockedResolveLicenseContent )
69
71
. calledWith ( dependency3 . paths [ 0 ] , expect . anything ( ) , expect . anything ( ) )
70
- . mockResolvedValue ( dependency3LicenseContent ) ;
72
+ . mockImplementation ( ( ) => {
73
+ throw new Error ( "Cannot find license content" ) ;
74
+ } ) ;
71
75
setUpPackageJson ( dependency3 . paths [ 0 ] , { name : dependency3 . name , version : "1.0.0" } ) ;
72
76
} ) ;
73
77
@@ -198,9 +202,28 @@ describe("resolveDependenciesForPnpmProject", () => {
198
202
. get ( dependency2LicenseContent )
199
203
?. find ( d => d . name === "dependency2" && d . version === "2.0.0" ) ,
200
204
) . toBeDefined ( ) ;
201
- expect ( licensesMap . get ( dependency3LicenseContent ) ) . toBeUndefined ( ) ;
202
205
} ) ;
203
206
207
+ it . each ( [ new Error ( "Something went wrong" ) , "Something went wrong" ] ) (
208
+ "should warning log if resolveLicenseContent throws an error" ,
209
+ async error => {
210
+ mockedGetPnpmVersion . mockResolvedValue ( pnpmVersion ) ;
211
+ mockedGetPnpmProjectDependencies . mockResolvedValue ( [ dependency1 , dependency2 , dependency3 ] ) ;
212
+
213
+ when ( mockedResolveLicenseContent )
214
+ . calledWith ( dependency1 . paths [ 0 ] , expect . anything ( ) , expect . anything ( ) )
215
+ . mockRejectedValue ( error ) ;
216
+
217
+ const licensesMap = new Map < LicenseContent , Dependency [ ] > ( ) ;
218
+
219
+ await resolveDependenciesForPnpmProject ( "/some/path/package.json" , licensesMap ) ;
220
+
221
+ expect ( mockedLogger . warn ) . toHaveBeenCalledWith (
222
+ `Unable to determine license content for ${ dependency1 . name } @1.0.0 with error:\nSomething went wrong\n` ,
223
+ ) ;
224
+ } ,
225
+ ) ;
226
+
204
227
describe ( "when the dependency is in the exclude list" , ( ) => {
205
228
it ( "should not call resolveLicenseContent" , async ( ) => {
206
229
mockedGetPnpmVersion . mockResolvedValue ( pnpmVersion ) ;
0 commit comments