Socket
Socket
Sign inDemoInstall

test-fixture

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-fixture

Copy test-fixtures to temp dir and get resolved file paths.


Version published
Weekly downloads
14
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage

test-fixture

Copy test fixtures to a temp dir and get resolved file paths.

Why?

I am tired of writing these:

  • path.resolve(__dirname, 'test', 'fixtures'),
  • tmp.dir(callback),
  • fse.copy(fixtures, dir)
  • path.join(fixtures, 'some-file.js')

EVERY DAY!

So, I got this.

Install

$ npm i test-fixture -D

Usage

// By default, it will use 'test/fixtures' dir.
const {copy, resolve} = require('test-fixture')()

// copy 'test/fixtures' to the temp dir
;(async () => {
  await copy()
  console.log(resolve('foo.js'))
  // '/<temp-dir>/foo.js'
})

fixtures(...paths): {resolve, copy}

  • paths Array<path> to define the root paths of the fixtures, which is similar as

Defines the root of the fixture

const path = require('path')
const fixturesRoot = path.resolve(projectRoot, 'test', 'fixtures')

path.resolve(fixturesRoot, ...args)
argumentsbase(dir of test fixtures)
undefinedtest/fixtures
'a'test/fixtures/a
'a', 'b'test/fixtures/a/b
'/path/to' (absolute)/path/to
'/path/to' (absolute), 'a'/path/to/a

Actually, the base is path.resolve('text/fixtures', path...)

await copy(to?)

  • to? path= the destination folder where the test fixtures will be copied to. If not specified, a temporary directory will be used.

Copy the test fixtures into another directory.

resolve(...paths)

Resolves the paths to get the path of the test fixtures

After .copy()ed, it will resolve paths based on the destination dir.

If not, it will use the base dir. But never use both of them simultaneously.

/path/to/<base>
             |-- a.js
/path/to/<to>
           |-- a.js
Without copying
const {resolve} = fixtures(base)
resolve('a.js')  // -> /path/to/<base>/a.js
Using .copy()
const {copy, resolve} = fixtures(base)

await copy('/path/to')

resolve('a.js') // -> /path/to/a.js

License

MIT

Keywords

FAQs

Package last updated on 11 May 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc