diff --git a/.gitignore b/.gitignore index 52428f17..4d02a77f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,10 +5,10 @@ # git config --global core.excludesfile ~/.gitignore_global #assety stuff -realtime/node_modules public/assets public/metamaps_mobile vendor/ +node_modules #secrets and config .env diff --git a/.travis.yml b/.travis.yml index 58bf9d25..30a831b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,21 @@ sudo: false language: ruby +cache: + bundler: true + directories: + - app/assets/javascripts/node_modules rvm: - 2.1.3 before_script: + - echo "Rspec setup" - export RAILS_ENV=test - cp .example-env .env - bundle exec rake db:create - bundle exec rake db:schema:load + - echo "node setup" + - . $HOME/.nvm/nvm.sh + - nvm install stable + - nvm use stable + - (cd app/assets/javascripts && npm install) +script: + - bundle exec rspec && (cd app/assets/javascripts && npm test) diff --git a/app/assets/javascripts/README-testing-js.md b/app/assets/javascripts/README-testing-js.md new file mode 100644 index 00000000..d83a29e1 --- /dev/null +++ b/app/assets/javascripts/README-testing-js.md @@ -0,0 +1,9 @@ +Change directories to where this file is, and then run + + npm install + +to set up your testing environment. Then use + + npm test + +to see the results of testing the current javascript files. diff --git a/app/assets/javascripts/package.json b/app/assets/javascripts/package.json new file mode 100644 index 00000000..a322d7ad --- /dev/null +++ b/app/assets/javascripts/package.json @@ -0,0 +1,22 @@ +{ + "name": "metamaps-frontend", + "version": "1.0.0", + "description": "Metamaps frontend - currently just tests", + "scripts": { + "test": "mocha test || echo 'Run `npm install` to setup testing'" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/metamaps/metamaps.git" + }, + "author": "", + "license": "AGPL-3.0", + "bugs": { + "url": "https://github.com/metamaps/metamaps/issues" + }, + "homepage": "https://github.com/metamaps/metamaps#readme", + "devDependencies": { + "chai": "^3.5.0", + "mocha": "^2.4.5" + } +} diff --git a/app/assets/javascripts/src/Metamaps.Import.js b/app/assets/javascripts/src/Metamaps.Import.js index e82a05c5..159298b8 100644 --- a/app/assets/javascripts/src/Metamaps.Import.js +++ b/app/assets/javascripts/src/Metamaps.Import.js @@ -320,3 +320,5 @@ Metamaps.Import = { Metamaps.Synapse.renderSynapse(mapping, synapse, node1, node2, true) } } + +module.exports = Metamaps.Import diff --git a/app/assets/javascripts/test/Metamaps.Import.spec.js b/app/assets/javascripts/test/Metamaps.Import.spec.js new file mode 100644 index 00000000..d8993e42 --- /dev/null +++ b/app/assets/javascripts/test/Metamaps.Import.spec.js @@ -0,0 +1,13 @@ +var chai = require('chai') +var expect = chai.expect + +Metamaps = {} +Metamaps.Import = require('../src/Metamaps.Import') + +describe('Metamaps.Import.js', function() { + it('has a topic whitelist', function() { + expect(Metamaps.Import.topicWhitelist).to.deep.equal( + ['id', 'name', 'metacode', 'x', 'y', 'description', 'link', 'permission'] + ) + }) +}) diff --git a/bin/jenkins-test.sh b/bin/jenkins-test.sh index 0afd3f66..f70a1e50 100755 --- a/bin/jenkins-test.sh +++ b/bin/jenkins-test.sh @@ -3,6 +3,7 @@ # jenkins machine prerequisites # sudo aptitude -q -y install libpq-dev # install rvm with user gemsets +# install node and npm source "$HOME/.rvm/scripts/rvm" rvm use $(cat .ruby-version) || \ @@ -19,10 +20,15 @@ export RAILS_ENV=test cp .example-env .env sed -i -e "s/DB_USERNAME='.*'/DB_USERNAME='jenkins'/" .env -#test +# rspec tests bundle install rake db:drop rake db:create rake db:schema:load rake db:migrate COVERAGE=on bundle exec rspec + +# javascript tests +cd app/assets/javascripts +npm install +npm test diff --git a/doc/RspecTesting.md b/doc/RspecTesting.md index 82cf74f7..d17dc0dd 100644 --- a/doc/RspecTesting.md +++ b/doc/RspecTesting.md @@ -1,3 +1,7 @@ +## Testing Javascript + +Javascript tests are under construction, but you can read more in the README in `app/assets/javascripts`. + ## Testing with RSpec RSpec is a ruby gem that allows you to test your code base. This is great -