bazel: wct tests.
Change-Id: I297312db715a0b8ca9b540ed4470e54a6b645592
This commit is contained in:
@@ -111,6 +111,14 @@ For interactively working on a single test file, do the following:
|
||||
|
||||
Then visit http://localhost:8081/elements/foo/bar_test.html
|
||||
|
||||
## Running tests (bazel)
|
||||
|
||||
Run
|
||||
|
||||
```sh
|
||||
WCT_ARGS='--some-flag' sh polygerrit-ui/app/run_test.sh
|
||||
```
|
||||
|
||||
## Style guide
|
||||
|
||||
We follow the [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml)
|
||||
|
||||
@@ -2,17 +2,10 @@ package(
|
||||
default_visibility = ["//visibility:public"])
|
||||
|
||||
load('//tools/bzl:genrule2.bzl', 'genrule2')
|
||||
load("//tools/bzl:js.bzl", "bower_component_bundle", "vulcanize")
|
||||
|
||||
bower_component_bundle(
|
||||
name = 'test_components',
|
||||
deps = [
|
||||
'//polygerrit-ui:polygerrit_components',
|
||||
'//lib/js:iron-test-helpers',
|
||||
'//lib/js:test-fixture',
|
||||
'//lib/js:web-component-tester',
|
||||
],
|
||||
)
|
||||
load(
|
||||
"//tools/bzl:js.bzl",
|
||||
"bower_component_bundle", "vulcanize",
|
||||
"bower_component", "js_component")
|
||||
|
||||
vulcanize(
|
||||
name = "gr-app",
|
||||
@@ -30,10 +23,10 @@ vulcanize(
|
||||
|
||||
filegroup(
|
||||
name = "top_sources",
|
||||
srcs = glob([
|
||||
srcs = [
|
||||
'favicon.ico',
|
||||
'index.html',
|
||||
]),
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
@@ -67,3 +60,46 @@ genrule2(
|
||||
],
|
||||
outs = [ "polygerrit_ui.zip" ],
|
||||
)
|
||||
|
||||
bower_component_bundle(
|
||||
name = 'test_components',
|
||||
deps = [
|
||||
'//polygerrit-ui:polygerrit_components',
|
||||
'//lib/js:iron-test-helpers',
|
||||
'//lib/js:test-fixture',
|
||||
'//lib/js:web-component-tester',
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "pg_code",
|
||||
srcs = glob([
|
||||
'**/*.html',
|
||||
'**/*.js',
|
||||
], exclude = [
|
||||
'bower_components/**',
|
||||
])
|
||||
)
|
||||
|
||||
genrule2(
|
||||
name = "pg_code_zip",
|
||||
outs = [ "pg_code.zip", ],
|
||||
srcs = [ ":pg_code" ],
|
||||
cmd = " && ".join([
|
||||
("tar -cf- --mtime=1980-01-01\\ 00:00 $(locations :pg_code) |"
|
||||
+ " tar --strip-components=2 -C $$TMP/ -xf-"),
|
||||
"cd $$TMP",
|
||||
"zip -rq $$ROOT/$@ *"])
|
||||
)
|
||||
|
||||
sh_test(
|
||||
name = "wct_test",
|
||||
srcs = [ "wct_test.sh" ],
|
||||
data = [
|
||||
":pg_code.zip",
|
||||
":test_components.zip",
|
||||
"test/index.html",
|
||||
],
|
||||
# Should not run sandboxed.
|
||||
tags = ["local"],
|
||||
)
|
||||
|
||||
24
polygerrit-ui/app/run_test.sh
Normal file
24
polygerrit-ui/app/run_test.sh
Normal file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
|
||||
wct_bin=$(which wct)
|
||||
if [[ -z "$wct_bin" ]]; then
|
||||
echo "WCT must be on the path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
npm_bin=$(which npm)
|
||||
if [[ -z "$npm_bin" ]]; then
|
||||
echo "NPM must be on the path."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# WCT tests are not hermetic, and need extra environment variables.
|
||||
# TODO(hanwen): does $DISPLAY even work on OSX?
|
||||
bazel test \
|
||||
--test_env="HOME=$HOME" \
|
||||
--test_env="WCT=${wct_bin}" \
|
||||
--test_env="WCT_ARGS=${WCT_ARGS}" \
|
||||
--test_env="NPM=${npm_bin}" \
|
||||
--test_env="DISPLAY=${DISPLAY}" \
|
||||
"$@" \
|
||||
//polygerrit-ui/app:wct_test
|
||||
56
polygerrit-ui/app/wct_test.sh
Executable file
56
polygerrit-ui/app/wct_test.sh
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/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/pg_code.zip
|
||||
|
||||
echo $t
|
||||
unzip -qd $t $components
|
||||
unzip -qd $t $code
|
||||
mkdir -p $t/test
|
||||
cp $TEST_SRCDIR/gerrit/polygerrit-ui/app/test/index.html $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' buck test --no-results-cache
|
||||
# --include web
|
||||
|
||||
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.11/chrome',
|
||||
'Windows 10/chrome',
|
||||
'Linux/firefox',
|
||||
'OS X 10.11/safari',
|
||||
'Windows 10/microsoftedge'
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
EOF
|
||||
|
||||
export PATH="$(dirname $WCT):$(dirname $NPM):$PATH"
|
||||
|
||||
cd $t
|
||||
test -n "${WCT}"
|
||||
|
||||
$(basename ${WCT}) ${WCT_ARGS}
|
||||
Reference in New Issue
Block a user