diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD index f334354170..04a1d69cbe 100644 --- a/polygerrit-ui/app/BUILD +++ b/polygerrit-ui/app/BUILD @@ -2,6 +2,7 @@ package( default_visibility = ["//visibility:public"], ) +load(":rules.bzl", "polygerrit_bundle") load("//tools/bzl:genrule2.bzl", "genrule2") load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary") load( @@ -12,8 +13,8 @@ load( "js_component", ) -vulcanize( - name = "gr-app", +polygerrit_bundle( + name = "polygerrit_ui", srcs = glob( [ "**/*.html", @@ -27,82 +28,7 @@ vulcanize( ], ), app = "elements/gr-app.html", - deps = ["//polygerrit-ui:polygerrit_components.bower_components"], -) - -closure_js_library( - name = "closure_lib", - srcs = ["gr-app.js"], - convention = "GOOGLE", - # TODO(davido): Clean up these issues: http://paste.openstack.org/show/608548 - # and remove this supression - suppress = ["JSC_UNUSED_LOCAL_ASSIGNMENT"], - deps = [ - "//lib/polymer_externs:polymer_closure", - "@io_bazel_rules_closure//closure/library", - ], -) - -closure_js_binary( - name = "closure_bin", - # Known issue: Closure compilation not compatible with Polymer behaviors. - # See: https://github.com/google/closure-compiler/issues/2042 - compilation_level = "WHITESPACE_ONLY", - defs = [ - "--polymer_pass", - "--jscomp_off=duplicate", - "--force_inject_library=es6_runtime", - ], - language = "ECMASCRIPT5", - deps = [":closure_lib"], -) - -filegroup( - name = "top_sources", - srcs = [ - "favicon.ico", - "index.html", - ], -) - -filegroup( - name = "css_sources", - srcs = glob(["styles/**/*.css"]), -) - -filegroup( - name = "app_sources", - srcs = [ - "closure_bin.js", - "gr-app.html", - ], -) - -genrule2( - name = "polygerrit_ui", - srcs = [ - "//lib/fonts:robotomono", - "//lib/js:highlightjs_files", - ":top_sources", - ":css_sources", - ":app_sources", - # we extract from the zip, but depend on the component for license checking. - "@webcomponentsjs//:zipfile", - "//lib/js:webcomponentsjs", - ], outs = ["polygerrit_ui.zip"], - cmd = " && ".join([ - "mkdir -p $$TMP/polygerrit_ui/{styles,fonts,bower_components/{highlightjs,webcomponentsjs},elements}", - "for f in $(locations :app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/gr-app.$$ext; done", - "cp $(locations //lib/fonts:robotomono) $$TMP/polygerrit_ui/fonts/", - "for f in $(locations :top_sources); do cp $$f $$TMP/polygerrit_ui/; done", - "for f in $(locations :css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done", - "for f in $(locations //lib/js:highlightjs_files); do cp $$f $$TMP/polygerrit_ui/bower_components/highlightjs/ ; done", - "unzip -qd $$TMP/polygerrit_ui/bower_components $(location @webcomponentsjs//:zipfile) webcomponentsjs/webcomponents-lite.js", - "cd $$TMP", - "find . -exec touch -t 198001010000 '{}' ';'", - "zip -qr $$ROOT/$@ *", - ]), ) bower_component_bundle( @@ -198,3 +124,49 @@ sh_test( "manual", ], ) + +# Embed bundle +polygerrit_bundle( + name = "polygerrit_embed_ui", + srcs = glob( + [ + "**/*.html", + "**/*.js", + ], + exclude = [ + "bower_components/**", + "index.html", + "test/**", + "**/*_test.html", + ], + ), + app = "embed/change-diff-views.html", + outs = ["polygerrit_embed_ui.zip"], +) + +filegroup( + name = "embed_test_files", + srcs = glob( + [ + "embed/**/*_test.html", + ], + ), +) + +sh_test( + name = "embed_test", + size = "large", + srcs = ["embed_test.sh"], + data = [ + "test/common-test-setup.html", + "embed/test.html", + ":embed_test_files", + ":polygerrit_embed_ui.zip", + ":test_components.zip", + ], + # Should not run sandboxed. + tags = [ + "local", + "manual", + ], +) diff --git a/polygerrit-ui/app/embed/embed_test.html b/polygerrit-ui/app/embed/embed_test.html new file mode 100644 index 0000000000..26ea8956a7 --- /dev/null +++ b/polygerrit-ui/app/embed/embed_test.html @@ -0,0 +1,51 @@ + + + + +change-diff-views-embed_test + + + + + + + + + + + + + + + + diff --git a/polygerrit-ui/app/embed/test.html b/polygerrit-ui/app/embed/test.html new file mode 100644 index 0000000000..0587562361 --- /dev/null +++ b/polygerrit-ui/app/embed/test.html @@ -0,0 +1,25 @@ + + + + +Embed Test Runner + + + + diff --git a/polygerrit-ui/app/embed_test.sh b/polygerrit-ui/app/embed_test.sh new file mode 100755 index 0000000000..adcc653fd5 --- /dev/null +++ b/polygerrit-ui/app/embed_test.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +set -ex + +t=$(mktemp -d || mktemp -d -t wct-XXXXXXXXXX) +components=$TEST_SRCDIR/gerrit/polygerrit-ui/app/test_components.zip +code=$TEST_SRCDIR/gerrit/polygerrit-ui/app/polygerrit_embed_ui.zip +index=$TEST_SRCDIR/gerrit/polygerrit-ui/app/embed/test.html +tests=$TEST_SRCDIR/gerrit/polygerrit-ui/app/embed/*_test.html + +unzip -qd $t $components +unzip -qd $t $code +mkdir -p $t/test +cp $index $t/test/ +cp $tests $t/test/ + +# For some reason wct tries to install selenium into its node_modules +# directory on first run. If you've installed into /usr/local and +# aren't running wct as root, you're screwed. Turning this option off +# through skipSeleniumInstall seems to still work, so there's that. + +# Sauce tests are disabled by default in order to run local tests +# only. Run it with (saucelabs.com account required; free for open +# source): WCT_ARGS='--plugin sauce' ./polygerrit-ui/app/embed_test.sh + +cat < $t/wct.conf.js +module.exports = { + 'suites': ['test'], + 'webserver': { + 'pathMappings': [ + {'/components/bower_components': 'bower_components'} + ] + }, + 'plugins': { + 'local': { + 'skipSeleniumInstall': true + }, + 'sauce': { + 'disabled': true, + 'browsers': [ + 'OS X 10.12/chrome', + 'Windows 10/chrome', + 'Linux/firefox', + 'OS X 10.12/safari', + 'Windows 10/microsoftedge' + ] + } + } + }; +EOF + +export PATH="$(dirname $WCT):$(dirname $NPM):$PATH" + +cd $t +test -n "${WCT}" + +$(basename ${WCT}) ${WCT_ARGS} diff --git a/polygerrit-ui/app/rules.bzl b/polygerrit-ui/app/rules.bzl new file mode 100644 index 0000000000..be80c13faf --- /dev/null +++ b/polygerrit-ui/app/rules.bzl @@ -0,0 +1,94 @@ +load("//tools/bzl:genrule2.bzl", "genrule2") +load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary") +load( + "//tools/bzl:js.bzl", + "bower_component_bundle", + "vulcanize", + "bower_component", + "js_component", +) + +def polygerrit_bundle(name, srcs, outs, app): + appName = app.split(".html")[0].split("/").pop() # eg: gr-app + + closure_js_binary( + name = name + "_closure_bin", + # Known issue: Closure compilation not compatible with Polymer behaviors. + # See: https://github.com/google/closure-compiler/issues/2042 + compilation_level = "WHITESPACE_ONLY", + defs = [ + "--polymer_pass", + "--jscomp_off=duplicate", + "--force_inject_library=es6_runtime", + ], + language = "ECMASCRIPT5", + deps = [name + "_closure_lib"], + ) + + closure_js_library( + name = name + "_closure_lib", + srcs = [appName + ".js"], + convention = "GOOGLE", + # TODO(davido): Clean up these issues: http://paste.openstack.org/show/608548 + # and remove this supression + suppress = ["JSC_UNUSED_LOCAL_ASSIGNMENT"], + deps = [ + "//lib/polymer_externs:polymer_closure", + "@io_bazel_rules_closure//closure/library", + ], + ) + + vulcanize( + name = appName, + srcs = srcs, + app = app, + deps = ["//polygerrit-ui:polygerrit_components.bower_components"], + ) + + native.filegroup( + name = name + "_app_sources", + srcs = [ + name + "_closure_bin.js", + appName + ".html", + ], + ) + + native.filegroup( + name = name + "_css_sources", + srcs = native.glob(["styles/**/*.css"]), + ) + + native.filegroup( + name = name + "_top_sources", + srcs = [ + "favicon.ico", + "index.html", + ], + ) + + genrule2( + name = name, + srcs = [ + name + "_app_sources", + name + "_css_sources", + name + "_top_sources", + "//lib/fonts:robotomono", + "//lib/js:highlightjs_files", + # we extract from the zip, but depend on the component for license checking. + "@webcomponentsjs//:zipfile", + "//lib/js:webcomponentsjs" + ], + outs = outs, + cmd = " && ".join([ + "mkdir -p $$TMP/polygerrit_ui/{styles,fonts,bower_components/{highlightjs,webcomponentsjs},elements}", + "for f in $(locations " + name + "_app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/" + appName + ".$$ext; done", + "cp $(locations //lib/fonts:robotomono) $$TMP/polygerrit_ui/fonts/", + "for f in $(locations " + name + "_top_sources); do cp $$f $$TMP/polygerrit_ui/; done", + "for f in $(locations "+ name + "_css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done", + "for f in $(locations //lib/js:highlightjs_files); do cp $$f $$TMP/polygerrit_ui/bower_components/highlightjs/ ; done", + "unzip -qd $$TMP/polygerrit_ui/bower_components $(location @webcomponentsjs//:zipfile) webcomponentsjs/webcomponents-lite.js", + "cd $$TMP", + "find . -exec touch -t 198001010000 '{}' ';'", + "zip -qr $$ROOT/$@ *", + ]), + ) diff --git a/polygerrit-ui/app/run_test.sh b/polygerrit-ui/app/run_test.sh index c2421ad5aa..0edf41c5b0 100755 --- a/polygerrit-ui/app/run_test.sh +++ b/polygerrit-ui/app/run_test.sh @@ -21,4 +21,5 @@ bazel test \ --test_env="NPM=${npm_bin}" \ --test_env="DISPLAY=${DISPLAY}" \ "$@" \ + //polygerrit-ui/app:embed_test \ //polygerrit-ui/app:wct_test