Log inGet started
Package

bench.module

README.md

bench

Run test cases in-process, without the engine's test runner.

The engine's own runner (`Test.run`, behind `tests.run` and a suite's `:run()`) closes the open scene before
the first test and reloads it from source after the last. That is right for a regression sweep and wrong while
other people are working in the same engine client. This bench runs the SAME cases against a small framework
of its own, touching nothing but the Lua values the cases make.

A case module is a plain module that returns a function taking the framework:

  -- myKit.package/tests/cases/heat.module/init.luau
  local Heat = require("myKit.modules.heat")
  return function(Test: any)
      Test.describe("myKit.heat", function()
          Test.it("adds the points of a named offence", function()
              Test.expect(Heat.new(cfg):add("seen")).toBe(12)
          end)
      end)
  end

The package's `.testSuite/init.luau` hands the engine's framework to the same modules, so the engine runner
and this bench run identical cases:

  local Test = asset.containing(__FILE__).modules.shared
  require("~.tests.cases.heat")(Test)
  return true

From an `execute` script:

  local Bench = require("caseBench.modules.bench")
  return Bench.run({
      { name = "myKit", cases = { require("myKit.tests.cases.heat") } },
  }, { filter = "heat", clock = os.clock })
  -- { total, passed, failed, skipped, seconds,
  --   suites = { { name, total, passed, failed, skipped, seconds } },
  --   failures = { { suite, group, test, errors = { "..." } } },
  --   slowest = { { name, seconds } } }

The framework it hands to cases (the subset of the engine's `Test` the cases may use):
  describe(name, fn)   it(name, fn(t))   skip(name, fn?)   beforeEach(fn)   afterEach(fn)
  expect(value) with toBe, toBeTruthy, toBeFalsy, toBeNil, notToBeNil, toBeType, toBeGreaterThan, toBeLessThan,
  toBeCloseTo(expected, within = 0.001), toContain, toMatch, toHaveLength, toThrow, and never() to negate.
As in the engine's framework a failed expectation is recorded and the body runs on; a raise ends the body.
Cases must be synchronous (no waitFrames): they are logic tests.

The interface is documented in the header of init.luau; this file repeats it for the asset browser.