New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bs-ospec

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bs-ospec

Hello! This project allows you to quickly get started with Reason and BuckleScript. If you wanted a more sophisticated version, try the `react` template (`bsb -theme react -init .`).

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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 tests are in a folder EXACTLY named tests/ (this limitation should soon be lifted).

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;

describe("Example", () => {

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

  testAsync("async example", done_ => {
    /* Note how we use testAsync() instead of test() !! */
    someTask()
    |> Task.run(result => {
      result |> equals("expected");
      done_()
    })
  });

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

    someLongTask()
    |> Task.run(result => {
      result |> equals("expected");
      done_()
    })
  });
});

Lastly, run ospec in your terminal to run your test suite.

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

Keywords

FAQs

Package last updated on 04 May 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc