Skip to content
This repository has been archived by the owner on Nov 10, 2019. It is now read-only.

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
Add unit tests, update mos to v1
  • Loading branch information
zkochan committed May 16, 2016
1 parent c1f3448 commit e99ee86
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 20 deletions.
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<!--@'# ' + package.name-->
<!--@'# ' + pkg.name-->
# mos-plugin-dependencies
<!--/@-->

<!--@'> ' + package.description-->
<!--@'> ' + pkg.description-->
> A mos plugin that creates dependencies sections
<!--/@-->
<!--@shields.flatSquare('npm', 'travis', 'coveralls')-->
[![NPM version](https://img.shields.io/npm/v/mos-plugin-dependencies.svg?style=flat-square)](https://www.npmjs.com/package/mos-plugin-dependencies)
[![Build status for master](https://img.shields.io/travis/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://travis-ci.org/mosjs/mos-plugin-dependencies)
[![Test coverage for master](https://img.shields.io/coveralls/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://coveralls.io/r/mosjs/mos-plugin-dependencies?branch=master)
[![npm version](https://img.shields.io/npm/v/mos-plugin-dependencies.svg?style=flat-square)](https://www.npmjs.com/package/mos-plugin-dependencies) [![Build Status](https://img.shields.io/travis/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://travis-ci.org/mosjs/mos-plugin-dependencies) [![Coverage Status](https://img.shields.io/coveralls/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://coveralls.io/r/mosjs/mos-plugin-dependencies?branch=master)
<!--/@-->

<!--@installation()-->
## Installation

This module is installed via npm:

``` sh
npm install mos-plugin-dependencies --save
```sh
npm i -S mos-plugin-dependencies
```
<!--/@-->

## Usage

Expand Down Expand Up @@ -50,24 +44,22 @@ You'll get a dependencies section with the list of the dependencies used in the

- `opts.shield` - _boolean_ or _string_ - tells whether to add a dependency shield or not. If `true`, adds a shield using default styling. If a `string`, adds a shield with the style specified by the string. Is `false` by default.

<!--@license()-->
## License

[MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io)
<!--/@-->

* * *

<!--@dependencies({ shield: 'flat-square' })-->
## Dependencies [![Dependency status for master](https://img.shields.io/david/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://david-dm.org/mosjs/mos-plugin-dependencies/master)
## <a name="dependencies">Dependencies</a> [![Dependency status for master](https://img.shields.io/david/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://david-dm.org/mosjs/mos-plugin-dependencies/master)

- [github-url-to-object](https://github.com/zeke/github-url-to-object): Extract user, repo, and other interesting properties from GitHub URLs
- [shieldman](https://github.com/zkochan/shieldman): Badges creator

<!--/@-->

<!--@devDependencies({ shield: 'flat-square' })-->
## Dev Dependencies [![devDependency status for master](https://img.shields.io/david/dev/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://david-dm.org/mosjs/mos-plugin-dependencies/master#info=devDependencies)
## <a name="dev-dependencies">Dev Dependencies</a> [![devDependency status for master](https://img.shields.io/david/dev/mosjs/mos-plugin-dependencies/master.svg?style=flat-square)](https://david-dm.org/mosjs/mos-plugin-dependencies/master#info=devDependencies)

- [chai](https://github.com/chaijs/chai): BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
- [cz-conventional-changelog](https://github.com/commitizen/cz-conventional-changelog): Commitizen adapter following the conventional-changelog format.
Expand All @@ -78,7 +70,9 @@ You'll get a dependencies section with the list of the dependencies used in the
- [ghooks](https://github.com/gtramontina/ghooks): Simple git hooks
- [istanbul](https://github.com/gotwarlost/istanbul): Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests
- [mocha](https://github.com/mochajs/mocha): simple, flexible, fun test framework
- [mos](https://github.com/zkochan/mos): A pluggable module that injects content into your markdown files via hidden JavaScript snippets
- [mos](https://github.com/mosjs/mos): A pluggable module that injects content into your markdown files via hidden JavaScript snippets
- [mos-plugin-ejs](https://github.com/mosjs/mos-plugin-ejs): A mos plugin that executes embedded js in markdown files
- [mos-processor](https://github.com/mosjs/mos-processor): A markdown processor for mos
- [semantic-release](https://github.com/semantic-release/semantic-release): automated semver compliant package publishing
- [validate-commit-msg](https://github.com/kentcdodds/validate-commit-msg): Script to validate a commit message follows the conventional changelog standard

Expand Down
34 changes: 33 additions & 1 deletion index.spec.js
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
require('.')
'use strict'
const describe = require('mocha').describe
const it = require('mocha').it
const expect = require('chai').expect
const path = require('path')
const fs = require('fs')
const ROOT = path.join(__dirname, 'test/fixtures')
const fixtures = fs.readdirSync(ROOT).filter(filepath => filepath.indexOf('.') !== 0)

const mos = require('mos-processor')
const ejs = require('mos-plugin-ejs')
const license = require('.')

describe('mos-plugin-toc', () => {
fixtures.forEach(fixture => {
const filepath = path.join(ROOT, fixture)
const output = fs.readFileSync(path.join(filepath, 'output.md'), 'utf-8')
const inputPath = path.join(filepath, 'input.md')
const input = fs.readFileSync(inputPath, 'utf-8')
const configPath = path.join(filepath, 'config.json')
const config = fs.existsSync(configPath) ? JSON.parse(fs.readFileSync(configPath, 'utf-8')) : {}

it('should pass fixture in dir ' + filepath, done => {
mos({ content: input, filePath: inputPath }, [ejs, { register: license, options: config }])
.then(processor => processor.process())
.then(result => {
expect(result).to.eq(output)
done()
})
.catch(done)
})
})
})
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
"lib"
],
"main": "index.js",
"mos": {
"installation": {
"useShortAlias": true
}
},
"scripts": {
"test": "mocha && npm run lint && mos test",
"test": "mocha && npm run lint && mos test -x=\"test/**\"",
"lint": "eslint lib/**/*.js index.js",
"commit": "git-cz",
"coverage": "istanbul cover -x \"**/*.spec.js\" node_modules/mocha/bin/_mocha -- -R spec",
"precoveralls": "istanbul cover -x \"**/*.spec.js\" node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && npm i coveralls@2",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"postcoveralls": "rm -rf ./coverage",
"md": "mos",
"md": "mos -x=\"test/**\"",
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
},
"repository": {
Expand Down Expand Up @@ -51,7 +56,9 @@
"ghooks": "^1.2.1",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"mos": "^0.13.1",
"mos": "^1.1.1",
"mos-plugin-ejs": "^1.0.1",
"mos-processor": "^1.1.1",
"semantic-release": "^4.3.5",
"validate-commit-msg": "^2.6.1"
},
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules
5 changes: 5 additions & 0 deletions test/fixtures/dependencies-with-no-shields/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--@dependencies()-->
<!--/@-->

<!--@devDependencies()-->
<!--/@-->

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

13 changes: 13 additions & 0 deletions test/fixtures/dependencies-with-no-shields/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--@dependencies()-->
## <a name="dependencies">Dependencies</a>

- [foo](https://github.com/zkochan/foo): foo descr

<!--/@-->

<!--@devDependencies()-->
## <a name="dev-dependencies">Dev Dependencies</a>

- [foo](https://github.com/zkochan/foo): foo descr

<!--/@-->
13 changes: 13 additions & 0 deletions test/fixtures/dependencies-with-no-shields/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test-pkg",
"dependencies": {
"foo": "*"
},
"devDependencies": {
"foo": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/zkochan/test-pkg"
}
}
5 changes: 5 additions & 0 deletions test/fixtures/dependencies-with-shields/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--@dependencies({ shield: 'flat-square' })-->
<!--/@-->

<!--@devDependencies({ shield: 'flat-square' })-->
<!--/@-->

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

13 changes: 13 additions & 0 deletions test/fixtures/dependencies-with-shields/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--@dependencies({ shield: 'flat-square' })-->
## <a name="dependencies">Dependencies</a> [![dependency status](https://img.shields.io/david/zkochan/test-pkg/master.svg?style=flat-square)](https://david-dm.org/zkochan/test-pkg/master)

- [foo](https://github.com/zkochan/foo): foo descr

<!--/@-->

<!--@devDependencies({ shield: 'flat-square' })-->
## <a name="dev-dependencies">Dev Dependencies</a> [![devDependency status](https://img.shields.io/david/dev/zkochan/test-pkg/master.svg?style=flat-square)](https://david-dm.org/zkochan/test-pkg/master#info=devDependencies)

- [foo](https://github.com/zkochan/foo): foo descr

<!--/@-->
13 changes: 13 additions & 0 deletions test/fixtures/dependencies-with-shields/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "test-pkg",
"dependencies": {
"foo": "*"
},
"devDependencies": {
"foo": "*"
},
"repository": {
"type": "git",
"url": "https://github.com/zkochan/test-pkg"
}
}

0 comments on commit e99ee86

Please sign in to comment.