diff --git a/package.json b/package.json new file mode 100644 index 0000000000..0c99089570 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "gerrit", + "version": "3.1.0-SNAPSHOT", + "description": "Gerrit Code Review", + "dependencies": {}, + "devDependencies": { + "web-component-tester": "^6.5.0" + }, + "scripts": { + "test": "WCT_HEADLESS_MODE=1 WCT_ARGS='--verbose -l chrome' ./polygerrit-ui/app/run_test.sh" + }, + "repository": { + "type": "git", + "url": "https://gerrit.googlesource.com/gerrit" + }, + "author": "", + "license": "Apache-2.0" +} diff --git a/polygerrit-ui/README.md b/polygerrit-ui/README.md index 5d0d22f6e8..f785ac9652 100644 --- a/polygerrit-ui/README.md +++ b/polygerrit-ui/README.md @@ -27,14 +27,14 @@ Various steps below require installing additional npm packages. The full list of dependencies can be installed with: ```sh +npm install sudo npm install -g \ eslint \ eslint-config-google \ eslint-plugin-html \ typescript \ fried-twinkie \ - polylint \ - web-component-tester + polylint ``` It may complain about a missing `typescript@2.3.4` peer dependency, which is @@ -53,14 +53,16 @@ you to use the "test data" technique described below. To test the local UI against gerrit-review.googlesource.com: ```sh -./run-server.sh +./polygerrit-ui/run-server.sh ``` Then visit http://localhost:8081 ## Local UI, Test Data -One-time setup: +```sh +./polygerrit-ui/run-server.sh --plugins=plugins/my_plugin/static/my_plugin.js,plugins/my_plugin/static/my_plugin.html +``` 1. [Build Gerrit](https://gerrit-review.googlesource.com/Documentation/dev-bazel.html#_gerrit_development_war_file) 2. Set up a local test site. Docs @@ -100,10 +102,17 @@ This step requires the `web-component-tester` npm module. Note: it may be necessary to add the options `--unsafe-perm=true --allow-root` to the `npm install` command to avoid file permission errors. -Run all web tests: +For daily development you typically only want to run and debug individual tests. +Run the local [Go proxy server](#go-server) and navigate for example to +. +Check "Disable cache" in the "Network" tab of Chrome's dev tools, so code +changes are picked up on "reload". + +Our CI integration ensures that all tests are run when you upload a change to +Gerrit, but you can also run all tests locally in headless mode: ```sh -./polygerrit-ui/app/run_test.sh +npm test ``` To allow the tests to run in Safari: @@ -111,24 +120,10 @@ To allow the tests to run in Safari: * In the Advanced preferences tab, check "Show Develop menu in menu bar". * In the Develop menu, enable the "Allow Remote Automation" option. -If you need to pass additional arguments to `wct`: - -```sh -WCT_ARGS='-p --some-flag="foo bar"' ./polygerrit-ui/app/run_test.sh -``` - -For interactively working on a single test file, do the following: - -```sh -./polygerrit-ui/run-server.sh -``` - -Then visit http://localhost:8081/elements/foo/bar_test.html - To run Chrome tests in headless mode: ```sh -WCT_HEADLESS_MODE=1 ./polygerrit-ui/app/run_test.sh +WCT_HEADLESS_MODE=1 WCT_ARGS='--verbose -l chrome' ./polygerrit-ui/app/run_test.sh ``` Toolchain requirements for headless mode: diff --git a/polygerrit-ui/app/run_test.sh b/polygerrit-ui/app/run_test.sh index 7b48480ce5..e9be18d65d 100755 --- a/polygerrit-ui/app/run_test.sh +++ b/polygerrit-ui/app/run_test.sh @@ -6,9 +6,29 @@ if [[ -z "$npm_bin" ]]; then exit 1 fi +# From https://www.linuxquestions.org/questions/programming-9/bash-script-return-full-path-and-filename-680368/page3.html +function abs_path { + if [[ -d "$1" ]] + then + pushd "$1" >/dev/null + pwd + popd >/dev/null + elif [[ -e $1 ]] + then + pushd "$(dirname "$1")" >/dev/null + echo "$(pwd)/$(basename "$1")" + popd >/dev/null + else + echo "$1" does not exist! >&2 + return 127 + fi +} wct_bin=$(which wct) if [[ -z "$wct_bin" ]]; then - echo "WCT must be on the path. (https://github.com/Polymer/web-component-tester)" + wct_bin=$(abs_path ./node_modules/web-component-tester/bin/wct); +fi +if [[ -z "$wct_bin" ]]; then + echo "wct_bin must be set or WCT locally installed (npm install wct)." exit 1 fi diff --git a/polygerrit-ui/app/wct_test.sh b/polygerrit-ui/app/wct_test.sh index a8394cdb31..dd16ba7e1d 100755 --- a/polygerrit-ui/app/wct_test.sh +++ b/polygerrit-ui/app/wct_test.sh @@ -60,9 +60,9 @@ module.exports = { }; EOF -export PATH="$(dirname $WCT):$(dirname $NPM):$PATH" +export PATH="$(dirname $NPM):$PATH" cd $t test -n "${WCT}" -$(basename ${WCT}) ${WCT_ARGS} +${WCT} ${WCT_ARGS}