Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@arktype/attest
Advanced tools
This package is under active development.
If you want to try it, you'll need to call our setup/cleanup methods before and after your tests run.
For example, in mocha:
import { cleanup, setup } from "@arktype/attest"
export const mochaGlobalSetup = setup
export const mochaGlobalTeardown = cleanup
Here are some simple examples of type assertions and snapshotting:
import { attest } from "@arktype/attest"
import { test } from "mocha"
const o = { ark: "type" } as const
const shouldThrow = (a: false) => {
if (a) {
throw new Error(`${a} is not assignable to false`)
}
}
test("value snap", () => {
attest(o).snap()
})
test("type snap", () => {
attest(o).type.toString.snap()
})
test("typed value assertions", () => {
// assert the type of `o` is exactly { readonly ark: "type" }
attest<{ readonly ark: "type" }>(o)
})
test("type-only assertions", () => {
// assert that two types are equivalent without a value
attest<{ readonly ark: "type" }, typeof o>()
})
test("chained snaps", () => {
attest(o).snap().type.toString.snap()
})
test("error and type error snap", () => {
// @ts-expect-error
attest(() => shouldThrow(true))
.throws.snap()
.type.errors.snap()
})
Benches are run separately from tests and don't require any special setup. If the below file was benches.ts
, you could run it using something like tsx benches.ts
or ts-node benches.ts
:
import { bench } from "@arktype/attest"
type MakeComplexType<S extends string> = S extends `${infer head}${infer tail}`
? head | tail | MakeComplexType<tail>
: S
bench(
"bench call single stat median",
() => "boofoozoo".includes("foo")
// will snapshot execution time
).median()
bench("bench type", () => {
return [] as any as MakeComplexType<"defenestration">
// will snapshot type instantiation count
// can be a bit finicky, sometimes requires the type to be returned or assigned to a variable
// if the result is 0, something is probably off :-)
}).types()
bench(
"bench call and type",
() =>
/.*foo.*/.test(
"boofoozoo"
) as any as MakeComplexType<"antidisestablishmenttarianism">
)
// runtime and type benchmarks can be chained for an expression
.mean()
.types()
FAQs
Attest is a testing library that makes your TypeScript types available at runtime, giving you access to precise type-level assertions and performance benchmarks.
The npm package @arktype/attest receives a total of 728 weekly downloads. As such, @arktype/attest popularity was classified as not popular.
We found that @arktype/attest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.