npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

test-fixture

v2.4.1

Published

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

Downloads

168

Readme

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, install, root}

  • 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, ...paths)

...paths | base(dir of test fixtures) --------- | -------------------- undefined | test/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', ...paths)

Without copying

const {resolve} = fixtures(p)
resolve('a.js')  // -> /path/to/<p>/a.js

Using .copy()

const {copy, resolve} = fixtures(p)

await copy('/path/to')

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

await copy(options?)

await copy(to?)

  • options? Object
    • to? path= the destination folder where the test fixtures will be copied to. If not specified, a temporary directory will be used.
    • clean? boolean=false whether should clean the directory to if options.to is specified.
    • install? boolean=false whether should run npm install after copying

Copy the test fixtures into another directory.

copy('/path/to')

// is equivalent to
copy({
  to: '/path/to',
  install: false
})

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

await install(options?)

Install packages in the working directory. If run after await copy(), then it will install packages in the directory which fixtures copied to.

getter: root string

The fixture root /<project-root>/test/fixtures

License

MIT