@@ -4,12 +4,13 @@ const mock = require("mock-require");
44const logger = require ( "@ui5/logger" ) ;
55const Configuration = require ( "../../../lib/specifications/Configuration" ) ;
66const Project = require ( "../../../lib/specifications/Project" ) ;
7- // const Extension = require("../../../lib/specifications/Extension");
7+ const Extension = require ( "../../../lib/specifications/Extension" ) ;
88
99function createProject ( name ) {
1010 const basicConfiguration = new Configuration ( {
1111 specVersion : "2.3" ,
1212 kind : "project" ,
13+ type : "application" ,
1314 metadata : { name}
1415 } ) ;
1516
@@ -20,6 +21,21 @@ function createProject(name) {
2021 configuration : basicConfiguration
2122 } ) ;
2223}
24+ function createExtension ( name ) {
25+ const basicConfiguration = new Configuration ( {
26+ specVersion : "2.3" ,
27+ kind : "extension" ,
28+ type : "task" ,
29+ metadata : { name}
30+ } ) ;
31+
32+ return new Extension ( {
33+ id : "application.a.id" ,
34+ version : "1.0.0" ,
35+ modulePath : "some path" ,
36+ configuration : basicConfiguration
37+ } ) ;
38+ }
2339
2440function traverseBreadthFirst ( ...args ) {
2541 return _traverse ( ...args , true ) ;
@@ -71,22 +87,15 @@ test("Instantiate a basic project graph", async (t) => {
7187 const { ProjectGraph} = t . context ;
7288 t . notThrows ( ( ) => {
7389 new ProjectGraph ( {
74- rootProjectName : "my root project" ,
75- extensions : [
76- "some extension"
77- ]
90+ rootProjectName : "my root project"
7891 } ) ;
7992 } , "Should not throw" ) ;
8093} ) ;
8194
8295test ( "Instantiate a basic project with missing parameter rootProjectName" , async ( t ) => {
8396 const { ProjectGraph} = t . context ;
8497 const error = t . throws ( ( ) => {
85- new ProjectGraph ( {
86- extensions : [
87- "some extension"
88- ]
89- } ) ;
98+ new ProjectGraph ( { } ) ;
9099 } ) ;
91100 t . is ( error . message , "Could not create ProjectGraph: Missing or empty parameter 'rootProjectName'" ,
92101 "Should throw with expected error message" ) ;
@@ -141,7 +150,7 @@ test("addProject: Add duplicate", async (t) => {
141150 graph . addProject ( project2 ) ;
142151 } ) ;
143152 t . is ( error . message ,
144- "Failed to add project application.a to the graph: A project with that name has already been added" ,
153+ "Failed to add project application.a to graph: A project with that name has already been added" ,
145154 "Should throw with expected error message" ) ;
146155
147156 const res = graph . getProject ( "application.a" ) ;
@@ -189,6 +198,61 @@ test("getProject: Project is not in graph", async (t) => {
189198 t . is ( res , undefined , "Should return undefined" ) ;
190199} ) ;
191200
201+ test ( "add-/getExtension" , async ( t ) => {
202+ const { ProjectGraph} = t . context ;
203+ const graph = new ProjectGraph ( {
204+ rootProjectName : "my root project"
205+ } ) ;
206+ const extension = createExtension ( "extension.a" ) ;
207+ graph . addExtension ( extension ) ;
208+ const res = graph . getExtension ( "extension.a" ) ;
209+ t . is ( res , extension , "Should return correct extension" ) ;
210+ } ) ;
211+
212+ test ( "addExtension: Add duplicate" , async ( t ) => {
213+ const { ProjectGraph} = t . context ;
214+ const graph = new ProjectGraph ( {
215+ rootProjectName : "my root project"
216+ } ) ;
217+ const extension1 = createExtension ( "extension.a" ) ;
218+ graph . addExtension ( extension1 ) ;
219+
220+ const extension2 = createExtension ( "extension.a" ) ;
221+ const error = t . throws ( ( ) => {
222+ graph . addExtension ( extension2 ) ;
223+ } ) ;
224+ t . is ( error . message ,
225+ "Failed to add extension extension.a to graph: An extension with that name has already been added" ,
226+ "Should throw with expected error message" ) ;
227+
228+ const res = graph . getExtension ( "extension.a" ) ;
229+ t . is ( res , extension1 , "Should return correct extension" ) ;
230+ } ) ;
231+
232+ test ( "addExtension: Add extension with integer-like name" , async ( t ) => {
233+ const { ProjectGraph} = t . context ;
234+ const graph = new ProjectGraph ( {
235+ rootProjectName : "my root project"
236+ } ) ;
237+ const extension = createExtension ( "1337" ) ;
238+
239+ const error = t . throws ( ( ) => {
240+ graph . addExtension ( extension ) ;
241+ } ) ;
242+ t . is ( error . message ,
243+ "Failed to add extension 1337 to graph: Extension name must not be integer-like" ,
244+ "Should throw with expected error message" ) ;
245+ } ) ;
246+
247+ test ( "getExtension: Project is not in graph" , async ( t ) => {
248+ const { ProjectGraph} = t . context ;
249+ const graph = new ProjectGraph ( {
250+ rootProjectName : "my root project"
251+ } ) ;
252+ const res = graph . getExtension ( "extension.a" ) ;
253+ t . is ( res , undefined , "Should return undefined" ) ;
254+ } ) ;
255+
192256test ( "declareDependency / getDependencies" , async ( t ) => {
193257 const { ProjectGraph} = t . context ;
194258 const graph = new ProjectGraph ( {
0 commit comments