Skip to content

Commit

Permalink
[INTERNAL] Workspace: Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Feb 1, 2023
1 parent f16d3f2 commit a807d70
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/graph/Module.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Module {
*
* @private
* @typedef {object} @ui5/project/graph/Module~SpecificationsResult
* @property {@ui5/project/specifications/Project|undefined} Project found in the module (if one is found)
* @property {@ui5/project/specifications/Project|null} Project found in the module (if one is found)
* @property {@ui5/project/specifications/Extension[]} Array of extensions found in the module
*
*/
Expand Down
12 changes: 7 additions & 5 deletions lib/graph/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Workspace {
* @param {string} options.cwd Path to use for resolving all paths of the workspace configuration from.
* This should contain platform-specific path separators (i.e. must not be POSIX on non-POSIX systems)
* @param {@ui5/project/graph/Workspace~Configuration} options.configuration
* Workspace configuration
* Workspace configuration
*/
constructor({cwd, configuration}) {
if (!cwd) {
Expand All @@ -75,12 +75,13 @@ class Workspace {

/**
* For a given project name (e.g. the value of the <code>metadata.name</code> property in a ui5.yaml),
* returns a Module instance or undefined depending on whether the project
* returns a [Module]{@ui5/project/graph/Module} instance or <code>undefined</code> depending on whether the project
* has been found in the configured dependency-management resolution paths of this workspace
*
* @public
* @param {string} projectName Name of the project
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
* @returns {Promise<@ui5/project/graph/Module|undefined>}
* Module instance of <code>undefined</code> if none is found
*/
async getModuleByProjectName(projectName) {
const {projectNameMap} = await this._getResolvedModules();
Expand All @@ -89,13 +90,14 @@ class Workspace {

/**
* For a given node id (e.g. the value of the name property in a package.json),
* returns a Module instance or undefined depending on whether the module
* returns a [Module]{@eId Node ID of} instance or <code>undefined</code> depending on whether the module
* has been found in the configured dependency-management resolution paths of this workspace
* and contains at least one project or extension
*
* @public
* @param {string} nodeId Node ID of the module
* @returns {Promise<@ui5/project/graph/Module|undefined>} Module instance of undefined if none is found
* @returns {Promise<@ui5/project/graph/Module|undefined>}
* Module instance of <code>undefined</code> if none is found
*/
async getModuleByNodeId(nodeId) {
const {moduleIdMap} = await this._getResolvedModules();
Expand Down
2 changes: 1 addition & 1 deletion test/lib/graph/Workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test.beforeEach(async (t) => {
isLevelEnabled: () => true
};

t.context.Workspace = await esmock.p("../../../lib/graph/Workspace.js", {
t.context.Workspace = await esmock("../../../lib/graph/Workspace.js", {
"@ui5/logger": {
getLogger: sinon.stub().withArgs("graph:Workspace").returns(t.context.log)
}
Expand Down
28 changes: 28 additions & 0 deletions test/lib/graph/helpers/createWorkspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,34 @@ test("createWorkspace: Using missing file and non-default name", async (t) => {
});

test("createWorkspace: Using non-default file and non-default name", async (t) => {
const {createWorkspace, workspaceConstructorStub, MockWorkspace} = t.context;

const res = await createWorkspace({
cwd: path.join(fixturesPath, "library.h"),
name: "library-d",
configPath: "custom-ui5-workspace.yaml"
});

t.true(res instanceof MockWorkspace, "Returned instance of Workspace");

t.is(workspaceConstructorStub.callCount, 1, "Workspace constructor got called once");
t.deepEqual(workspaceConstructorStub.getCall(0).args[0], {
cwd: libraryHPath,
configuration: {
specVersion: "workspace/1.0",
metadata: {
name: "library-d"
},
dependencyManagement: {
resolutions: [{
path: "../library.d"
}]
}
}
}, "Created Workspace instance with correct parameters");
});

test("createWorkspace: Using non-default file and non-default name which is not in file", async (t) => {
const {createWorkspace, workspaceConstructorStub} = t.context;

const err = await t.throwsAsync(createWorkspace({
Expand Down

0 comments on commit a807d70

Please sign in to comment.