@tapjs/chdir
a built-in tap extension for t.chdir()
Last updated 4 months 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.0.0                                ...           latest (4 months ago)

10 Versions

  • 3.0.0                                ...           4 months ago
  • 2.0.3                                ...           5 months ago
  • 2.0.2                                ...           5 months ago
  • 2.0.1                                ...           5 months ago
  • 2.0.0                                ...           5 months ago
  • 1.1.4                                ...           5 months ago
  • 1.1.3                                ...           5 months ago
  • 1.1.2                                ...           5 months ago
  • 1.1.1                                ...           5 months ago
  • 1.1.0                                ...           5 months ago
Maintainers (2)
Downloads
Total 5
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

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