Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

tdd-buffet

Package Overview
Dependencies
Maintainers
2
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tdd-buffet

All you can eat TDD tools and libraries

latest
Source
npmnpm
Version
4.0.0
Version published
Maintainers
2
Created
Source

All you can eat TDD tools and libraries

Build Status codecov npm type definitions

Install

npm install tdd-buffet

Testing

This package exposes a wrapper over Jest that provides the same building blocks for writing tests (describe and it) and also provides the same CLI.

Create a Node test

Ideally you should have many of these since they're fast to run. They execute in a jsdom environment so you can test both your Node libraries and your React components. Since they're fast, you should use them to check your code's correctness and achieve satisfactory coverage.

import { describe, it } from 'tdd-buffet/suite/node';
import { expect } from 'tdd-buffet/suite/chai';

describe('Node suite', () => {
  it('should run a test', () => {
    expect(1).to.equal(1); 
  });
});

Create a GUI test

These tests will spin up Puppeteer in headless mode and pass the page instance in the test callback. The browser and page will be set up once per test suite and persisted between individual tests.

These tests are slower than Node tests. Therefore, you should not rely on them to exhaustively check the correctness of your code. You can start with them to have some basic coverage, but try to make your down to smaller, faster, more focused tests.

import { describe, it } from 'tdd-buffet/suite/gui';

describe('Gui suite', () => {
  it('should run a test', async (page) => {
    await page.goto('http://github.com');
  });
});

Assertions

You can choose between jest's builtin assertions or chai's assertions.

import { describe, it } from 'tdd-buffet/suite/node';
import { expect as chaiExpect } from 'tdd-buffet/expect/chai';
import { expect as jestExpect } from 'tdd-buffet/expect/jest';

describe('Expect', () => {
  describe('chai', () => {
    it('should compare things', () => {
      chaiExpect(1).to.equal(1);
      chaiExpect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
    });
  });

  describe('jest', () => {
    it('should compare things', () => {
      jestExpect(1).toEqual(1);
      jestExpect({ foo: 'bar' }).toEqual({ foo: 'bar' });
    });
  });
});

Run the tests

npx tdd-buffet test

This will run all the tests matched by the default Jest config. You can pass your own config through the --config option. The command accepts all Jest arguments:

npx tdd-buffet test --runInBand tests/my-test.spec.tsx

Coverage

You can pass the --coverage option to generate coverage with the options specified in the Jest config.

You can control how coverage is collected (output folder, thresholds etc.) through Jest's coverage options.

Keywords

tdd

FAQs

Package last updated on 16 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts