Closed oguzeroglu closed 4 years ago
Please get rid of
done
entirely. This means that patterns such as this:fromFile('test/fixtures/bpmn/error/no-xml.txt').catch(function(err) { expect(err).to.exist; done(); }); });
...should be transformed to
try { await ... } ...
blocks.
In this test we benefit from the done() behavior, as we'd like to check if fromFile fails. The alternative would be:
var err;
try {
// await stuff...
} catch(error){
err = error;
}
expect(err).not.to.be.undefined;
Which in my opinion is not prettier, nor worth the effort just for the sake of getting rid of "done".
This does not only have the benefit of getting rid of done but also the benefit of being more understandable.
Updated the tests 👍
Added three changes on top:
Both follow the pattern we're taking with moddle-xml
.
Looking at the API I find it a bit odd that read returns a structured object (including warnings) while write returns the plain result (i.e. only the written XML string).
I remember we had an issue somewhere that write warnings are currently simply emitted to the console, as the current API does not support exposing it. Returning a complex object ({ xml, warnings, ... }
) would allow us to export that meta-data in the future. It would also mean that we offer the same, semantic API for read and write.
Getting the XML would still be as simple as
const { xml } = await moddle.write(definitions);
What do you think?
I updated the API accordingly, also squashed your commits.
Closes #71