Skip to content

Commit b0b6dcc

Browse files
committed
refactor(project): Adapt tests after refactoring of resource tag handling
1 parent 940376d commit b0b6dcc

9 files changed

Lines changed: 81 additions & 81 deletions

File tree

packages/project/lib/build/ProjectBuilder.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,16 +485,11 @@ class ProjectBuilder {
485485
});
486486

487487
deferredWork.push(
488-
this._writeToDisk(resourcesToWrite, target, resources, taskUtil, project, isRootProject, outputStyle));
488+
this._writeToDisk(resourcesToWrite, target, resources, project, isRootProject, outputStyle));
489489
}
490490

491-
async _writeToDisk(resourcesToWrite, target, resources, taskUtil, project, isRootProject, outputStyle) {
491+
async _writeToDisk(resourcesToWrite, target, resources, project, isRootProject, outputStyle) {
492492
await Promise.all(resourcesToWrite.map((resource) => {
493-
if (taskUtil.getTag(resource, taskUtil.STANDARD_TAGS.OmitFromBuildResult)) {
494-
this.#log.silly(`Skipping write of resource tagged as "OmitFromBuildResult": ` +
495-
resource.getPath());
496-
return; // Skip target write for this resource
497-
}
498493
return target.write(resource);
499494
}));
500495

packages/project/lib/build/helpers/createBuildManifest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function getVersion(pkg) {
88
}
99

1010
function getSortedTags(project) {
11-
const tags = project.getResourceTagCollection().getAllTags();
11+
const tags = project.getProjectResourceTagCollection().getAllTags();
1212
const entities = Object.entries(tags);
1313
entities.sort(([keyA], [keyB]) => {
1414
return keyA.localeCompare(keyB);

packages/project/lib/resources/ProjectResources.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ class ProjectResources {
391391
};
392392
}
393393

394+
/**
395+
* Returns the project-level resource tag collection.
396+
*
397+
* This provides direct access to the collection holding project-level tags
398+
* (e.g. ui5:IsDebugVariant, ui5:HasDebugVariant), which is needed for
399+
* build manifest creation and reading.
400+
*
401+
* @returns {@ui5/fs/internal/ResourceTagCollection} The project-level resource tag collection
402+
*/
403+
getProjectResourceTagCollection() {
404+
return this.#getProjectResourceTagCollection();
405+
}
406+
394407
#getProjectResourceTagCollection() {
395408
if (!this.#projectResourceTagCollection) {
396409
this.#projectResourceTagCollection = new ResourceTagCollection({

packages/project/lib/specifications/Project.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ class Project extends Specification {
332332
return this.#projectResources.getResourceTagCollection(resource, tag);
333333
}
334334

335+
/**
336+
* Returns the project-level resource tag collection
337+
*
338+
* @returns {@ui5/fs/internal/ResourceTagCollection} The project-level resource tag collection
339+
*/
340+
getProjectResourceTagCollection() {
341+
return this.#projectResources.getProjectResourceTagCollection();
342+
}
343+
335344
/* === Internals === */
336345
/**
337346
* @private

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ test("build", async (t) => {
122122
buildProject: buildProjectStub,
123123
writeBuildCache: writeBuildCacheStub,
124124
requiresBuild: requiresBuildStub,
125-
getProject: sinon.stub().returns(getMockProject("library"))
125+
getProject: sinon.stub().returns(getMockProject("library")),
126+
buildFinished: sinon.stub()
126127
};
127128
const getRequiredProjectContextsStub = sinon.stub(builder._buildContext, "getRequiredProjectContexts")
128129
.resolves(new Map().set("project.a", projectBuildContextMock));
@@ -295,21 +296,24 @@ test.serial("build: Multiple projects", async (t) => {
295296
prepareProjectBuildAndValidateCache: sinon.stub().resolves(false),
296297
buildProject: buildProjectAStub,
297298
writeBuildCache: writeBuildCacheStub,
298-
getProject: sinon.stub().returns(getMockProject("library", "a"))
299+
getProject: sinon.stub().returns(getMockProject("library", "a")),
300+
buildFinished: sinon.stub()
299301
};
300302
const projectBuildContextMockB = {
301303
possiblyRequiresBuild: sinon.stub().returns(false),
302304
prepareProjectBuildAndValidateCache: sinon.stub().resolves(false),
303305
buildProject: buildProjectBStub,
304306
writeBuildCache: writeBuildCacheStub,
305-
getProject: sinon.stub().returns(getMockProject("library", "b"))
307+
getProject: sinon.stub().returns(getMockProject("library", "b")),
308+
buildFinished: sinon.stub()
306309
};
307310
const projectBuildContextMockC = {
308311
possiblyRequiresBuild: sinon.stub().returns(true),
309312
prepareProjectBuildAndValidateCache: sinon.stub().resolves(false),
310313
buildProject: buildProjectCStub,
311314
writeBuildCache: writeBuildCacheStub,
312-
getProject: sinon.stub().returns(getMockProject("library", "c"))
315+
getProject: sinon.stub().returns(getMockProject("library", "c")),
316+
buildFinished: sinon.stub()
313317
};
314318
const getRequiredProjectContextsStub = sinon.stub(builder._buildContext, "getRequiredProjectContexts")
315319
.resolves(new Map()
@@ -492,7 +496,9 @@ test("_writeResults", async (t) => {
492496
write: sinon.stub().resolves()
493497
};
494498

495-
await builder._writeResults(projectBuildContextMock, writerMock);
499+
const deferredWork = [];
500+
await builder._writeResults(projectBuildContextMock, writerMock, deferredWork);
501+
await Promise.all(deferredWork);
496502

497503
t.is(getReaderStub.callCount, 1, "One reader requested");
498504
t.deepEqual(getReaderStub.getCall(0).args[0], {
@@ -572,7 +578,9 @@ test.serial("_writeResults: Create build manifest", async (t) => {
572578
write: sinon.stub().resolves()
573579
};
574580

575-
await builder._writeResults(projectBuildContextMock, writerMock);
581+
const deferredWork = [];
582+
await builder._writeResults(projectBuildContextMock, writerMock, deferredWork);
583+
await Promise.all(deferredWork);
576584

577585
t.is(getReaderStub.callCount, 1, "One reader requested");
578586
t.deepEqual(getReaderStub.getCall(0).args[0], {
@@ -670,7 +678,9 @@ test.serial("_writeResults: Flat build output", async (t) => {
670678
write: sinon.stub().resolves()
671679
};
672680

673-
await builder._writeResults(projectBuildContextMock, writerMock);
681+
const deferredWork = [];
682+
await builder._writeResults(projectBuildContextMock, writerMock, deferredWork);
683+
await Promise.all(deferredWork);
674684

675685
t.is(getReaderStub.callCount, 2, "One reader requested");
676686
t.deepEqual(getReaderStub.getCall(0).args[0], {

packages/project/test/lib/build/cache/ProjectBuildCache.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ function createMockProject(name = "test.project", id = "test-project-id") {
1414
byPath: sinon.stub().resolves(null)
1515
});
1616

17-
return {
18-
getName: () => name,
19-
getId: () => id,
20-
getSourceReader: sinon.stub().callsFake(() => createReader()),
21-
getReader: sinon.stub().callsFake(() => createReader()),
17+
const projectResources = {
2218
getStage: sinon.stub().returns({
2319
getId: () => currentStage.id || "initial",
2420
getWriter: sinon.stub().returns({
@@ -38,6 +34,19 @@ function createMockProject(name = "test.project", id = "test-project-id") {
3834
useResultStage: sinon.stub().callsFake(() => {
3935
currentStage = {id: "result"};
4036
}),
37+
getResourceTagOperations: sinon.stub().returns({
38+
projectTagOperations: new Map(),
39+
buildTagOperations: new Map(),
40+
}),
41+
buildFinished: sinon.stub(),
42+
};
43+
44+
return {
45+
getName: () => name,
46+
getId: () => id,
47+
getSourceReader: sinon.stub().callsFake(() => createReader()),
48+
getReader: sinon.stub().callsFake(() => createReader()),
49+
getProjectResources: () => projectResources,
4150
_getCurrentStage: () => currentStage,
4251
_getResultStageReader: () => resultStageReader
4352
};
@@ -192,9 +201,9 @@ test("setTasks initializes project stages", async (t) => {
192201

193202
await cache.setTasks(["task1", "task2", "task3"]);
194203

195-
t.true(project.initStages.calledOnce, "initStages called once");
204+
t.true(project.getProjectResources().initStages.calledOnce, "initStages called once");
196205
t.deepEqual(
197-
project.initStages.firstCall.args[0],
206+
project.getProjectResources().initStages.firstCall.args[0],
198207
["task/task1", "task/task2", "task/task3"],
199208
"Stage names generated correctly"
200209
);
@@ -207,7 +216,7 @@ test("setTasks with empty task list", async (t) => {
207216

208217
await cache.setTasks([]);
209218

210-
t.true(project.initStages.calledWith([]), "initStages called with empty array");
219+
t.true(project.getProjectResources().initStages.calledWith([]), "initStages called with empty array");
211220
});
212221

213222
test("allTasksCompleted switches to result stage", async (t) => {
@@ -217,7 +226,7 @@ test("allTasksCompleted switches to result stage", async (t) => {
217226

218227
const changedPaths = await cache.allTasksCompleted();
219228

220-
t.true(project.useResultStage.calledOnce, "useResultStage called");
229+
t.true(project.getProjectResources().useResultStage.calledOnce, "useResultStage called");
221230
t.true(Array.isArray(changedPaths), "Returns array of changed paths");
222231
t.true(cache.isFresh(), "Cache is fresh after all tasks completed");
223232
});
@@ -277,7 +286,7 @@ test("prepareTaskExecutionAndValidateCache: task needs execution when no cache e
277286
const canUseCache = await cache.prepareTaskExecutionAndValidateCache("myTask");
278287

279288
t.false(canUseCache, "Task cannot use cache");
280-
t.true(project.useStage.calledWith("task/myTask"), "Project switched to task stage");
289+
t.true(project.getProjectResources().useStage.calledWith("task/myTask"), "Project switched to task stage");
281290
});
282291

283292
test("prepareTaskExecutionAndValidateCache: switches project to correct stage", async (t) => {
@@ -288,7 +297,7 @@ test("prepareTaskExecutionAndValidateCache: switches project to correct stage",
288297
await cache.setTasks(["task1", "task2"]);
289298
await cache.prepareTaskExecutionAndValidateCache("task2");
290299

291-
t.true(project.useStage.calledWith("task/task2"), "Switched to task2 stage");
300+
t.true(project.getProjectResources().useStage.calledWith("task/task2"), "Switched to task2 stage");
292301
});
293302

294303
test("recordTaskResult: creates task cache", async (t) => {
@@ -595,5 +604,5 @@ test("Empty task list doesn't fail", async (t) => {
595604

596605
await cache.setTasks([]);
597606

598-
t.true(project.initStages.calledWith([]), "initStages called with empty array");
607+
t.true(project.getProjectResources().initStages.calledWith([]), "initStages called with empty array");
599608
});

packages/project/test/lib/build/helpers/ProjectBuildContext.js

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,7 @@ test("executeCleanupTasks", (t) => {
126126
});
127127

128128
test.serial("getResourceTagCollection", async (t) => {
129-
const projectAcceptsTagStub = sinon.stub().returns(false);
130-
projectAcceptsTagStub.withArgs("project-tag").returns(true);
131-
const projectContextAcceptsTagStub = sinon.stub().returns(false);
132-
projectContextAcceptsTagStub.withArgs("project-context-tag").returns(true);
133-
134-
class DummyResourceTagCollection {
135-
constructor({allowedTags, allowedNamespaces}) {
136-
t.deepEqual(allowedTags, [
137-
"ui5:OmitFromBuildResult",
138-
"ui5:IsBundle"
139-
],
140-
"Correct allowedTags parameter supplied");
141-
142-
t.deepEqual(allowedNamespaces, [
143-
"build"
144-
],
145-
"Correct allowedNamespaces parameter supplied");
146-
}
147-
acceptsTag(tag) {
148-
// Redirect to stub
149-
return projectContextAcceptsTagStub(tag);
150-
}
151-
}
152-
153-
const ProjectBuildContext = await esmock("../../../../lib/build/helpers/ProjectBuildContext.js", {
154-
"@ui5/fs/internal/ResourceTagCollection": DummyResourceTagCollection
155-
});
129+
const ProjectBuildContext = (await import("../../../../lib/build/helpers/ProjectBuildContext.js")).default;
156130
const buildContext = {};
157131
const project = {
158132
getName: () => "project",
@@ -163,30 +137,24 @@ test.serial("getResourceTagCollection", async (t) => {
163137
project
164138
);
165139

166-
const fakeProjectCollection = {
167-
acceptsTag: projectAcceptsTagStub
140+
const fakeCollection = {
141+
acceptsTag: sinon.stub().returns(true)
168142
};
143+
const getResourceTagCollectionStub = sinon.stub().returns(fakeCollection);
169144
const fakeResource = {
170145
getProject: () => {
171146
return {
172-
getResourceTagCollection: () => fakeProjectCollection
147+
getResourceTagCollection: getResourceTagCollectionStub
173148
};
174149
},
175150
getPath: () => "/resource/path",
176151
hasProject: () => true
177152
};
178-
const collection1 = projectBuildContext.getResourceTagCollection(fakeResource, "project-tag");
179-
t.is(collection1, fakeProjectCollection, "Returned tag collection of resource project");
180-
181-
const collection2 = projectBuildContext.getResourceTagCollection(fakeResource, "project-context-tag");
182-
t.true(collection2 instanceof DummyResourceTagCollection,
183-
"Returned tag collection of project build context");
184-
185-
t.throws(() => {
186-
projectBuildContext.getResourceTagCollection(fakeResource, "not-accepted-tag");
187-
}, {
188-
message: `Could not find collection for resource /resource/path and tag not-accepted-tag`
189-
});
153+
const collection = projectBuildContext.getResourceTagCollection(fakeResource, "some-tag");
154+
t.is(collection, fakeCollection, "Returned tag collection from resource's project");
155+
t.is(getResourceTagCollectionStub.callCount, 1, "getResourceTagCollection called once");
156+
t.is(getResourceTagCollectionStub.firstCall.args[0], fakeResource, "Called with resource");
157+
t.is(getResourceTagCollectionStub.firstCall.args[1], "some-tag", "Called with tag");
190158
});
191159

192160
test("getResourceTagCollection: Assigns project to resource if necessary", (t) => {
@@ -404,9 +372,7 @@ test("possiblyRequiresBuild: has build-manifest", (t) => {
404372
getType: sinon.stub().returns("bar"),
405373
getBuildManifest: () => {
406374
return {
407-
buildManifest: {
408-
manifestVersion: "0.1"
409-
},
375+
manifestVersion: "0.1",
410376
timestamp: "2022-07-28T12:00:00.000Z"
411377
};
412378
}
@@ -425,9 +391,7 @@ test.serial("getBuildMetadata", (t) => {
425391
getType: sinon.stub().returns("bar"),
426392
getBuildManifest: () => {
427393
return {
428-
buildManifest: {
429-
manifestVersion: "0.1"
430-
},
394+
manifestVersion: "0.1",
431395
timestamp: "2022-07-28T12:00:00.000Z"
432396
};
433397
}

packages/project/test/lib/build/helpers/createBuildManifest.integration.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const buildConfig = {
4545

4646
test("Create project from application project providing a build manifest", async (t) => {
4747
const inputProject = await Specification.create(applicationAConfig);
48-
inputProject.getResourceTagCollection().setTag("/resources/id1/foo.js", "ui5:HasDebugVariant");
48+
inputProject.getProjectResourceTagCollection().setTag("/resources/id1/foo.js", "ui5:HasDebugVariant");
4949

5050
const taskRepository = {
5151
getVersions: async () => ({a: "a", b: "b"})
@@ -63,7 +63,7 @@ test("Create project from application project providing a build manifest", async
6363
t.truthy(project, "Module was able to create project from build manifest metadata");
6464
t.is(project.getName(), project.getName(), "Archive project has correct name");
6565
t.is(project.getNamespace(), project.getNamespace(), "Archive project has correct namespace");
66-
t.is(project.getResourceTagCollection().getTag("/resources/id1/foo.js", "ui5:HasDebugVariant"), true,
66+
t.is(project.getProjectResourceTagCollection().getTag("/resources/id1/foo.js", "ui5:HasDebugVariant"), true,
6767
"Archive project has correct tag");
6868
t.is(project.getVersion(), "2.0.0", "Archive project has version from archive module");
6969

@@ -77,7 +77,7 @@ test("Create project from application project providing a build manifest", async
7777

7878
test("Create project from library project providing a build manifest", async (t) => {
7979
const inputProject = await Specification.create(libraryEConfig);
80-
inputProject.getResourceTagCollection().setTag("/resources/library/e/file.js", "ui5:HasDebugVariant");
80+
inputProject.getProjectResourceTagCollection().setTag("/resources/library/e/file.js", "ui5:HasDebugVariant");
8181

8282
const taskRepository = {
8383
getVersions: async () => ({a: "a", b: "b"})
@@ -95,7 +95,7 @@ test("Create project from library project providing a build manifest", async (t)
9595
t.truthy(project, "Module was able to create project from build manifest metadata");
9696
t.is(project.getName(), project.getName(), "Archive project has correct name");
9797
t.is(project.getNamespace(), project.getNamespace(), "Archive project has correct namespace");
98-
t.is(project.getResourceTagCollection().getTag("/resources/library/e/file.js", "ui5:HasDebugVariant"), true,
98+
t.is(project.getProjectResourceTagCollection().getTag("/resources/library/e/file.js", "ui5:HasDebugVariant"), true,
9999
"Archive project has correct tag");
100100
t.is(project.getVersion(), "2.0.0", "Archive project has version from archive module");
101101

packages/project/test/lib/build/helpers/createBuildManifest.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ test("Missing parameter: signature", async (t) => {
7777

7878
test("Create application from project with build manifest", async (t) => {
7979
const project = await Specification.create(applicationProjectInput);
80-
project.getResourceTagCollection().setTag("/resources/id1/foo.js", "ui5:HasDebugVariant");
80+
project.getProjectResourceTagCollection().setTag("/resources/id1/foo.js", "ui5:HasDebugVariant");
8181

8282
const taskRepository = {
8383
getVersions: async () => ({builderVersion: "<builder version>", fsVersion: "<builder fs version>"})
@@ -133,7 +133,7 @@ test("Create application from project with build manifest", async (t) => {
133133

134134
test("Create library from project with build manifest", async (t) => {
135135
const project = await Specification.create(libraryProjectInput);
136-
project.getResourceTagCollection().setTag("/resources/library/d/foo.js", "ui5:HasDebugVariant");
136+
project.getProjectResourceTagCollection().setTag("/resources/library/d/foo.js", "ui5:HasDebugVariant");
137137

138138
const taskRepository = {
139139
getVersions: async () => ({builderVersion: "<builder version>", fsVersion: "<builder fs version>"})

0 commit comments

Comments
 (0)