Skip to content

Commit

Permalink
Merge pull request #9 from rei/add-coverage-report
Browse files Browse the repository at this point in the history
Adding report generation if running coverage.
  • Loading branch information
peripateticus committed Mar 7, 2019
2 parents 2203ed9 + 423c2dc commit 49d29b8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 41 deletions.
20 changes: 11 additions & 9 deletions README.md
Expand Up @@ -2,9 +2,9 @@

## Description

Unit testing for Vue components. This tool allows you to easily test your Vue components using
[mocha](https://mochajs.org) and [vue-test-utils](https://vue-test-utils.vuejs.org/). It is based on the following documents:
* [vue-test-utils
Unit testing for Vue components. This tool allows you to easily test your Vue components using
[mocha](https://mochajs.org) and [vue-test-utils](https://vue-test-utils.vuejs.org/). It is based on the following documents:
* [vue-test-utils
for Mocha](https://vue-test-utils.vuejs.org/guides/testing-single-file-components-with-mocha-webpack.html)
* [example](https://github.com/vuejs/vue-test-utils-mocha-webpack-example)

Expand All @@ -22,15 +22,17 @@ for Mocha](https://vue-test-utils.vuejs.org/guides/testing-single-file-component

npx vunit --spec=<glob-to-specs> --coverage [--watch]

Report is generated at `./coverage-vue`

## Creating Unit Tests

See the [vue-test-utils documentation](https://vue-test-utils.vuejs.org/) for creating unit tests
using `vue-test-utils`.
using `vue-test-utils`.

Create your spec files via [mocha](https://mochajs.org) syntax.

## Update `npm test` Script(s)

Add `test` script to your `package.json`:

{
Expand All @@ -43,19 +45,19 @@ Add `test` script to your `package.json`:

## Command-line Options

The following options are available to the tool:
The following options are available to the tool:

spec: {String} The path glob to your Vue unit tests (required)
webpack-config: {String} The path to your webpack.config.js (optional)
watch: {String} Comma-separated list of directories to watch for changes, e.g.
watch: {String} Comma-separated list of directories to watch for changes, e.g.
--watch=src,test (optional).
coverage: {None} Flag indicating whether or not to run coverage.
coverage: {None} Flag indicating whether or not to run coverage. Report is generated at `./coverage-vue`

## Programmatic API

To use package via programmatic API, just `require` the module and call the exposed `run` command
with above options passed in as an object:

const vunit = require('vunit');
vunit.run({
spec: '/glob/to/specs',
Expand Down
9 changes: 7 additions & 2 deletions core.js
Expand Up @@ -16,6 +16,7 @@ const preProcess = conf => ({
webpackConfig: `${conf['webpack-config'] ? conf['webpack-config'] : path.join(__dirname, 'webpack.config.js')}`,
specGlob: `${conf.spec ? conf.spec : ''}`,
coverage: conf.coverage,
report: conf.report
});

module.exports.preProcess = preProcess;
Expand Down Expand Up @@ -47,6 +48,8 @@ module.exports.run = (conf) => {
'BABEL_ENV=test',
'NODE_ENV=test',
'nyc',
'--reporter=lcov',
'--report-dir=coverage-vue',
'mocha-webpack',
'--require', path.join(__dirname, 'setup.js'),
'--colors',
Expand All @@ -57,11 +60,13 @@ module.exports.run = (conf) => {
confPreprocessed.specGlob,
];

// Remove nyc if not running coverage.
// Remove nyc its options if not running coverage.
if (!confPreprocessed.coverage) {
spawnCmd.splice(3, 1);
spawnCmd.splice(3, 3);
}

// Remove reporter if not running

// Execute mocha-webpack.
const cmd = cp.spawn('npx', spawnCmd);

Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "@rei/vunit",
"description": "Write unit tests against your Vue components using mocha and vue-test-utils",
"version": "1.2.2",
"version": "1.3.0",
"author": "Alex Perkins <peripateticus.gh@gmail.com>",
"repository": "https://github.com/rei/vunit",
"license": "MIT",
Expand Down

0 comments on commit 49d29b8

Please sign in to comment.