You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

render-helper.js 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var fs = require('fs');
  2. var path = require('path');
  3. var _files = path.join(__dirname, '_files');
  4. function getContents (testName, ext) {
  5. try {
  6. return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8');
  7. } catch (ex) {
  8. return null;
  9. }
  10. }
  11. function getView (testName) {
  12. var view = getContents(testName, 'js');
  13. if (!view) throw new Error('Cannot find view for test "' + testName + '"');
  14. return view;
  15. }
  16. function getPartial (testName) {
  17. try {
  18. return getContents(testName, 'partial');
  19. } catch (error) {
  20. // No big deal. Not all tests need to test partial support.
  21. }
  22. }
  23. // You can put the name of a specific test to run in the TEST environment
  24. // variable (e.g. TEST=backslashes mocha test/render-test.js)
  25. var testToRun = process.env.TEST;
  26. var testNames;
  27. if (testToRun) {
  28. testNames = testToRun.split(',');
  29. } else {
  30. testNames = fs.readdirSync(_files).filter(function (file) {
  31. return (/\.js$/).test(file);
  32. }).map(function (file) {
  33. return path.basename(file).replace(/\.js$/, '');
  34. });
  35. }
  36. function getTest (testName) {
  37. return {
  38. name: testName,
  39. view: getView(testName),
  40. template: getContents(testName, 'mustache'),
  41. partial: getPartial(testName),
  42. expect: getContents(testName, 'txt')
  43. };
  44. }
  45. exports.getTests = function getTests () {
  46. return testNames.map(getTest);
  47. };