Skip to content

Commit df275e5

Browse files
committed
test(project): Add case for dependency content changes
This test should cover a scenario with an application depending on a library. Specifically, we're directly modifying the contents of the library which should have effects on the application because a custom task will detect it and modify the application's resources. The application is expected to get rebuilt.
1 parent 5531cd9 commit df275e5

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This is a modified version of the compileLicenseSummary example of the UI5 CLI.
2+
// (https://github.com/UI5/cli/blob/b72919469d856508dd757ecf325a5fb45f15e56d/internal/documentation/docs/pages/extensibility/CustomTasks.md#example-libtaskscompilelicensesummaryjs)
3+
4+
module.exports = async function ({dependencies, log, taskUtil, workspace, options: {projectNamespace}}) {
5+
const {createResource} = taskUtil.resourceFactory;
6+
const projectsVisited = new Set();
7+
8+
async function processProject(project) {
9+
return Promise.all(taskUtil.getDependencies().map(async (projectName) => {
10+
if (projectName !== "library.d") {
11+
return;
12+
}
13+
if (projectsVisited.has(projectName)) {
14+
return;
15+
}
16+
projectsVisited.add(projectName);
17+
const project = taskUtil.getProject(projectName);
18+
const newLibraryFile = await project.getReader().byGlob("**/newLibraryFile.js");
19+
if (newLibraryFile.length > 0) {
20+
console.log('New Library file found. We are in #4 build.');
21+
// Change content of application.a:
22+
const applicationResource = await workspace.byPath("/resources/id1/test.js");
23+
const content = (await applicationResource.getString()) + "\n console.log('something new');";
24+
await workspace.write(createResource({
25+
path: "/test.js",
26+
string: content
27+
}));
28+
} else {
29+
console.log(`New Library file not found. We are still in an earlier build.`);
30+
}
31+
return processProject(project);
32+
}));
33+
}
34+
// Start processing dependencies of the root project
35+
await processProject(taskUtil.getProject());
36+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
specVersion: "2.3"
3+
type: application
4+
metadata:
5+
name: application.a
6+
builder:
7+
customTasks:
8+
- name: dependency-change
9+
afterTask: minify
10+
---
11+
specVersion: "5.0"
12+
kind: extension
13+
type: task
14+
metadata:
15+
name: dependency-change
16+
task:
17+
path: task.dependency-change.js
18+

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

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,90 @@ test.serial.skip("Build application.a (multiple custom tasks 2)", async (t) => {
361361
await t.throwsAsync(fs.readFile(`${destPath}/test.js`, {encoding: "utf8"}));
362362
});
363363

364+
test.only("Build application.a (dependency content changes)", async (t) => {
365+
const fixtureTester = new FixtureTester(t, "application.a");
366+
const destPath = fixtureTester.destPath;
367+
368+
// This test should cover a scenario with an application depending on a library.
369+
// Specifically, we're directly modifying the contents of the library
370+
// which should have effects on the application because a custom task will detect it
371+
// and modify the application's resources. The application is expected to get rebuilt.
372+
373+
// #1 build (no cache, no changes, no dependencies)
374+
await fixtureTester.buildProject({
375+
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
376+
config: {destPath, cleanDest: true},
377+
assertions: {
378+
projects: {
379+
"application.a": {}
380+
}
381+
}
382+
});
383+
384+
385+
// #2 build (with cache, no changes, no dependencies)
386+
await fixtureTester.buildProject({
387+
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
388+
config: {destPath, cleanDest: true},
389+
assertions: {
390+
projects: {}
391+
}
392+
});
393+
394+
395+
// Change content of library.d (this will not affect application.a):
396+
const someJsOfLibrary = `${fixtureTester.fixturePath}/node_modules/library.d/main/src/library/d/some.js`;
397+
await fs.appendFile(someJsOfLibrary, `\ntest("line added");\n`);
398+
399+
// #3 build (with cache, with changes, with dependencies)
400+
await fixtureTester.buildProject({
401+
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
402+
config: {destPath, cleanDest: true, dependencyIncludes: {includeAllDependencies: true}},
403+
assertions: {
404+
projects: {
405+
"library.d": {},
406+
"library.a": {},
407+
"library.b": {},
408+
"library.c": {},
409+
}
410+
}
411+
});
412+
413+
// Check if library contains correct changed content:
414+
const builtFileContent = await fs.readFile(`${destPath}/resources/library/d/some.js`, {encoding: "utf8"});
415+
t.true(builtFileContent.includes(`test("line added");`), "Build dest contains changed file content");
416+
417+
418+
// Change content of library.d again (this time it affects application.a):
419+
await fs.writeFile(`${fixtureTester.fixturePath}/node_modules/library.d/main/src/library/d/newLibraryFile.js`,
420+
`console.log("SOME NEW CONTENT");`);
421+
422+
// #4 build (no cache, with changes, with dependencies)
423+
// This build should execute the custom task "task.dependency-change.js" again which now detects "newLibraryFile.js"
424+
// and modifies a resource of application.a (namely "test.js").
425+
await fixtureTester.buildProject({
426+
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
427+
config: {destPath, cleanDest: true, dependencyIncludes: {includeAllDependencies: true}},
428+
assertions: {
429+
projects: {
430+
"library.d": {},
431+
"application.a": { // FIXME: currently failing (getting skipped entirely)
432+
skippedTasks: [
433+
"enhanceManifest",
434+
"escapeNonAsciiCharacters",
435+
"generateFlexChangesBundle",
436+
"replaceCopyright",
437+
]
438+
},
439+
}
440+
}
441+
});
442+
443+
// Check that application.a contains correct changed content (test.js):
444+
const builtFileContent2 = await fs.readFile(`${destPath}/test.js`, {encoding: "utf8"});
445+
t.true(builtFileContent2.includes(`console.log('something new');`), "Build dest contains changed file content");
446+
});
447+
364448
test.serial("Build library.d project multiple times", async (t) => {
365449
const fixtureTester = new FixtureTester(t, "library.d");
366450
const destPath = fixtureTester.destPath;

0 commit comments

Comments
 (0)