diff --git a/examples/source_map_support/test/a.ts b/examples/source_map_support/test/a.ts deleted file mode 100644 index 0354556..0000000 --- a/examples/source_map_support/test/a.ts +++ /dev/null @@ -1,17 +0,0 @@ -try { - require('./b')() -} catch (e) { - const assert = require('assert') - const frames = e.stack - .split('\n') - .slice(1) - .map((s) => s.trim()) - assert.deepEqual( - frames.filter((f) => f.includes('source_map_support/test/a')), - [`at Object. (examples/source_map_support/test/a.ts:2:11)`], - ) - assert.deepEqual( - frames.filter((f) => f.includes('source_map_support/test/b')), - [`at foo (examples/source_map_support/test/b.ts:2:9)`], - ) -} diff --git a/examples/source_map_support/test/BUILD.bazel b/examples/source_map_support/test/simple/BUILD.bazel similarity index 100% rename from examples/source_map_support/test/BUILD.bazel rename to examples/source_map_support/test/simple/BUILD.bazel diff --git a/examples/source_map_support/test/simple/a.ts b/examples/source_map_support/test/simple/a.ts new file mode 100644 index 0000000..fe9a111 --- /dev/null +++ b/examples/source_map_support/test/simple/a.ts @@ -0,0 +1,19 @@ +try { + require("./b")(); +} catch (e) { + const assert = require("assert"); + const frames = e.stack + .split("\n") + .slice(1) + .map((s) => s.trim()); + assert.deepEqual( + frames.filter((f) => f.includes("source_map_support/test/simple/a")), + [ + `at Object. (examples/source_map_support/test/simple/a.ts:2:11)`, + ], + ); + assert.deepEqual( + frames.filter((f) => f.includes("source_map_support/test/simple/b")), + [`at foo (examples/source_map_support/test/simple/b.ts:2:9)`], + ); +} diff --git a/examples/source_map_support/test/b.ts b/examples/source_map_support/test/simple/b.ts similarity index 100% rename from examples/source_map_support/test/b.ts rename to examples/source_map_support/test/simple/b.ts diff --git a/examples/source_map_support/test/swcrc/.swcrc b/examples/source_map_support/test/swcrc/.swcrc new file mode 100644 index 0000000..75f0573 --- /dev/null +++ b/examples/source_map_support/test/swcrc/.swcrc @@ -0,0 +1,3 @@ +{ + "sourceMaps": "inline" +} \ No newline at end of file diff --git a/examples/source_map_support/test/swcrc/BUILD.bazel b/examples/source_map_support/test/swcrc/BUILD.bazel new file mode 100644 index 0000000..f016c12 --- /dev/null +++ b/examples/source_map_support/test/swcrc/BUILD.bazel @@ -0,0 +1,36 @@ +load("@aspect_rules_swc//swc:defs.bzl", "swc") +load("//examples/source_map_support:defs.bzl", "js_test") + +swc( + name = "compile", + srcs = [ + "a.ts", + "b.ts", + ], + swcrc = ".swcrc", +) + +js_test( + name = "stack_trace_support_test", + data = [":compile"], + entry_point = ":a.js", + target_compatible_with = select({ + # TODO(jbedard): fix CI failure, like + # https://github.com/aspect-build/rules_swc/actions/runs/4471322159/jobs/7856057314?pr=187 + "@platforms//os:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), +) + +js_test( + name = "stack_trace_support_with_chdir_test", + chdir = "examples", + data = [":compile"], + entry_point = ":a.js", + target_compatible_with = select({ + # TODO(jbedard): fix CI failure, like + # https://github.com/aspect-build/rules_swc/actions/runs/4471322159/jobs/7856057314?pr=187 + "@platforms//os:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), +) diff --git a/examples/source_map_support/test/swcrc/a.ts b/examples/source_map_support/test/swcrc/a.ts new file mode 100644 index 0000000..714b303 --- /dev/null +++ b/examples/source_map_support/test/swcrc/a.ts @@ -0,0 +1,19 @@ +try { + require("./b")(); +} catch (e) { + const assert = require("assert"); + const frames = e.stack + .split("\n") + .slice(1) + .map((s) => s.trim()); + assert.deepEqual( + frames.filter((f) => f.includes("source_map_support/test/swcrc/a")), + [ + `at Object. (examples/source_map_support/test/swcrc/a.ts:2:11)`, + ], + ); + assert.deepEqual( + frames.filter((f) => f.includes("source_map_support/test/swcrc/b")), + [`at foo (examples/source_map_support/test/swcrc/b.ts:2:9)`], + ); +} diff --git a/examples/source_map_support/test/swcrc/b.ts b/examples/source_map_support/test/swcrc/b.ts new file mode 100644 index 0000000..7cb351a --- /dev/null +++ b/examples/source_map_support/test/swcrc/b.ts @@ -0,0 +1,3 @@ +module.exports = function foo() { + throw new Error('test') +}