Skip to content

Instantly share code, notes, and snippets.

@d0c-s4vage
Created October 22, 2014 11:05
Show Gist options
  • Save d0c-s4vage/9aaa97cbb875b172a6c3 to your computer and use it in GitHub Desktop.
Save d0c-s4vage/9aaa97cbb875b172a6c3 to your computer and use it in GitHub Desktop.
mocha-phantomjs html generator
#!/usr/bin/env python
import os
import glob
import sys
def create_html_for_js(js_file):
html = """<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>
<script>
mocha.ui('bdd');
mocha.reporter('html');
expect = chai.expect;
</script>
<script src="%s"></script>
<script>
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.run();
}
</script>
</body>
</html>
""" % (js_file)
with open(js_file.replace(".js", ".html"), "w") as f:
f.write(html)
if __name__ == "__main__":
for js_file in glob.glob(os.path.join(sys.argv[1], "*.js")):
create_html_for_js(js_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment