diff options
author | 2022-02-15 13:44:34 -0800 | |
---|---|---|
committer | 2022-02-15 13:44:34 -0800 | |
commit | 37bc3c887224a4b5ac2bdbdfa5b21f54de718a49 (patch) | |
tree | 989e69a032af5cbe0dd1de49f348bcb7ef186b0f | |
parent | 55825c0e33b0959c68ceff5af0510abcf3124742 (diff) | |
download | bun-37bc3c887224a4b5ac2bdbdfa5b21f54de718a49.tar.gz bun-37bc3c887224a4b5ac2bdbdfa5b21f54de718a49.tar.zst bun-37bc3c887224a4b5ac2bdbdfa5b21f54de718a49.zip |
[bun test] Auto rewrite `@jest/globals` and `vitest` to `bun:test`
-rw-r--r-- | src/linker.zig | 15 | ||||
-rw-r--r-- | src/options.zig | 2 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/linker.zig b/src/linker.zig index 6f565f0fb..278d57927 100644 --- a/src/linker.zig +++ b/src/linker.zig @@ -259,6 +259,21 @@ pub const Linker = struct { continue; } + // TODO: this is technical debt + if (linker.options.rewrite_jest_for_tests) { + if (strings.eqlComptime( + import_record.path.text, + "@jest/globals", + ) or strings.eqlComptime( + import_record.path.text, + "vitest", + )) { + import_record.path.namespace = "bun"; + import_record.path.text = "test"; + continue; + } + } + if (import_record.path.text.len > 4 and strings.eqlComptime(import_record.path.text[0.."bun:".len], "bun:")) { import_record.path = Fs.Path.init(import_record.path.text["bun:".len..]); import_record.path.namespace = "bun"; diff --git a/src/options.zig b/src/options.zig index 393c1e128..7e7f6a7c3 100644 --- a/src/options.zig +++ b/src/options.zig @@ -1107,6 +1107,8 @@ pub const BundleOptions = struct { transform_options: Api.TransformOptions, polyfill_node_globals: bool = true, + rewrite_jest_for_tests: bool = false, + macro_remap: MacroRemap = MacroRemap{}, conditions: ESMConditions = undefined, |