React component unit test script generator
Last updated 3 years ago by jussikan .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install leyati 
SYNC missed versions from official npm registry.


Inspector Leyati runs unit tests from templates for a collection of React components and saves the successful and retained into a final unit test script.

The location and name of a component are placed into given template that is saved as an "alpha test script". The tests in this script are run and those passed are written to a final test script. Failed tests are not written to the final test script unless they have the annotation @leyati-retain right above them.

Leyati uses babel, babylon, and Mocha.


npm install --save leyati


bin/leyati.js <command> (commands: "init")

bin/leyati.js <template file name> <test script destination> <source location> [component name]

  • Inspector

new Inspector(templateFilename, testsPath, componentName)


The shape of config is as follows and can be found in config.js:

	createTestScriptEvenIfAllTestsFail: true,
	leaveAlphaTestScript: false,
	babelOptions: {...},
	babylonOptions: {...},
	mochaOptions: {...}

inspector.setConstant(name, value)

Set value for a placeholder that is found in given template by name.

inspector.on(eventType, fn)

Set callbacks for events. For now there is only one, "finalized", that is called after all tests in a script have been run and the final test script been written.


Replaces placeholders in given template file with the given constants.


Saves the source code processed in processTemplate() as an alpha test script.


Runs the tests in an alpha test script and saves the successful and retained into a final unit test script.


Calls processTemplate(), saveAlphaTestScript(), and runTests().

  • LeyatiAnnotation

A singleton that provides all available Leyati annotations and a RegExp pattern for them.


const Inspector = require("leyati").Inspector;
const inspector = new Inspector("tpl/essential.js.tpl", "tests", "Foo");

inspector.setConstant("%COMPONENT_NAME%", "Foo");
inspector.setConstant("%COMPONENT_PATH%", "src/Foo.js");


The placeholder format in the templates bundled with Leyati is "%PLACEHOLDER_NAME%", but Leyati accepts any format.


Leyati/Inspector uses eshal to find out the names of exported components in an ES6 file so naming testable components is not necessary on the command line.


Writes alpha and final test scripts. By default, an alpha test script is removed after a final test script is written.

Current Tags

  • 1.0.2                                ...           latest (3 years ago)

2 Versions

  • 1.0.2                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (20)
Dev Dependencies (9)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |