Testend
Integrations
jest

Jest Integration

taskend provides a compatibility package for jest users.

Installation

# npm
npm i -D @taskend/compat-jest
# yarn
yarn add -D @taskend/compat-jest
# pnpm
pnpm i -D @taskend/compat-jest

Usage

taskend.config.ts:

import { graph, config, comamnds, subcommand } from "taskend";
 
const testFiles = graph({
    name: "unitTests",
    files: ["tests/**/*.ts"],
});
 
export const commands = comamnds(() => {
    test: subcommand({
        default: {
            async run() {
                const tests = await unitTests.getChangedFiles();
                if (tests.length) {
                    await $`jest --runTestsByPath ${tests}`;
                    await unitTests.markAsTested();
                }
            },
        },
        // Only if you want to use Jest's watch mode
 
        watch: {
            async run() {
                // You may prefer to use `jest --watch` directly instead
                await $`TE_GRAPH=unitTests jest --watch`;
            },
        },
    }),
})
 
export default config({
    graphs: {
        unitTests,
    },
});

If you want to use Jest's watch mode, you need to enable the watch plugin provided by this package in your jest config.

jest.config.ts:

import type { Config } from "jest";
 
const config: Config = {
    watchPlugins: ["@taskend/compat-jest/watch-plugin"],
};

Then, you can do npx te test or npx te test watch to run your tests.