Comparing version 0.0.1 to 0.1.0
{ | ||
"name": "fixd", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Test fixture utility", | ||
@@ -35,2 +35,4 @@ "main": "fixd.js", | ||
"mocha": "^3.3.0", | ||
"sinon": "^2.2.0", | ||
"sinon-chai": "^2.10.0", | ||
"standard": "^10.0.2" | ||
@@ -49,5 +51,9 @@ }, | ||
"it", | ||
"expect" | ||
"expect", | ||
"sandbox" | ||
] | ||
}, | ||
"dependencies": { | ||
"halcyon": "^0.19.1" | ||
} | ||
} |
113
README.md
@@ -0,3 +1,114 @@ | ||
[![Travis](https://img.shields.io/travis/TechnologyAdvice/fixd.svg)](https://travis-ci.org/TechnologyAdvice/fixd) | ||
[![Codecov](https://img.shields.io/codecov/c/github/TechnologyAdvice/fixd.svg)](https://codecov.io/gh/TechnologyAdvice/fixd) | ||
# Fixd | ||
A Utility for Fixtures | ||
Fixd is a JavaScript utility for creating better fixtures. Fixtures created with Fixd are stored in the library and, when needed, are created as non-referenced instances to prevent side effects in testing data. | ||
## Installation | ||
`npm i fixd --save-dev` | ||
## Quick Start | ||
```javascript | ||
// Require the library | ||
const fixd = require('fixd') | ||
// Tell Fixd which plugin(s) to use | ||
fixd.use('object') | ||
// Add a fixture | ||
fixd.addObject('foo', { foo: 'bar' }) | ||
// Create a new instance of the fixture | ||
const fooOne = fixd.create('foo') // -> { foo: 'bar' } | ||
// Create a different instance with alterations to original object | ||
const fooTwo = fixd.create('foo', { foo: 'baz' }) // -> { foo: 'baz' } | ||
``` | ||
## Plugins | ||
Fixd uses plugins to allow the developer to specify which type of fixtures to | ||
use. At initialization you must specify which plugins you wish to utilize. From | ||
the example above: | ||
```javascript | ||
fixd.use('object') | ||
``` | ||
The `use` method will use a built-in (single string), a path to a custom plugin, | ||
or an already `require`'d plugin object. | ||
Custom plugins must be an object with property `name` and two methods: `add` and | ||
`create`: | ||
- `name`: Specifies the reference to the plugin to be used | ||
- `add`: Does any checks/validation or modification, then returns the fixture. This fixture is saved to Fixd's main object and retrieved on `create` | ||
- `create`: Creates a new instance by returning the original fixture plus any modifications. This should return a new instance of the fixture. | ||
## Built-In Plugins | ||
Fixd comes with the following built-in fixture plugins: | ||
### Object | ||
Adds ability to create object fixtures: | ||
```javascript | ||
fixd.use('object') | ||
fixd.addObject('foo', { foo: 'bar' }) | ||
const fooFixture = fixd.create('foo') // -> { foo: 'bar' } | ||
``` | ||
On `create`, an optional (`Object`) argument can be passed to alter the original fixture: | ||
```javascript | ||
const fooFixture = fixd.create('foo', { foo: 'bam' }) // -> { foo: 'bam' } | ||
``` | ||
### Array | ||
Adds ability to create array fixtures: | ||
```javascript | ||
fixd.use('array') | ||
fixd.addArray('bar', [ 'bin', 'baz', 'quz' ]) | ||
const barFixture = fixd.create('bar') // -> [ 'bin', 'baz', 'quz' ] | ||
``` | ||
On `create`, an optional (`Object`) argument can be passed with params `add` and `remove` to modify the original fixture: | ||
```javascript | ||
const barFixture = fixd.create('bar', { | ||
add: [ 'zap', 'zip' ], | ||
remove: [ 'quz' ] | ||
}) // -> [ 'bin', 'baz', 'zap', 'zip' ] | ||
``` | ||
### JSON | ||
Adds ability to create JSON fixtures: | ||
```javascript | ||
fixd.use('json') | ||
fixd.addJSON('fizz', { "buzz": true }) | ||
const fizzFixture = fixd.create('fizz') // -> { "buzz": true } | ||
``` | ||
On create, an optional (`Object`) argument can be passed to alter the original fixture: | ||
```javascript | ||
const fizzFixture = fixd.create('fizz', { zap: 'bang' }) // -> { "buzz": true, "zap": "bang" } | ||
``` | ||
## License | ||
Fixd is developed and maintained by TechnologyAdvice and released under the ISC license |
const chai = require('chai') | ||
const sinon = require('sinon') | ||
const dirtyChai = require('dirty-chai') | ||
const sinonChai = require('sinon-chai') | ||
const mod = require('module') | ||
const path = require('path') | ||
// Globals | ||
global.expect = chai.expect | ||
global.sinon = sinon | ||
// Chai | ||
chai.use(dirtyChai) | ||
chai.use(sinonChai) | ||
// allow require() from project root | ||
// Sandbox | ||
global.sandbox = sinon.sandbox.create() | ||
afterEach(() => global.sandbox.restore()) | ||
// Allow require() from project root: ../../src/something => src/something | ||
process.env.NODE_PATH = path.join(process.cwd(), process.env.NODE_PATH || '') | ||
mod._initPaths() | ||
mod._initPaths() |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
16
381
114
70384
1
7
6
+ Addedhalcyon@^0.19.1
+ Addedhalcyon@0.19.1(transitive)