Use node modules in wct tests

Update wct tests to use node modules instead of bower components.

Change-Id: I1533279c9bc92b56b2de29070e6b2cc2137e7b06
This commit is contained in:
Dmitrii Filippov 2020-01-23 18:14:51 +01:00
parent fbdc89d307
commit e629c9b0ba
21 changed files with 7023 additions and 142 deletions

@ -56,6 +56,7 @@ go_binary(
srcs = ["server.go"],
data = [
":fonts.zip",
"@ui_dev_npm//:node_modules",
"@ui_npm//:node_modules",
],
deps = [

@ -1,6 +1,7 @@
load("//tools/bzl:genrule2.bzl", "genrule2")
load("//tools/bzl:js.bzl", "bower_component_bundle")
load(":rules.bzl", "polygerrit_bundle")
load("//tools/node_tools/polygerrit_app_preprocessor:index.bzl", "update_links")
package(default_visibility = ["//visibility:public"])
@ -83,15 +84,38 @@ genrule2(
]),
)
# update_links - temporary action. Later links/references will be updated in repository,
# so this rule will be removed.
update_links(
name = "test-srcs-updated-links",
srcs = [
"test/common-test-setup.html",
"test/index.html",
":pg_code",
],
redirects = "redirects.json",
)
# Workaround for https://github.com/bazelbuild/bazel/issues/1305
filegroup(
name = "test-srcs-updated-links-fg",
srcs = [
":test-srcs-updated-links",
"@ui_dev_npm//:node_modules",
"@ui_npm//:node_modules",
],
)
sh_test(
name = "wct_test",
size = "enormous",
srcs = ["wct_test.sh"],
args = [
"$(location @ui_dev_npm//web-component-tester/bin:wct)",
],
data = [
"test/common-test-setup.html",
"test/index.html",
":pg_code.zip",
":test_components.zip",
":test-srcs-updated-links-fg",
"@ui_dev_npm//web-component-tester/bin:wct",
],
# Should not run sandboxed.
tags = [
@ -116,14 +140,37 @@ sh_test(
],
)
# update_links - temporary action. Later links/references will be updated in repository,
# so this rule will be removed.
update_links(
name = "polylint-updated-links",
srcs = [
":pg_code_without_test",
],
redirects = "redirects.json",
)
# Workaround for https://github.com/bazelbuild/bazel/issues/1305
filegroup(
name = "polylint-updated-links-fg",
srcs = [
":polylint-updated-links",
"@ui_npm//:node_modules",
],
)
sh_test(
name = "polylint_test",
size = "large",
srcs = ["polylint_test.sh"],
args = [
"$(location @tools_npm//polymer-cli/bin:polymer)",
"$(location polymer.json)",
],
data = [
"polymer.json",
":pg_code_without_test",
"//polygerrit-ui:polygerrit_components.bower_components.zip",
":polylint-updated-links-fg",
"@tools_npm//polymer-cli/bin:polymer",
],
# Should not run sandboxed.
tags = [
@ -153,7 +200,6 @@ DIRECTORIES = [
data = [
":pg_code",
":template_test_srcs",
"//polygerrit-ui:polygerrit_components.bower_components.zip",
],
tags = [
# Should not run sandboxed.

@ -98,6 +98,7 @@ shortcuts are.
-->
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="/bower_components/iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<script src="../../types/polymer-behaviors.js"></script>
<script>
(function(window) {

@ -24,6 +24,7 @@ limitations under the License.
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<script src="../../../test/test-pre-setup.js"></script>
<script src="/components/web-component-tester/data/a11ySuite.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<script src="/bower_components/page/page.js"></script>
<link rel="import" href="../../diff/gr-comment-api/gr-comment-api.html">

@ -24,6 +24,7 @@ limitations under the License.
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<script src="../../../test/test-pre-setup.js"></script>
<link rel="import" href="/bower_components/iron-overlay-behavior/iron-overlay-manager.html">
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-reply-dialog.html">

@ -203,9 +203,17 @@ limitations under the License.
suite('annotateWithElement', () => {
const fullText = '01234567890123456789';
let mockSanitize;
let originalSanitizeDOMValue;
setup(() => {
mockSanitize = sandbox.spy(window.Polymer, 'sanitizeDOMValue');
originalSanitizeDOMValue = window.Polymer.sanitizeDOMValue;
assert.isDefined(originalSanitizeDOMValue);
mockSanitize = sandbox.spy(originalSanitizeDOMValue);
window.Polymer.sanitizeDOMValue = mockSanitize;
});
teardown(() => {
window.Polymer.sanitizeDOMValue = originalSanitizeDOMValue;
});
test('annotates when fully contained', () => {

@ -24,6 +24,7 @@ limitations under the License.
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<script src="../../../test/test-pre-setup.js"></script>
<script src="/components/web-component-tester/data/a11ySuite.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<script src="../../../scripts/util.js"></script>

@ -74,9 +74,7 @@ limitations under the License.
setup(() => {
sandbox = sinon.sandbox.create();
stub('gr-external-style', {
importHref: (url, resolve) => resolve(),
});
sandbox.stub(Polymer, 'importHref', (url, resolve) => resolve());
sandbox.stub(Gerrit, 'awaitPluginsLoaded').returns(Promise.resolve());
});
@ -87,7 +85,7 @@ limitations under the License.
test('imports plugin-provided module', async () => {
lateRegister();
await new Promise(flush);
assert.isTrue(element.importHref.calledWith(new URL(TEST_URL)));
assert.isTrue(Polymer.importHref.calledWith(new URL(TEST_URL)));
});
test('applies plugin-provided styles', async () => {
@ -119,7 +117,7 @@ limitations under the License.
test('loads and applies preloaded modules', async () => {
earlyRegister();
await new Promise(flush);
assert.isTrue(element.importHref.calledWith(new URL(TEST_URL)));
assert.isTrue(Polymer.importHref.calledWith(new URL(TEST_URL)));
assert.isTrue(element._applyStyle.calledWith('some-module'));
});
});

@ -45,7 +45,7 @@ limitations under the License.
element = fixture('basic');
sandbox = sinon.sandbox.create();
sandbox.stub(document.body, 'appendChild');
sandbox.stub(element, 'importHref');
sandbox.stub(Polymer, 'importHref');
});
teardown(() => {

@ -22,7 +22,6 @@ limitations under the License.
<link rel="import" href="/bower_components/iron-dropdown/iron-dropdown.html">
<link rel="import" href="/bower_components/iron-fit-behavior/iron-fit-behavior.html">
<link rel="import" href="../../shared/gr-cursor-manager/gr-cursor-manager.html">
<script src="../../../types/polymer-behaviors.js"></script>
<script src="../../../scripts/rootElement.js"></script>
<link rel="import" href="../../../styles/shared-styles.html">

@ -17,6 +17,7 @@ limitations under the License.
<link rel="import" href="/bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
<link rel="import" href="/bower_components/iron-overlay-behavior/iron-overlay-behavior.html">
<link rel="import" href="/bower_components/iron-dropdown/iron-dropdown.html">
<link rel="import" href="/bower_components/paper-input/paper-input.html">
<link rel="import" href="../../../behaviors/fire-behavior/fire-behavior.html">

@ -26,6 +26,14 @@ limitations under the License.
<script src="../../../test/test-pre-setup.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-fixed-panel.html">
<style>
/* Prevent horizontal scrolling on page.
New version of web-component-tester creates body with margins */
body {
margin: 0px;
padding: 0px;
}
</style>
<script>void(0);</script>

@ -2,37 +2,12 @@
set -ex
npm_bin=$(which npm)
if [[ -z "$npm_bin" ]]; then
echo "NPM must be on the path."
exit 1
fi
node_bin=$(which node)
if [[ -z "$node_bin" ]]; then
echo "node must be on the path."
exit 1
fi
polymer_bin=$(which polymer)
if [[ -z "$polymer_bin" ]]; then
polymer_bin=$(abs_path ./node_modules/polymer-cli/bin/polymer.js);
fi
if [[ -z "$polymer_bin" ]]; then
echo "polymer must be set or polymer-cli locally installed (npm install polymer-cli)."
exit 1
fi
unzip -o polygerrit-ui/polygerrit_components.bower_components.zip -d polygerrit-ui/app
# In this commit, bower_components are used for testing.
# The import statement in font-roboto-local-loader.js breaks tests.
# Temporoary disable this test.
# In the next change this line is removed.
exit 0
DIR=$(pwd)
ln -s $RUNFILES_DIR/ui_npm/node_modules $TEST_TMPDIR/node_modules
cp $2 $TEST_TMPDIR/polymer.json
cp -R -L polygerrit-ui/app/polylint-updated-links/polygerrit-ui/app/* $TEST_TMPDIR
#Can't use --root with polymer.json - see https://github.com/Polymer/tools/issues/2616
#Change current directory to the root folder
cd polygerrit-ui/app
$polymer_bin lint --component-dir 'bower_components' --verbose
cd $TEST_TMPDIR/
$DIR/$1 lint --verbose

@ -1,37 +1,5 @@
#!/usr/bin/env bash
npm_bin=$(which npm)
if [[ -z "$npm_bin" ]]; then
echo "NPM must be on the path. (https://www.npmjs.com/)"
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
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
bazel_bin=$(which bazelisk 2>/dev/null)
if [[ -z "$bazel_bin" ]]; then
echo "Warning: bazelisk is not installed; falling back to bazel."
@ -42,9 +10,7 @@ fi
# TODO(hanwen): does $DISPLAY even work on OSX?
${bazel_bin} 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}" \
--test_env="WCT_HEADLESS_MODE=${WCT_HEADLESS_MODE}" \
"$@" \

@ -21,6 +21,13 @@ limitations under the License.
<meta charset="utf-8">
<script src="/bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="/bower_components/web-component-tester/browser.js"></script>
<style>
/* Prevent horizontal scrolling on page.
New version of web-component-tester creates very narrow iframe */
#subsuites {
width: 1500px !important;
}
</style>
<script>
const testFiles = [];
const scriptsPath = '../scripts/';

@ -49,4 +49,9 @@ function PolymerMixins() {
};
}
};
/**
* @polymerBehavior
* */
Polymer.IronA11yKeysBehavior = [];
}

@ -0,0 +1,63 @@
/**
* @license
* Copyright (C) 2020 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.
*/
/*
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): ./polygerrit-ui/app/run_test.sh --test_arg=--plugin --test_arg=sauce
*/
const headless = 'WCT_HEADLESS_MODE' in process.env ?
process.env['WCT_HEADLESS_MODE'] !== '0' : false;
const headlessBrowserOptions = {
chrome: ['start-maximized', 'headless', 'disable-gpu', 'no-sandbox'],
firefox: ['-headless'],
};
const defaultBrowserOptions = {
chrome: ['start-maximized'],
firefox: [],
};
module.exports = {
suites: ['test'],
npm: true,
moduleResolution: 'node',
wctPackageName: 'wct-browser-legacy',
plugins: {
local: {
skipSeleniumInstall: true,
browserOptions: headless ? headlessBrowserOptions : defaultBrowserOptions,
},
sauce: {
disabled: true,
browsers: [
'OS X 10.12/chrome',
'Windows 10/chrome',
'Linux/firefox',
'OS X 10.12/safari',
'Windows 10/microsoftedge',
],
},
},
};

@ -1,73 +1,27 @@
#!/bin/sh
set -ex
root_dir=$(pwd)
t=$TEST_TMPDIR
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
mkdir -p $t/node_modules
# WCT doesn't implement node module resolution.
# WCT uses only node_module/ directory from current directory when looking for a module
# So, it is impossible to make hierarchical node_modules. Instead, we copy
# all node_modules to one directory.
cp -R -L ./external/ui_dev_npm/node_modules/* $t/node_modules
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/
# Copy ui_npm, so it will override ui_dev_npm modules (in case of conflicts)
# Because browser always requests specific exact files (i.e. not a directory),
# it always receives file from ui_npm. It can broke WCT itself but luckely it works.
cp -R -L ./external/ui_npm/node_modules/* $t/node_modules
# In this commit, bower_components are used for testing.
# The import statement in font-roboto-local-loader.js breaks tests.
# Clear content of the file to fix tests.
# In the next change this line is removed.
echo -n "" > $t/elements/font-roboto-local-loader.js
if [ "${WCT_HEADLESS_MODE:-0}" != "0" ]; then
CHROME_OPTIONS=[\'start-maximized\',\'headless\',\'disable-gpu\',\'no-sandbox\']
FIREFOX_OPTIONS=[\'-headless\']
else
CHROME_OPTIONS=[\'start-maximized\']
FIREFOX_OPTIONS=[\'\']
fi
# 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/run_test.sh
cat <<EOF > $t/wct.conf.js
module.exports = {
'suites': ['test'],
'webserver': {
'pathMappings': [
{'/components/bower_components': 'bower_components'}
]
},
'plugins': {
'local': {
'skipSeleniumInstall': true,
'browserOptions': {
'chrome': ${CHROME_OPTIONS},
'firefox': ${FIREFOX_OPTIONS}
}
},
'sauce': {
'disabled': true,
'browsers': [
'OS X 10.12/chrome',
'Windows 10/chrome',
'Linux/firefox',
'OS X 10.12/safari',
'Windows 10/microsoftedge'
]
}
}
};
EOF
cp -R -L ./polygerrit-ui/app/test-srcs-updated-links/polygerrit-ui/app/* $t/
export PATH="$(dirname $NPM):$PATH"
cd $t
test -n "${WCT}"
${WCT} ${WCT_ARGS}
# If wct doesn't receive any paramenters, it fails (can't find files)
# Pass --config-file as a parameter to have some arguments in command line
$root_dir/$1 --config-file wct.conf.js ${WCT_ARGS}

@ -4,6 +4,11 @@
"browser": true,
"dependencies": {},
"devDependencies": {
"@polymer/iron-test-helpers": "^3.0.1",
"chai": "^4.2.0",
"mocha": "^6.2.2",
"wct-browser-legacy": "^1.0.2",
"web-component-tester": "^6.9.2"
},
"license": "Apache-2.0",
"private": true

@ -1,3 +1,20 @@
/**
* @license
* Copyright (C) 2020 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.
*/
var path = require('path');
var ret = {

File diff suppressed because it is too large Load Diff