[ANN] rescript-vitest v1.0.0 released

9 Likes

Sorry to go off topic, but what is it about async/await compatibility? Is it the ReScript async/await, or the JS async/await? :thinking:

1 Like

Itā€™s ReScriptā€™ async/await and Js.Promise2

You might find the discussions interesting:

1 Like

Iā€™m giving this a try. When the .test.res file is changed, the underlying .test.bs.js file is updated as expected. I can look at the .bs.js file and see something like expect(4).toEqual(5) But the vitest output in the terminal still shows everything passing. I have to go into the .test.bs.js file and save it, causing a reformat, for vitest to notice the test has changed and update the results. Somehow the vitest watcher isnā€™t noticing when the auto-generated .bs.js file is changed. Have you seen this?

ā€”-

I set the vitest config include property to look for the generated test.bs.js files so I donā€™t know why it doesnā€™t notice when these files change. I have to change them manually by doing a file save on them. How is your vitest configured? Is some rescript plug-in or something needed?

Nothing special in my vitest config. But I use rescript-vitest with vite-plugin-resscript

When I attempt to use the vite-plugin-rescript installation instructions Iā€™m receiving an error that the Js.Promise2 library is not found. This is using:

  "devDependencies": {
    "@jihchi/vite-plugin-rescript": "^5.0.0",
    "@testing-library/jest-dom": "^5.16.5",
    "@testing-library/react": "^13.4.0",
    "@vitejs/plugin-react": "^3.0.1",
    "jsdom": "^21.0.0",
    "rescript-vitest": "^1.0.1",
    "vite": "^4.0.4",
    "vitest": "^0.26.3"
  },
  "dependencies": {
    "@rescript/react": "0.11",
    "@ryyppy/rescript-promise": "^2.1.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "rescript": "^10.0.1",
    "rescript-webapi": "^0.7.0"
  }
}

Is this a known incompatibility?

You need to use rescript@10.1.x

1 Like

The watcher problem I was having fixed itself when I upgraded vitest to ^0.27.1. But now I have a different issue. Are there any special steps you need to take to install rescript-vitest to get it working? Iā€™ve done thisā€¦

  1. Add rescript-vitest to devDependencies in package.json
  2. Add rescript-vitest to bs-dependencies in bsconfig.json
  3. Configure vite.config.js to something like thisā€¦
export default defineConfig({
  plugins: [react()],
  test: {
    include: [...configDefaults.include, "**/*.{test,spec}.bs.js"],
  },
});

My tests wonā€™t run. I get this errorā€¦

Error: No test suite found in
file /Users/.../Source/vite-experiments/vite2/src/MathTest.test.bs.js

Here is the generated test fileā€¦

// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Vitest from "rescript-vitest/src/Vitest.bs.js";
import * as Vitest$1 from "vitest";

Vitest.describe("Math test suite", undefined, function (param) {
  Vitest.test("addition", 2500, function (_t) {
    Vitest$1.expect(8).toEqual(8);
  });
});

export {};
/*  Not a pure module */

Note that if I instead copy the Vitest.res file into my project src folder, as if I wrote it myself, the tests run just fine. I searched the internet for ā€œvitest No test suite foundā€ it looks like there are some similar bugs in the vitest repository.

1 Like

Iā€™ll add a section to the README about the including files setting.

The problem you reported is probably related to the bundler.
Could you try to resolve it with refering to Dep Optimization Options | Vite?

Sorry I barely understand the docs on Dep Optimization Options and how this could relate to the problem Iā€™m seeing with No Test Suite found. I donā€™t know what to try.

Iā€™m porting my tests over to your bindings. I use data driven tests a lot, like test.each, and it doesnā€™t look like this is implemented in your bindings. Iā€™ve started trying to write these bindings; just trying to get a bare minimum working. It doesnā€™t follow your current approach of functors. Iā€™m not very familiar with vitest. Iā€™m just trying to get something to compile. You could probably do it properly a LOT faster than me. I think we need testObject - for an array of objects - and test2, test3, test4, etc. for test case arrays of length 2, 3, 4, etc. And these need async and non-async version. And the timeout options. Iā€™ve gotten these below to work.

module Each = {
  type test

  @module("vitest") @val
  external _test: test = "test"

  @send
  external _testObj: (
    ~test: test,
    ~cases: array<'c>,
    . ~name: string,
    ~f: @uncurry ('c => unit),
    ~param: Js.undefined<int>,
  ) => unit = "each"

  @send
  external _testArray2: (
    ~test: test,
    ~cases: array<('a, 'b)>,
    . ~name: string,
    ~f: @uncurry ('a, 'b) => unit,
    ~param: Js.undefined<int>,
  ) => unit = "each"

  @inline
  let testObject = (cases, name, f) =>
    _testObj(~test=_test, ~cases)(. ~name, ~f, ~param=Js.Undefined.empty)

  @inline
  let test2 = (cases, name, f) =>
    _testArray2(~test=_test, ~cases)(. ~name, ~f, ~param=Js.Undefined.empty)
}

I finished the bindings for test.each and describe.each. Tried creating a pull request - never done this before. Check it out.

1 Like

Sorry, I meant vitest config something like:

// in your vitest.config.ts or vite.config.ts
import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    deps: {
      inline: true, // this
      fallbackCjs: true, // or this
    },
  },
});