@@ -7,23 +7,41 @@ import * as taskRepository from "@ui5/builder/internal/taskRepository";
77import { graphFromPackageDependencies } from "../../../lib/graph/graph.js" ;
88
99test . beforeEach ( ( t ) => {
10- t . context . sinon = sinonGlobal . createSandbox ( ) ;
10+ const sinon = t . context . sinon = sinonGlobal . createSandbox ( ) ;
11+
12+ t . context . logEventStub = sinon . stub ( ) ;
13+ t . context . buildMetadataEventStub = sinon . stub ( ) ;
14+ t . context . projectBuildMetadataEventStub = sinon . stub ( ) ;
15+ t . context . buildStatusEventStub = sinon . stub ( ) ;
16+ t . context . projectBuildStatusEventStub = sinon . stub ( ) ;
17+
18+ process . on ( "ui5.log" , t . context . logEventStub ) ;
19+ process . on ( "ui5.build-metadata" , t . context . buildMetadataEventStub ) ;
20+ process . on ( "ui5.project-build-metadata" , t . context . projectBuildMetadataEventStub ) ;
21+ process . on ( "ui5.build-status" , t . context . buildStatusEventStub ) ;
22+ process . on ( "ui5.project-build-status" , t . context . projectBuildStatusEventStub ) ;
1123} ) ;
1224
1325test . afterEach . always ( ( t ) => {
1426 t . context . sinon . restore ( ) ;
1527 delete process . env . UI5_DATA_DIR ;
28+
29+ process . off ( "ui5.log" , t . context . logEventStub ) ;
30+ process . off ( "ui5.build-metadata" , t . context . buildMetadataEventStub ) ;
31+ process . off ( "ui5.project-build-metadata" , t . context . projectBuildMetadataEventStub ) ;
32+ process . off ( "ui5.build-status" , t . context . buildStatusEventStub ) ;
33+ process . off ( "ui5.project-build-status" , t . context . projectBuildStatusEventStub ) ;
1634} ) ;
1735
1836test . serial ( "Build application project multiple times" , async ( t ) => {
1937 const fixtureTester = new FixtureTester ( t , "application.a" ) ;
2038
21- let projectBuilder ;
39+ let projectBuilder ; let buildStatusEventArgs ;
2240 const destPath = fixtureTester . destPath ;
2341
2442 // #1 build (with empty cache)
2543 projectBuilder = await fixtureTester . createProjectBuilder ( ) ;
26- await projectBuilder . build ( { destPath} ) ;
44+ await projectBuilder . build ( { destPath, cleanDest : false /* No clean dest needed for build #1 */ } ) ;
2745
2846 t . is ( projectBuilder . _buildProject . callCount , 1 ) ;
2947 t . is (
@@ -32,9 +50,15 @@ test.serial("Build application project multiple times", async (t) => {
3250 "application.a built in build #1"
3351 ) ;
3452
53+ buildStatusEventArgs = t . context . projectBuildStatusEventStub . args . map ( ( args ) => args [ 0 ] ) ;
54+ t . deepEqual (
55+ buildStatusEventArgs . filter ( ( { status} ) => status === "task-skip" ) , [ ] ,
56+ "No 'task-skip' status in build #1"
57+ ) ;
58+
3559 // #2 build (with cache, no changes)
3660 projectBuilder = await fixtureTester . createProjectBuilder ( ) ;
37- await projectBuilder . build ( { destPath} ) ;
61+ await projectBuilder . build ( { destPath, cleanDest : true } ) ;
3862
3963 t . is ( projectBuilder . _buildProject . callCount , 0 , "No projects built in build #2" ) ;
4064
@@ -44,7 +68,7 @@ test.serial("Build application project multiple times", async (t) => {
4468
4569 // #3 build (with cache, with changes)
4670 projectBuilder = await fixtureTester . createProjectBuilder ( ) ;
47- await projectBuilder . build ( { destPath} ) ;
71+ await projectBuilder . build ( { destPath, cleanDest : true } ) ;
4872
4973 t . is ( projectBuilder . _buildProject . callCount , 1 ) ;
5074 t . is (
@@ -53,9 +77,50 @@ test.serial("Build application project multiple times", async (t) => {
5377 "application.a rebuilt in build #3"
5478 ) ;
5579
56- // #4 build (with cache, no changes)
80+ buildStatusEventArgs = t . context . projectBuildStatusEventStub . args . map ( ( args ) => args [ 0 ] ) ;
81+ t . deepEqual (
82+ buildStatusEventArgs . filter ( ( { status} ) => status === "task-skip" ) , [
83+ {
84+ level : "info" ,
85+ projectName : "application.a" ,
86+ projectType : "application" ,
87+ status : "task-skip" ,
88+ taskName : "escapeNonAsciiCharacters" ,
89+ } ,
90+ // Note: replaceCopyright task is expected to be skipped as the project
91+ // does not define a copyright in its ui5.yaml.
92+ {
93+ level : "info" ,
94+ projectName : "application.a" ,
95+ projectType : "application" ,
96+ status : "task-skip" ,
97+ taskName : "replaceCopyright" ,
98+ } ,
99+ {
100+ level : "info" ,
101+ projectName : "application.a" ,
102+ projectType : "application" ,
103+ status : "task-skip" ,
104+ taskName : "enhanceManifest" ,
105+ } ,
106+ {
107+ level : "info" ,
108+ projectName : "application.a" ,
109+ projectType : "application" ,
110+ status : "task-skip" ,
111+ taskName : "generateFlexChangesBundle" ,
112+ } ,
113+ ] ,
114+ "'task-skip' status in build #3 for tasks that did not need to be re-executed based on changed test.js file"
115+ ) ;
116+
117+ // Check whether the changed file is in the destPath
118+ const builtFileContent = await fs . readFile ( `${ destPath } /test.js` , { encoding : "utf8" } ) ;
119+ t . true ( builtFileContent . includes ( `test("line added");` ) , "Build dest contains changed file content" ) ;
120+
121+ // // #4 build (with cache, no changes)
57122 projectBuilder = await fixtureTester . createProjectBuilder ( ) ;
58- await projectBuilder . build ( { destPath} ) ;
123+ await projectBuilder . build ( { destPath, cleanDest : true } ) ;
59124
60125 t . is ( projectBuilder . _buildProject . callCount , 0 , "No projects built in build #4" ) ;
61126} ) ;
@@ -90,6 +155,7 @@ class FixtureTester {
90155
91156 async createProjectBuilder ( ) {
92157 await this . _initialize ( ) ;
158+ this . _sinon . resetHistory ( ) ; // Reset history of spies/stubs from previous builds (e.g. process event handlers)
93159 const graph = await graphFromPackageDependencies ( {
94160 cwd : this . fixturePath
95161 } ) ;
0 commit comments