https://github.com/cometkim/rescript-vitest
ReScript bindings to Vitest
https://github.com/cometkim/rescript-vitest
rescript rescript-bindings vite vitest
Last synced: 4 months ago
JSON representation
ReScript bindings to Vitest
- Host: GitHub
- URL: https://github.com/cometkim/rescript-vitest
- Owner: cometkim
- License: mit
- Created: 2022-01-16T07:43:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-27T04:22:52.000Z (10 months ago)
- Last Synced: 2024-10-29T14:44:43.498Z (8 months ago)
- Topics: rescript, rescript-bindings, vite, vitest
- Language: ReScript
- Homepage:
- Size: 3.36 MB
- Stars: 43
- Watchers: 3
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rescript-vitest
[](https://www.npmjs.com/package/rescript-vitest)
[](https://www.npmjs.com/package/rescript-vitest)
[](#LICENSE)[ReScript](https://rescript-lang.org) bindings to [Vitest](https://vitest.dev)
## Prerequisite
ReScript v10.1+ is required since v1.0.0. To use `Js.Promise2` and `async`/`await` for tests.
ReScript v11.x with the [uncurried mode](https://rescript-lang.org/blog/uncurried-mode) is supported since v2.x (unreleased).
## Config
Configure with plain `vite.config.js`.
You can use [vite-plugin-rescript](https://github.com/jihchi/vite-plugin-rescript) to build ReScript automatically before the test.
## Usage
You can find examples on [tests](./tests)
### Basic
```res
open Vitestdescribe("Hello, Vitest", () => {
test("This is a test case", t => {
// t is `expect` object for suite-wide assertions
t->assertions(3)// Test using the `Expect` module
t->expect(1 + 2)->Expect.toBe(3)// There are some nested modules for specific type
t->expect([1, 2, 3])
->Expect.Array.toContain(2)t->expect("Hello, ReScript-Vitest!")
->Expect.String.toContain("ReScript")// You can specify timeout for a test suite
}, ~timeout=2000)
})
```### In-source testing (experimental)
Vitest support [in-source testing](https://vitest.dev/guide/in-source)
```res
// This if block can be removed from production code.
// You need to define `import.meta.vitest` to `undefined`
if Vitest.inSource {
open Vitest.InSourcetest("In-source testing", t => {
t->expect(1 + 2)->Expect.toBe(3)
})
}
```### Migration from 1.x
You need to bind test context `t` explicitly.
If you're migrating from 1.x, there is a built-in context binding in `Vitest.Bindings.BuiltIn`.
```diff
open Vitest
+open Vitest.Bindings.BuiltIndescribe("Hello, Vitest", t => {
test("This is a test case", t => {
- t->assertions(3)
+ assertions(3)- t->expect(1 + 2)->Expect.toBe(3)
+ expect(1 + 2)->Expect.toBe(3)
})
})
```You can use simple flags for `skip`, `concurrent`, and `only`.
```res
Skip.test("This will be skipped", t => {
// ...
})// Use simple flags instead.
test(~skip=true, "This will be skipped", t => {
// ...
})
```Module bindings will be deprecated and removed in next major (v3)
## LICENCE
MIT