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

Commit

Permalink
test: test actual md files
Browse files Browse the repository at this point in the history
  • Loading branch information
zkochan committed May 15, 2016
1 parent 9aa87e3 commit 737d910
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 116 deletions.
10 changes: 5 additions & 5 deletions README.md
@@ -1,8 +1,8 @@
<!--@'# ' + package.name-->
<!--@'# ' + pkg.name-->
# mos-plugin-license
<!--/@-->

<!--@'> ' + package.description-->
<!--@'> ' + pkg.description-->
> A mos plugin for generating a license section
<!--/@-->
Expand All @@ -13,10 +13,8 @@
<!--@installation()-->
## Installation

This module is installed via npm:

```sh
npm install mos-plugin-license --save
npm install --save mos-plugin-license
```
<!--/@-->

Expand Down Expand Up @@ -66,6 +64,8 @@ You'll get a license section with the license and author specified in the `packa
- [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-plugin-ejs](https://github.com/zkochan/mos-plugin-ejs): A mos plugin that executes embedded js in markdown files
- [mos-processor](https://github.com/zkochan/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
31 changes: 30 additions & 1 deletion index.js
@@ -1,5 +1,34 @@
'use strict'
module.exports = (mos, md) => Object.assign(mos.scope, require('./lib')(md))
const fileExists = require('file-exists')
const path = require('path')
const m = require('markdownscript')
const h2 = m.h2
const link = m.link
const paragraph = m.paragraph

module.exports = (mos, markdown) => {
Object.assign(mos.scope, {
license: compileLicense,
})

function compileLicense () {
const licensePath = path.resolve(path.dirname(markdown.filePath), 'LICENSE')
const licenseFileExists = fileExists(licensePath)

return [
h2(['License']),
paragraph([
(licenseFileExists
? link({url: './LICENSE'}, [markdown.pkg.license])
: markdown.pkg.license),
' © ',
(markdown.pkg.author.url
? link({url: markdown.pkg.author.url}, [markdown.pkg.author.name])
: markdown.pkg.author.name),
]),
]
}
}

module.exports.attributes = {
pkg: require('./package.json'),
Expand Down
34 changes: 33 additions & 1 deletion 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)
})
})
})
10 changes: 0 additions & 10 deletions lib/index.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/index.spec.js

This file was deleted.

25 changes: 0 additions & 25 deletions lib/render-license.js

This file was deleted.

67 changes: 0 additions & 67 deletions lib/render-license.spec.js

This file was deleted.

11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -3,19 +3,18 @@
"version": "0.0.0-placeholder",
"description": "A mos plugin for generating a license section",
"files": [
"index.js",
"lib"
"index.js"
],
"main": "index.js",
"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 +50,9 @@
"ghooks": "^1.2.1",
"istanbul": "^0.4.2",
"mocha": "^2.3.4",
"mos": "^0.16.1",
"mos": "^1.0.0",
"mos-plugin-ejs": "^1.0.0",
"mos-processor": "^1.1.0",
"semantic-release": "^4.3.5",
"validate-commit-msg": "^2.6.1"
},
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/has-all-links/LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Zoltan Kochan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions test/fixtures/has-all-links/input.md
@@ -0,0 +1,2 @@
<!--@license()-->
<!--/@-->
5 changes: 5 additions & 0 deletions test/fixtures/has-all-links/output.md
@@ -0,0 +1,5 @@
<!--@license()-->
## License

[MIT](./LICENSE) © [James Bond](http://jbond.uk)
<!--/@-->
8 changes: 8 additions & 0 deletions test/fixtures/has-all-links/package.json
@@ -0,0 +1,8 @@
{
"name": "foo",
"author": {
"name": "James Bond",
"url": "http://jbond.uk"
},
"license": "MIT"
}
21 changes: 21 additions & 0 deletions test/fixtures/has-license-link/LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Zoltan Kochan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions test/fixtures/has-license-link/input.md
@@ -0,0 +1,2 @@
<!--@license()-->
<!--/@-->
5 changes: 5 additions & 0 deletions test/fixtures/has-license-link/output.md
@@ -0,0 +1,5 @@
<!--@license()-->
## License

[MIT](./LICENSE) © James Bond
<!--/@-->
5 changes: 5 additions & 0 deletions test/fixtures/has-license-link/package.json
@@ -0,0 +1,5 @@
{
"name": "foo",
"author": "James Bond",
"license": "MIT"
}
2 changes: 2 additions & 0 deletions test/fixtures/has-no-links/input.md
@@ -0,0 +1,2 @@
<!--@license()-->
<!--/@-->
5 changes: 5 additions & 0 deletions test/fixtures/has-no-links/output.md
@@ -0,0 +1,5 @@
<!--@license()-->
## License

MIT © James Bond
<!--/@-->
5 changes: 5 additions & 0 deletions test/fixtures/has-no-links/package.json
@@ -0,0 +1,5 @@
{
"name": "foo",
"author": "James Bond",
"license": "MIT"
}

0 comments on commit 737d910

Please sign in to comment.