Skip to content

Commit

Permalink
[INTERNAL] ProjectBuildContext: Create and expose an instance of @ui5…
Browse files Browse the repository at this point in the history
…/fs.ResourceTagCollection

Based on proposed RFC 0008:
SAP/ui5-tooling#243
  • Loading branch information
RandomByte committed Aug 11, 2020
1 parent 31fc208 commit 6efffd6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/builder/ProjectBuildContext.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const ResourceTagCollection = require("@ui5/fs").ResourceTagCollection;

const TAGS = Object.freeze({
HideFromBuildResult: "ui5:HideFromBuildResult"
});

/**
* Build context of a single project. Always part of an overall
* [Build Context]{@link module:@ui5/builder.builder.BuildContext}
Expand All @@ -16,6 +22,12 @@ class ProjectBuildContext {
this.queues = {
cleanup: []
};

this.TAGS = TAGS;

this._resourceTagCollection = new ResourceTagCollection({
allowedTags: Object.values(this.TAGS)
});
}

isRootProject() {
Expand All @@ -31,6 +43,10 @@ class ProjectBuildContext {
return callback();
}));
}

getResourceTagCollection() {
return this._resourceTagCollection;
}
}

module.exports = ProjectBuildContext;
1 change: 1 addition & 0 deletions test/lib/builder/BuildContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const mock = require("mock-require");

test.afterEach.always((t) => {
sinon.restore();
mock.stopAll();
});

const BuildContext = require("../../../lib/builder/BuildContext");
Expand Down
43 changes: 42 additions & 1 deletion test/lib/builder/ProjectBuildContext.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const test = require("ava");
const sinon = require("sinon");
const mock = require("mock-require");

test.afterEach.always((t) => {
sinon.restore();
mock.stopAll();
});

const ProjectBuildContext = require("../../../lib/builder/ProjectBuildContext");
Expand Down Expand Up @@ -54,7 +56,6 @@ test("registerCleanupTask", (t) => {
t.is(projectBuildContext.queues.cleanup[1], "my task 2", "Cleanup task registered");
});


test("executeCleanupTasks", (t) => {
const projectBuildContext = new ProjectBuildContext({
buildContext: {
Expand All @@ -73,3 +74,43 @@ test("executeCleanupTasks", (t) => {
t.is(task1.callCount, 1, "Cleanup task 1 got called");
t.is(task2.callCount, 1, "my task 2", "Cleanup task 2 got called");
});

test("TAGS constant", (t) => {
const projectBuildContext = new ProjectBuildContext({
buildContext: {
getRootProject: () => "root project"
},
project: "no root project",
resources: "resources"
});

t.deepEqual(projectBuildContext.TAGS, {
HideFromBuildResult: "ui5:HideFromBuildResult"
}, "Exposes correct TAGS constant");
});

test.serial("getResourceTagCollection", (t) => {
class DummyResourceTagCollection {
constructor({allowedTags}) {
t.deepEqual(allowedTags, ["ui5:HideFromBuildResult"],
"Correct allowedTags parameter supplied");
}
}
mock("@ui5/fs", {
ResourceTagCollection: DummyResourceTagCollection
});

const ProjectBuildContext = mock.reRequire("../../../lib/builder/ProjectBuildContext");
const projectBuildContext = new ProjectBuildContext({
buildContext: {
getRootProject: () => "root project"
},
project: "no root project",
resources: "resources"
});

const collection = projectBuildContext.getResourceTagCollection();

t.true(collection instanceof DummyResourceTagCollection,
"Returned an instance of mocked DummyResourceTagCollection");
});

0 comments on commit 6efffd6

Please sign in to comment.