Skip to content

Commit

Permalink
chore: add example --config=debug settings to .bazelrc.common and exa…
Browse files Browse the repository at this point in the history
…mple debuggle target with sourcemaps back to .ts sources (aspect-build#168)
  • Loading branch information
gregmagolan authored Oct 4, 2022
1 parent 9345044 commit 6dce878
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .bazelrc.common
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@
# Take care to document any settings that you expect users to apply.
# Settings that apply only to CI are in .github/workflows/ci.bazelrc

# ======================================================================================================================
# Support for debugging Node.js tests
# Use `--config=debug` to enable these settings

# Use bazel run with `--config=debug` to turn on the NodeJS inspector agent.
# The node process will break before user code starts and wait for the debugger to connect.
# Pass the --inspect-brk option to all tests which enables the node inspector agent.
# See https://nodejs.org/de/docs/guides/debugging-getting-started/#command-line-options for more details.
run:debug -- --node_options=--inspect-brk

# Stream stdout/stderr output from each test in real-time.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_output for more details.
test:debug --test_output=streamed

# Run one test at a time.
test:debug --test_strategy=exclusive

# Prevent long running tests from timing out.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--test_timeout for more details.
test:debug --test_timeout=9999

# Always run tests even if they have cached results.
test:debug --nocache_test_results

# Changes the build output of certain rules such as terser. May not be desirable in all cases.
# Rules may change their build outputs if the compilation mode is set to dbg. For example,
# minifiers such as terser may make their output more human readable when this is set. Node.js rules that change their
# behavior based on compilation mode will pass ctx.var["COMPILATION_MODE"] to `js_binary` executables via
# the actions.run env attribute.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--compilation_mode for more details.
build:debug --compilation_mode=dbg
# ======================================================================================================================

# Allow the Bazel server to check directory sources for changes.
# Recommended when using copy_directory, see
# https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md
Expand Down
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach nodejs_binary",
"internalConsoleOptions": "neverOpen",
"resolveSourceMapLocations": null
}
]
}
26 changes: 26 additions & 0 deletions examples/js_test/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
load("@aspect_rules_js//js:defs.bzl", "js_test")

ts_project(
name = "compile",
srcs = ["test.ts"],
tsconfig = {
"compilerOptions": {
"inlineSourceMap": True,
},
},
)

# If run with
#
# ```
# bazel run //examples/js_test:test --config=debug
# ```
#
# will start a debug session that can be connected to with Visual Studio Code. VSCode will follow
# the inline source maps to the TypeScript source files (their copies in the output tree) so the
# debugger will show the TypeScript sources when stepping through code.
js_test(
name = "test",
entry_point = "test.js",
)
2 changes: 2 additions & 0 deletions examples/js_test/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const msg: string = '\n\n\nThis is only a test.\n\n\n'
console.log(msg)

0 comments on commit 6dce878

Please sign in to comment.