Skip to content

Commit

Permalink
Rewrite Jest to Vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
hjellek committed Apr 17, 2024
1 parent 98aff25 commit 3637839
Show file tree
Hide file tree
Showing 256 changed files with 3,721 additions and 7,016 deletions.
66 changes: 0 additions & 66 deletions .aspect/workflows/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions .aspect/workflows/bazelrc

This file was deleted.

46 changes: 0 additions & 46 deletions .aspect/workflows/config.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion .bazelignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
e2e/
node_modules
example/node_modules
jest/tests/node_modules
example/snapshots_files/node_modules
vitest/tests/node_modules
4 changes: 2 additions & 2 deletions .bcr/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# See https://github.com/bazel-contrib/publish-to-bcr#a-note-on-release-automation
fixedReleaser:
login: gregmagolan
email: greg@aspect.dev
login: hjellek
email: knut.hjelle@fremtind.no
10 changes: 5 additions & 5 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"homepage": "https://docs.aspect.build/rules/aspect_rules_jest",
"homepage": "https://github.com/fremtind/rules_vitest",
"maintainers": [
{
"name": "Greg Magolan",
"email": "greg@aspect.dev",
"github": "gregmagolan"
"name": "Knut Eirik Leira Hjelle",
"email": "knut.hjelle@fremtind.no",
"github": "hjellek"
}
],
"repository": ["github:aspect-build/rules_jest"],
"repository": ["github:fremtind/rules_vitest"],
"versions": [],
"yanked_versions": {}
}
2 changes: 1 addition & 1 deletion .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bcr_test_module:
module_path: "e2e/smoke"
matrix:
bazel: ['7.x', '6.x']
bazel: ["7.x", "6.x"]
platform: ["debian10", "macos", "ubuntu2004", "windows"]
tasks:
run_tests:
Expand Down
2 changes: 1 addition & 1 deletion .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"integrity": "**leave this alone**",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_jest-{TAG}.tar.gz"
"url": "https://github.com/{OWNER}/{REPO}/releases/download/{TAG}/rules_vitest-{TAG}.tar.gz"
}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ jobs:
release:
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v2
with:
release_files: rules_jest-*.tar.gz
release_files: rules_vitest-*.tar.gz
10 changes: 5 additions & 5 deletions .github/workflows/release_prep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set -o errexit -o nounset -o pipefail
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives
PREFIX="rules_jest-${TAG:1}"
ARCHIVE="rules_jest-$TAG.tar.gz"
PREFIX="rules_vitest-${TAG:1}"
ARCHIVE="rules_vitest-$TAG.tar.gz"
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip >$ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

Expand All @@ -18,7 +18,7 @@ cat <<EOF
2. Add to your \`MODULE.bazel\` file:
\`\`\`starlark
bazel_dep(name = "aspect_rules_jest", version = "${TAG:1}")
bazel_dep(name = "rules_vitest", version = "${TAG:1}")
\`\`\`
## Using WORKSPACE
Expand All @@ -28,10 +28,10 @@ Paste this snippet into your \`WORKSPACE.bazel\` file:
\`\`\`starlark
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "aspect_rules_jest",
name = "rules_vitest",
sha256 = "${SHA}",
strip_prefix = "${PREFIX}",
url = "https://github.com/aspect-build/rules_jest/releases/download/${TAG}/${ARCHIVE}",
url = "https://github.com/fremtind/rules_vitest/releases/download/${TAG}/${ARCHIVE}",
)
EOF

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bazel-*
.bazelrc.user
**/.terraform/*
.ijwb/*
node_modules
example/node_modules
20 changes: 10 additions & 10 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("//jest:defs.bzl", "jest_test")
load("//vitest:defs.bzl", "vitest_test")

npm_link_all_packages(name = "node_modules")

Expand Down Expand Up @@ -46,23 +46,23 @@ alias(
actual = "//tools:format",
)

# Test case 3: jest config file in root package
# Test case 3: vitest config file in root package
# Copy files from tests package to keep the root package clean.
copy_file(
name = "case3_test_js",
src = "//jest/tests:case3.test.js",
src = "//vitest/tests:case3.test.js",
out = "case3.test.js",
)

copy_file(
name = "case3_jest_config_js",
src = "//jest/tests:case3.jest.config.js",
out = "case3.jest.config.js",
name = "case3_vitest_config_mjs",
src = "//vitest/tests:case3.vitest.config.mjs",
out = "case3.vitest.config.mjs",
)

jest_test(
vitest_test(
name = "case3",
config = "case3.jest.config.js",
config = "case3.vitest.config.mjs",
data = [
"case3.test.js",
],
Expand All @@ -71,13 +71,13 @@ jest_test(

copy_to_bin(
name = "case8.config",
srcs = ["test_case8.jest.config.js"],
srcs = ["test_case8.vitest.config.js"],
visibility = ["//visibility:public"],
)

bzl_library(
name = "internal_deps",
srcs = ["internal_deps.bzl"],
visibility = ["//visibility:public"],
deps = ["//jest/private:maybe"],
deps = ["//vitest/private:maybe"],
)
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ Run `bazel run //:gazelle` to keep them up-to-date.
## Using this as a development dependency of other rules

You'll commonly find that you develop in another WORKSPACE, such as
some other ruleset that depends on rules_jest, or in a nested
some other ruleset that depends on rules_vitest, or in a nested
WORKSPACE in the integration_tests folder.

To always tell Bazel to use this directory rather than some release
artifact or a version fetched from the internet, run this from this
directory:

```sh
OVERRIDE="--override_repository=rules_jest=$(pwd)/rules_jest"
OVERRIDE="--override_repository=rules_vitest=$(pwd)/rules_vitest"
echo "build $OVERRIDE" >> ~/.bazelrc
echo "fetch $OVERRIDE" >> ~/.bazelrc
echo "query $OVERRIDE" >> ~/.bazelrc
```

This means that any usage of `@rules_jest` on your system will point to this folder.
This means that any usage of `@rules_vitest` on your system will point to this folder.

## Releasing

Expand Down
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"aspect-build/rules_jest"
"aspect-build/rules_vitest"

module(
name = "aspect_rules_jest",
name = "fremtind_rules_vitest",
version = "0.0.0",
compatibility_level = 1,
)
Expand Down
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# Bazel rules for jest
# Bazel rules for vitest

Runs tests with the https://jestjs.io/ test runner under Bazel.
Runs tests with the https://vitest.dev/ test runner under Bazel.

Many companies are successfully testing with rules_jest. If you're getting value from the project, please let us know! Just comment on our [Adoption Discussion](https://github.com/aspect-build/rules_js/discussions/1000).

rules_jest is just a part of what Aspect provides:

- _Need help?_ This ruleset has support provided by https://aspect.dev.
- See our other Bazel rules, especially those built for rules_js, such as rules_ts for TypeScript: https://github.com/aspect-build
rules_vitest is very much based on [rules_vitest](https://github.com/aspect-build/rules_vitest) by by https://aspect.dev

## Installation

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

## Usage

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

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.
See [vitest_test](docs/vitest_test.md) API documentation and the example usages in the [example](https://github.com/aspect-build/rules_vitest/tree/main/example/) folder.

> Note that the example also relies on code in the `/WORKSPACE` file in the root of this repo.
## Troubleshooting and common challenges

⚠️ `vite`, `vitest`, `react (optional)`, `jsdom (optional)` must be installed at root ⚠️

For troubleshooting and common challenges, see [docs/troubleshooting.md](docs/troubleshooting.md).
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Declare the local Bazel workspace.
workspace(name = "aspect_rules_jest")
workspace(name = "fremtind_rules_vitest")

load(":internal_deps.bzl", "rules_jest_internal_deps")
load(":internal_deps.bzl", "rules_vitest_internal_deps")

# Fetch deps needed only locally for development
rules_jest_internal_deps()
rules_vitest_internal_deps()

load("//jest:dependencies.bzl", "rules_jest_dependencies")
load("//vitest:dependencies.bzl", "rules_vitest_dependencies")

# Fetch dependencies which users need as well
rules_jest_dependencies()
rules_vitest_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

Expand Down Expand Up @@ -39,7 +39,7 @@ go_register_toolchains(version = "1.19.3")

gazelle_dependencies()

# Test case 4 (see //jest/tests)
# Test case 4 (see //vitest/tests)
local_repository(
name = "case4",
path = "e2e/case4",
Expand Down
6 changes: 3 additions & 3 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")

stardoc_with_diff_test(
name = "jest_test",
bzl_library_target = "//jest:defs",
symbol_names = ["jest_test"],
name = "vitest_test",
bzl_library_target = "//vitest:defs",
symbol_names = ["vitest_test"],
)

update_docs(name = "update")
Expand Down
Loading

0 comments on commit 3637839

Please sign in to comment.