hexo-test-utils
A set of utils for easy testing Hexo plugins
Last updated a year ago by ertrzyiks .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hexo-test-utils 
SYNC missed versions from official npm registry.

hexo-test-utils

Build Status

Hexo is quite easy to write tests for, but the needed boilerplate code can be a barrier. This packages provides a set of utils to simplify testing Hexo plugins.

Offered features:

  • Sandbox environment
  • high level functions for Hexo internals
  • ECMAScript5 compatibility

Installation

npm install hexo-test-utils

Sandbox

The main feature is a Sandbox. It allows to create an isolated environment of Hexo blog. Combined with a fixture, it's easy to prepare all need files, process the blog and assert the output.

To create a Sandbox instance, first you need to create a factory with createSandbox:

const {createSandbox} = require('hexo-test-utils')
const Hexo = require('hexo')
const path = require('path')

const sandbox = createSandbox(Hexo, {
  fixture_folder: path.join(__dirname, '..', 'fixtures'),
  plugins: [
    path.join(__dirname, '..', 'src')
  ]
})

Now, the sandbox is a function which returns a new context - an instance of Hexo blog which is ready for processing.

Using fixture folder

If fixture_folder is set, the factory function accepts one parameter, name of the fixture folder where live all fixture files.

To prepare a fixture with one post, create folder ./fixtures/one-post/source/_posts/ and put the markdown file there.

const context = sandbox('one-post')

At this moment, the Hexo blog is created, but no files are loaded. To start the loading process, call process method.

const {process} = require('hexo-test-utils/core')

process(context).then(() => {
  // Hexo processed the ./fixtures/one-post/ folder as a blog
})

Now you can start check the behavior of your plugin.

Note: no files were actually saved on the hard drive, all the process happened in memory.

Empty Sandbox

You can skip fixture_folder if you don't need any files to exists, for example when testing a view helper in isolation. The factory function will have no parameters then and the Sandbox will be an empty Hexo project - no posts, no theme, no assets.

You can still use Hexo API to provide fixtures programmatically.

Documentation

Read API documentation here

Current Tags

  • 0.4.1                                ...           latest (a year ago)

13 Versions

  • 0.4.1                                ...           a year ago
  • 0.4.0                                ...           a year ago
  • 0.3.1                                ...           3 years ago
  • 0.3.0                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.3                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (2)
Dev Dependencies (11)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |