Methods
(static) createSandbox(Hexo, options) → {sandboxFactoryFn}
// CommonJS
const {createSandbox} = require('hexo-test-utils')
// ES2015
import {createSandbox} from 'hexo-test-utils'
This is the main function of hexo-test-utils
used to build a factory of sandboxes.
By default it uses an empty fixture folder, which means no source files, no theme, no config, etc. To prepare data for your test you have multiple options:
- use HexoContext methods directly
- use helper methods from this package, like mockConfig
- provide a folder with fixture files
Examples
const {createSandbox} = require('hexo-test-utils')
const Hexo = require('hexo')
const sandbox = createSandbox(Hexo)
const ctx = await sandbox()
const {createSandbox} = require('hexo-test-utils')
const Hexo = require('hexo')
const path = require('path')
const sandbox = createSandbox(Hexo, {
fixture_folder: path.join(__dirname, '..', 'fixtures')
})
// Create a context with a fixture folder set to '../fixtures/test1'
const ctx = await sandbox('test1')
const {createSandbox} = require('hexo-test-utils')
const Hexo = require('hexo')
const path = require('path')
const sandbox = createSandbox(Hexo, {
plugins: [
require.resolve('hexo-some-plugin'),
require.resolve('../src')
]
})
const ctx = await sandbox()
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Hexo |
constructor | Hexo constructor to be used |
|||||||||
options |
Object | Sandbox options Properties
|
Returns:
a Sandbox factory function
- Type
- sandboxFactoryFn
(static) init(ctx) → {Promise.<HexoContext>}
// CommonJS
const {init} = require('hexo-test-utils')
// ES2015
import {init} from 'hexo-test-utils'
Initializes all plugins, generates content from folders. Useful if you need to mock main configuration like source_dir
Use with skipInit
in sandboxFactoryFn.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
HexoContext |
Returns:
- Type
- Promise.<HexoContext>
(static) mockConfig(ctx, name, value)
// CommonJS
const {mockConfig} = require('hexo-test-utils')
// ES2015
import {mockConfig} from 'hexo-test-utils'
Mocks the Hexo configuration. Useful to test the plugin with different configurations without using fixtures.
Note: Make sure to call it before
process
Parameters:
Name | Type | Description |
---|---|---|
ctx |
HexoContext | |
name |
string | a name of configuration, it the config YML file it would be the root key |
value |
* | a new configuration for a given name, usually an Object |
(static) process(ctx) → {Promise.<HexoContext>}
// CommonJS
const {process} = require('hexo-test-utils')
// ES2015
import {process} from 'hexo-test-utils'
Loads and processes all the blog data. After calling this function the passed HexoContext will have all information about the blog.
Parameters:
Name | Type | Description |
---|---|---|
ctx |
HexoContext |
Returns:
- Type
- Promise.<HexoContext>