Skip to content

Commit afd95cc

Browse files
committed
Fix tests III, cleanup TaskUtil
1 parent e534189 commit afd95cc

File tree

3 files changed

+165
-79
lines changed

3 files changed

+165
-79
lines changed

lib/tasks/TaskUtil.js

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ class TaskUtil {
1919
* @public
2020
* @typedef {object} module:@ui5/builder.tasks.TaskUtil~StandardBuildTags
2121
* @property {string} OmitFromBuildResult
22-
* Setting this tag to true for a resource will prevent it from being written to the build target
22+
* Setting this tag to true will prevent the resource from being written to the build target directory
2323
* @property {string} IsBundle
2424
* This tag identifies resources that contain (i.e. bundle) multiple other resources
25+
* @property {string} IsDebugVariant
26+
* This tag identifies resources that are a debug variant (typically named with a "-dbg" suffix)
27+
* of another resource. This tag is part of the build manifest.
28+
* @property {string} HasDebugVariant
29+
* This tag identifies resources for which a debug variant has been created.
30+
* This tag is part of the build manifest.
2531
*/
2632

2733
/**
@@ -34,20 +40,21 @@ class TaskUtil {
3440
*/
3541
constructor({projectBuildContext}) {
3642
this._projectBuildContext = projectBuildContext;
37-
38-
this.GLOBAL_TAGS = Object.freeze({
39-
IsDebugVariant: "ui5:IsDebugVariant",
40-
HasDebugVariant: "ui5:HasDebugVariant"
41-
});
42-
4343
/**
4444
* @member {module:@ui5/builder.tasks.TaskUtil~StandardBuildTags}
4545
* @public
4646
*/
4747
this.STANDARD_TAGS = Object.freeze({
48+
// "Project" tags:
49+
// Will be stored on project instance and are hence part of the build manifest
50+
IsDebugVariant: "ui5:IsDebugVariant",
51+
HasDebugVariant: "ui5:HasDebugVariant",
52+
53+
// "Build" tags:
54+
// Will be stored on the project build context
55+
// They are only available to the build tasks of a single project
4856
OmitFromBuildResult: "ui5:OmitFromBuildResult",
49-
IsBundle: "ui5:IsBundle",
50-
...this.GLOBAL_TAGS
57+
IsBundle: "ui5:IsBundle"
5158
});
5259
}
5360

@@ -69,7 +76,7 @@ class TaskUtil {
6976
setTag(resource, tag, value) {
7077
if (typeof resource === "string") {
7178
throw new Error("Deprecated parameter: " +
72-
"Since UI5 Tooling 3.0, setTag requires a resource instance. Strings are no longer accepted");
79+
"Since UI5 Tooling 3.0, #setTag requires a resource instance. Strings are no longer accepted");
7380
}
7481

7582
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
@@ -92,7 +99,7 @@ class TaskUtil {
9299
getTag(resource, tag) {
93100
if (typeof resource === "string") {
94101
throw new Error("Deprecated parameter: " +
95-
"Since UI5 Tooling 3.0, getTag requires a resource instance. Strings are no longer accepted");
102+
"Since UI5 Tooling 3.0, #getTag requires a resource instance. Strings are no longer accepted");
96103
}
97104
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
98105
return collection.getTag(resource, tag);
@@ -113,7 +120,7 @@ class TaskUtil {
113120
clearTag(resource, tag) {
114121
if (typeof resource === "string") {
115122
throw new Error("Deprecated parameter: " +
116-
"Since UI5 Tooling 3.0, clearTag requires a resource instance. Strings are no longer accepted");
123+
"Since UI5 Tooling 3.0, #clearTag requires a resource instance. Strings are no longer accepted");
117124
}
118125
const collection = this._projectBuildContext.getResourceTagCollection(resource, tag);
119126
return collection.clearTag(resource, tag);
@@ -164,6 +171,10 @@ class TaskUtil {
164171
/**
165172
* Retrieve a single project from the dependency graph
166173
*
174+
* </br></br>
175+
* This method is only available to custom task extensions defining
176+
* <b>Specification Version 2.7 and above</b>.
177+
*
167178
* @param {string} projectName Name of the project to retrieve
168179
* @returns {module:@ui5/project.specifications.Project|undefined}
169180
* project instance or undefined if the project is unknown to the graph
@@ -173,18 +184,6 @@ class TaskUtil {
173184
return this._projectBuildContext.getProject(projectName);
174185
}
175186

176-
createResource(parameters) {
177-
if (!parameters.project) {
178-
parameters.project = this.getProject();
179-
}
180-
const Resource = require("@ui5/fs").Resource;
181-
return new Resource(parameters);
182-
}
183-
184-
getCreateResourceFn() {
185-
return this.createResource.bind(this);
186-
}
187-
188187
/**
189188
* Get an interface to an instance of this class that only provides those functions
190189
* that are supported by the given custom task extension specification version.
@@ -210,18 +209,16 @@ class TaskUtil {
210209
case "2.5":
211210
case "2.6":
212211
return baseInterface;
213-
case "3.0":
212+
case "2.7":
214213
baseInterface.getProject = (projectName) => {
215214
const project = this.getProject(projectName);
216215
const baseProjectInterface = {};
217216
bindFunctions(project, baseProjectInterface, [
218217
"getName", "getVersion", "getNamespace"
219218
]);
220219
switch (specVersion) {
221-
case "3.0":
220+
case "2.7":
222221
return baseProjectInterface;
223-
default:
224-
throw new Error(`TaskUtil: Unknown or unsupported Specification Version ${specVersion}`);
225222
}
226223
};
227224
return baseInterface;

test/lib/processors/manifestCreator.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ test.serial("default manifest creation (multi-line documentation)", async (t) =>
186186
t.is(errorLogStub.callCount, 0);
187187
});
188188

189-
190189
test.serial("default manifest creation i18n empty string", async (t) => {
191190
const {manifestCreator, errorLogStub, getProjectVersion} = t.context;
192191
const prefix = "/resources/sap/ui/mine/";
@@ -331,7 +330,7 @@ test.serial("default manifest creation with sourceTemplate and thirdparty", asyn
331330
t.is(errorLogStub.callCount, 0);
332331
});
333332

334-
test.serial("default manifest creation no dependency version", async (t) => {
333+
test.serial("default manifest creation no project versions", async (t) => {
335334
const {manifestCreator, errorLogStub, getProjectVersion} = t.context;
336335
const prefix = "/resources/sap/ui/mine/";
337336
const libraryResource = {
@@ -358,13 +357,13 @@ test.serial("default manifest creation no dependency version", async (t) => {
358357
}
359358
};
360359

361-
const error = await t.throwsAsync(manifestCreator({
362-
libraryResource,
363-
resources: [],
364-
getProjectVersion
365-
}));
366-
t.deepEqual(error.message,
367-
"Couldn't find version for library 'my.lib', project dependency missing?", "error message correct");
360+
const expectedManifestContentObjectModified = expectedManifestContentObject();
361+
expectedManifestContentObjectModified["sap.app"]["i18n"] = undefined;
362+
expectedManifestContentObjectModified["sap.app"]["applicationVersion"] = {};
363+
expectedManifestContentObjectModified["sap.ui5"]["dependencies"]["libs"]["my.lib"] = {};
364+
const expectedManifestContent = JSON.stringify(expectedManifestContentObjectModified, null, 2);
365+
const result = await manifestCreator({libraryResource, resources: [], getProjectVersion, options: {}});
366+
t.is(await result.getString(), expectedManifestContent, "Correct result returned");
368367
t.is(errorLogStub.callCount, 0);
369368
});
370369

0 commit comments

Comments
 (0)