diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..d5100db --- /dev/null +++ b/.jscsrc @@ -0,0 +1,89 @@ +{ + "disallowEmptyBlocks": true, + "disallowImplicitTypeConversion": [ + "binary", + "numeric", + "string" + ], + "disallowKeywordsOnNewLine": [ + "catch", + "else" + ], + "disallowMixedSpacesAndTabs": true, + "disallowMultipleSpaces": true, + "disallowMultipleVarDecl": true, + "disallowNewlineBeforeBlockStatements": true, + "disallowQuotedKeysInObjects": true, + "disallowSpaceAfterObjectKeys": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforeComma": true, + "disallowSpaceBeforeSemicolon": true, + "disallowSpacesInCallExpression": true, + "disallowSpacesInFunction": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInsideArrayBrackets": true, + "disallowSpacesInsideBrackets": true, + "disallowSpacesInsideObjectBrackets": true, + "disallowSpacesInsideParentheses": true, + "disallowTrailingComma": true, + "disallowTrailingWhitespace": true, + "disallowYodaConditions": true, + "maximumLineLength": 200, + "requireBlocksOnNewline": true, + "requireCapitalizedConstructors": true, + "requireCommaBeforeLineBreak": true, + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "try", + "catch" + ], + "requireDotNotation": true, + "requireLineBreakAfterVariableAssignment": true, + "requireLineFeedAtFileEnd": true, + "requireObjectKeysOnNewLine": true, + "requireParenthesesAroundIIFE": true, + "requireSemicolons": true, + "requireSpaceAfterBinaryOperators": true, + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "try", + "catch" + ], + "requireSpaceAfterLineComment": { + "allExcept": [ + "=" + ] + }, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpaceBeforeObjectValues": true, + "requireSpaceBetweenArguments": true, + "requireSpacesInConditionalExpression": true, + "requireSpacesInForStatement": true, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "validateIndentation": "\t", + "validateLineBreaks": "LF", + "validateNewlineAfterArrayElements": true, + "validateParameterSeparator": ", ", + "validateQuoteMarks": "'", + + "excludeFiles": [ + "coverage", + "node_modules", + "public/js/site.min.js", + "public/js/vendor" + ] +} diff --git a/.jshintignore b/.jshintignore new file mode 100644 index 0000000..0ccb3ce --- /dev/null +++ b/.jshintignore @@ -0,0 +1,4 @@ +coverage +node_modules +public/js/site.min.js +public/js/vendor diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..d5df1f0 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,29 @@ +{ + "browser": true, + "curly": true, + "eqeqeq": true, + "forin": true, + "globals": { + "after": true, + "afterEach": true, + "before": true, + "beforeEach": true, + "describe": true, + "it": true + }, + "latedef": "nofunc", + "maxcomplexity": 6, + "maxdepth": 2, + "maxparams": 4, + "noarg": true, + "node": true, + "nonew": true, + "nonstandard": true, + "regexp": true, + "shadow": true, + "strict": true, + "sub": true, + "trailing": true, + "undef": true, + "unused": true +} diff --git a/.travis.yml b/.travis.yml index 366e5e7..b339f33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,18 @@ # Language/versions language: node_js -node_js: - - "0.10" +matrix: + include: + + # Run tests in Node.js 0.10 (unsupported) + - node_js: '0.10' + + # Run tests in Node.js 0.12 + - node_js: '0.12' + + # Allow Node.js 0.10 to fail – it's unsupported + allow_failures: + - node_js: '0.10' # Build only master (and pull-requests) branches: @@ -15,15 +25,7 @@ services: # Build script before_script: - - npm install -g grunt-cli - cp config/test.sample.json config/test.json - - grunt start-test & + - NODE_ENV=test node index.js & - sleep 5 # give server time to start -script: 'grunt ci' - -# Notifications -notifications: - email: - - j.robinson@nature.com - - perry.harlock@nature.com - - rowan.manning@nature.com +script: 'make ci' diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 415eb79..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,53 +0,0 @@ - -How To Contribute -================= - -pa11y-dashboard accepts contributions from anyone, as long as you follow the guidelines below. If you'd like to contribute but aren't sure what there is for you to do, check the issue tracker for [things ready to be worked on][ready] and [known bugs][bugs]. - -It might be an idea to focus efforts on the goal of the [next milestone][milestones] before jumping onto anything too far ahead on the roadmap. - - -Features --------- - -We won't accept features without prior discussion in the [issue tracker][issues]. Two heads are always better than one – this blanket rule stops you from spending your valuable time on features which may not make it back into pa11y-dashboard. - -If you want to fork the project and build on it by yourself, of course that's absolutely fine! Just don't expect your code to me merged back upstream :) - - -Refactoring/Rewriting ---------------------- - -We will accept refactors where it makes an improvement to the maintainability of the code-base or makes code more readable/understandable. If there's an argument about what's readable or not, chat about it in a pull-request. - - -Coding Guidelines ------------------ - -* No trailing whitespace please (except in Markdown) -* Generally follow the style that is currently present in the code – consistency is important -* Keep indentation consistent (tabs) -* Don't commit code with lint errors (run `grunt lint` to run JSHint with the correct configurations) -* Don't commit code without passing tests (run `grunt test`). - - -Versioning ----------- - -We use [Semantic Versioning][semver] in this project. The process for releasing a new version is as follows; this should only be done by core contributors – you don't need to include a tagged version in your pull-requests. - -* Switch to `master` and merge the `develop` branch into it -* Update the version number in `package.json` and `README.md` -* Commit the changes with the message: "Version x.x.x" (x.x.x being the new version number) -* Tag the commit with the version number (just the numbers, no "version" or "v"): `git tag x.x.x` -* Push with tags: `git push && git push --tags` -* Check out the `develop` branch, merge `master` into it, and push -* On GitHub, add [release notes][release-notes] for the new version. The title should be "Version x.x.x", and the description should be a list of new features/fixes - - -[bugs]: https://github.com/springernature/pa11y-dashboard/issues?labels=bug&state=open -[ready]: https://github.com/springernature/pa11y-dashboard/issues?labels=ready&state=open -[issues]: https://github.com/springernature/pa11y-dashboard/issues -[milestones]: https://github.com/springernature/pa11y-dashboard/issues/milestones -[release-notes]: https://github.com/springernature/pa11y-dashboard/releases -[semver]: http://semver.org/ diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 8b3d233..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,135 +0,0 @@ -// This file is part of pa11y-dashboard. -// -// pa11y-dashboard is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// pa11y-dashboard is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with pa11y-dashboard. If not, see . - -module.exports = function (grunt) { - - grunt.initConfig({ - - jshint: { - all: [ - '**/*.js', - '!node_modules/**/*.js', - '!public/js/vendor/**/*.js', - '!public/js/site.min.js' - ], - options: { - es3: false, - indent: 4, - latedef: false, - maxcomplexity: 6, - maxdepth: 2, - maxlen: 100, - maxparams: 4, - maxstatements: false, - node: true, - quotmark: 'single' - } - }, - - less: { - all: { - options: { - cleancss: true - }, - files: { - 'public/css/site.min.css': 'public/less/main.less' - } - } - }, - - mochaTest: { - functional: { - src: ['test/functional/**/*.js'], - options: { - reporter: 'spec', - timeout: 4000 - } - } - }, - - nodemon: { - development: { - options: { - cwd: __dirname, - file: 'index.js', - env: { - NODE_ENV: 'development' - } - } - }, - test: { - options: { - cwd: __dirname, - file: 'index.js', - env: { - NODE_ENV: 'test' - } - } - } - }, - - uglify: { - options: { - mangle: false - }, - all: { - files: { - 'public/js/site.min.js': [ - 'public/js/vendor/jquery/jquery.min.js', - 'public/js/vendor/bootstrap/js/alert.js', - 'public/js/vendor/bootstrap/js/dropdown.js', - 'public/js/vendor/bootstrap/js/tooltip.js', - 'public/js/vendor/bootstrap/js/transition.js', - 'public/js/vendor/bootstrap/js/collapse.js', - 'public/js/vendor/flot/jquery.flot.js', - 'public/js/vendor/flot/jquery.flot.dashes.js', - 'public/js/vendor/flot/jquery.flot.time.js', - 'public/js/vendor/flot/jquery.flot.selection.js', - 'public/js/vendor/flot/jquery.flot.resize.js', - 'public/js/site.js' - ] - } - } - }, - - watch: { - less: { - files: ['public/less/**/*.less'], - tasks: ['less'] - }, - js: { - files: ['public/js/**/*.js', '!public/js/site.min.js'], - tasks: ['uglify'] - } - } - - }); - - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-contrib-less'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-mocha-test'); - grunt.loadNpmTasks('grunt-nodemon'); - - grunt.registerTask('lint', ['jshint']); - grunt.registerTask('test', ['mochaTest']); - grunt.registerTask('compile', ['less', 'uglify']); - grunt.registerTask('start', ['nodemon:development']); - grunt.registerTask('start-test', ['nodemon:test']); - grunt.registerTask('default', ['compile', 'lint', 'test']); - grunt.registerTask('ci', ['lint', 'test']); - -}; diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5fb72e6 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ + +# Color helpers +C_CYAN=\x1b[34;01m +C_RESET=\x1b[0m + +# Group targets +all: deps lint test +ci: lint test + +# Install dependencies +deps: + @echo "$(C_CYAN)> installing dependencies$(C_RESET)" + @npm install + +# Lint JavaScript +lint: jshint jscs + +# Run JSHint +jshint: + @echo "$(C_CYAN)> linting javascript$(C_RESET)" + @./node_modules/.bin/jshint . + +# Run JavaScript Code Style +jscs: + @echo "$(C_CYAN)> checking javascript code style$(C_RESET)" + @./node_modules/.bin/jscs . + +# Run all tests +test: test-integration + +# Run integration tests +test-integration: + @echo "$(C_CYAN)> running integration tests$(C_RESET)" + @./node_modules/.bin/mocha ./test/integration --reporter spec --recursive --timeout 5000 --slow 50 + +# Add fixtures +fixtures: + @echo "$(C_CYAN)> adding fixtures$(C_RESET)" + @node ./script/fixtures.js + +# Compile LESS +less: + @echo "$(C_CYAN)> compiling less$(C_RESET)" + @./node_modules/.bin/lessc -x ./public/less/main.less ./public/css/site.min.css + +# Compile client-side JavaScript +uglify: + @echo "$(C_CYAN)> compiling client-side JavaScript$(C_RESET)" + @./node_modules/.bin/uglifyjs \ + public/js/vendor/jquery/jquery.min.js \ + public/js/vendor/bootstrap/js/alert.js \ + public/js/vendor/bootstrap/js/dropdown.js \ + public/js/vendor/bootstrap/js/tooltip.js \ + public/js/vendor/bootstrap/js/transition.js \ + public/js/vendor/bootstrap/js/collapse.js \ + public/js/vendor/flot/jquery.flot.js \ + public/js/vendor/flot/jquery.flot.dashes.js \ + public/js/vendor/flot/jquery.flot.time.js \ + public/js/vendor/flot/jquery.flot.selection.js \ + public/js/vendor/flot/jquery.flot.resize.js \ + public/js/site.js \ + -o ./public/js/site.min.js + +.PHONY: test diff --git a/README.md b/README.md index f8fb4bf..cf8db60 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ You'll then need to clone this repo locally and install dependencies with `npm i Once you have a local clone, you'll need to copy some sample configuration files in order to run the application. From within the repo, run the following commands: ```sh -$ cp config/development.sample.json config/development.json -$ cp config/production.sample.json config/production.json -$ cp config/test.sample.json config/test.json +cp config/development.sample.json config/development.json +cp config/production.sample.json config/production.json +cp config/test.sample.json config/test.json ``` Each of these files defines configurations for a different environment. If you're just running the application locally, then you should be OK with just development configurations. The [available configurations are documented here](#configurations). @@ -32,9 +32,9 @@ Each of these files defines configurations for a different environment. If you'r Now that you've got your application configured, you can run in each mode with the following commands: ```sh -$ NODE_ENV=production node . # Run in production -$ NODE_ENV=development node . # Run in development -$ NODE_ENV=test node . # Run in test +NODE_ENV=production node index.js # Run in production +NODE_ENV=development node index.js # Run in development +NODE_ENV=test node index.js # Run in test ``` Check the [development instructions](#development) for more information about running locally (and restarting automatically when files change). @@ -64,29 +64,30 @@ This can either be an object containing [pa11y-webservice configurations][pa11y- Development ----------- -To develop pa11y-dashboard, you'll need to clone the repo and get set up as outlined in the [setup guide](#setup). You'll also need [Grunt][grunt] to be installed globally in order to run tests, you can do this with `npm install -g grunt-cli`. +To develop pa11y-dashboard, you'll need to clone the repo and get set up as outlined in the [setup guide](#setup). -Once you've done this, you'll need to start the application in test mode with: +You'll need to start the application in test mode with: ```sh -$ grunt start-test +NODE_ENV=test node index.js ``` Now you'll be able to run the following commands: ```sh -$ grunt # Run the lint and test tasks together -$ grunt lint # Run JSHint with the correct config -$ grunt compile # Compile front-end assets -$ grunt start # Run app in development mode, restarting if files change -$ grunt start-test # Run app in test mode, restarting if files change -$ grunt test # Run functional tests -$ grunt watch # Watch for file changes and compile assets +make # Run the lint and test tasks together +make lint # Run linters with the correct config +make test # Run integration tests ``` Code with lint errors or failing tests will not be accepted, please use the build tools outlined above. -For users with push-access, don't commit to the master branch. Code should be in `develop` until it's ready to be released. +To compile the client-side JavaScript and CSS, you'll need the following commands. Compiled code is committed to the repository. + +```sh +make css # Compile the site CSS from LESS files +make uglify # Compile and uglify the client-side JavaScript +``` License @@ -98,7 +99,6 @@ pa11y-dashboard is licensed under the [GNU General Public License 3.0][gpl]. [gpl]: http://www.gnu.org/licenses/gpl-3.0.html -[grunt]: http://gruntjs.com/ [mongo]: http://www.mongodb.org/ [node]: http://nodejs.org/ [pa11y]: https://github.com/springernature/pa11y diff --git a/package.json b/package.json index 34e6328..15f9a27 100644 --- a/package.json +++ b/package.json @@ -31,19 +31,18 @@ }, "devDependencies": { "bower": "~1.2", - "grunt": "~0.4", - "grunt-contrib-jshint": "~0.7", - "grunt-contrib-less": "~0.8", - "grunt-contrib-uglify": "~0.2", - "grunt-contrib-watch": "~0.5", - "grunt-mocha-test": "~0.7", - "grunt-nodemon": "~0.1", - "jsdom": "~0.8", - "proclaim": "~2.0", - "request": "~2.27" + "jscs": "^2", + "jsdom": "^3", + "jshint": "^2", + "less": "~1.5", + "mocha": "^2", + "proclaim": "^3", + "request": "~2.27", + "uglify-js": "~2.4" }, "scripts": { - "start": "node ." + "start": "node index.js", + "test": "make ci" } } diff --git a/test/functional/helper/navigate.js b/test/integration/helper/navigate.js similarity index 100% rename from test/functional/helper/navigate.js rename to test/integration/helper/navigate.js diff --git a/test/functional/helper/webservice.js b/test/integration/helper/webservice.js similarity index 100% rename from test/functional/helper/webservice.js rename to test/integration/helper/webservice.js diff --git a/test/functional/route/index.js b/test/integration/route/index.js similarity index 100% rename from test/functional/route/index.js rename to test/integration/route/index.js diff --git a/test/functional/route/new.js b/test/integration/route/new.js similarity index 100% rename from test/functional/route/new.js rename to test/integration/route/new.js diff --git a/test/functional/route/result/download.js b/test/integration/route/result/download.js similarity index 100% rename from test/functional/route/result/download.js rename to test/integration/route/result/download.js diff --git a/test/functional/route/result/index.js b/test/integration/route/result/index.js similarity index 100% rename from test/functional/route/result/index.js rename to test/integration/route/result/index.js diff --git a/test/functional/route/task/delete.js b/test/integration/route/task/delete.js similarity index 100% rename from test/functional/route/task/delete.js rename to test/integration/route/task/delete.js diff --git a/test/functional/route/task/edit.js b/test/integration/route/task/edit.js similarity index 100% rename from test/functional/route/task/edit.js rename to test/integration/route/task/edit.js diff --git a/test/functional/route/task/index.js b/test/integration/route/task/index.js similarity index 100% rename from test/functional/route/task/index.js rename to test/integration/route/task/index.js diff --git a/test/functional/route/task/run.js b/test/integration/route/task/run.js similarity index 100% rename from test/functional/route/task/run.js rename to test/integration/route/task/run.js diff --git a/test/functional/setup.js b/test/integration/setup.js similarity index 94% rename from test/functional/setup.js rename to test/integration/setup.js index e8a0d9b..1e4e935 100644 --- a/test/functional/setup.js +++ b/test/integration/setup.js @@ -1,15 +1,15 @@ // This file is part of pa11y-dashboard. -// +// // pa11y-dashboard is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // pa11y-dashboard is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with pa11y-dashboard. If not, see . @@ -43,7 +43,7 @@ afterEach(function (done) { function assertTestAppIsRunning (url, done) { request(url, function (err) { if (err) { - console.error('Error: Test app not started; run with `grunt start-test`'); + console.error('Error: Test app not started; run with `NODE_ENV=test node index.js`'); process.exit(1); } done();