Package Exports
- test-fixture
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (test-fixture) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 -DUsage
// 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.jsUsing .copy()
const {copy, resolve} = fixtures(p)
await copy('/path/to')
resolve('a.js') // -> /path/to/a.jsawait 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=falsewhether should clean the directorytoifoptions.tois specified. - install?
boolean=falsewhether should run npm install after copying
- to?
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.jsawait install(options?)
- options?
Objectoptions ofnpminstall
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