Library to create plugins for komondor
.
To create a plugin, you need to export a activate()
function as follow:
import { Registrar } from 'komondor-plugin'
export function activate(registrar: Registrar) {
registrar.register(
'function',
subject => typeof subject === 'function',
(context, subject) => { /* spy implementation */ },
(context, subject, action) => { /* stub implementation */ })
}
The Spy
is used to record the actions performed,
while the Stub
is used to replay the actions recorded.
Register a plugin.
Name of the plugin.
The name should be unique. If consumer loads two plugins with the same name, an error will be thrown.
This name should be used as the scope name of your actions.
For example, if your plugin is node
which as childProcess
and stream
,
then your action types should be node/childProcess
, node/stream
, etc.
A predicate to determine if the plugin supports the subject
.
For example, for the generic function
plugin,
the predicate is subject => typeof subject === 'function'
.
Creates a spied subject.
Creates a stubbed subject.
SpecExpectation
is a partial SpecAction
to be used in a the spec.satisfy()
call.
Use this function to create helper functions for the user to create their expectations easily.
createScopedCreateExpectation(scopy: string): (subType: string, name: string) => (payload, meta?) => SpecExpectation
Create a scoped createExpectation()
.
When writing your plugin, you can consider using komondor-test
to help testing your plugin.
When testing your plugin,
you can use speced.satisfy([...])
instead of speced.done()
to ensure the actions are recorded properly.
# right after fork
npm install
# begin making changes
git checkout -b <branch>
npm run watch
# edit `webpack.config.dev.js` to exclude dependencies for the global build.
# after making change(s)
git commit -m "<commit message>"
git push
# create PR
There are a few useful commands you can use during development.
# Run tests (and lint) automatically whenever you save a file.
npm run watch
# Run tests with coverage stats (but won't fail you if coverage does not meet criteria)
npm run test
# Manually verify the project.
# This will be ran during 'npm preversion' so you normally don't need to run this yourself.
npm run verify
# Build the project.
# You normally don't need to do this.
npm run build
# Run tslint
# You normally don't need to do this as `npm run watch` and `npm version` will automatically run lint for you.
npm run lint
Generated by generator-unional@0.0.1