Downport "Simplify running frontend tests via package.json"
package.json is an NPM manifest file that allows a project to declare its depedencies. We already ask people to use npm in our readme [1], listing the packages they need to install. This easily gets out of date. The standard for NPM is to list deps in and their versions in package.json instead. This change only adds the deps needed to run the tests, and configures the `npm test` command to run all Gerrit frontend tests. In future iterations we should also add other devDependencies and simplify our docs. If the general approach is accepted, I can send follow up changes to do that. This change further makes run_test.sh and friends work for locally installed WCT. That is generally preferrable since it does not require root, does not clutter global system paths etc. The global version is still used when installed though (for backward compatibility - we might decide to change that in future). [1] https://gerrit.googlesource.com/gerrit/+/master/polygerrit-ui/ Change-Id: I854f7b9c981721f3a00b496124110db04cc93ab6
This commit is contained in:

committed by
Thomas Draebing

parent
235eccffe0
commit
169d30d683
18
package.json
Normal file
18
package.json
Normal file
@@ -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"
|
||||
}
|
@@ -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
|
||||
<http://localhost:8081/elements/change/gr-account-entry/gr-account-entry_test.html>.
|
||||
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:
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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}
|
||||
|
Reference in New Issue
Block a user