From ba19c00617d74c0bbce16e1ded0e6c3546db88ab Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Thu, 20 Oct 2016 22:32:46 -0500 Subject: [PATCH] Setup up non-API tests to not need server and mongo running chore(travis): Build files before running tests chore(travis): require server for api tests --- .travis.yml | 1 + gulp/gulp-tests.js | 4 ++-- package.json | 1 + test/helpers/api-integration/v3/index.js | 1 - test/helpers/globals.helper.js | 22 ---------------------- test/helpers/start-server.js | 21 +++++++++++++++++++++ 6 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 test/helpers/start-server.js diff --git a/.travis.yml b/.travis.yml index b23e24ae99..cd874ce06a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ before_install: - npm install -g npm@3 - if [ $REQUIRES_SERVER ]; then sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10; echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list; sudo apt-get update; sudo apt-get install mongodb-org-server; fi before_script: + - npm run test:build - cp config.json.example config.json - if [ $REQUIRES_SERVER ]; then until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done; export DISPLAY=:99; fi after_script: diff --git a/gulp/gulp-tests.js b/gulp/gulp-tests.js index 570d3b3fb9..10169c9cd3 100644 --- a/gulp/gulp-tests.js +++ b/gulp/gulp-tests.js @@ -270,7 +270,7 @@ gulp.task('test:e2e:safe', ['test:prepare', 'test:prepare:server'], (cb) => { gulp.task('test:api-v3:unit', (done) => { let runner = exec( - testBin('mocha test/api/v3/unit --recursive'), + testBin('mocha test/api/v3/unit --recursive --require ./test/helpers/start-server'), (err, stdout, stderr) => { if (err) { process.exit(1); @@ -288,7 +288,7 @@ gulp.task('test:api-v3:unit:watch', () => { gulp.task('test:api-v3:integration', (done) => { let runner = exec( - testBin('mocha test/api/v3/integration --recursive'), + testBin('mocha test/api/v3/integration --recursive --require ./test/helpers/start-server'), {maxBuffer: 500 * 1024}, (err, stdout, stderr) => { if (err) { diff --git a/package.json b/package.json index 866f618428..cb3ad4fe17 100644 --- a/package.json +++ b/package.json @@ -129,6 +129,7 @@ "scripts": { "lint": "eslint --ext .js,.vue .", "test": "npm run lint && gulp test && npm run client:unit", + "test:build": "gulp test:prepare:build", "test:api-v3": "gulp test:api-v3", "test:api-v3:unit": "gulp test:api-v3:unit", "test:api-v3:integration": "gulp test:api-v3:integration", diff --git a/test/helpers/api-integration/v3/index.js b/test/helpers/api-integration/v3/index.js index a7692d4b19..fd33cfd032 100644 --- a/test/helpers/api-integration/v3/index.js +++ b/test/helpers/api-integration/v3/index.js @@ -1,5 +1,4 @@ /* eslint-disable no-use-before-define */ - // Import requester function, set it up for v3, export it import { requester } from '../requester'; requester.setApiVersion('v3'); diff --git a/test/helpers/globals.helper.js b/test/helpers/globals.helper.js index 339a603021..23c9a24e3c 100644 --- a/test/helpers/globals.helper.js +++ b/test/helpers/globals.helper.js @@ -15,25 +15,3 @@ global.expect = chai.expect; global.sinon = require('sinon'); global.sandbox = sinon.sandbox.create(); global.Promise = Bluebird; - -import nconf from 'nconf'; -import mongoose from 'mongoose'; - -//------------------------------ -// Load nconf for unit tests -//------------------------------ -if (process.env.LOAD_SERVER === '0') { // when the server is in a different process we simply connect to mongoose - require('../../website/server/libs/setupNconf')('./config.json'); - // Use Q promises instead of mpromise in mongoose - mongoose.Promise = Bluebird; - mongoose.connect(nconf.get('TEST_DB_URI')); -} else { // When running tests and the server in the same process - require('../../website/server/libs/setupNconf')('./config.json.example'); - nconf.set('NODE_DB_URI', nconf.get('TEST_DB_URI')); - nconf.set('NODE_ENV', 'test'); - nconf.set('IS_TEST', true); - // We require src/server and npt src/index because - // 1. nconf is already setup - // 2. we don't need clustering - require('../../website/server/server'); -} diff --git a/test/helpers/start-server.js b/test/helpers/start-server.js new file mode 100644 index 0000000000..7e0ea3c00a --- /dev/null +++ b/test/helpers/start-server.js @@ -0,0 +1,21 @@ +/* eslint-disable no-process-env */ +import nconf from 'nconf'; +import mongoose from 'mongoose'; +import Bluebird from 'bluebird'; +import setupNconf from '../../website/server/libs/setupNconf'; + +if (process.env.LOAD_SERVER === '0') { // when the server is in a different process we simply connect to mongoose + setupNconf('./config.json'); + // Use Q promises instead of mpromise in mongoose + mongoose.Promise = Bluebird; + mongoose.connect(nconf.get('TEST_DB_URI')); +} else { // When running tests and the server in the same process + setupNconf('./config.json.example'); + nconf.set('NODE_DB_URI', nconf.get('TEST_DB_URI')); + nconf.set('NODE_ENV', 'test'); + nconf.set('IS_TEST', true); + // We require src/server and npt src/index because + // 1. nconf is already setup + // 2. we don't need clustering + require('../../website/server/server'); // eslint-disable-line global-require +}