Skip to content

Commit 252b966

Browse files
committed
test(project): Add case for multiple custom tasks (tag handling)
1 parent a263757 commit 252b966

File tree

5 files changed

+170
-1
lines changed

5 files changed

+170
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = async function ({
2+
workspace, taskUtil,
3+
options: {projectNamespace}
4+
}) {
5+
console.log("Custom task 0 executed");
6+
7+
// For #1 Build: Read a file which is an input of custom-task-1 (which sets a tag on it)
8+
const testJS = await workspace.byPath(`/resources/${projectNamespace}/test.js`);
9+
10+
// For #3 Build: Read a different file (which is NOT an input of custom-task-1)
11+
const test2JS = await workspace.byPath(`/resources/${projectNamespace}/test2.js`);
12+
13+
const tag = taskUtil.getTag(testJS, taskUtil.STANDARD_TAGS.IsDebugVariant);
14+
if (!test2JS && testJS) {
15+
// For #1 Build:
16+
if (tag) {
17+
throw new Error("Tag set by custom-task-1 is present in custom-task-0, which is UNEXPECTED.");
18+
} else {
19+
console.log("Tag set by custom-task-1 is not present in custom-task-0, as EXPECTED.");
20+
}
21+
} else {
22+
// For #3 Build (NEW behavior expected as in #1):
23+
if (tag) {
24+
console.log("Tag set by custom-task-1 is present in custom-task-0 now, as EXPECTED.");
25+
} else {
26+
throw new Error("Tag set by custom-task-1 is NOT present in custom-task-0, which is UNEXPECTED.");
27+
}
28+
}
29+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = async function ({
2+
workspace, taskUtil,
3+
options: {projectNamespace}
4+
}) {
5+
console.log("Custom task 1 executed");
6+
7+
// Set a tag on a specific resource
8+
const resource = await workspace.byPath(`/resources/${projectNamespace}/test.js`);
9+
if (resource) {
10+
taskUtil.setTag(resource, taskUtil.STANDARD_TAGS.IsDebugVariant);
11+
};
12+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = async function ({
2+
workspace, taskUtil,
3+
options: {projectNamespace}
4+
}) {
5+
console.log("Custom task 2 executed");
6+
7+
// For #1 Build: Read a file which is an input of custom-task-1 (which sets a tag on it)
8+
const testJS = await workspace.byPath(`/resources/${projectNamespace}/test.js`);
9+
10+
// For #3 Build: Read a different file (which is NOT an input of custom-task-1)
11+
const test2JS = await workspace.byPath(`/resources/${projectNamespace}/test2.js`);
12+
13+
const tag = taskUtil.getTag(testJS, taskUtil.STANDARD_TAGS.IsDebugVariant);
14+
if (!test2JS && testJS) {
15+
// For #1 Build:
16+
if (tag) {
17+
console.log("Tag set by custom-task-1 is present in custom-task-2, as EXPECTED.");
18+
} else {
19+
throw new Error("Tag set by custom-task-1 is NOT present in custom-task-2, which is UNEXPECTED.");
20+
}
21+
} else {
22+
// For #3 Build (SAME behavior expected as in #1):
23+
if (tag) {
24+
console.log("Tag set by custom-task-1 is present in custom-task-2, as EXPECTED.");
25+
} else {
26+
throw new Error("Tag set by custom-task-1 is NOT present in custom-task-2, which is UNEXPECTED.");
27+
}
28+
}
29+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
specVersion: "5.0"
3+
type: application
4+
metadata:
5+
name: application.a
6+
builder:
7+
customTasks:
8+
- name: custom-task-0
9+
afterTask: minify
10+
- name: custom-task-1
11+
afterTask: custom-task-0
12+
- name: custom-task-2
13+
afterTask: custom-task-1
14+
---
15+
specVersion: "5.0"
16+
kind: extension
17+
type: task
18+
metadata:
19+
name: custom-task-0
20+
task:
21+
path: custom-tasks/custom-task-0.js
22+
---
23+
specVersion: "5.0"
24+
kind: extension
25+
type: task
26+
metadata:
27+
name: custom-task-1
28+
task:
29+
path: custom-tasks/custom-task-1.js
30+
---
31+
specVersion: "5.0"
32+
kind: extension
33+
type: task
34+
metadata:
35+
name: custom-task-2
36+
task:
37+
path: custom-tasks/custom-task-2.js

packages/project/test/lib/build/ProjectBuilder.integration.js

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ test.serial.skip("Build application.a (custom task and tag handling)", async (t)
207207

208208
// Create new file which should get tagged as "OmitFromBuildResult" by a custom task
209209
await fs.writeFile(`${fixtureTester.fixturePath}/webapp/fileToBeOmitted.js`,
210-
`console.log("this file should be ommited in the build result")`);
210+
`console.log("this file should be omitted in the build result")`);
211211

212212
// #2 build (with cache, with changes, with custom tasks)
213213
await fixtureTester.buildProject({
@@ -258,6 +258,68 @@ test.serial.skip("Build application.a (custom task and tag handling)", async (t)
258258
});
259259
});
260260

261+
262+
test.only("Build application.a (multiple custom tasks)", async (t) => {
263+
const fixtureTester = new FixtureTester(t, "application.a");
264+
const destPath = fixtureTester.destPath;
265+
266+
// This test should cover a scenario with multiple custom tasks.
267+
// Specifically, a tag is set in custom-task-1 on a resource which is read in custom-task-0 and custom-task-2.
268+
// The expected behavior is that the tag is not present in custom-task-0 (which runs before custom-task-1),
269+
// but is present in custom-task-2 (which runs after custom-task-1).
270+
// (for testing purposes, the custom tasks already check for this tag by themselves and handle errors accordingly)
271+
272+
// #1 build (no cache, no changes, with custom tasks)
273+
await fixtureTester.buildProject({
274+
graphConfig: {rootConfigPath: "ui5-multiple-customTasks.yaml"},
275+
config: {destPath, cleanDest: true},
276+
assertions: {
277+
projects: {
278+
"application.a": {}
279+
}
280+
}
281+
});
282+
283+
// #2 build (with cache, no changes, with custom tasks)
284+
await fixtureTester.buildProject({
285+
graphConfig: {rootConfigPath: "ui5-multiple-customTasks.yaml"},
286+
config: {destPath, cleanDest: true},
287+
assertions: {
288+
projects: {}
289+
}
290+
});
291+
292+
293+
// Create a new file to allow a new build:
294+
// Logic of custom-task-1 will NOT handle this file, while custom-task-0 and 2 WILL DO it,
295+
// resulting in custom-task-1 getting skipped (cache reuse).
296+
// The test should then verify that the tag is still set and now readable for custom-task-0 AND 2.
297+
// (as in #1 build, the custom tasks already check for this tag by themselves and handle errors accordingly)
298+
await fs.cp(`${fixtureTester.fixturePath}/webapp/test.js`,
299+
`${fixtureTester.fixturePath}/webapp/test2.js`);
300+
301+
// #3 build (with cache, with changes, with custom tasks)
302+
// FIXME: Currently failing, because for custom-task-0 and 2 the tag is NOT set yet.
303+
await fixtureTester.buildProject({
304+
graphConfig: {rootConfigPath: "ui5-multiple-customTasks.yaml"},
305+
config: {destPath, cleanDest: true},
306+
assertions: {
307+
projects: {
308+
"application.a": {
309+
skippedTasks: [
310+
"custom-task-1", // SHOULD BE SKIPPED
311+
// remaining skipped tasks don't matter here:
312+
"enhanceManifest",
313+
"escapeNonAsciiCharacters",
314+
"generateFlexChangesBundle",
315+
"replaceCopyright",
316+
]
317+
}
318+
}
319+
}
320+
});
321+
});
322+
261323
test.serial("Build library.d project multiple times", async (t) => {
262324
const fixtureTester = new FixtureTester(t, "library.d");
263325
const destPath = fixtureTester.destPath;

0 commit comments

Comments
 (0)