Skip to content

Commit 4dc9a0e

Browse files
maxreichmannRandomByte
authored andcommitted
test: E2E-tests: Cover scenario for "ui5-tooling-stringreplace" (Currently FAILING)
+ Refactor "ui5-tooling-modules" test
1 parent 71ddb60 commit 4dc9a0e

4 files changed

Lines changed: 68 additions & 23 deletions

File tree

internal/e2e-tests/fixtures/application.a/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"devDependencies": {
1010
"@openui5/types": "1.115.1",
1111
"ui5-task-zipper": "3.6.0",
12-
"ui5-tooling-modules": "3.35.0"
12+
"ui5-tooling-modules": "3.35.0",
13+
"ui5-tooling-stringreplace": "3.6.0"
1314
}
1415
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
specVersion: "5.0"
2+
metadata:
3+
name: application.a
4+
type: application
5+
builder:
6+
customTasks:
7+
- name: ui5-tooling-stringreplace-task
8+
afterTask: replaceVersion
9+
configuration:
10+
files:
11+
- "**/*.js"
12+
replace:
13+
- placeholder: ${PLACEHOLDER_TEXT}
14+
value: "'INSERTED_TEXT'"
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
sap.ui.define(["chart.js"], (chartJS) => {
1+
sap.ui.define([], () => {
22
return Controller.extend("application.a.controller.Test",{
33
onInit() {
44
const z = {
@@ -10,9 +10,7 @@ sap.ui.define(["chart.js"], (chartJS) => {
1010
second: "test"
1111
};
1212
console.log(z.first.a);
13-
14-
// For "ui5-tooling-modules" test:
15-
console.log(chartJS);
1613
}
1714
});
1815
});
16+

internal/e2e-tests/test/build.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)