You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

@tapjs/chdir

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tapjs/chdir

a built-in tap extension for t.chdir()

Source
npmnpm
Version
3.3.1
Version published
Weekly downloads
143K
5.28%
Maintainers
2
Weekly downloads
 
Created
Source

@tapjs/chdir

A default tap plugin for changing the working directory for the context of a single test, and then returning to the original working directory when the test is over.

Usage

import t from 'tap'

t.test('using t.chdir() example', t => {
  const dir = t.testdir({
    'some-file.txt': 'hello',
  })
  t.chdir(dir)
  t.equal(readFileSync('./some-file.txt', 'utf8'), 'hello')
  t.equal(process.cwd(), t.testdirName)
  // when the test ends, the original working dir is restored
  t.end()
})

// without this plugin, you'd have to do it this way:
t.test('without t.chdir() example', t => {
  const dir = t.testdir({
    'some-file.txt': 'hello',
  })
  const cwd = process.cwd()
  t.teardown(() => process.chdir(cwd))
  process.chdir(dir)
  // run tests...
  t.end()
})

API

  • t.chdir(dir: string) Change the process working directory to the supplied path. When the test ends, the original dir is restored.

Keywords

tapjs plugin

FAQs

Package last updated on 05 Feb 2026

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