diff --git a/.npmignore b/.npmignore index bb179e7..9a57e4e 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ +test/ .* AUTHORS.md bower.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09b7c49..8755e99 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 diff --git a/Gruntfile.js b/Gruntfile.js index 6d8e611..6318a26 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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' ], @@ -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') @@ -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) diff --git a/bower.json b/bower.json index cfc486e..21c128a 100644 --- a/bower.json +++ b/bower.json @@ -30,8 +30,9 @@ "node" ], "ignore": [ - ".*", "src/", + "test/", + ".*", "AUTHORS.md", "CHANGES.md", "CONTRIBUTING.md", diff --git a/package.json b/package.json index 1301d45..bd70f72 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/.eslintrc.json b/test/.eslintrc.json new file mode 100644 index 0000000..ba3ed6c --- /dev/null +++ b/test/.eslintrc.json @@ -0,0 +1,6 @@ +{ + "extends": "../.eslintrc.json", + "env": { + "mocha": true + } +} diff --git a/test/api.spec.js b/test/api.spec.js new file mode 100644 index 0000000..2e04a92 --- /dev/null +++ b/test/api.spec.js @@ -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 +})