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

@bemedev/vitest-extended

v1.5.3

Published

Extensions to build tests in vitest

Readme

@bemedev/vitest-extended

Extensions pour faciliter la création de tests avec Vitest.

Installation

npm install @bemedev/vitest-extended

ou

pnpm add @bemedev/vitest-extended

ou

yarn add @bemedev/vitest-extended

Utilisation

Importation des fonctions

import {
  useTestFunctionAcceptation,
  useTFA /* Alias of useTestFunctionAcceptation*/,
  createTests,
  doneTest,
  useEach,
  useEachAsync,
  useEachCases,
} from '@bemedev/vitest-extended';

Exemples

Création de tests

import { createTests } from '@bemedev/vitest-extended';

const add = (a: number, b: number) => a + b;

describe('Addition', () => {
  const { success } = createTests(
    add,
    {}, // all options (optional)
  );

  success(
    { invite: 'addition de 1 et 2', parameters: [1, 2], expected: 3 },
    { invite: 'addition de 2 et 3', parameters: [2, 3], expected: 5 },
  );
});

Utilisation de doneTest

import { doneTest } from '@bemedev/vitest-extended';
import { createMachine, interpret, typings } from 'xstate';

const machine = createMachine(
  {
    id: 'my-machine',
    initial: 'idle',
    states: {
      idle: {
        on: {
          START: '/running',
        },
      },
      running: {
        on: {
          STOP: '/idle',
          FINISH: '/done',
        },
      },
      done: { entry: 'onDone' },
    },
  },
  typings({
    context: 'boolean',
    eventsMap: {
      START: 'primitive',
      STOP: 'primitive',
      FINISH: 'primitive',
    },
  }),
);

doneTest('test avec done', done => {
  const service = interpret(machine, { context: false });
  service.addOptions(({ voidAction }) => ({
    actions: {
      onDone: voidAction(done),
    },
  }));

  service.start();
  service.send('START');
  service.send('STOP');
  service.send('START');
  service.send('FINISH');
});

API

useTestFunctionAcceptation

Test d'acceptation pour une fonction.

useTFA

Alias de useTFA.

createTests

Crée des tests pour une fonction avec des cas spécifiques.

doneTest

Crée un test avec une fonction done et un timeout.

useEach

Version améliorée de test.each suivant le principe de la librairie.

useEachAsync

Version asynchrone de useEach.

useErrorAsync

Version asynchrone de useError.

NB:

  • You can mock the function and assign a value to this function at runtime
import { createTests } from '@bemedev/vitest-extended';

type Add_F = (numb1: number, numb2: number) => number;
const add: Add_F = (numb1, numb2) => numb1 + numb2;
const addTest = undefined as unknown as Add_F;

describe('#2 => CreateTests, funcTest is initialazed after', () => {
  const { success } = createTests.withImplementation(addTest, {
    instanciation: () => add,
    name: 'add', // Add a name because name is not provided at static time
  });

  describe(
    '#01 => success',
    success(
      {
        invite: '0 + 0 = 0',
        parameters: [0, 0],
        expected: 0,
      },
      {
        invite: '99 + 1 = 0',
        parameters: [99, 1],
        expected: 100,
      },
      {
        invite: '1 + 1 = 0',
        parameters: [1, 1],
        expected: 2,
      },
    ),
  );
});
  • And you can transform the function to test
import { createTests } from '@bemedev/vitest-extended';

const noArgs = () => 'no args';

describe('#1 => Transform', () => {
  const { success } = createTests(noArgs, { transform: () => 'result' });

  describe(
    '#01 => success',
    success({
      invite: 'no args',
      parameters: [],
      // Here the result is transformed from value "no args" to "result"
      expected: 'result',
    }),
  );
});
  • And customize the test function
import { createTests } from '@bemedev/vitest-extended';

describe('#01 => Add', () => {
  const add = (a: number, b: number) => a + b;
  const { success } = createTests(add, x => x.toLocaleString());

  describe(
    '#01 => success',
    success(
      {
        invite: '1 + 2',
        parameters: [1, 2],
        expected: '3',
      },
      {
        invite: '1 + 2, with specific test',
        parameters: [1, 2],
        expected: '31',
        test: (value, expected) => {
          expect(value + 1).toBe(expected);
        },
      },
    ),
  );
});

Licence

MIT

CHANGE_LOG

Auteur

Charles-Lévi BRI,

My github