sweet 0.1.12

Declarative testing framework
Documentation

sweet

Write many tests quickly and cleanly.

Features

  • 🔥 Parallel
  • 🕙 Async
  • 🌍 WASM
  • ☮️ Intuitive matchers
  • 🌈 Pretty output
pub use sweet::*;

sweet! {
  it "works" {
		// use regular assertions
		assert!(true == false);
		// or pretty matchers
		expect(true).to_be_false()?;
		expect("some string").not().to_start_with("some")?;
  }
}

Native

The Sweet harness has a couple of advantages over default tests.

  • Suites - Organize your tests into collections
  • Matchers - Matchers specific to a type enables a harness to output more intuitive results instead of an opaque panic!
    •   expect("foo").not().to_start_with("bar")
        //expected: NOT to start with 'bar'
        //received: 'foo'
      
  • Single Binary - The default intergration test approach creates a seperate binary for each test, which ramps up compile times, see this blog for more info.

Quickstart

  1. edit cargo.toml
    [dev-dependencies]
    
    sweet = # current version here
    
    
    
    [[test]]
    
    name = "sweet"
    
    path = "test/sweet.rs"
    
    harness = false
    
    
  2. create file test/sweet.rs
    #![feature(imported_main)]
    pub use sweet::*;
    
    sweet! {
      it "works" {
        expect(true).to_be_false()?;
      }
    }
    
  3. run cargo test --test sweet

Features - CLI

  • Run
    • cargo test --test sweet
  • With watch
    • cargo watch -q -x 'test --test sweet -- -w'
    • Clears terminal on each run
    • Returns an exit code zero (cleaner output)
  • Specify filename
    • cargo test --test sweet -- my_test
    • Use forward-slash / to specify directories
      • cargo test --test sweet -- my_dir/my_test

WASM

The wasm test harness has different priorities from wasm-bindgen-test

  • UI - Tests are run in a *mostly isolated iframe (see TODO)
  • Interactive - the runner will list all tests and they can be run at-will in the browser.

Quickstart

  1. Follow native quickstart
  2. install the cli
    • cargo install forky_cli
  3. forky_cli sweet
    • or for workspaces forky_cli sweet -p my_package

Features - Summary

  • Pretty Messages
    • Success
      • success
    • In progress
      • progress
    • Failure
      • failure

Dont Panic

Or do, thats ok too. Currently you'll get the prettiest output by using the provided matchers that return results intstead of panicing, especially in wasm as panic=unwind isnt yet supported for wasm.

Reference

  • Matchers inspired by jest
  • WASM runner inspired by cypress

TODO

  • wasm
    • node & headless support
    • seperate interactive runner from tests, currently the runner code, css etc is included.
    • catch panics in test, like how wasm-bindgen-test does it