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 🙏

© 2024 – Pkg Stats / Ryan Hefner

typed-jest

v0.2.1

Published

An all-in-one test framework supporting TypeScript out-of-box.

Downloads

69

Readme

typed-jest

License Version Downloads Dependencies Size

An all-in-one test framework supporting TypeScript out-of-box.

Features

  • 100% compatible with Jest. Use typed-jest just like you would use jest.
  • Out-of-the-box TypeScript support.
  • All in one. The best practice to use jest in TypeScript (CJS) project.
  • No implicit globals.
  • Sensible defaults adhering to best practices. Most projects work seamlessly with zero configuration.
  • Integrated supertest in it.

Why

This is an all-in-one test framework designed for legacy CommonJS TypesScript project, supporting experimentalDecorators and emitDecoratorMetadata. For modern ESM project, you should consider to use Vitest.

Usage

  1. Uninstall jest, @types/jest, and ts-jest if they are already installed in your project.
pnpm remove jest @types/jest ts-jest
  1. Install typed-jest.
pnpm add -D typed-jest
  1. Create an app.ts file.
import fs from "node:fs";
import express, { type Express } from "express";

const json = fs.readFileSync("package.json", "utf-8");

const app: Express = express();
app.get("/pkg", function (_req, res) {
  console.log("package.json", json);
  res.status(200).json(JSON.parse(json));
});

export default app;
  1. Create an app.spec.ts file.
import { afterEach, beforeEach, describe, expect, it, jest } from "typed-jest";
import supertest from "typed-jest/supertest";
import app from "./app";

jest.mock("node:fs", () => ({
  readFileSync: () => JSON.stringify({ foo: "bar" }),
}));

describe("app", () => {
  beforeEach(() => {
    console.log("========beforeEach running========");
  });
  afterEach(() => {
    console.log("========afterEach running========");
  });
  it("should be 2", () => {
    expect(1 + 1).toBe(2);
  });
  it("should success", async () => {
    const response = await supertest(app).get("/pkg");
    expect(response.status).toEqual(200);
    expect(response.body).toStrictEqual({ foo: "bar" });
  });
});
  1. Run pnpm jest to execute tests.

Note: For the projects using npm as its package manager, please use npx typed-jest instead.

Configuration

  1. Add more CLI configurations after the pnpm jest command. For example, run pnpm jest --coverage to collect test coverage. Run pnpm jest -h for more CLI options information.
  2. Add a jest.config.js file in the root of your project. Consult the official Jest documentation for more information.

How it works

If you don't include CLI options when running pnpm jest, we will append some sensible defaults:

  • --transform='{"^.+\\\\.tsx?$":"ts-jest"}': This option transforms TypeScript files, so you can support TypeScript projects without additional configurations or installations.
  • --passWithNoTests: This option prevents the CLI from producing errors if no tests are found. You can override this default by pnpm jest --passWithNoTests=false.
  • --collectCoverageFrom='**/src/**/*.{js,mjs,cjs,jsx,ts,mts,cts,tsx}': This option specifies the location for collecting test coverage. Override it as needed: pnpm jest --collectCoverageFrom='**/lib/**/*.js'

License

MIT