xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.19k stars 375 forks source link

Mention XML string parse script #879

Closed silverbucket closed 3 years ago

sonnyp commented 3 years ago

thanks for the contribution

Can I ask what is your use case and why you use parse ?

I'm not 100% about publicly exposing it yet

silverbucket commented 3 years ago

Hi @sonnyp, I use it for writing unit tests. I have a list of incoming XML stanzas as strings, and need to verify that my module produces the expected output. However since xmpp.js already provides xml objects to the stanza handler, I need an easy way to call the stanza handler with the same xml object. I imagine this would be useful for just about anyone that wants to write unit tests for their stanza handler.

An example of a WIP set of tests: https://github.com/sockethub/sockethub/blob/c353a87a3f260b65ffc2afe738716e6d19801ae2/packages/sockethub-platform-xmpp/src/incoming-handlers.test.js

It actually took me a while to find out how to parse an XML string and I think that with xmpp.js being the authoritative tool for XMPP in node.js, it should be a clearly documented feature.

sonnyp commented 3 years ago

Thanks.

Okay there is nothing specific about it being unit tests, it's just how you choose to write xml there correct?

It actually took me a while to find out how to parse an XML string and I think that with xmpp.js being the authoritative tool for XMPP in node.js, it should be a clearly documented feature.

Fair

There should be a warning about untrusted input though and how it should not be used with substitutions. I will add one and merge.

silverbucket commented 3 years ago

Okay there is nothing specific about it being unit tests, it's just how you choose to write xml there correct?

Correct, it seems easier to write the XML stanza as the test input, rather than writing out xml objects by hand.

There should be a warning about untrusted input though and how it should not be used with substitutions. I will add one and merge.

Great, thanks!