@@ -5,13 +5,104 @@ import { HardhatError } from "@nomicfoundation/hardhat-errors";
5
5
6
6
import { RESERVED_PARAMETER_NAMES } from "../../../src/internal/parameters.js" ;
7
7
import {
8
+ EmptyTaskDefinitionBuilderImplementation ,
8
9
NewTaskDefinitionBuilderImplementation ,
9
10
TaskOverrideDefinitionBuilderImplementation ,
10
11
} from "../../../src/internal/tasks/builders.js" ;
11
12
import { ParameterType } from "../../../src/types/common.js" ;
12
13
import { TaskDefinitionType } from "../../../src/types/tasks.js" ;
13
14
14
15
describe ( "Task builders" , ( ) => {
16
+ describe ( "EmptyTaskDefinitionBuilderImplementation" , ( ) => {
17
+ it ( "should create an empty task definition builder" , ( ) => {
18
+ const builder = new EmptyTaskDefinitionBuilderImplementation ( "task-id" ) ;
19
+ const taskDefinition = builder . build ( ) ;
20
+
21
+ assert . deepEqual ( taskDefinition , {
22
+ type : TaskDefinitionType . EMPTY_TASK ,
23
+ id : [ "task-id" ] ,
24
+ description : "" ,
25
+ } ) ;
26
+ } ) ;
27
+
28
+ it ( "should create an empty task definition builder with an array of ids" , ( ) => {
29
+ const ids = [ "task-id" , "subtask-id" , "sub-subtask-id" ] ;
30
+ const builder = new EmptyTaskDefinitionBuilderImplementation ( ids ) ;
31
+ const taskDefinition = builder . build ( ) ;
32
+
33
+ assert . deepEqual ( taskDefinition , {
34
+ type : TaskDefinitionType . EMPTY_TASK ,
35
+ id : ids ,
36
+ description : "" ,
37
+ } ) ;
38
+ } ) ;
39
+
40
+ describe ( "Task id validation" , ( ) => {
41
+ it ( "should throw if the id is an empty string" , ( ) => {
42
+ assert . throws ( ( ) => new EmptyTaskDefinitionBuilderImplementation ( "" ) , {
43
+ name : "HardhatError" ,
44
+ message :
45
+ "HHE208: Task id cannot be an empty string or an empty array" ,
46
+ } ) ;
47
+ } ) ;
48
+
49
+ it ( "should throw if the array of ids is empty" , ( ) => {
50
+ const ids : string [ ] = [ ] ;
51
+
52
+ assert . throws ( ( ) => new EmptyTaskDefinitionBuilderImplementation ( ids ) , {
53
+ name : "HardhatError" ,
54
+ message :
55
+ "HHE208: Task id cannot be an empty string or an empty array" ,
56
+ } ) ;
57
+ } ) ;
58
+ } ) ;
59
+
60
+ describe ( "Adding a description" , ( ) => {
61
+ it ( "should create an empty task definition builder with a description in the constructor" , ( ) => {
62
+ const builder = new EmptyTaskDefinitionBuilderImplementation (
63
+ "task-id" ,
64
+ "Task description" ,
65
+ ) ;
66
+ const taskDefinition = builder . build ( ) ;
67
+
68
+ assert . deepEqual ( taskDefinition , {
69
+ type : TaskDefinitionType . EMPTY_TASK ,
70
+ id : [ "task-id" ] ,
71
+ description : "Task description" ,
72
+ } ) ;
73
+ } ) ;
74
+
75
+ it ( "should set the task description" , ( ) => {
76
+ const builder = new EmptyTaskDefinitionBuilderImplementation ( "task-id" ) ;
77
+ const taskDefinition = builder
78
+ . setDescription ( "Task description" )
79
+ . build ( ) ;
80
+
81
+ assert . deepEqual ( taskDefinition , {
82
+ type : TaskDefinitionType . EMPTY_TASK ,
83
+ id : [ "task-id" ] ,
84
+ description : "Task description" ,
85
+ } ) ;
86
+ } ) ;
87
+
88
+ it ( "should override the description set in the constructor" , ( ) => {
89
+ const builder = new EmptyTaskDefinitionBuilderImplementation (
90
+ "task-id" ,
91
+ "Task description" ,
92
+ ) ;
93
+ const taskDefinition = builder
94
+ . setDescription ( "New task description" )
95
+ . build ( ) ;
96
+
97
+ assert . deepEqual ( taskDefinition , {
98
+ type : TaskDefinitionType . EMPTY_TASK ,
99
+ id : [ "task-id" ] ,
100
+ description : "New task description" ,
101
+ } ) ;
102
+ } ) ;
103
+ } ) ;
104
+ } ) ;
105
+
15
106
describe ( "NewTaskDefinitionBuilderImplementation" , ( ) => {
16
107
it ( "should create a new task definition builder" , ( ) => {
17
108
const builder = new NewTaskDefinitionBuilderImplementation ( "task-id" ) ;
0 commit comments