
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
@glennsl/rescript-jest
Advanced tools
NOTE: The NPM package has moved to @glennsl/rescript-jest
. Remember to update both package.json
AND bsconfig.json
.
afterAllAsync
and afterAllPromise
hooks now time-out consistent with the behavior of beforeAllAsync
and beforeAllPromise
in version 0.7.0 of bs-jest. beforeAllAsync
and beforeAllPromise
also now behave consistently with 'afterAllAsync
and afterAllPromise
when included in skipped test suites.rescript-promise
in place of Js.Promise
.@bs.send.pipe
bindings were converted to rescript @send
bindings.To generate ES6 bindings for your project, update bsconfig.json
"suffix": ".mjs",
"package-specs": {
"module": "ES6",
"in-source": true
},
Then add @babel/core, @babel/present-env and babel-jest packages to your project. Also, add babel.config.js
module.exports = {
presets: [
['@babel/preset-env',
{targets: {node: 'current'}}
]
],
"plugins": []
}
Finally, add minimal jest.config.js
module.exports = {
moduleFileExtensions: [
"js",
"mjs",
],
testMatch: [
"**/__tests__/**/*_test.mjs",
"**/__tests__/**/*_test.bs.js",
],
transform: {
"^.+\.m?js$": "babel-jest"
},
transformIgnorePatterns: [
"node_modules/(?!(rescript)/)"
],
Update testMatch, transform and transformIgnorePatterns settings depending on where your tests are stored, and other dependenies of your project that may need to be transformed to ES6 format.
Most of what's commonly used is very stable. But the more js-y parts should be considered experimental, such as mocking and some of the expects that don't transfer well, or just don't make sense for testing idiomatic Reason/OCaml code but could be useful for testing js interop.
require.*
ExpectJs
. Some functionality does not make sense in a typed language, or is not possible to implement sensibly in Rescript.MockJs
module as it's very quirky to use with native code. A separate native from-scratch implementation might suddenly appear as Mock
.JestJs
. It's mostly implemented, but experimental and largely untested.open Jest;
describe("Expect", () => {
open Expect;
test("toBe", () =>
expect(1 + 2) -> toBe(3))
});
describe("Expect.Operators", () => {
open Expect;
open! Expect.Operators;
test("==", () =>
expect(1 + 2) === 3)
}
);
See the tests for more examples.
npm install --save-dev @glennsl/rescript-jest
or
yarn install --save-dev @glennsl/rescript-jest
Then add @glennsl/rescript-jest
to bs-dev-dependencies
in your bsconfig.json
:
{
...
"bs-dev-dependencies": ["@glennsl/rescript-jest"]
}
Then add __tests__
to sources
in your bsconfig.json
:
"sources": [
{
"dir": "src"
},
{
"dir": "__tests__",
"type": "dev"
}
]
Put tests in a __tests__
directory and use the suffix *test.res
/ (Make sure to use valid module names. e.g. <name>_test.res
is valid while <name>.test.res
is not). When compiled they will be put in a __tests__
directory under lib
, with a *test.bs.js
suffix, ready to be picked up when you run jest
. If you're not already familiar with Jest, see the Jest documentation.
One very important difference from Jest is that assertions are not imperative. That is, expect(1 + 2) -> toBe(3)
, for example, will not "execute" the assertion then and there. It will instead return an assertion
value which must be returned from the test function. Only after the test function has completed will the returned assertion be checked. Any other assertions will be ignored, but unless you explicitly ignore them, it will produce compiler warnings about unused values. This means there can be at most one assertion per test. But it also means there must be at least one assertion per test. You can't forget an assertion in a branch, and think the test passes when in fact it doesn't even test anything. It will also force you to write simple tests that are easy to understand and refactor, and will give you more information about what's wrong when something does go wrong.
At first sight this may still seem very limiting, and if you write very imperative code it really is, but I'd argue the real problem then is the imperative code. There are however some workarounds that can alleviate this:
expect((this, that)) -> toBe((3, 4))
testAll
function to generate tests based on a list of datadescribe
and/or beforeAll
to do setup for a group of tests. Code written in Rescript is immutable by default. Take advantage of it.For the moment, please refer to Jest.resi.
If you encounter the error SyntaxError: Cannot use import statement outside a module
, it may be that you are mixing es6
and commonjs
modules in your project. For example, this can happen when you are building a React project since React builds are always in ES6. To fix this, please do the following:
bsconfig.json
compiles "es6"
or "es6-global"
: "package-specs": {
"module": "es6",
}
yarn
or npm
as a devDependency
.rescript build -with-deps
.jest
of your package.json
):{
"transform": {
"^.+\\.jsx?$": "esbuild-jest"
},
"transformIgnorePatterns": ["<rootDir>/node_modules/(?!(rescript|@glennsl/rescript-jest)/)"]
}
"transformIgnorePatterns"
is an array of strings. Either you do some regex or organize them in an array. Please make sure all folders in node_modules
involving compiled .res/.ml/.re files and the like such as rescript
or @glennsl/rescript-jest
are mentioned in the aforementioned array.This problem is also addressed in Issue #63.
git clone https://github.com/glennsl/rescript-jest.git
cd rescript-jest
npm install
Then build and run tests with npm test
, start watchers for rescript
and jest
with npm run watch:rescript
and npm run watch:jest
respectively. Install screen
to be able to use npm run watch:screen
to run both watchers in a single terminal window.
glennsl/rescript-jest
to glennsl/rescript-jest
@glennsl/rescript-jest
|>
operator is deprecated in Recript 9.x, all APIs now use data-first (->
) semantics.toThrowException
, toThrowMessage
and toThrowMessageRe
as they relied on assumptions about BuckleScript internals that no longer hold.Expect.toContainEqual
Expect.toMatchInlineSnapshot
Todo.test
describe
callbacks by explicitly returning undefined
(otherwise BuckleScript will return something else like ()
, which is represented as 0
)Jest.advanceTimersByTime
, which is basically just an alias of Jest.runTimersToTime
Expect.not__
for transitional compatibility with Reason syntax change of "unkeywording" not
by mangling it into not_
, and not_
into not__
and so on.afterAllPromise
too.bs-platform
4.0.7 (Thanks Bob!)MockJs.new0
, new1
and new2
timeout
argument to testAsync
and testPromise
functionsbeforeEachAsync
, beforeEachPromise
, afterEachAsync
and afterEachPromise
beforeAllAsync
, beforeAllPromise
, afterAllAsync
and afterAllPromise
reasonml-community/bs-jest
to glennsl/bs-jest
bs-jest
to @glennsl/bs-jest
toThrowException
test
function from jestnot_ |> toBeLessThanEqual
testAll
, Only.testAll
, Skip.testAll
that generates tests from a list of inputsfail
expectFn
FAQs
Rescript bindings to the Jest testing framework
The npm package @glennsl/rescript-jest receives a total of 409 weekly downloads. As such, @glennsl/rescript-jest popularity was classified as not popular.
We found that @glennsl/rescript-jest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.