Skip to content

Commit

Permalink
added xml validation in typescript tests via @raxb/validate-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
jueseitz committed Aug 2, 2024
1 parent 6ee556d commit 2add9ee
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"vitest": "^2.0.5"
},
"devDependencies": {
"@raxb/validate-wasm": "^0.5.0",
"@tsconfig/node20": "^20.1.4",
"@tsconfig/recommended": "^1.0.6",
"@types/node": "^22.0.2",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/quality_report_minimal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@ import quality_report_minimal from './quality_report_minimal.json'
import fs from 'fs'
import path from 'path'
const __dirname = import.meta.dirname;
import xmlvalidate, { XmlValidatorError } from '@raxb/validate-wasm'
const xsdBundle = fs.readFileSync(path.resolve(__dirname, '../target/schemas/out/980faa7cf81d51eab3f26de770ae345d.xsdb')).buffer;

describe("simple xml generation via wasm", async () => {
const { XmlValidator } = await xmlvalidate();
const validator = new XmlValidator(new Uint8Array(xsdBundle));
validator.init((err: string) => {
console.error(err);
});

it("should be able to create quality report xml", async () => {
const xml = create_vorgang_transportieren_2010(quality_report_minimal as any as VorgangTransportieren2010)
.replace("https://gitlab.opencode.de/akdb/xoev/xwasser/-/raw/main/V0_5_0 xwasser.xsd", "https://gitlab.opencode.de/akdb/xoev/xwasser/-/raw/main/V0_5_0 ../schemas/V0_5_0/xwasser.xsd");
const expected_xml = fs.readFileSync(path.resolve(__dirname, './quality_report_minimal_test_result.xml'), 'utf-8');
expect(xml).to.equal(expected_xml);
validator.validateXml(xml, (err: XmlValidatorError) => {
console.log({ level: err.level, line: err.line, message: err.message });
})
});

it("should be able to parse quality report xml", async () => {
const source = fs.readFileSync(path.resolve(__dirname, './quality_report_minimal.xml'), 'utf-8');
const obj = parse_vorgang_transportieren_2010(source)
Expand Down

0 comments on commit 2add9ee

Please sign in to comment.