Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests #8

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
test/
.*
AUTHORS.md
bower.json
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ If you have any questions about [YOURLS API](https://github.com/neocotic/yourls-
Please [search existing issues](https://github.com/neocotic/yourls-api/issues) for the same feature and/or issue before
raising a new issue. Commenting on an existing issue is usually preferred over raising duplicate issues.

Please ensure that all files conform to the coding standards, using the same coding style as the rest of the code base.
This can be done easily via command-line:
Please ensure that all files conform to the coding standards, using the same coding style as the rest of the code base,
and that you add/update any relevant unit tests (found in the `test` directory) and ensure that all tests are currently
passing. This can be done easily via command-line:

``` bash
# install/update package dependencies
Expand Down
13 changes: 12 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

mochaTest: {
test: {
options: {
reporter: 'spec',
require: 'reify'
},
src: [ 'test/**/*.spec.js' ]
}
},

watch: {
all: {
files: [ 'src/**/*.js' ],
Expand All @@ -63,7 +73,7 @@ module.exports = function(grunt) {

var buildTasks = [ 'compile' ]
var compileTasks = []
var testTasks = [ 'compile' ]
var testTasks = [ 'compile', 'mochaTest' ]

if (semver.satisfies(process.version, '>=0.12')) {
nodeResolve = require('rollup-plugin-node-resolve')
Expand Down Expand Up @@ -150,6 +160,7 @@ module.exports = function(grunt) {
}

grunt.loadNpmTasks('grunt-contrib-watch')
grunt.loadNpmTasks('grunt-mocha-test')

grunt.registerTask('default', [ 'build' ])
grunt.registerTask('build', buildTasks)
Expand Down
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
"node"
],
"ignore": [
".*",
"src/",
"test/",
".*",
"AUTHORS.md",
"CHANGES.md",
"CONTRIBUTING.md",
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@
"url": "https://github.com/neocotic/yourls-api.git"
},
"devDependencies": {
"chai": "^3.5.0",
"eslint-config-skelp": "^0.1.5",
"grunt": "^1.0.1",
"grunt-cli": "^1.2.0",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-eslint": "^19.0.0",
"grunt-mocha-test": "^0.13.2",
"grunt-rollup": "^1.0.1",
"mocha": "^3.1.2",
"oopsy": "^0.2.0",
"reify": "^0.4.1",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1",
"semver": "^5.3.0"
"semver": "^5.3.0",
"sinon": "^1.17.6"
},
"main": "dist/yourls.js",
"jsnext:main": "src/yourls.js",
Expand Down
6 changes: 6 additions & 0 deletions test/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../.eslintrc.json",
"env": {
"mocha": true
}
}
33 changes: 33 additions & 0 deletions test/api.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2016 Alasdair Mercer
*
* 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.
*/

import { expect } from 'chai'

import { API } from '../src/api'

describe('API', function() {
it('should be exported as a constructor', function() {
expect(API).to.be.a('function')
})

// TODO: Complete unit tests
})