Allow option to run template test on individual files

Also adds some basic documentation on using the bazel test target.

Sample usage:
bazel test //polygerrit-ui/app:template_test --test_output errors \
--test_arg=gr-list-view

Change-Id: I013f4c4e8411b6f34afb31e9baae3bb30dea5ad4
This commit is contained in:
Becky Siegel
2017-08-14 13:51:24 -07:00
parent 000ad99e84
commit 00136aacd1
3 changed files with 36 additions and 2 deletions

View File

@@ -161,4 +161,25 @@ To run polylint, execute the following command.
```sh
bazel test //polygerrit-ui/app:polylint_test
```
## Template Type Safety
Polymer elements are not type checked against the element definition, making it trivial to break the display when refactoring or moving code. We now run additional tests to help ensure that template types are checked.
A few notes to ensure that these tests pass
- Any functions with optional parameters will need closure annotations.
- Any Polymer parameters that are nullable or can be multiple types (other than the one explicitly delared) will need type annotations.
A few dependencies are necessary to run these tests:
``` sh
npm install -g typescript fried-twinkie
```
To run on all files, execute the following command:
```sh
bazel test //polygerrit-ui/app:template_test
```
To run on a specific file (ex: gr-list-view), execute the following command:
```sh
bazel test //polygerrit-ui/app:template_test --test_arg=gr-list-view
```

View File

@@ -34,4 +34,5 @@ export NODE_PATH=$(get_node_path)
unzip -o polygerrit-ui/polygerrit_components.bower_components.zip -d polygerrit-ui/app
python $TEST_SRCDIR/gerrit/polygerrit-ui/app/template_test_srcs/convert_for_template_tests.py
${node_bin} $TEST_SRCDIR/gerrit/polygerrit-ui/app/template_test_srcs/template_test.js
# Pass a file name argument from the --test_args (example: --test_arg=gr-list-view)
${node_bin} $TEST_SRCDIR/gerrit/polygerrit-ui/app/template_test_srcs/template_test.js $1

View File

@@ -42,9 +42,21 @@ fs.readdir('./polygerrit-ui/temp/behaviors/', (err, data) => {
});
}
const mappings = JSON.parse(fs.readFileSync(
let mappings = JSON.parse(fs.readFileSync(
`./polygerrit-ui/temp/map.json`, 'utf-8'));
// If a particular file was passed by the user, don't test everything.
const file = process.argv[2];
if (file) {
const mappingSpecificFile = {};
for (key of Object.keys(mappings)) {
if (key.includes(file)) {
mappingSpecificFile[key] = mappings[key];
}
}
mappings = mappingSpecificFile;
}
externs.push({
path: 'custom-externs.js',
src: '/** @externs */' +