Skip to content

Commit

Permalink
test: Add test for xmlParser
Browse files Browse the repository at this point in the history
  • Loading branch information
maxreichmann committed Jul 16, 2024
1 parent 0f0215f commit b1bef5c
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions test/lib/utils/xmlParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import test from "ava";
import {parseXML} from "../../../src/utils/xmlParser.js";
import {ReadStream} from "node:fs";
import {Readable} from "node:stream";
import {SaxEventType, Tag as SaxTag} from "sax-wasm";

test("Test xmlParser with .library", async (t) => { //TODO: Remove .only

Check failure on line 7 in test/lib/utils/xmlParser.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Expected exception block, space or tab after '//' in comment
const rawContent = `<?xml version="1.0" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd">
<name>library.with.custom.paths</name>
<vendor>SAP SE</vendor>
<version>1.0</version>
<copyright>any</copyright>
<dependencies>
<dependency>
<libraryName>sap.ui.core</libraryName>
</dependency>
<dependency>
<libraryName>sap.ca.scfld.md</libraryName>
</dependency>
<dependency>
<libraryName>sap.ca.scfld.md</libraryName>
</dependency>
<dependency>
<libraryName>sap.ca.ui</libraryName>
</dependency>
</dependencies>
</library>`;

// Convert raw .library content into stream
const contentStream = new Readable() as ReadStream;
// eslint-disable-next-line @typescript-eslint/no-empty-function
contentStream._read = () => {};
contentStream.push(rawContent);

// Call SAXParser with the contentStream
const libs = new Set();
await parseXML(contentStream, (event, tag): void => {
if (tag instanceof SaxTag &&
event === SaxEventType.CloseTag &&
tag.value === "libraryName") {
libs.add(tag);
}
});

//TODO: Test if the array "libs" contains the expected values

Check failure on line 46 in test/lib/utils/xmlParser.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Expected exception block, space or tab after '//' in comment

// t.is(libs.size, 4, "Parsed .library XML should contain 4 libraries");
//TODO: Check if first lib is "sap.ui.core"

Check failure on line 49 in test/lib/utils/xmlParser.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Expected exception block, space or tab after '//' in comment


Check failure on line 51 in test/lib/utils/xmlParser.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

More than 1 blank line not allowed
t.is(true, true, "should be true"); //TODO: remove this line

Check failure on line 52 in test/lib/utils/xmlParser.ts

View workflow job for this annotation

GitHub Actions / General checks, tests and coverage reporting

Expected exception block, space or tab after '//' in comment
});

0 comments on commit b1bef5c

Please sign in to comment.