{"id":"horsenuggets/testable","name":"testable","scope":"horsenuggets","platform":"roblox","description":"A Luau testing framework based off of TestEZ.","version":"1.7.0","latest":"1.7.0","versions":["0.0.0","0.0.3","0.0.4","0.0.5","0.1.0","0.1.1","0.1.2","1.0.0","1.0.1","1.1.0","1.1.1","1.1.2","1.1.3","1.1.4","1.1.5","1.1.6","1.2.0","1.3.0","1.4.0","1.5.0","1.6.0","1.6.1","1.6.2","1.7.0"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"503f97494b8889d6035141391d7650a7d1f5bf7eacef06e425532c932f7afc10","likes":0,"downloads":0,"install":"forest install horsenuggets/testable","url":"https://forest.dev/p/roblox/horsenuggets/testable","files":"https://api.forest.dev/ai/package/roblox/horsenuggets/testable/files","readme":"# testable\n\nA Luau testing framework based off of TestEZ. Testable extends TestEZ with parallel test\nexecution and support for [Lune](https://lune-org.github.io/docs), allowing you to run\ntests outside of the Roblox environment.\n\n## Usage\n\nA spec is a module that returns a function. It requires `describe`, `it`, `expect`, and\nwhatever else it needs from Testable...\n\n```luau\nconst Testable = require(\"@devpackages/testable\")\nconst describe, expect, it = Testable.describe, Testable.expect, Testable.it\n\nreturn function()\n    describe(\"parser\", function()\n        it(\"reads an empty document\", function()\n            expect(parse(\"\")).to.be.a(\"table\")\n        end)\n    end)\nend\n```\n\nA test script prints a report and receives the results along with whether every test\npassed. On Roblox, `Testable.run` takes an instance whose `.spec` modules are collected.\nOn Lune, [Spec Discovery](#spec-discovery) finds the spec paths for `Testable.runFiles`,\nwhich can run them locally or in isolated worker VMs...\n\n```luau\nconst Testable = require(\"@devpackages/testable\")\n\nconst files = Testable.Discovery.findSpecs({ Include = { \"Tests/**/*.spec.luau\" } })\nconst results, passed = Testable.runFiles(files)\n\nif passed then\n    print(\"All tests passed!\")\nelse\n    print(\"Some tests failed.\")\nend\n```\n\n`Testable.run` also accepts already-loaded test roots. A root can be a table with a `Name`\nand a `Func`, which works on both platforms (e.g.,\n`{ Name = \"ParserTest\", Func = require(\"./ParserTest.spec\") }`). See the\n[TestEZ documentation](https://roblox.github.io/testez/api-reference/) for the basics of\nwriting tests. The sections below cover what Testable adds, and their examples assume that\nthe functions they call were required as shown above.\n\n## Writing Specs\n\nEverything a spec can call is exported from Testable, including the lifecycle hooks\n(`beforeAll`, `beforeEach`, `afterEach`, and `afterAll`), `fail`, and the focus and skip\nvariants (`fit`, `xit`, `fdescribe`, `xdescribe`, `itFOCUS`, `itSKIP`, and so on).\nRequired functions are fully typed, work the same on Lune and Roblox, and don't need a\nlist of globals in `.luaurc`.\n\n**Injected Globals**\n\nSpecs written for TestEZ use the same functions as globals that Testable injects into the\nspec function, without requiring anything. That style keeps working, and both styles can\nbe mixed in one run. Once every spec requires its functions, set `InjectGlobals = false`\nso that Testable stops rewriting function environments, which lets Luau optimize spec code\nagain.\n\n**Late Registration**\n\nCalling `describe`, `it`, or a hook after its block has been collected (e.g., from inside\na running test) is an error in both styles, rather than a registration that silently never\nruns.\n\n**Threads Started by a Test**\n\nTestable ties `expect` and `fail` to a test through the coroutine that runs it, including\nacross yields. A thread that the test starts itself (e.g., with `task.spawn`) isn't tied\nto it, so there `fail` and `expect.extend` raise an error and `expect` only offers the\nbuilt-in matchers. Wrap the function with `Testable.bindTest` to tie it to the test that\nis running when `bindTest` is called...\n\n```luau\nit(\"fails from another thread\", function()\n    task.spawn(Testable.bindTest(function()\n        fail(\"This fails the test above.\")\n    end))\nend)\n```\n\nInjected globals behave the same way on the test's own coroutine. In other threads they\nfall back to the test in their block that started most recently, as they always have.\n\n**Custom Matcher Types**\n\n`Testable.Expect` takes the shape of matchers added with `expect.extend`, so they can be\ntyped as well...\n\n```luau\ntype Matchers = { beEven: () -> any }\n\nconst expect: Testable.Expect<Matchers> = Testable.expect :: any\n```\n\n## Matchers\n\nOn top of the TestEZ matchers (`equal`, `ok`, `near`, `throw`, and `a`), `expect` offers a\nricher vocabulary in the same chain style. All of them can be negated with `.never`...\n\n```luau\nexpect({ 1, { 2 } }).to.deepEqual({ 1, { 2 } })\nexpect(\"hello world\").to.contain(\"world\")\nexpect({ 1, 2, 3 }).to.have.length(3)\nexpect(\"abc123\").to.match(\"%a+%d+\")\nexpect(5).to.be.greaterThan(3)\nexpect(nil).never.to.be.truthy()\n```\n\n- `deepEqual(expected)` → Compares tables recursively by contents. NaN equals NaN, and\n  cyclic tables are safe.\n- `contain(item)` → Finds a plain substring in a string, or a deeply equal element in an\n  array.\n- `length(count)` → Checks `#value` for a string or a table.\n- `match(pattern)` → Matches a string against a Luau string pattern.\n- `greaterThan(bound)`, `greaterThanOrEqual(bound)`, `lessThan(bound)`, and\n  `lessThanOrEqual(bound)` → Order two numbers or two strings.\n- `truthy()` and `falsy()` → Check whether the value is anything but `false` and `nil`, or\n  one of those two.\n- `none()` → Checks that the value is exactly `nil`.\n- `a(typeName)` → Accepts either the `typeof` name (e.g., `\"Vector3\"`) or the `type` name\n  (e.g., `\"userdata\"`).\n- `matchSnapshot(hint)` → Compares the value against the one stored from an earlier run\n  (see [Snapshots](#snapshots)).\n\nFailed comparisons report `Expected` and `Received` lines. Tables are pretty-printed with\nsorted keys, and deeply nested values are shortened to `{...}` in the message only. Using\na matcher on the wrong kind of value (e.g., `greaterThan` with a table) fails the test\nwith a message that names the matcher, even under `.never`. These names are reserved, so\n`expect.extend` rejects custom matchers that reuse them.\n\n## Skipping, Todo Tests & Focus\n\nSkipped tests never affect whether a run passes. Every skip variant takes an optional\nreason as its last argument, and the reason is shown next to the test when `PrintSkipped`\nis on...\n\n```luau\nitSKIP(\"retries the upload\", function() end, \"waiting on the new API\")\n\ndescribeSKIP(\"matchmaking\", function()\n    it(\"fills a lobby\", function() end)\nend, \"needs a live server\")\n\ndescribe(\"trading\", function()\n    SKIP(\"blocked on the inventory rewrite\")\nend)\n\nitFIXME(\"rounds prices\", function() end, \"off by one cent\")\nitTODO(\"rejects expired offers\")\n```\n\n- `itSKIP` and `xit` → Skip one test.\n- `describeSKIP`, `xdescribe`, and `SKIP()` → Skip a whole block. Its tests inherit the\n  block's reason unless they carry their own.\n- `itFIXME` and `FIXME()` → Skip a broken test with the reason `fixme`, followed by the\n  optional message.\n- `itTODO` → Record a test you intend to write. It takes a name only, so passing a body is\n  an error, and it is reported as skipped with the reason `todo`.\n\n**Focus Guard**\n\nA test or block marked with `itFOCUS`, `fit`, `describeFOCUS`, `fdescribe`, or `FOCUS()`\nskips every other test, and those tests get the reason `excluded by focus`. The summary\nalways says how many tests focus excluded. Because a focus modifier that gets committed by\naccident would otherwise leave the run green, set `ForbidFocus` in CI to fail the run\nwhenever focus excluded a test...\n\n```luau\nTestable.configure({ ForbidFocus = process.env.CI ~= nil })\n```\n\nThe failure counts as one failed test in the results, so `passed` is `false` and\n`results.failureCount` goes up by one. Results also expose `results.focusExcludedCount`,\nand each skipped result node carries its reason in `skipReason`.\n\n## Timeouts\n\nA test that yields forever (e.g., one waiting on a signal that never fires) would\notherwise hang the whole run. Set the `Timeout` option to give every test a time budget in\nseconds. It's off by default, so tests may run for as long as they like until you set\nit...\n\n```luau\nTestable.configure({ Timeout = 5 })\n```\n\nA single test can raise or lower its budget with an options table as the third argument of\n`it` (or `itFOCUS` and `fit`). Use `math.huge` to turn the limit off for that test. The\noption on a test works even when no `Timeout` is configured...\n\n```luau\nit(\"waits for a slow service\", function()\n    -- ...\nend, { Timeout = 30 })\n```\n\nA test that runs past its budget is reported as failed with a message naming the budget,\nits thread is cancelled, its `afterEach` hooks still run, and the rest of the run carries\non. Here's what else to know...\n\n- Every `beforeEach` and `afterEach` hook gets the same budget as the test it surrounds,\n  counted separately for each hook, so a slow hook doesn't use up the time of the test.\n- The `beforeAll` and `afterAll` hooks get the configured budget, since they belong to no\n  single test.\n- Only code that yields can be interrupted. A busy loop that never yields blocks the Luau\n  scheduler, so the budget can't stop it and the run still hangs. Work that doesn't yield\n  but does return still counts against the budget, so a test that finishes over budget is\n  reported as timed out.\n- Cancelling a test stops its own thread only. Threads that the test started with\n  `task.spawn` or `task.delay` keep running.\n\nAny hook can set a budget of its own with an options table as its second argument, which\nwins over the one it would inherit. Use `math.huge` to turn the limit off for that hook...\n\n```luau\nbeforeAll(function()\n    -- ...\nend, { Timeout = 30 })\n```\n\n## Serial Tests\n\nTests run in parallel by default, so tests that share global state (a module-level\nvariable, `Testable.configure`, a file on disk) can see each other's changes. Mark a test\nor a whole describe block as `Serial` to run it with no other test of the run executing at\nthe same time...\n\n```luau\nit(\"writes the shared fixture\", function()\n    -- ...\nend, { Serial = true })\n\ndescribe(\"configuration\", function()\n    -- ...\nend, { Serial = true })\n```\n\n- A serial test waits for the tests that are already running to finish, and keeps new ones\n  from starting until it is done.\n- Every test under a serial describe block runs one at a time, and the block as a whole\n  waits for the rest of the run.\n- Serial tests anywhere in the run wait for each other, even across specs.\n- Ordinary tests keep running in parallel, so only mark what shares state, since serial\n  tests trade speed for isolation.\n\n## Snapshots\n\nCall `matchSnapshot` to compare a value against the one stored from an earlier run...\n\n```luau\nit(\"renders the summary\", function()\n    expect(render(report)).to.matchSnapshot()\n    expect(render(report, { Compact = true })).to.matchSnapshot(\"compact layout\")\nend)\n```\n\nA value with nothing stored is written and passes, so review new snapshot files before\ncommitting them. A value that equals the stored one passes, and a different value fails\nwith a line diff labeled by the snapshot's key. Set `UpdateSnapshots = true` to accept\nchanged values instead. This repository's own runner turns it on with\n`./Scripts/RunTests.exec.luau --update-snapshots`.\n\nEach key is the full test name (the spec name, describe blocks, and test joined by `>`)\nfollowed by the snapshot's number within the test, or by the hint when one is given.\nValues are serialized with sorted keys and no depth cap. Functions, threads, and userdata\nare written as their type name (e.g., `<function>`), while a cyclic value or a table key\nthat is not a string, number, or boolean fails the assertion.\n\nIn Lune, snapshots live in a plain text file beside the spec, at\n`__snapshots__/<spec file name>.snap`, and should be committed with the tests. Pass\n`SnapshotPath` on a test root to choose another location...\n\n```luau\nTestable.run({\n    { Name = \"ReportTest\", Func = require(\"./ReportTest.spec\"), SnapshotPath = \"Snapshots/Report.snap\" },\n})\n```\n\nRoblox has no filesystem, so set `SnapshotStore` to a table with `read(path)` (returning\nthe contents or `nil`) and `write(path, contents)` functions. Without one, `matchSnapshot`\nfails there. `Testable.Snapshots.MemorySnapshotStore.new(files)` keeps files in a table\nthat you can seed before a run and persist afterward.\n\nStored snapshots that no test produced are listed as obsolete in the run summary, and\nupdate mode removes them. Detection only covers snapshot files used during the run, and it\nis skipped when the run was focused or filtered, or when a test or describe block in the\nspec failed or was skipped.\n\n## Configuration\n\nOptions are set with `Testable.configure()` before a run. Only the keys you pass change,\nand `Testable.resetConfig()` puts every option back to its default...\n\n```luau\nconst Testable = require(\"@devpackages/testable\")\n\nTestable.configure({\n    MaxConcurrency = 8,\n    PrintSkipped = true,\n    Timeout = 5,\n})\n```\n\n| Option              | Type                                        | Default        | Description                                                                                                                                |\n| ------------------- | ------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |\n| `AlphabeticalSort`  | `boolean`                                   | `false`        | Sorts test results alphabetically instead of in definition order.                                                                          |\n| `Coverage`          | `boolean`                                   | `false`        | Measures line coverage during the run, which only works in Lune (see [Coverage](#coverage)).                                               |\n| `CoverageRoots`     | `any?`                                      | `nil`          | Script instances or string paths, optionally in a named dictionary, whose modules coverage is reported for.                                |\n| `CoverageRows`      | `number`                                    | `20`           | File rows listed in the coverage table before the rest fold into a summary row.                                                            |\n| `CoverageSort`      | `\"Percentage\" \\| \"HitLines\"`                | `\"Percentage\"` | Orders coverage rows by percentage or by hit lines, both descending.                                                                       |\n| `CoverageThreshold` | `number`                                    | `0`            | Fails the run when total coverage is below this percentage, from `0` to `100`.                                                             |\n| `Filter`            | `string?`                                   | `nil`          | Only runs tests whose full name contains this text (see [Filtering Tests](#filtering-tests)).                                              |\n| `ForbidFocus`       | `boolean`                                   | `false`        | Fails the run when a focus modifier excluded any test.                                                                                     |\n| `Indent`            | `string`                                    | `\"   \"`        | Indentation string used for nested test output.                                                                                            |\n| `InjectGlobals`     | `boolean`                                   | `true`         | Injects `describe`, `it`, `expect`, and the rest into spec functions as globals.                                                           |\n| `Log`               | `((message: string) -> ())?`                | `nil`          | Receives native verbose messages instead of printing them. Does not receive reports or test-owned output.                                  |\n| `MaxConcurrency`    | `number`                                    | `4`            | Maximum number of tests to run in parallel within each VM.                                                                                 |\n| `Parallel`          | `boolean`                                   | `true`         | Runs tests in parallel instead of one after another.                                                                                       |\n| `PrintSkipped`      | `boolean`                                   | `false`        | Includes skipped tests in the output.                                                                                                      |\n| `ReporterOutputs`   | `{ [s","readmeTruncated":true,"readmeFull":"https://api.forest.dev/v1/package/horsenuggets/roblox/testable/1.7.0/readme"}