Skip to content

Commit

Permalink
fix: failing test and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
marufrasully committed Aug 7, 2024
1 parent 151616f commit 7d30ae9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
4 changes: 3 additions & 1 deletion packages/context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"lodash": "4.17.21",
"semver": "7.3.7",
"vscode-languageserver": "8.0.2",
"vscode-uri": "2.1.2"
"vscode-uri": "2.1.2",
"@xml-tools/ast": "5.0.0",
"@xml-tools/parser": "1.0.7"
},
"devDependencies": {
"@sap-ux/vocabularies-types": "0.10.14",
Expand Down
7 changes: 3 additions & 4 deletions packages/context/src/utils/view-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ async function processViewFiles(
export async function getViewFiles(
webappPath: string
): Promise<Record<DocPath, XMLDocument>> {
let files = cache.getViewFiles(webappPath);
if (Object.keys(files).length > 0) {
return files;
if (Object.keys(cache.getViewFiles(webappPath)).length > 0) {
return cache.getViewFiles(webappPath);
}
files = await processViewFiles(webappPath);
const files = await processViewFiles(webappPath);
cache.setViewFiles(webappPath, files);
return files;
}
7 changes: 6 additions & 1 deletion packages/context/test/unit/utils/view-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ describe("view-files", () => {
const getViewFilesStub = jest
.spyOn(cache, "getViewFiles")
.mockReturnValue({ documentPath: {} as XMLDocument });

const projectRoot = testFramework.getProjectRoot();
const webapp = join(projectRoot, "app", "manage_travels", "webapp");
// act
const viewFiles = await getViewFiles(webapp);
// assert
expect(getViewFilesStub).toHaveBeenCalledOnce();
expect(getViewFilesStub).toHaveBeenCalledTimes(2);
expect(Object.keys(viewFiles).length).toBeGreaterThan(0);
});

it("get view files", async () => {
// arrange
cache.reset();
const getViewFilesStub = jest
.spyOn(cache, "getViewFiles")
.mockReturnValue({});
const projectRoot = testFramework.getProjectRoot();
const webapp = join(projectRoot, "app", "manage_travels", "webapp");
const documentPath = join(
Expand All @@ -57,6 +61,7 @@ describe("view-files", () => {
// act
const viewFiles = await getViewFiles(webapp);
// assert
expect(getViewFilesStub).toHaveBeenCalledTimes(1);
expect(Object.keys(viewFiles).length).toBeGreaterThan(1);
expect(viewFiles[documentPath]).toBeDefined();
});
Expand Down
5 changes: 3 additions & 2 deletions packages/language-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,9 @@ connection.onDidChangeWatchedFiles(async (changeEvent): Promise<void> => {
} else if (uri.endsWith(".xml")) {
await reactOnXmlFileChange(uri, change.type);
if (
change.type === FileChangeType.Created ||
change.type === FileChangeType.Deleted
isXMLView(uri) &&
(change.type === FileChangeType.Created ||
change.type === FileChangeType.Deleted)
) {
// revalidate - needed to assure unique ID
validateOpenDocuments();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("index", () => {
let uri = "";
const pathSegments = ["src", "view", "App.view.xml"];
beforeEach(function () {
context.cache.reset();
const useConfig: Config = {
projectInfo: {
name: ProjectName.tsFreeStyle,
Expand All @@ -35,7 +36,7 @@ describe("index", () => {
// arrange
const param: DefinitionParams = {
position: {} as Position,
textDocument: { uri: "file:\\dummy" },
textDocument: { uri },
};
jest.spyOn(fs.promises, "readFile").mockResolvedValue("");
// act
Expand Down
1 change: 1 addition & 0 deletions packages/xml-views-validation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@ui5-language-assistant/semantic-model": "4.0.17",
"@ui5-language-assistant/test-utils": "4.0.14",
"@xml-tools/parser": "1.0.7",
"chevrotain": "10.4.2",
"@ui5-language-assistant/test-framework": "4.0.12"
},
"scripts": {
Expand Down

0 comments on commit 7d30ae9

Please sign in to comment.