Skip to content

Vitest and Rollup

Dipend integrates cleanly with modern development tools like Vitest for testing and Rollup for bundling. This guide walks you through how to configure each.

Vitest is a fast unit test framework built on top of Vite, with first-class TypeScript support.

Terminal window
npm install --save-dev vitest @vitest/ui @rollup/plugin-typescript ts-patch

If not already done:

Terminal window
npx dipend init

Create or edit a file called vitest.config.ts:

vitest.config.ts
import { defineConfig } from "vitest/config";
import tsPlugin from "@rollup/plugin-typescript";
const tspCompiler = require("ts-patch/compiler");
export default defineConfig({
test: {
coverage: {
enabled: true,
exclude: ["**/node_modules/**", "**/vitest.config.ts", "**/dist/**"],
},
},
server: {
host: "127.0.0.1",
},
plugins: [tsPlugin({ typescript: tspCompiler })],
});

Create a test like this:

greeter.test.ts
import { describe, it, expect, vi } from "vitest";
import { DependencyContainer } from "dipend";
import { Greeter } from "./greeter";
import { ILogger } from "./logger";
describe("Greeter", () => {
const dependencyContainer = new DependencyContainer();
afterEach(() => {
vi.restoreAllMocks();
dependencyContainer.reset(); // clean the container
});
it("greets with a name", () => {
const logger: ILogger = { info: vi.fn() };
dependencyContainer.addSingletonInstance<ILogger>({ instance: logger });
dependencyContainer.addSingleton<Greeter>();
const greeter = dependencyContainer.getDependency<Greeter>();
expect(greeter.greet("Alice")).toBe("Hello, Alice!");
expect(logger.info).toHaveBeenCalledWith("Hello, Alice!");
});
});
Terminal window
npx vitest run

Or with UI:

Terminal window
npx vitest --ui

Rollup is a modern bundler ideal for building TypeScript libraries and applications.

Terminal window
npm install --save-dev rollup @rollup/plugin-typescript ts-patch

If not already done:

Terminal window
npx dipend init

Create a rollup.config.js file:

rollup.config.js
import typescript from "@rollup/plugin-typescript";
const tspCompiler = require("ts-patch/compiler");
export default {
input: "./index.ts",
output: {
dir: "dist",
format: "esm",
sourcemap: true,
},
plugins: [typescript({ typescript: tspCompiler })],
};
Terminal window
npx rollup -c

This will bundle your application or library into the dist folder.


You’re now set up for a full development workflow using Dipend, Vitest, and Rollup!