npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bs-ospec

v1.0.0

Published

BuckleScript bindings for ospec.

Downloads

2

Readme

bs-ospec

BuckleScript bindings for the excellent and minimal ospec testing library. Perfect for simple testing and constructing your own, custom assertions.

Installation

$ npm install --save-dev ospec bs-ospec

Then add "bs-ospec" to your bsconfig.json dev dependencies:

{
  ...
  "bs-dev-dependencies": [
    "bs-ospec"
  ]
}

Example Usage

First make sure your test files names are easily distinguishable. Here are some examples:

| Format | Command to Run | | ---- | ---- | | Within a tests/ folder | ospec | | Within a custom folder like spec/ | ospec 'spec/**/*.bs.js' | | Named MyModuleTest.re in any folder | ospec '**/*Test.bs.js' |

Next, write your tests. Ospec uses a single function o() to do pretty much everything. However, OCaml doesn't support overloaded functions, so bs-ospec separates each use case into its own function (it all compiles to a single function in the end).

open BsOspec.Cjs;

describe("Example", () => {

  test("sync example", () => {
    f(x,y) |. equals(123);
    f(x,y) |. equals(~m="A descriptive failure message", 123);
    g(x,y) |. deepEquals(["another", "correct", "value"]);
  });

  testAsync("async example", done_ => {
    /* _ _  _  _  _   ___ _ _   _ _ __ __  __ _ _  __ _ */
    /* Note how we use testAsync() instead of test() !! */
    /*  ^^^ ^ ^ ^ ^^ ^ ^ ^ ^^ ^ ^ ^ ^ ^  ^^^ ^ ^^ ^^^ ^ */
    someFuture()
    |. Future.get(result => {
      result |. equals("expected");
      done_()
    })
  });

  testAsyncLong("longer async example", (done_, timeout) => {
    timeout(2000) /* ospec default is 50 milliseconds. */

    someLongFuture()
    |. Future.get(result => {
      result |. equals("expected");
      done_()
    })
  });
});

Lastly, run your test suite by running an ospec command like the table shown above.

ES Modules

BsOspec supports both CommonJS and ES Modules (ESM). BuckleScript is configured to use CommonJS by default; if you are using ESM, first configure your bsconfig.json to use es6-global:

{
  ...
  "package-specs": {
    "module": "es6-global",
    "in-source": true
  }
}

Then just write open BsOspec.Esm; instead of open BsOspec.Cjs; in your test files.

If you're interested in using ESM today, you can install the esm package and add --require esm to the end of your ospec command. For example:

ospec '**/*Test.bs.js' --require esm

Bindings

See the source for the full details.

Test Definitions:

  • describe - Group a collection of tests. Not required.
  • test - Define a synchronous test
  • testAsync - Define an async test
  • testAsyncLong - Define an async test expected to last longer than 50ms.
  • testOnly, testAsyncOnly, testAsyncLongOnly - Define and only run this test. Useful for focusing on a single test.

Hooks:

  • beforeEach, beforeEachAsync - Run code before each test
  • afterEach, afterEachAsync - Run code after each test
  • before, beforeAsync - Run code once before all tests
  • after, afterAsync - Run code once after all tests

Assertions:

  • equals(expected, ~m=?, actual) - Expect a value to equal another value. Optionally pass in ~m="my msg" to show a custom message if the assertion fails.
  • deepEquals(expected, ~m=?, actual) - Expect a value to deep equal another value.
  • notEquals(expected, ~m=?, actual)
  • notDeepEquals(expected, ~m=?, actual)

Build

npm run build

Build + Watch

npm run start

Editor

If you use vscode, Press Windows + Shift + B it will build automatically