mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Set up content tests
This commit is contained in:
@@ -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',
|
||||
|
||||
7
test/content/mocha.content.opts
Normal file
7
test/content/mocha.content.opts
Normal file
@@ -0,0 +1,7 @@
|
||||
--colors
|
||||
--reporter spec
|
||||
--timeout 8000
|
||||
--check-leaks
|
||||
--growl
|
||||
--compilers js:babel/register
|
||||
--require ./test/helpers/content.helper.js
|
||||
13
test/content/translaotr.js
Normal file
13
test/content/translaotr.js
Normal 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);
|
||||
});
|
||||
});
|
||||
18
test/helpers/content.helper.js
Normal file
18
test/helpers/content.helper.js
Normal 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);
|
||||
}
|
||||
8
test/helpers/globals.helper.js
Normal file
8
test/helpers/globals.helper.js
Normal file
@@ -0,0 +1,8 @@
|
||||
//------------------------------
|
||||
// Global modules
|
||||
//------------------------------
|
||||
|
||||
global._ = require("lodash")
|
||||
global.chai = require("chai")
|
||||
chai.use(require("sinon-chai"))
|
||||
global.expect = chai.expect
|
||||
Reference in New Issue
Block a user