@tapjs/chdir
a built-in tap extension for t.chdir()
Last updated a year ago by isaacs .
BlueOak-1.0.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @tapjs/chdir 
SYNC missed versions from official npm registry.

@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.

Current Tags

  • 3.3.13                                ...           latest (24 days ago)

34 Versions

  • 3.3.13                                ...           24 days ago
  • 3.3.12                                ...           3 months ago
  • 3.3.11                                ...           4 months ago
  • 3.3.10                                ...           6 months ago
  • 3.3.9                                ...           6 months ago
  • 3.3.8                                ...           7 months ago
  • 3.3.7                                ...           7 months ago
  • 3.3.6                                ...           7 months ago
  • 3.3.5                                ...           8 months ago
  • 3.3.4                                ...           9 months ago
  • 3.3.3                                ...           9 months ago
  • 3.3.2                                ...           9 months ago
  • 3.3.1                                ...           10 months ago
  • 3.3.0                                ...           a year ago
  • 3.2.1                                ...           a year ago
  • 3.2.0                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.7                                ...           a year ago
  • 3.0.6                                ...           a year ago
  • 3.0.5                                ...           a year ago
  • 3.0.4                                ...           a year ago
  • 3.0.3                                ...           a year ago
  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.0.3                                ...           2 years ago
  • 2.0.2                                ...           2 years ago
  • 2.0.1                                ...           2 years ago
  • 2.0.0                                ...           2 years ago
  • 1.1.4                                ...           2 years ago
  • 1.1.3                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
Maintainers (2)
Downloads
Total 81
Today 0
This Week 0
This Month 73
Last Day 0
Last Week 33
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE