@@ -1493,7 +1493,7 @@ describe("TaskManagerImplementation", () => {
1493
1493
) ;
1494
1494
} ) ;
1495
1495
1496
- it ( "should throw if an action url is provided and the module can't be resolved" , async ( ) => {
1496
+ it ( "should throw if an action url is provided but the corresponding module can't be resolved" , async ( ) => {
1497
1497
const hre = await createHardhatRuntimeEnvironment ( {
1498
1498
plugins : [
1499
1499
{
@@ -1520,7 +1520,70 @@ describe("TaskManagerImplementation", () => {
1520
1520
) ;
1521
1521
} ) ;
1522
1522
1523
- it ( "should throw if an action url is provided and the module doesn't have a default export" , async ( ) => {
1523
+ /**
1524
+ * There are multiple scenarios where detectPluginNpmDependencyProblems
1525
+ * can throw an error. We're not trying to test all of them, just verify
1526
+ * that the logic is being called and that the error is being thrown.
1527
+ */
1528
+ it ( "should throw if an action url is provided but the corresponding module can't be resolved due to a missing package" , async ( ) => {
1529
+ const nonInstalledPackageActionUrl = import . meta. resolve (
1530
+ "./fixture-projects/not-installed-package/index.js" ,
1531
+ ) ;
1532
+
1533
+ // the missing dependency is used in the NEW_TASK action
1534
+ let hre = await createHardhatRuntimeEnvironment ( {
1535
+ plugins : [
1536
+ {
1537
+ id : "plugin1" ,
1538
+ npmPackage : "non-installed-package" ,
1539
+ tasks : [
1540
+ new NewTaskDefinitionBuilderImplementation ( "task1" )
1541
+ . setAction ( nonInstalledPackageActionUrl )
1542
+ . build ( ) ,
1543
+ ] ,
1544
+ } ,
1545
+ ] ,
1546
+ } ) ;
1547
+
1548
+ await assert . rejects (
1549
+ hre . tasks . getTask ( "task1" ) . run ( { } ) ,
1550
+ new HardhatError ( HardhatError . ERRORS . PLUGINS . PLUGIN_NOT_INSTALLED , {
1551
+ pluginId : "plugin1" ,
1552
+ } ) ,
1553
+ ) ;
1554
+
1555
+ // the missing dependency is used in the TASK_OVERRIDE action
1556
+ hre = await createHardhatRuntimeEnvironment ( {
1557
+ plugins : [
1558
+ {
1559
+ id : "plugin1" ,
1560
+ tasks : [
1561
+ new NewTaskDefinitionBuilderImplementation ( "task1" )
1562
+ . setAction ( ( ) => { } )
1563
+ . build ( ) ,
1564
+ ] ,
1565
+ } ,
1566
+ {
1567
+ id : "plugin2" ,
1568
+ npmPackage : "non-installed-package" ,
1569
+ tasks : [
1570
+ new TaskOverrideDefinitionBuilderImplementation ( "task1" )
1571
+ . setAction ( nonInstalledPackageActionUrl )
1572
+ . build ( ) ,
1573
+ ] ,
1574
+ } ,
1575
+ ] ,
1576
+ } ) ;
1577
+
1578
+ await assert . rejects (
1579
+ hre . tasks . getTask ( "task1" ) . run ( { } ) ,
1580
+ new HardhatError ( HardhatError . ERRORS . PLUGINS . PLUGIN_NOT_INSTALLED , {
1581
+ pluginId : "plugin2" ,
1582
+ } ) ,
1583
+ ) ;
1584
+ } ) ;
1585
+
1586
+ it ( "should throw if an action url is provided and the corresponding module doesn't have a default export" , async ( ) => {
1524
1587
const actionUrl = import . meta. resolve (
1525
1588
"./fixture-projects/file-actions/no-default.js" ,
1526
1589
) ;
@@ -1551,7 +1614,7 @@ describe("TaskManagerImplementation", () => {
1551
1614
) ;
1552
1615
} ) ;
1553
1616
1554
- it ( "should throw if an action url is provided and the module default export is not a function" , async ( ) => {
1617
+ it ( "should throw if an action url is provided and the corresponding module default export is not a function" , async ( ) => {
1555
1618
const actionUrl = import . meta. resolve (
1556
1619
"./fixture-projects/file-actions/no-default-fn.js" ,
1557
1620
) ;
0 commit comments