Skip to content

Idea for Output Validation Testing#86

Open
kellertobias wants to merge 1 commit intojslno:mainfrom
kellertobias:main
Open

Idea for Output Validation Testing#86
kellertobias wants to merge 1 commit intojslno:mainfrom
kellertobias:main

Conversation

@kellertobias
Copy link

@kellertobias kellertobias commented Jul 13, 2025

Here's an Idea on how you could add output validation testing to your project.
We are using the java library "mustang" - you need to have java installed, the jar file is downloaded automatically during test setup.

Alternatively we could implement this using testcontainers (and the setup installed in there).

Here you could add multiple scenarios and validate their output.

Just a quick draft, nothing sophisticated

@kellertobias
Copy link
Author

Edit: oh, I didn't see that you have already installed a testing framework in a subfolder. You of course could move the tests down there.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 13, 2025

Open in StackBlitz

npm i https://pkg.pr.new/jslno/node-zugferd/@node-zugferd/api@86
npm i https://pkg.pr.new/jslno/node-zugferd@86

commit: 240af47

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic found 4 issues across 7 files. Review them in cubic.dev

React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.

testTimeout: 60000,
hookTimeout: 60000,
// Run all test files sequentially to avoid DynamoDB table race conditions
fileParallelism: false,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'fileParallelism' is not a documented Vitest configuration option. The correct option to control parallelism is 'threads' or 'sequence.concurrent'. Using undocumented options may have no effect and could cause confusion.

if (!Array.isArray(current) || current.length <= index - 1) {
return;
}
current = current[index - 1];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code accesses current[index - 1], but index is already zero-based. This will result in off-by-one errors, returning the wrong element or undefined. It should use current[index].

Suggested change
current = current[index - 1];
current = current[index];

return;
}

if (!Array.isArray(current) && index === 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is incorrect: it checks for index === 1, but array indices are zero-based. It also skips the array check if index is 1, which is inconsistent with the rest of the function and may cause incorrect traversal or missed elements.

Suggested change
if (!Array.isArray(current) && index === 1) {
if (!Array.isArray(current) && index > 0) { continue; }

* @param location - The dot-separated path (e.g., 'CrossIndustryInvoice[0].TypeCode[1]')
* @returns The value at the specified location, or undefined if not found
*/
export function getValueFromXmlJson(source: any, location: string) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function does not ignore XML namespaces when matching tags, despite the documentation stating it should. It directly accesses current[tag], which will not work if the keys include namespaces (e.g., 'ram:TypeCode'). This can cause the function to fail to retrieve values as intended.

@jslno
Copy link
Owner

jslno commented Aug 7, 2025

Thanks, this was very helpful!
I ended up taking a slightly different approach to support third-party validators outside of tests as well.
Once #105 is more stable and merged, I’ll plan to close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants