New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

fixd

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fixd - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

.travis.yml

10

package.json
{
"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

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