forked from bazel-contrib/rules_nodejs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix formatting of Karma stack traces
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
Showing
15 changed files
with
2,548 additions
and
5 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
packages/concatjs/third_party/google3/rules_typescript/.bazelignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...atjs/third_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/.bazelrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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=/ |
52 changes: 52 additions & 0 deletions
52
...s/third_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
57 changes: 57 additions & 0 deletions
57
...tjs/third_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/WORKSPACE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
9 changes: 9 additions & 0 deletions
9
...ird_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/failing.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
8 changes: 8 additions & 0 deletions
8
.../third_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...y/google3/rules_typescript/internal/e2e/package_karma_stack_trace/test_folder/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
) |
7 changes: 7 additions & 0 deletions
7
...arty/google3/rules_typescript/internal/e2e/package_karma_stack_trace/test_folder/hello.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
11 changes: 11 additions & 0 deletions
11
.../google3/rules_typescript/internal/e2e/package_karma_stack_trace/test_folder/test.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...d_party/google3/rules_typescript/internal/e2e/package_karma_stack_trace/test_sourcemap.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Empty file.
Oops, something went wrong.