npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rbxts-transformer-jest

v0.0.8

Published

A Jest transformer for Roblox TypeScript (rbxts) projects.

Readme

rbxts-transformer-jest

npm version CI License: MIT

TypeScript custom transformer for roblox-ts that hoists jest.mock() and jest.unmock() calls above imports at compile time.

The Problem

Jest requires jest.mock() calls to execute before the modules they target are imported. You could manually place mocks above imports, but that's tedious and easy to forget. Without Babel in the roblox-ts pipeline, there's no built-in way to automate it.

This transformer reorders statements at the AST level so mocks run before imports.

Prerequisites

Requires @rbxts/jest and @rbxts/jest-globals.

Install

pnpm i -D rbxts-transformer-jest

Setup

Add to your tsconfig.json:

{
	"compilerOptions": {
		"plugins": [
			{
				"transform": "rbxts-transformer-jest",
			},
		],
	},
}

Before / After

Input:

import { jest } from "@rbxts/jest-globals";

import { MyService } from "./my-service";

const mockHandler = jest.fn();
jest.mock("./my-service", () => ({ handler: mockHandler }));

Output (reordered at compile time):

import { jest } from "@rbxts/jest-globals";

const mockHandler = jest.fn();
jest.mock("./my-service", () => ({ handler: mockHandler }));

import { MyService } from "./my-service";

The @rbxts/jest-globals import always stays first. Mock-prefix variables referenced in factories get hoisted alongside the mock call.

String Require Support

The transformer can resolve package specifiers like "@rbxts/services" into Roblox instance paths at compile time, so you can write:

jest.mock<typeof import("@rbxts/services")>("@rbxts/services", () => {
	return { Workspace: {} as Workspace };
});

This compiles to the equivalent of:

jest.mock(game:GetService("ReplicatedStorage"):FindFirstChild("rbxts_include"):FindFirstChild("node_modules"):FindFirstChild("@rbxts"):FindFirstChild("services"), function() ... end)

Note: This string-specifier support applies to every method whose first argument the transformer resolves: jest.mock(), jest.unmock(), jest.doMock(), jest.dontMock(), and jest.requireActual(). If your @rbxts/jest types only accept ModuleScript for any of these (they don't account for string specifiers being rewritten at compile time), you must augment @rbxts/jest-globals with a string overload for that method — e.g. declare module "@rbxts/jest-globals" { namespace jest { function doMock<T = unknown>(moduleScript: string, factory?: () => T): typeof jest; } } — or pnpm typecheck will reject the string argument.

Per-test Mocking (doMock / dontMock)

jest.mock() / jest.unmock() are hoisted to file scope, so they apply to the whole test file. For per-test or per-describe mocking, use the imperative jest.doMock() / jest.dontMock(). These are not hoisted (they run where you write them) and their factories are not validated, so the factory may reference imported helpers:

import { beforeEach, describe, expect, it, jest } from "@rbxts/jest-globals";

import { createServicesMock } from "./test/mock-services";

describe("server", () => {
	beforeEach(() => {
		jest.resetModules();
		jest.doMock("@rbxts/services", () => {
			return createServicesMock({ RunService: { IsServer: () => true } });
		});
	});

	it("sees IsServer() === true via dynamic import", async () => {
		const { RunService } = await import("@rbxts/services");
		expect(RunService.IsServer()).toBe(true);
	});
});

The transformer resolves the module-string first argument of doMock, dontMock, and requireActual to a Roblox instance path, exactly as it does for hoisted mock / unmock. Chained doMock / dontMock calls are supported. (As with mock / unmock, the string overload must exist in your @rbxts/jest types — see the note above.)

License

MIT