Skip to content

Commit

Permalink
executeJsdocSdkTransformation: Skip projects with missing api.json
Browse files Browse the repository at this point in the history
Prominent example: theme libraries
  • Loading branch information
RandomByte committed Mar 14, 2019
1 parent 480b832 commit 7d3e696
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/tasks/jsdoc/executeJsdocSdkTransformation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const log = require("@ui5/logger").getLogger("builder:tasks:executeJsdocSdkTransformation");
const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized;
const fsInterface = require("@ui5/fs").fsInterface;
const sdkTransformer = require("../../processors/jsdoc/sdkTransformer");
Expand Down Expand Up @@ -28,8 +29,9 @@ const executeJsdocSdkTransformation = async function({workspace, dependencies, o
dependencies.byGlob("/test-resources/**/designtime/api.json")
]);
if (!apiJsons.length) {
throw new Error(`[executeJsdocSdkTransformation]: Failed to locate api.json resource for project ` +
`${options.projectName}.`);
log.info(`Failed to locate api.json resource for project ${options.projectName}. ` +
`Skipping SDK Transformation...`);
return;
} else if (apiJsons.length > 1) {
throw new Error(`[executeJsdocSdkTransformation]: Found more than one api.json resources for project ` +
`${options.projectName}.`);
Expand Down
28 changes: 22 additions & 6 deletions test/lib/tasks/jsdoc/executeJsdocSdkTransformation.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ test.serial("executeJsdocSdkTransformation", async (t) => {
t.deepEqual(writeStub.getCall(1).args[0], "resource B", "Write got called with correct arguments");

mock.stop("../../../../lib/processors/jsdoc/sdkTransformer");

sinon.restore();
mock.reRequire("../../../../lib/tasks/jsdoc/executeJsdocSdkTransformation");
});

test("executeJsdocSdkTransformation with missing parameters", async (t) => {
Expand All @@ -97,7 +100,15 @@ test("executeJsdocSdkTransformation with missing parameters", async (t) => {
"Correct error message thrown");
});

test("executeJsdocSdkTransformation with missing project api.json", async (t) => {
test.serial("executeJsdocSdkTransformation with missing project api.json (skips processing)", async (t) => {
const logger = require("@ui5/logger");
const infoLogStub = sinon.stub();
const myLoggerInstance = {
info: infoLogStub
};
sinon.stub(logger, "getLogger").returns(myLoggerInstance);
const executeJsdocSdkTransformation = mock.reRequire("../../../../lib/tasks/jsdoc/executeJsdocSdkTransformation");

const byGlobWorkspaceStub = sinon.stub()
.onFirstCall().resolves([])
.onSecondCall().resolves([{
Expand All @@ -116,17 +127,22 @@ test("executeJsdocSdkTransformation with missing project api.json", async (t) =>
byGlob: byGlobDependenciesStub
};

const error = await t.throws(executeJsdocSdkTransformation({
await executeJsdocSdkTransformation({
workspace,
dependencies,
options: {
projectName: "some.project",
dotLibraryPattern: "some .library pattern"
}
}));
t.deepEqual(error.message,
"[executeJsdocSdkTransformation]: Failed to locate api.json resource for project some.project.",
"Correct error message thrown");
});

t.deepEqual(infoLogStub.callCount, 1, "One message has been logged");
t.deepEqual(infoLogStub.getCall(0).args[0],
"Failed to locate api.json resource for project some.project. Skipping SDK Transformation...",
"Correct message has been logged");

sinon.restore();
mock.reRequire("../../../../lib/tasks/jsdoc/executeJsdocSdkTransformation");
});

test("executeJsdocSdkTransformation too many project api.json resources", async (t) => {
Expand Down

0 comments on commit 7d3e696

Please sign in to comment.