From e99ee862066eab9eecf2efdc33b768dc941a4513 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 16 May 2016 23:45:24 +0300 Subject: [PATCH] test: add unit tests Add unit tests, update mos to v1 --- README.md | 26 ++++++-------- index.spec.js | 34 ++++++++++++++++++- package.json | 13 +++++-- test/fixtures/.gitignore | 1 + .../dependencies-with-no-shields/input.md | 5 +++ .../node_modules/foo/package.json | 8 +++++ .../dependencies-with-no-shields/output.md | 13 +++++++ .../dependencies-with-no-shields/package.json | 13 +++++++ .../dependencies-with-shields/input.md | 5 +++ .../node_modules/foo/package.json | 8 +++++ .../dependencies-with-shields/output.md | 13 +++++++ .../dependencies-with-shields/package.json | 13 +++++++ 12 files changed, 132 insertions(+), 20 deletions(-) create mode 100644 test/fixtures/.gitignore create mode 100644 test/fixtures/dependencies-with-no-shields/input.md create mode 100644 test/fixtures/dependencies-with-no-shields/node_modules/foo/package.json create mode 100644 test/fixtures/dependencies-with-no-shields/output.md create mode 100644 test/fixtures/dependencies-with-no-shields/package.json create mode 100644 test/fixtures/dependencies-with-shields/input.md create mode 100644 test/fixtures/dependencies-with-shields/node_modules/foo/package.json create mode 100644 test/fixtures/dependencies-with-shields/output.md create mode 100644 test/fixtures/dependencies-with-shields/package.json diff --git a/README.md b/README.md index d7228c3..0a0e8d9 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,20 @@ - + # mos-plugin-dependencies - + > A mos plugin that creates dependencies sections -[![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 -This module is installed via npm: - -``` sh -npm install mos-plugin-dependencies --save +```sh +npm i -S mos-plugin-dependencies ``` - ## Usage @@ -50,16 +44,14 @@ 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 [MIT](./LICENSE) © [Zoltan Kochan](http://kochan.io) - * * * -## 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) +## 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) - [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 @@ -67,7 +59,7 @@ You'll get a dependencies section with the list of the dependencies used in the -## 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) +## 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) - [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. @@ -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 diff --git a/index.spec.js b/index.spec.js index c2720a4..fb86486 100644 --- a/index.spec.js +++ b/index.spec.js @@ -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) + }) + }) +}) diff --git a/package.json b/package.json index 9023e95..6db9b5a 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" }, diff --git a/test/fixtures/.gitignore b/test/fixtures/.gitignore new file mode 100644 index 0000000..cf4bab9 --- /dev/null +++ b/test/fixtures/.gitignore @@ -0,0 +1 @@ +!node_modules diff --git a/test/fixtures/dependencies-with-no-shields/input.md b/test/fixtures/dependencies-with-no-shields/input.md new file mode 100644 index 0000000..858152e --- /dev/null +++ b/test/fixtures/dependencies-with-no-shields/input.md @@ -0,0 +1,5 @@ + + + + + diff --git a/test/fixtures/dependencies-with-no-shields/node_modules/foo/package.json b/test/fixtures/dependencies-with-no-shields/node_modules/foo/package.json new file mode 100644 index 0000000..e39a210 --- /dev/null +++ b/test/fixtures/dependencies-with-no-shields/node_modules/foo/package.json @@ -0,0 +1,8 @@ +{ + "name": "foo", + "description": "foo descr", + "repository": { + "type": "git", + "url": "https://github.com/zkochan/foo" + } +} diff --git a/test/fixtures/dependencies-with-no-shields/output.md b/test/fixtures/dependencies-with-no-shields/output.md new file mode 100644 index 0000000..f739d4c --- /dev/null +++ b/test/fixtures/dependencies-with-no-shields/output.md @@ -0,0 +1,13 @@ + +## Dependencies + +- [foo](https://github.com/zkochan/foo): foo descr + + + + +## Dev Dependencies + +- [foo](https://github.com/zkochan/foo): foo descr + + diff --git a/test/fixtures/dependencies-with-no-shields/package.json b/test/fixtures/dependencies-with-no-shields/package.json new file mode 100644 index 0000000..560a6b0 --- /dev/null +++ b/test/fixtures/dependencies-with-no-shields/package.json @@ -0,0 +1,13 @@ +{ + "name": "test-pkg", + "dependencies": { + "foo": "*" + }, + "devDependencies": { + "foo": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/zkochan/test-pkg" + } +} diff --git a/test/fixtures/dependencies-with-shields/input.md b/test/fixtures/dependencies-with-shields/input.md new file mode 100644 index 0000000..90e0e95 --- /dev/null +++ b/test/fixtures/dependencies-with-shields/input.md @@ -0,0 +1,5 @@ + + + + + diff --git a/test/fixtures/dependencies-with-shields/node_modules/foo/package.json b/test/fixtures/dependencies-with-shields/node_modules/foo/package.json new file mode 100644 index 0000000..e39a210 --- /dev/null +++ b/test/fixtures/dependencies-with-shields/node_modules/foo/package.json @@ -0,0 +1,8 @@ +{ + "name": "foo", + "description": "foo descr", + "repository": { + "type": "git", + "url": "https://github.com/zkochan/foo" + } +} diff --git a/test/fixtures/dependencies-with-shields/output.md b/test/fixtures/dependencies-with-shields/output.md new file mode 100644 index 0000000..521b83f --- /dev/null +++ b/test/fixtures/dependencies-with-shields/output.md @@ -0,0 +1,13 @@ + +## Dependencies [![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 + + + + +## Dev Dependencies [![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 + + diff --git a/test/fixtures/dependencies-with-shields/package.json b/test/fixtures/dependencies-with-shields/package.json new file mode 100644 index 0000000..560a6b0 --- /dev/null +++ b/test/fixtures/dependencies-with-shields/package.json @@ -0,0 +1,13 @@ +{ + "name": "test-pkg", + "dependencies": { + "foo": "*" + }, + "devDependencies": { + "foo": "*" + }, + "repository": { + "type": "git", + "url": "https://github.com/zkochan/test-pkg" + } +}