Skip to content

Commit

Permalink
😄
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiang.wly committed Jan 10, 2016
1 parent 9c044ee commit 9acff4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![License](http://img.shields.io/npm/l/check-taggable.svg?style=flat-square)](LICENSE)
[![npm download](https://img.shields.io/npm/dm/check-taggable.svg?style=flat-square)](https://npmjs.org/package/check-taggable)

Check whether the tag can be used
> Check whether the tag can be used
## Installation

Expand All @@ -19,6 +19,24 @@ $ npm install --save check-taggable

## Usage

Promise check(tag[, cwd])

```javascript
const checker = require('check-taggable');
checker('publish/sometag', '/Users/xxx/project_dir') // default process.cwd()
.then(result => {
/*
result = {
// check result
success: true|false
}
*/
if(result.success)
console.log('Passed');
})
.catch(e => console.error(e.message));
```

## Test

```bash
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const co = require('co');

module.exports = co.wrap(function*(tag, cwd) {
cwd = cwd || process.cwd();
if (typeof tag !== 'string') throw Promise.reject(new TypeError('Expected tag to be a string'));
if (typeof cwd !== 'string') throw Promise.reject(new TypeError('Expected cwd to be a string'));
if (typeof tag !== 'string') return Promise.reject(new TypeError('Expected tag to be a string'));
if (typeof cwd !== 'string') return Promise.reject(new TypeError('Expected cwd to be a string'));
let cmdRst = '';
try {
cmdRst = execSync('git tag', {
Expand Down
14 changes: 9 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require('should');
const checker = require('../index');
const fs = require('fs');
const path = require('path');
const os = require('os');
const execSync = require('child_process').execSync;

Expand All @@ -16,8 +14,8 @@ describe('check-tracked', () => {
});
});
describe('fail', () => {
beforeEach(() => execSync('git tag -a publish/test'));
afterEach(() => execSync('git tag -d publish/test'));
beforeEach(() => execSync('git tag -a publish/fail -m fail'));
afterEach(() => execSync('git tag -d publish/fail'));
it('should resolve object with success false if tag had been used', () => {
return checker('publish/fail').should.be.fulfilledWith({
success: false
Expand All @@ -31,9 +29,15 @@ describe('check-tracked', () => {
});
});
it('should reject with an error when cwd is not a string', () => {
return checker('publish/test', {}).should.be.rejectedWith(TypeError, {
return checker('publish/error', {}).should.be.rejectedWith(TypeError, {
message: 'Expected cwd to be a string'
});
});
it('should reject with an error when no git repository found', () => {
let dir = os.tmpdir();
return checker('publish/error', dir).should.be.rejectedWith(Error, {
message: `No git repository was found in ${dir}`
});
});
});
});

0 comments on commit 9acff4c

Please sign in to comment.