Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: run_tests.py

Issue 5090313282519040: Issue 517 - [Typed objects] Make unit tests compatible with Chrome and Safari (Closed)
Patch Set: Created May 19, 2014, 7:52 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « .hgsubstate ('k') | test/common.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: run_tests.py
===================================================================
--- a/run_tests.py
+++ b/run_tests.py
@@ -26,24 +26,36 @@ app = flask.Flask(__name__)
def js_encode(str):
return re.sub(r"(['\\])", r"\\\1", str)
@app.route("/<path:path>", methods = ["GET"])
@app.route("/", methods = ["GET"])
def multiplex(path=""):
request_url = urlparse(flask.request.url)
request_path = request_url.path
- if request_path.startswith("/lib/"):
- path = flask.safe_join(os.path.dirname(__file__), request_path.lstrip("/"))
+ islib = request_path.startswith("/lib/")
+ backcompat = request_url.query == "backcompat"
+
+ rootdir = os.path.dirname(__file__)
+ if not islib:
+ rootdir = os.path.join("test")
+
+ if islib or backcompat:
+ path = flask.safe_join(rootdir, request_path.lstrip("/"))
if not os.path.isfile(path):
return flask.abort(404)
- with open(path, "rb") as file:
- module = os.path.splitext(request_path[len("/lib/"):])[0]
- data = "require.scopes['%s'] = function(){exports={};%s\nreturn exports;}();" % (module, file.read())
- return (data, 200, {"Content-Type": "application/javascript; charset=utf-8"})
+ module = os.path.splitext(request_path[len("/lib/"):])[0]
+ if backcompat:
+ from jshydra.abp_rewrite import doRewrite
+ data = doRewrite([os.path.abspath(path)], ["module=true"] if islib else [])
+ data = re.sub(r"require\.scopes\[.*?\]", "require.scopes['%s']" % module, data)
+ else:
+ with open(path, "rb") as file:
+ data = "require.scopes['%s'] = function(){var exports={};%s\nreturn exports;}();" % (module, file.read())
+ return (data, 200, {"Content-Type": "application/javascript; charset=utf-8"})
else:
if request_path.endswith("/"):
request_path += "index.html"
- return flask.send_from_directory(os.path.join(os.path.dirname(__file__), "test"), request_path.lstrip("/"))
+ return flask.send_from_directory(rootdir, request_path.lstrip("/"))
if __name__ == "__main__":
app.run(debug=True)
« no previous file with comments | « .hgsubstate ('k') | test/common.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld