Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: mention @swc/jest specifically #300

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ Many companies are successfully testing with rules_jest. If you're getting value

rules_jest is just a part of what Aspect provides:

- _Need help?_ This ruleset has support provided by https://aspect.build/services
- _Need help?_ This ruleset has support provided by https://aspect.build/services.
- See our other Bazel rules, especially those built for rules_js, such as rules_ts for TypeScript: https://github.com/aspect-build

## Installation

From the release you wish to use:
Follow instructions from the release you wish to use:
<https://github.com/aspect-build/rules_jest/releases>
copy the WORKSPACE snippet into your `WORKSPACE` file.

## Usage

Run all Jest tests in the workspace: `bazel test --test_lang_filters=jest //...`

See [jest_test](docs/jest_test.md) API documentation and the example usages in the [example](https://github.com/aspect-build/rules_jest/tree/main/example/) folder.

> Note that the example also relies on code in the `/WORKSPACE` file in the root of this repo.
> Note that the example also relies on code in the `/MODULE.bazel` file in the root of this repo.

## Troubleshooting and common challenges

Expand Down
6 changes: 3 additions & 3 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ _Note_: If you are importing a preset, and _it_ declares its own `haste` config,

## Pre-transpiled sources

Frequently outside the Bazel ecosystem sources such as `*.ts` are transpiled on the fly using tools such as `ts-jest` or `babel-jest`. Such tools are designed for Jest and transpile to a javascript format ideal for Jest but normally not for production use.
Frequently outside the Bazel ecosystem sources such as `*.ts` are transpiled on the fly using tools such as `ts-jest`, `babel-jest`, or `@swc/jest`. Such tools are designed for Jest and transpile to a javascript format ideal for Jest but normally not for production use.

Transpiling in bazel is normally done ahead of time to take advantage of bazel caching, ensure that the build is hermetic, ensure the tested code is the same as production code etc. However this transpiling is no longer designed specifically for Jest like `ts-jest` or `babel-jest` which may lead to certain limitations. For example:
Transpiling in bazel is normally done ahead of time to take advantage of bazel caching, ensure that the build is hermetic, and to ensure the tested code is the same as production code. However this transpiling is no longer designed specifically for Jest like `ts-jest` or `babel-jest` which may lead to certain limitations. For example:

### Runtime tsconfig dependency

If a plugin such as `ts-jest` or `ts-node` is replaced with `rules_ts` (to pre-compile ts files instead of runtime compilation), features such as runtime `tsconfig` path mapping must be replaced with other tools such as `tsconfig-paths`.

### ESM Modules

Normally Jest uses CommonJS modules (such as when `ts-jest` or `babel-jest` does transpiling on the fly), but with bazel the transpiled sources are normally pre-transpiled and remain as native ESM modules for optimal use by bundlers and other tools.
Normally Jest uses CommonJS modules (such as when `ts-jest`, `babel-jest`, or `@swc/jest` does transpiling on the fly), but with Bazel the transpiled sources are normally pre-transpiled and remain as native ESM modules for optimal use by bundlers and other tools.

ESM modules come with certain challenges in NodeJS and therefor also in Jest, see:

Expand Down
2 changes: 2 additions & 0 deletions e2e/swc/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Example showing usage and challenges using rules_jest with swc (via rules_swc)

NB: this example predates the https://swc.rs/docs/usage/jest package, which likely solves these problems.

## Mocking of esm exports when transforming to commonjs

When transforming esm to commonjs, swc defines the exports as readonly.
Expand Down