@@ -35,22 +35,21 @@ class FixtureHelper {
3535 // Delete everything from the tmp/<projectname> folder except .ui5 & dist folders
3636 const entries = await fs . readdir ( this . tmpPath , { withFileTypes : true } ) ;
3737 for ( const entry of entries ) {
38- if ( entry . name === ".ui5" || entry . name === "dist" ) {
38+ if ( entry . name === ".ui5" || entry . name === "dist" || entry . name === "node_modules" ) {
3939 continue ;
4040 }
4141 const entryPath = path . resolve ( this . tmpPath , entry . name ) ;
4242 await fs . rm ( entryPath , { recursive : true , force : true } ) ;
4343 }
4444 // Copy source files to temp location
4545 await fs . cp ( this . originFixturePath , this . tmpPath , { recursive : true } ) ;
46- // Install node_modules
47- await this . _installNodeModules ( ) ;
4846 }
4947
50- async _installNodeModules ( ) {
48+ async build ( assert , ui5YamlName ) {
5149 await new Promise ( ( resolve , reject ) => {
52- execFile ( "npm " , [ "install" ] , { cwd : this . tmpPath } , ( error , stdout , stderr ) => {
50+ execFile ( "node " , [ ui5CliPath , "build" , "--config" , ui5YamlName , "--dest" , this . distPath ] , async ( error , stdout , stderr ) => {
5351 if ( error ) {
52+ assert . fail ( error ) ;
5453 reject ( error ) ;
5554 return ;
5655 }
@@ -59,11 +58,10 @@ class FixtureHelper {
5958 } ) ;
6059 }
6160
62- async build ( assert , ui5YamlName ) {
61+ async _installNodeModules ( ) {
6362 await new Promise ( ( resolve , reject ) => {
64- execFile ( "node " , [ ui5CliPath , "build" , "--config" , ui5YamlName , "--dest" , this . distPath ] , async ( error , stdout , stderr ) => {
63+ execFile ( "npm " , [ "install" ] , { cwd : this . tmpPath } , ( error , stdout , stderr ) => {
6564 if ( error ) {
66- assert . fail ( error ) ;
6765 reject ( error ) ;
6866 return ;
6967 }
@@ -162,17 +160,12 @@ describe("ui5 build", () => {
162160 process . chdir ( fixtureHelper . tmpPath ) ;
163161 const ui5YamlName = "ui5-tooling-modules.yaml" ;
164162
165- // #1 Build
163+ // #1 Build (no thirdparty module yet -> just checking that the build succeeds)
166164 await fixtureHelper . build ( assert , ui5YamlName ) ;
167165
168- // Test: the dist contains the expected preload with the correct content
169- const componentPreload = await fs . readFile ( path . resolve ( fixtureHelper . distPath , "Component-preload.js" ) , "utf-8" ) ;
170- assert . ok ( componentPreload . includes ( "sap.ui.predefine(\"application/a/controller/Test.controller\", [\"application/a/thirdparty/chart.js\"]" ) , "Component-preload.js should contain the 'Test' controller and its dependency" ) ;
171-
172-
173166 // --------------------------------------------------------------------------------------------
174167
175- // Add a new source file with another third party import
168+ // Add a new source file with a third party import
176169 await fixtureHelper . prepareForNextRun ( ) ;
177170 const newControllerPath = path . resolve ( fixtureHelper . tmpPath , "webapp/controller/New.controller.js" ) ;
178171 const newControllerContent =
@@ -188,9 +181,48 @@ describe("ui5 build", () => {
188181 // #2 Build
189182 await fixtureHelper . build ( assert , ui5YamlName ) ;
190183
191- // Test: the dist contains the new controller and the new import
184+ // Test: the dist contains the new controller and the third party import
192185 const newComponentPreload = await fs . readFile ( path . resolve ( fixtureHelper . distPath , "Component-preload.js" ) , "utf-8" ) ;
193- assert . ok ( newComponentPreload . includes ( "sap.ui.predefine(\"application/a/controller/Test.controller\", [\"application/a/thirdparty/chart.js\"]" ) , "Component-preload.js should contain the 'Test' controller and its dependency" ) ;
194- assert . ok ( newComponentPreload . includes ( "sap.ui.predefine(\"application/a/controller/New.controller\", [\"application/a/thirdparty/chart.js\"]" ) , "Component-preload.js should contain the 'New' controller and its dependency" ) ;
186+ assert . ok ( newComponentPreload . includes ( "sap.ui.predefine(\"application/a/controller/New.controller\", [\"application/a/thirdparty/chart.js\"]" ) , "Component-preload.js should contain the 'New' controller and chart.js" ) ;
187+ } ) ;
188+
189+ // FIXME: Currently failing
190+ test ( "ui5-tooling-stringreplace" , async ( { assert} ) => {
191+ const fixtureHelper = new FixtureHelper ( "application.a" ) ;
192+ await fixtureHelper . init ( ) ;
193+ process . env . UI5_DATA_DIR = `${ fixtureHelper . dotUi5Path } ` ;
194+ process . chdir ( fixtureHelper . tmpPath ) ;
195+ const ui5YamlName = "ui5-tooling-stringreplace.yaml" ;
196+
197+ // #1 Build (no string replacing yet -> just checking that the build succeeds)
198+ await fixtureHelper . build ( assert , ui5YamlName ) ;
199+
200+ // --------------------------------------------------------------------------------------------
201+
202+
203+ // Add a new source file with a placeholder string
204+ await fixtureHelper . prepareForNextRun ( ) ;
205+ const newControllerPath = path . resolve ( fixtureHelper . tmpPath , "webapp/controller/New.controller.js" ) ;
206+ const newControllerContent =
207+ `sap.ui.define([], () => {
208+ return Controller.extend("application.a.controller.New",{
209+ onInit() {
210+ console.log(\${PLACEHOLDER_TEXT});
211+ }
212+ });
213+ });` ;
214+ await fs . writeFile ( newControllerPath , newControllerContent , "utf-8" ) ;
215+
216+ // #2 Build
217+ // FIXME: Currently failing here (April 02 2026)
218+ // Error message:
219+ // ("Minification failed with error: Unexpected token punc «{», expected punc «,» in file /resources/application/a/controller/New.controller.js (line 4, col 16, pos 114)")
220+ //
221+ // -> Probably, the string replacement doesn't get executed as very first middleware (minify happens earlier unexpectedly)
222+ await fixtureHelper . build ( assert , ui5YamlName ) ;
223+
224+ // Test: the placeholder in the source file is replaced in the dist output
225+ const componentPreload = await fs . readFile ( path . resolve ( fixtureHelper . distPath , "Component-preload.js" ) , "utf-8" ) ;
226+ assert . ok ( componentPreload . includes ( "console.log(\"INSERTED_TEXT\")" ) , "The placeholder should get replaced with the expected text in the component preload" ) ;
195227 } ) ;
196228} ) ;
0 commit comments