docson
docson copied to clipboard
Revive tests/test.html
As mentioned in #77, tests/test.html appears to have been left behind and currently neither works nor tests the current code. There are automated tests now, which is certainly better, but their coverage is limited, so I think the examples in test.html are still useful as additional manual regression tests. This commit revives them.
Fixing the “works” part required:
- Adapting paths to the move of several things into public/.
- Fixing the
$.get()
call that does not seem to automatically decode JSON when it's coming from a file:// URL.
To fix the “test the current code” part, it replaces the outdated public/docson.js by public/js/docson.js that is built from current sources: A script that can be loaded in the browser and exports the docson API as a global variable. (It also exports the bundled jQuery as a convenience to test.html that uses it, so it doesn’t have to bring its own copy, but if there is a better solution for that, src/index.js could also be webpacked directly.) Note that I’m not familiar with webpack and may be using it wrong, I just did what appears to work.
As an alternative solution, I first tried using widget.js, but gave up after hitting several obstacles: #73, it wouldn’t work when the <script>
tags were generated by code rather than present in static HTML (apparently document.write()
has no effect then), and the many iframes just looked messy.
The commit also removes public/lib/ that is not used by anything anymore.
I’m not sure what to do about the new generated file public/js/docson.js (as well as lib/docson.browser.js, which occured as a byproduct and is probably useless): My usual solution would be to add it to .gitignore, but then other generated files are committed and appear to be updated occasionally in a separate commit before a release, so I left it alone.
This reveals several deficiencies compared to http://lbovet.github.io/docson/tests/test.html, I will try to fix some of them in subsequent pull requests to make the tests useful again for regression-testing my own changes.