-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INTERNAL] Enable stricter parsing of analyseLibraryJS
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
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
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,78 @@ | ||
const test = require("ava"); | ||
const sinon = require("sinon"); | ||
const mock = require("mock-require"); | ||
|
||
function createMockResource(content, path) { | ||
return { | ||
async getBuffer() { | ||
return content; | ||
}, | ||
getPath() { | ||
return path; | ||
} | ||
}; | ||
} | ||
|
||
test("analyze: library.js with non supported property", async (t) => { | ||
const libraryJS = `sap.ui.define([ | ||
'sap/ui/core/Core', | ||
], function(Core) { | ||
"use strict"; | ||
sap.ui.getCore().initLibrary({ | ||
name : "library.test", | ||
version: "1.0.0", | ||
customProperty1: "UI5", | ||
dependencies : ["sap.ui.core"], | ||
types: [ | ||
"library.test.ButtonType", | ||
"library.test.DialogType", | ||
], | ||
interfaces: [ | ||
"library.test.IContent", | ||
], | ||
controls: [ | ||
"library.test.Button", | ||
"library.test.CheckBox", | ||
"library.test.Dialog", | ||
"library.test.Input", | ||
"library.test.Label", | ||
"library.test.Link", | ||
"library.test.Menu", | ||
"library.test.Text" | ||
], | ||
elements: [ | ||
"library.test.MenuItem" | ||
], | ||
extensions: { | ||
customExtension: "UI5" | ||
}, | ||
customProperty2: "UI5" | ||
}); | ||
return thisLib; | ||
});`; | ||
|
||
const librayJSPath = "library/test/library.js"; | ||
const logger = require("@ui5/logger"); | ||
const errorLogStub = sinon.stub(); | ||
const myLoggerInstance = { | ||
error: errorLogStub | ||
}; | ||
sinon.stub(logger, "getLogger").returns(myLoggerInstance); | ||
const analyzeLibraryJSWithStubbedLogger = mock.reRequire("../../../../lib/lbt/analyzer/analyzeLibraryJS"); | ||
|
||
const mockResource = createMockResource(libraryJS, librayJSPath); | ||
|
||
await analyzeLibraryJSWithStubbedLogger(mockResource); | ||
|
||
t.is(errorLogStub.callCount, 2, "Error log is called twice"); | ||
t.is(errorLogStub.getCall(0).args[0], | ||
"Unexpected property: 'customProperty1' in sap.ui.getCore().initLibrary call in 'library/test/library.js'", | ||
"The error log message of the first call is correct"); | ||
t.is(errorLogStub.getCall(1).args[0], | ||
"Unexpected property: 'customProperty2' in sap.ui.getCore().initLibrary call in 'library/test/library.js'", | ||
"The error log message of the first call is correct"); | ||
}); |