Commit 27d5bb46 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Prefix includes in html files generated by js_unit_test.py

This allows the html files generated under out/foo/gen/.... to be opened
in Chrome as a file:/// URL. It doesn't affect how the files are served
by the embedded test server (leading ../..'s are ignored).

Bug: 860355
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I6a7a8838c6158f9f5cdeb9fa8e0745c23d88f602
Reviewed-on: https://chromium-review.googlesource.com/c/1264095Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597016}
parent 9998d996
...@@ -26,6 +26,8 @@ def main(): ...@@ -26,6 +26,8 @@ def main():
help='List of additional js files to load before others') help='List of additional js files to load before others')
parser.add_argument('-o', '--output', parser.add_argument('-o', '--output',
help='Generated html output with flattened dependencies') help='Generated html output with flattened dependencies')
parser.add_argument('-I', '--include_prefix', default='',
help='Prefix added to src= paths to find .js files')
args = parser.parse_args() args = parser.parse_args()
uniquedeps = Flatten([args.input]) uniquedeps = Flatten([args.input])
...@@ -46,9 +48,9 @@ window.addEventListener('error', function(e) { ...@@ -46,9 +48,9 @@ window.addEventListener('error', function(e) {
""") """)
for file in args.mocks: for file in args.mocks:
out.write('<script src="%s"></script>\n' % (file)) out.write('<script src="%s%s"></script>\n' % (args.include_prefix, file))
for file in uniquedeps: for file in uniquedeps:
out.write('<script src="%s"></script>\n' % (file)) out.write('<script src="%s%s"></script>\n' % (args.include_prefix, file))
out.write('</body>\n</html>\n') out.write('</body>\n</html>\n')
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -61,6 +61,14 @@ template("js_unit_tests") { ...@@ -61,6 +61,14 @@ template("js_unit_tests") {
args = [ "--output" ] + rebase_path(outputs, root_build_dir) args = [ "--output" ] + rebase_path(outputs, root_build_dir)
args += [ "--input" ] + [ "{{source}}" ] args += [ "--input" ] + [ "{{source}}" ]
# js_unit_test.py needs to walk .js_library dependency files relative to the
# gen_dir, but we'd like to reference the corresponding .js source files
# in the source dir, not the gen dir. Pass a prefix to remap --input args.
args += [
"--include_prefix",
rebase_path("//", "{{root_gen_dir}}", "//"),
]
if (defined(mocks)) { if (defined(mocks)) {
args += [ "--mocks" ] + rebase_path(mocks, root_build_dir) args += [ "--mocks" ] + rebase_path(mocks, root_build_dir)
data = mocks data = mocks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment