1. @tapjs/before
a built-in tap extension for t.before()
@tapjs/before
Package: @tapjs/before
Created by: tapjs
Last modified: Tue, 26 Mar 2024 23:27:12 GMT
Version: 1.1.20
License: BlueOak-1.0.0
Downloads: 121,025
Repository: https://github.com/tapjs/tapjs

Install

npm install @tapjs/before
yarn add @tapjs/before

@tapjs/before

A default tap plugin providing t.before().

USAGE

This plugin is installed with tap by default. If you had
previously removed it, you can tap plugin add @tapjs/before to
bring it back.

 import t from 'tap'
t.before(() => {
  // this will run before the tests in this file start
})

If the method returns a promise, it will be awaited before moving
on to the next test.

A t.before() method will run prior to any subsequent child
tests. If it's called before any child tests have started, then
it will be run right away.

So, this test:

 import t from 'tap'

t.before(() => {
  console.error('before initial')
})

t.test('first test', t => {
  t.before(async () => {
    // this will wait before moving on
    await new Promise(res => setTimeout(res, 100))
    console.error('before in first test')
  })
  console.error('in first test')
  t.test('child test', t => {
    console.error('child of first test')
    t.end()
  })
  t.end()
})

t.before(() => {
  console.error('before between')
})

t.test('second test', t => {
  console.error('in second test')
  t.end()
})

will print:

before initial
in first test
before in first test
child of first test
before between
in second test

Essentially, t.before() is a bit like a child test method that
doesn't get a Test object as an argument.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code