|
| 1 | +const test = require("ava"); |
| 2 | +const sinon = require("sinon"); |
| 3 | +const mock = require("mock-require"); |
| 4 | + |
| 5 | +function createMockResource(content, path) { |
| 6 | + return { |
| 7 | + async getBuffer() { |
| 8 | + return content; |
| 9 | + }, |
| 10 | + getPath() { |
| 11 | + return path; |
| 12 | + } |
| 13 | + }; |
| 14 | +} |
| 15 | + |
| 16 | +test("analyze: library.js with non supported property", async (t) => { |
| 17 | + const libraryJS = `sap.ui.define([ |
| 18 | + 'sap/ui/core/Core', |
| 19 | + ], function(Core) { |
| 20 | +
|
| 21 | + "use strict"; |
| 22 | +
|
| 23 | + sap.ui.getCore().initLibrary({ |
| 24 | + name : "library.test", |
| 25 | + version: "1.0.0", |
| 26 | + customProperty1: "UI5", |
| 27 | + dependencies : ["sap.ui.core"], |
| 28 | + types: [ |
| 29 | + "library.test.ButtonType", |
| 30 | + "library.test.DialogType", |
| 31 | + ], |
| 32 | + interfaces: [ |
| 33 | + "library.test.IContent", |
| 34 | + ], |
| 35 | + controls: [ |
| 36 | + "library.test.Button", |
| 37 | + "library.test.CheckBox", |
| 38 | + "library.test.Dialog", |
| 39 | + "library.test.Input", |
| 40 | + "library.test.Label", |
| 41 | + "library.test.Link", |
| 42 | + "library.test.Menu", |
| 43 | + "library.test.Text" |
| 44 | + ], |
| 45 | + elements: [ |
| 46 | + "library.test.MenuItem" |
| 47 | + ], |
| 48 | + extensions: { |
| 49 | + customExtension: "UI5" |
| 50 | + }, |
| 51 | + customProperty2: "UI5" |
| 52 | + }); |
| 53 | +
|
| 54 | + return thisLib; |
| 55 | +
|
| 56 | + });`; |
| 57 | + |
| 58 | + const librayJSPath = "library/test/library.js"; |
| 59 | + const logger = require("@ui5/logger"); |
| 60 | + const errorLogStub = sinon.stub(); |
| 61 | + const myLoggerInstance = { |
| 62 | + error: errorLogStub |
| 63 | + }; |
| 64 | + sinon.stub(logger, "getLogger").returns(myLoggerInstance); |
| 65 | + const analyzeLibraryJSWithStubbedLogger = mock.reRequire("../../../../lib/lbt/analyzer/analyzeLibraryJS"); |
| 66 | + |
| 67 | + const mockResource = createMockResource(libraryJS, librayJSPath); |
| 68 | + |
| 69 | + await analyzeLibraryJSWithStubbedLogger(mockResource); |
| 70 | + |
| 71 | + t.is(errorLogStub.callCount, 2, "Error log is called twice"); |
| 72 | + t.is(errorLogStub.getCall(0).args[0], |
| 73 | + "Unexpected property: 'customProperty1' in sap.ui.getCore().initLibrary call in 'library/test/library.js'", |
| 74 | + "The error log message of the first call is correct"); |
| 75 | + t.is(errorLogStub.getCall(1).args[0], |
| 76 | + "Unexpected property: 'customProperty2' in sap.ui.getCore().initLibrary call in 'library/test/library.js'", |
| 77 | + "The error log message of the first call is correct"); |
| 78 | +}); |
0 commit comments