🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

contentfaux

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contentfaux

A way to stub requests to Contentful.

0.2.0
latest
Source
npm
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

contentfaux

A way to stub requests to Contentful.

Status

npm Travis Coverage Status Dependency Status devDependency Status npm

How does it work.

Contentfaux will first need to be setup. It loads real data from a space configured and uses that to perform unit testing locally. Requests made to Contentful are intercepted and Contentfaux feeds the preloaded data instead.

Quick Start

To install, simply use npm

npm i -D contentfaux

You will also need to add variables to allow the setup data to be loaded before testing. This can be added either in your package.json file, or with environment variables.

package.json

If you choose to use the package.json approach, add the following parameters to your package.json file.

{
  ...
  "config": {
    "contentfaux": {
      "spaceid": "abcd1234",
      "apikey": "aaaabbbbccccdddd1111222233334444",
      "dir": "path/to/directory"
    }
  }
}
  • spaceid - Your Contentful space id.
  • apikey - The api key provided by Contentful.
  • dir - The directory to add the mock data. This will be relative to where you call Contentfaux. Defaults too /approot/contentfaux.

Environment variables

Alternatively, if you choose to use environment variables, the following can be used:

CONTENTFAUX_SPACEID=abcd1234
CONTENTFAUX_APIKEY=aaaabbbbccccdddd1111222233334444
CONTENTFAUX_DIR=path/to/directory

After it has been installed, add this block to your scripts in package.json:

{
  "scripts": {
    ...,
    "contentfaux": "contentfaux setup"
  }
}

And run it!

npm run contentfaux

Stubbing

To stub, before calling any Contentful-related tests, include Contentfaux.

require('contentfaux')

or

import 'contentfaux'

If you choose to do other tests with Contentful, be sure to keep a reference of Contentfaux and unstub.

const Contentfaux = require('contentfaux')
...
Contentfaux.unstub()

or

import Contentfaux from 'contentfaux'
...
Contentfaux.unstub()

License

MIT

Keywords

contentful

FAQs

Package last updated on 30 Nov 2017

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