Set up content tests

This commit is contained in:
Blade Barringer
2015-09-29 07:55:13 -05:00
parent 2db4b7b7b2
commit 1b9c7c51c2
5 changed files with 83 additions and 1 deletions

View File

@@ -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',

View File

@@ -0,0 +1,7 @@
--colors
--reporter spec
--timeout 8000
--check-leaks
--growl
--compilers js:babel/register
--require ./test/helpers/content.helper.js

View File

@@ -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);
});
});

View File

@@ -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);
}

View File

@@ -0,0 +1,8 @@
//------------------------------
// Global modules
//------------------------------
global._ = require("lodash")
global.chai = require("chai")
chai.use(require("sinon-chai"))
global.expect = chai.expect