@@ -2,13 +2,15 @@ import assert from "node:assert/strict";
22import { describe , it } from "node:test" ;
33import path from "node:path" ;
44import fs from "node:fs" ;
5+ import { createRequire } from "node:module" ;
56import fswin from "fswin" ;
67
78import {
89 determineModuleContext ,
910 findNodeApiModulePaths ,
1011 findNodeAddonForBindings ,
1112 findPackageDependencyPaths ,
13+ resolvePackageRoot ,
1214 getLibraryName ,
1315 isNodeApiModule ,
1416 stripExtension ,
@@ -355,6 +357,34 @@ describe("findPackageDependencyPaths", () => {
355357 } ) ;
356358} ) ;
357359
360+ describe ( "resolvePackageRoot" , ( ) => {
361+ it ( "logs the original package resolution error" , ( context ) => {
362+ const tempDir = setupTempDirectory ( context , {
363+ "node_modules/broken-package/package.json" : JSON . stringify ( {
364+ name : "broken-package" ,
365+ main : "missing.js" ,
366+ } ) ,
367+ } ) ;
368+ const requireFromRoot = createRequire ( path . join ( tempDir , "noop.js" ) ) ;
369+ const debug = context . mock . method ( console , "debug" , ( ) => { } ) ;
370+
371+ assert . equal (
372+ resolvePackageRoot ( requireFromRoot , "broken-package" ) ,
373+ undefined ,
374+ ) ;
375+ assert . equal ( debug . mock . callCount ( ) , 1 ) ;
376+
377+ const call = debug . mock . calls [ 0 ] ;
378+ assert ( call ) ;
379+ assert . equal ( call . arguments . length , 1 ) ;
380+ assert . equal ( typeof call . arguments [ 0 ] , "string" ) ;
381+ assert . match (
382+ String ( call . arguments [ 0 ] ) ,
383+ / F a i l e d t o r e s o l v e p a c k a g e r o o t f o r " b r o k e n - p a c k a g e " : C a n n o t f i n d m o d u l e .* b r o k e n - p a c k a g e [ \\ / ] m i s s i n g \. j s / ,
384+ ) ;
385+ } ) ;
386+ } ) ;
387+
358388describe ( "findNodeApiModulePaths" , ( ) => {
359389 it ( "should find .apple.node paths" , async ( context ) => {
360390 const tempDir = setupTempDirectory ( context , {
0 commit comments