Skip to content

Commit

Permalink
fix: fix formatting of Karma stack traces
Browse files Browse the repository at this point in the history
Make the paths(with and without sourcemaps) relative to the project root so that the file locations are linkified in editors like VS Code.

Tested in angular/angular using VS Code.

Closes bazel-contrib#369

PiperOrigin-RevId: 231730383
  • Loading branch information
vikerman authored and alexeagle committed Jan 31, 2019
1 parent a8b1e81 commit 7cfe065
Show file tree
Hide file tree
Showing 15 changed files with 2,548 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules
internal/e2e/ts_auto_deps
internal/e2e/package_karma
internal/e2e/package_karma_stack_trace
internal/e2e/package_typescript_2.7
internal/e2e/package_typescript_2.8
internal/e2e/package_typescript_2.9
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Don't create symlinks like bazel-out in the project.
# These cause VSCode to traverse a massive tree, opening file handles and
# eventually a surprising failure with auto-discovery of the C++ toolchain in
# MacOS High Sierra.
# See https://github.com/bazelbuild/bazel/issues/4603
build --symlink_prefix=/
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# 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.

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library", "ts_web_test_suite")

package(default_visibility = ["//visibility:public"])

exports_files(["tsconfig.json"])

ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["*.spec.ts"]),
deps = [
"@npm//@types/jasmine",
],
)

# This is a test with failing test. This test is not directly run by CI.
# The sh_test below invokes this test and checks the source mapped lines in the
# stack trace.
ts_web_test_suite(
name = "karma_test",
browsers = [
"@io_bazel_rules_webtesting//browsers:chromium-local",
],
tags = ["manual"], # not run by CI
deps = [
":test_lib",
"//test_folder:test_lib",
],
)

sh_test(
name = "test_sourcemap",
srcs = ["test_sourcemap.sh"],
data = [
":karma_test",
"@bazel_tools//tools/bash/runfiles",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# 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.

workspace(name = "package_karma_stack_trace")

local_repository(
name = "build_bazel_rules_typescript",
path = "../../..",
)

load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")

rules_typescript_dependencies()

load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")

rules_nodejs_dependencies()

load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories", "yarn_install")

node_repositories(preserve_symlinks = True)

yarn_install(
name = "npm",
package_json = "//:package.json",
yarn_lock = "//:yarn.lock",
)

load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains()

load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories")

web_test_repositories()

browser_repositories(
chromium = True,
firefox = True,
)

load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

ts_setup_workspace()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// This dummy export ensures that this file is compiled as a module instead
// of a script.
export {};

describe('stack trace', () => {
it('failing test', () => {
expect(true).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dependencies": {
"@bazel/typescript": "file:../build_bazel_rules_typescript/bazel-bin/internal/npm_package",
"@bazel/karma": "file:../build_bazel_rules_typescript/bazel-bin/internal/karma/npm_package",
"@types/jasmine": "2.8.2",
"typescript": "3.1.x"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# 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.

load("@build_bazel_rules_typescript//:defs.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
name = "hello",
srcs = glob(
["*.ts"],
exclude = ["*.spec.ts"],
),
)

ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["*.spec.ts"]),
deps = [
":hello",
"@npm//@types/jasmine",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function sayHello() {
return 'Hello';
}

export function error() {
throw new Error('Error here');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { sayHello, error } from "./hello";

describe('multiple stack frames', () => {
it('failing test', () => {
expect(sayHello()).toBe('World');
});

it('another failing test', () => {
expect(error()).toBe(null);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Execute first test.
OUTPUT=$(${RUNFILES_DIR}/package_karma_stack_trace/karma_test_chromium-local)

# Test whether the package relative TS path is printed in stack trace.
echo ${OUTPUT} | grep -q "(failing.spec.ts:7:17"
if [[ "$?" != "0" ]]; then
echo "Did not find 'failing.spec.ts:7:17' in Karma stack trace"
exit 1
fi

# Test whether the package relative path inside a subdirectory is printed.
echo ${OUTPUT} | grep -q "(test_folder/test.spec.ts:5:23"
if [[ "$?" != "0" ]]; then
echo "Did not find 'test_folder/test.spec.ts:5:23' in Karma stack trace"
exit 1
fi

# Test whether stack trace with multiple stack frames mapped get printed.
echo ${OUTPUT} | grep -q "(test_folder/hello.ts:6:8"
if [[ "$?" != "0" ]]; then
echo "Did not find 'test_folder/hello.ts:6:8' in Karma stack trace"
exit 1
fi

exit 0
Loading

0 comments on commit 7cfe065

Please sign in to comment.