Use typescript output to run tests
This change updates build rules to run tests on top of compiled typescript code. Additionally, it includes converted base-url-behavior.ts file to ensure that new changes work correctly with .ts files. Change-Id: I860b78c664eba88713fe1291704639e1736140cc
This commit is contained in:
45
polygerrit-ui/app/.eslint-ts-resolver.js
Normal file
45
polygerrit-ui/app/.eslint-ts-resolver.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright (C) 2017 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is a very simple resolver for the 'js imports ts' case. It is used only
|
||||
* by eslint and must be removed after switching to typescript is finished.
|
||||
* The resolver searches for .ts files instead of .js
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
function isRelativeImport(source) {
|
||||
return source.startsWith('./') || source.startsWith('../');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
interfaceVersion: 2,
|
||||
resolve: function(source, file, config) {
|
||||
if (!isRelativeImport(source) || !source.endsWith('.js')) {
|
||||
return {found: false};
|
||||
}
|
||||
const tsSource = source.slice(0, -3) + '.ts';
|
||||
|
||||
const fullPath = path.resolve(path.dirname(file), tsSource);
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
return {found: false};
|
||||
}
|
||||
return {found: true, path: fullPath};
|
||||
}
|
||||
};
|
@@ -17,6 +17,7 @@
|
||||
|
||||
// Do not add any bazel-specific properties in this file to keep it clean.
|
||||
// Please add such properties to the .eslintrc-bazel.js file
|
||||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
"extends": ["eslint:recommended", "google"],
|
||||
@@ -263,6 +264,10 @@ module.exports = {
|
||||
"prettier"
|
||||
],
|
||||
"settings": {
|
||||
"html/report-bad-indent": "error"
|
||||
"html/report-bad-indent": "error",
|
||||
"import/resolver": {
|
||||
"node": {},
|
||||
[path.resolve(__dirname, './.eslint-ts-resolver.js')]: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@@ -29,9 +29,31 @@ compiled_pg_srcs = compile_ts(
|
||||
"**/*_test.js",
|
||||
],
|
||||
),
|
||||
# The same outdir also appears in the following files:
|
||||
# polylint_test.sh
|
||||
ts_outdir = "_pg_ts_out",
|
||||
)
|
||||
|
||||
compiled_pg_srcs_with_tests = compile_ts(
|
||||
name = "compile_pg_with_tests",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.js",
|
||||
"**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"node_modules/**",
|
||||
"node_modules_licenses/**",
|
||||
"template_test_srcs/**",
|
||||
"rollup.config.js",
|
||||
],
|
||||
),
|
||||
# The same outdir also appears in the following files:
|
||||
# wct_test.sh
|
||||
# karma.conf.js
|
||||
ts_outdir = "_pg_with_tests_out",
|
||||
)
|
||||
|
||||
polygerrit_bundle(
|
||||
name = "polygerrit_ui",
|
||||
srcs = compiled_pg_srcs,
|
||||
@@ -39,43 +61,42 @@ polygerrit_bundle(
|
||||
entry_point = "_pg_ts_out/elements/gr-app.js",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "eslint_src_code",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.html",
|
||||
"**/*.js",
|
||||
"**/*.ts",
|
||||
],
|
||||
exclude = [
|
||||
"node_modules/**",
|
||||
"node_modules_licenses/**",
|
||||
],
|
||||
) + [
|
||||
"@ui_dev_npm//:node_modules",
|
||||
"@ui_npm//:node_modules",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "pg_code",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.html",
|
||||
"**/*.js",
|
||||
],
|
||||
exclude = [
|
||||
"node_modules/**",
|
||||
"node_modules_licenses/**",
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "pg_code_without_test",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.html",
|
||||
"**/*.js",
|
||||
],
|
||||
exclude = [
|
||||
"node_modules/**",
|
||||
"node_modules_licenses/**",
|
||||
"test/**",
|
||||
"samples/**",
|
||||
"**/*_test.js",
|
||||
],
|
||||
),
|
||||
) + compiled_pg_srcs_with_tests,
|
||||
)
|
||||
|
||||
# Workaround for https://github.com/bazelbuild/bazel/issues/1305
|
||||
filegroup(
|
||||
name = "test-srcs-fg",
|
||||
srcs = [
|
||||
"test/common-test-setup.js",
|
||||
"test/common-test-setup-karma.js",
|
||||
"rollup.config.js",
|
||||
":pg_code",
|
||||
"@ui_dev_npm//:node_modules",
|
||||
"@ui_npm//:node_modules",
|
||||
@@ -86,10 +107,13 @@ filegroup(
|
||||
# The eslint macro creates 2 rules: lint_test and lint_bin
|
||||
eslint(
|
||||
name = "lint",
|
||||
srcs = [":test-srcs-fg"],
|
||||
srcs = [":eslint_src_code"],
|
||||
config = ".eslintrc-bazel.js",
|
||||
# The .eslintrc-bazel.js extends the .eslintrc.js config, pass it as a dependency
|
||||
data = [".eslintrc.js"],
|
||||
data = [
|
||||
# The .eslintrc-bazel.js extends the .eslintrc.js config, pass it as a dependency
|
||||
".eslintrc.js",
|
||||
".eslint-ts-resolver.js",
|
||||
],
|
||||
extensions = [
|
||||
".html",
|
||||
".js",
|
||||
@@ -104,13 +128,14 @@ eslint(
|
||||
],
|
||||
)
|
||||
|
||||
# Workaround for https://github.com/bazelbuild/bazel/issues/1305
|
||||
filegroup(
|
||||
name = "polylint-fg",
|
||||
srcs = [
|
||||
":pg_code_without_test",
|
||||
# Workaround for https://github.com/bazelbuild/bazel/issues/1305
|
||||
"@ui_npm//:node_modules",
|
||||
],
|
||||
] +
|
||||
# Polylinter can't check .ts files, run it on compiled srcs
|
||||
compiled_pg_srcs,
|
||||
)
|
||||
|
||||
sh_test(
|
||||
|
@@ -5,7 +5,7 @@ set -ex
|
||||
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/* $TEST_TMPDIR
|
||||
cp -R -L polygerrit-ui/app/_pg_ts_out/* $TEST_TMPDIR
|
||||
|
||||
#Can't use --root with polymer.json - see https://github.com/Polymer/tools/issues/2616
|
||||
#Change current directory to the root folder
|
||||
|
23
polygerrit-ui/app/types/globals.ts
Normal file
23
polygerrit-ui/app/types/globals.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
CANONICAL_PATH?: string;
|
||||
}
|
||||
}
|
@@ -44,8 +44,10 @@ function getUiDevNpmFilePath(importPath) {
|
||||
}
|
||||
|
||||
module.exports = function(config) {
|
||||
const rootDir = runUnderBazel ?
|
||||
'polygerrit-ui/app/_pg_with_tests_out/' : 'polygerrit-ui/app/';
|
||||
const testFilesLocationPattern =
|
||||
'polygerrit-ui/app/**/!(template_test_srcs)/';
|
||||
`${rootDir}**/!(template_test_srcs)/`;
|
||||
// Use --test-files to specify pattern for a test files.
|
||||
// It can be just a file name, without a path:
|
||||
// --test-files async-foreach-behavior_test.js
|
||||
|
Reference in New Issue
Block a user