mocha-automatic-coffeemaker
Generate a test code of mocha by the same path structure
Installation
npm install -g mocha-automatic-coffeemaker
Example
There is a targeted file of testing:
$ tree ./liblib└── util.js
Generate a mocha's test code:
$ genmochatest lib/utils.jsGenerated successfully!root: /home/username/your-projectsrc : lib/utils.jstest: test/lib/utils.js$ cat test/lib/utils.jsdescribe
Usage
$ genmochatest [options] <target-file-path>
<target-file-path>
A file path of the code that you want to write a test
e.g.
lib/foo.js
/path/to/lib/x/y/foo.js
[options]
--dirname, -d
Default: 'test'
--extensions, -e
Default: 'js,es,es6,es7,coffee,ts,jsx'
--force, -f
Default: false
Overwrite a test code, even if it already exists
--omission, -o
Default: null
Excluded from the path in front match at the time of test generation
--root, -r
Default: process.cwd()
--template, -t
Default: process.cwd() + '/mocha-automatic-coffeemaker-template.js'
Default options can also be defined in the package.json:
"mocha-automatic-coffeemaker": {
"dirname": "spec",
"force": true
},
Template Example
You can specify the template of test code like the following code:
module { // e.g. "foo/bar/baz.js" var filePath = datafilePath; // e.g. "foo/bar/baz" var noExtensionFilePath = datanoExtensionFilePath; // e.g. "baz.js" var fileName = datafileName; // e.g. "baz" var noExtensionFileName = datanoExtensionFileName; // e.g. If you specified `--omission bar`, then it assigned "foo/baz.js" var omittedFilePath = dataomittedFilePath; var noExtensionOmittedFilePath = datanoExtensionOmittedFilePath; return "describe('" + noExtensionFilePath + "', function() {" "});" ;};