From 1b9c7c51c2e831a8aad3551b6526d3a96a15a330 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Tue, 29 Sep 2015 07:55:13 -0500 Subject: [PATCH] Set up content tests --- tasks/gulp-tests.js | 38 ++++++++++++++++++++++++++++++++- test/content/mocha.content.opts | 7 ++++++ test/content/translaotr.js | 13 +++++++++++ test/helpers/content.helper.js | 18 ++++++++++++++++ test/helpers/globals.helper.js | 8 +++++++ 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 test/content/mocha.content.opts create mode 100644 test/content/translaotr.js create mode 100644 test/helpers/content.helper.js create mode 100644 test/helpers/globals.helper.js diff --git a/tasks/gulp-tests.js b/tasks/gulp-tests.js index 704b0fc2a2..5cc3831f4a 100644 --- a/tasks/gulp-tests.js +++ b/tasks/gulp-tests.js @@ -11,8 +11,9 @@ const TEST_DB = 'habitrpg_test' const TEST_DB_URI = `mongodb://localhost/${TEST_DB}` -const API_TEST_COMMAND = 'mocha test/api'; +const API_TEST_COMMAND = 'mocha test/api --opts test/mocha.opts'; const COMMON_TEST_COMMAND = 'mocha test/common'; +const CONTENT_TEST_COMMAND = 'mocha test/content --opts test/content/mocha.content.opts'; const KARMA_TEST_COMMAND = 'karma start'; const SERVER_SIDE_TEST_COMMAND = 'mocha test/server_side'; @@ -85,6 +86,40 @@ gulp.task('test:common:safe', ['test:prepare:build'], (cb) => { pipe(runner); }); +gulp.task('test:content', ['test:prepare:build'], (cb) => { + let runner = exec( + testBin(CONTENT_TEST_COMMAND), + (err, stdout, stderr) => { + cb(err); + } + ); + pipe(runner); +}); + +gulp.task('test:content:clean', (cb) => { + pipe(exec(testBin(CONTENT_TEST_COMMAND), () => cb())); +}); + +gulp.task('test:content:watch', ['test:content:clean'], () => { + gulp.watch(['common/script/src/content/**', 'test/**'], ['test:content:clean']); +}); + +gulp.task('test:content:safe', ['test:prepare:build'], (cb) => { + let runner = exec( + testBin(CONTENT_TEST_COMMAND), + (err, stdout, stderr) => { + testResults.push({ + suite: 'Content Specs\t', + pass: testCount(stdout, /(\d+) passing/), + fail: testCount(stderr, /(\d+) failing/), + pend: testCount(stdout, /(\d+) pending/) + }); + cb(); + } + ); + pipe(runner); +}); + gulp.task('test:server_side', ['test:prepare:build'], (cb) => { let runner = exec( testBin(SERVER_SIDE_TEST_COMMAND), @@ -243,6 +278,7 @@ gulp.task('test:e2e:safe', ['test:prepare'], (cb) => { gulp.task('test', [ 'test:common:safe', + 'test:content:safe', 'test:server_side:safe', 'test:karma:safe', 'test:api:safe', diff --git a/test/content/mocha.content.opts b/test/content/mocha.content.opts new file mode 100644 index 0000000000..610fc454d3 --- /dev/null +++ b/test/content/mocha.content.opts @@ -0,0 +1,7 @@ +--colors +--reporter spec +--timeout 8000 +--check-leaks +--growl +--compilers js:babel/register +--require ./test/helpers/content.helper.js diff --git a/test/content/translaotr.js b/test/content/translaotr.js new file mode 100644 index 0000000000..1baf6c257f --- /dev/null +++ b/test/content/translaotr.js @@ -0,0 +1,13 @@ +import {translator} from '../../common/script/src/content/helpers'; + +describe('Translator', () => { + it('returns error message if string is not properly formatted', () => { + let improperlyFormattedString = translator('petName', {attr: 0})(); + expect(improperlyFormattedString).to.eql(STRING_ERROR_MSG); + }); + + it('returns an error message if string does not exist', () => { + let stringDoesNotExist = translator('stringDoesNotExist')(); + expect(stringDoesNotExist).to.match(STRING_DOES_NOT_EXIST_MSG); + }); +}); diff --git a/test/helpers/content.helper.js b/test/helpers/content.helper.js new file mode 100644 index 0000000000..21f6f37ead --- /dev/null +++ b/test/helpers/content.helper.js @@ -0,0 +1,18 @@ +require('./globals.helper'); + +import i18n from '../../common/script/src/i18n'; +require('coffee-script'); +i18n.translations = require('../../website/src/i18n.js').translations; + +global.STRING_ERROR_MSG = 'Error processing the string. Please see Help > Report a Bug.'; +global.STRING_DOES_NOT_EXIST_MSG = /^String '.*' not found.$/; + +global.expectValidTranslationString = (attribute) => { + expect(attribute).to.be.a('function'); + + let translatedString = attribute(); + + expect(translatedString).to.not.be.empty; + expect(translatedString).to.not.eql(STRING_ERROR_MSG); + expect(translatedString).to.not.match(STRING_DOES_NOT_EXIST_MSG); +} diff --git a/test/helpers/globals.helper.js b/test/helpers/globals.helper.js new file mode 100644 index 0000000000..892d086dc8 --- /dev/null +++ b/test/helpers/globals.helper.js @@ -0,0 +1,8 @@ +//------------------------------ +// Global modules +//------------------------------ + +global._ = require("lodash") +global.chai = require("chai") +chai.use(require("sinon-chai")) +global.expect = chai.expect