Embedded PolyGerrit integrity test

Also, consolidate package building into a macro in
polygerrit-ui/app/rules.bzl.

Change-Id: If1f6b86639d7400760a53c7e293216da767d86a9
This commit is contained in:
Viktar Donich 2017-06-23 16:04:04 -07:00
parent 902a181aa8
commit dbe8aa864a
6 changed files with 277 additions and 77 deletions

View File

@ -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",
],
)

View File

@ -0,0 +1,51 @@
<!DOCTYPE html>
<!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>change-diff-views-embed_test</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../polygerrit_ui/elements/change-diff-views.html"/>
<script>void(0);</script>
<test-fixture id="change-view">
<template>
<gr-change-view></gr-change-view>
</template>
</test-fixture>
<test-fixture id="diff-view">
<template>
<gr-diff-view></gr-diff-view>
</template>
</test-fixture>
<script>
suite('embed test', () => {
test('gr-change-view is embedded', () => {
const element = fixture('change-view');
assert.equal(element.is, 'gr-change-view');
});
test('diff-view is embedded', () => {
const element = fixture('diff-view');
assert.equal(element.is, 'gr-diff-view');
});
});
</script>

View File

@ -0,0 +1,25 @@
<!DOCTYPE html>
<!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>Embed Test Runner</title>
<meta charset="utf-8">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<script>
WCT.loadSuites(['embed_test.html']);
</script>

57
polygerrit-ui/app/embed_test.sh Executable file
View File

@ -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 <<EOF > $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}

View File

@ -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/$@ *",
]),
)

View File

@ -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