-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ca55c37
commit 480b832
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const {test} = require("ava"); | ||
const sinon = require("sinon"); | ||
const mock = require("mock-require"); | ||
const sdkTransformer = require("../../../../lib/processors/jsdoc/sdkTransformer"); | ||
|
||
test.afterEach.always((t) => { | ||
sinon.restore(); | ||
}); | ||
|
||
test.serial("sdkTransformer", async (t) => { | ||
const transformerStub = sinon.stub().resolves("api.json content"); | ||
mock("../../../../lib/processors/jsdoc/lib/transform-apijson-for-sdk", transformerStub); | ||
const createResourceStub = sinon.stub(require("@ui5/fs").resourceFactory, "createResource") | ||
.returns("result resource"); | ||
|
||
const sdkTransformer = mock.reRequire("../../../../lib/processors/jsdoc/sdkTransformer"); | ||
|
||
const res = await sdkTransformer({ | ||
apiJsonPath: "/some/path/api.json", | ||
dotLibraryPath: "/some/path/.library", | ||
targetApiJsonPath: "/some/other/path/api.json", | ||
dependencyApiJsonPaths: [ | ||
"/some/path/x/api.json", | ||
"/some/path/y/api.json" | ||
], | ||
fs: "custom fs" | ||
}); | ||
|
||
t.deepEqual(res.length, 1, "Returned one resource"); | ||
t.deepEqual(res[0], "result resource", "Returned one resource"); | ||
|
||
t.deepEqual(transformerStub.callCount, 1, "generateJsdocConfig called once"); | ||
t.deepEqual(transformerStub.getCall(0).args[0], "/some/path/api.json", | ||
"transform-apijson-for-sdk called with correct argument #1"); | ||
t.deepEqual(transformerStub.getCall(0).args[1], "/ignore/this/path/resource/will/be/returned", | ||
"transform-apijson-for-sdk called with correct argument #2"); | ||
t.deepEqual(transformerStub.getCall(0).args[2], "/some/path/.library", | ||
"transform-apijson-for-sdk called with correct argument #3"); | ||
t.deepEqual(transformerStub.getCall(0).args[3], [ | ||
"/some/path/x/api.json", | ||
"/some/path/y/api.json" | ||
], "transform-apijson-for-sdk called with correct argument #4"); | ||
t.deepEqual(transformerStub.getCall(0).args[4], { | ||
customFs: "custom fs", | ||
returnOutputFile: true | ||
}, "transform-apijson-for-sdk called with correct argument #5"); | ||
|
||
t.deepEqual(createResourceStub.callCount, 1, "createResource called once"); | ||
t.deepEqual(createResourceStub.getCall(0).args[0], { | ||
path: "/some/other/path/api.json", | ||
string: "api.json content" | ||
}, "createResource called with correct arguments"); | ||
|
||
mock.stop("../../../../lib/processors/jsdoc/lib/transform-apijson-for-sdk"); | ||
}); | ||
|
||
test("sdkTransformer missing parameters", async (t) => { | ||
const error = await t.throws(sdkTransformer()); | ||
t.deepEqual(error.message, "[sdkTransformer]: One or more mandatory parameters not provided", | ||
"Correct error message thrown"); | ||
}); |