From 2add9ee6ec13e7d684f8cbcb456e68b8ad0fd36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Seitz?= Date: Fri, 2 Aug 2024 16:43:57 +0200 Subject: [PATCH] added xml validation in typescript tests via @raxb/validate-wasm --- package.json | 1 + pnpm-lock.yaml | 8 ++++++++ tests/quality_report_minimal.test.ts | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/package.json b/package.json index 317c195..5a04510 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a809f41..30198b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,6 +15,9 @@ importers: specifier: ^2.0.5 version: 2.0.5(@types/node@22.0.2)(jsdom@24.1.0) devDependencies: + '@raxb/validate-wasm': + specifier: ^0.5.0 + version: 0.5.0 '@tsconfig/node20': specifier: ^20.1.4 version: 20.1.4 @@ -221,6 +224,9 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} + '@raxb/validate-wasm@0.5.0': + resolution: {integrity: sha512-r7ANN/weOwK01hq1TImESuWpK8NAa2FgLELYZurxizuoIP6aDs487vJRbx9BWxgY22yQ8jWp+5VGPFJ7h1wadA==} + '@rollup/plugin-virtual@3.0.2': resolution: {integrity: sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==} engines: {node: '>=14.0.0'} @@ -1385,6 +1391,8 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true + '@raxb/validate-wasm@0.5.0': {} + '@rollup/plugin-virtual@3.0.2(rollup@4.18.0)': optionalDependencies: rollup: 4.18.0 diff --git a/tests/quality_report_minimal.test.ts b/tests/quality_report_minimal.test.ts index 67f0bb7..1e0dc5b 100644 --- a/tests/quality_report_minimal.test.ts +++ b/tests/quality_report_minimal.test.ts @@ -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)