index.test.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. var fs = require('fs');
  3. var assert = require('assert');
  4. var lineJSON = require('line-json');
  5. var strip = require('../');
  6. var dir = __dirname + '/cases/';
  7. fs.readdirSync(dir).forEach(function (testCase) {
  8. if (/\.input\.json$/.test(testCase)) {
  9. test(testCase, function () {
  10. var stem = testCase.replace(/\.input\.json$/, '.');
  11. function test (name, options) {
  12. var input = fs.readFileSync(dir + testCase, 'utf8');
  13. input = lineJSON.parse(input);
  14. var result = strip(input, options);
  15. expect(result).toMatchSnapshot();
  16. }
  17. test('unbuffered');
  18. test('buffered', { stripBuffered: true, stripUnbuffered: false });
  19. test('both', { stripBuffered: true });
  20. });
  21. }
  22. });
  23. var edir = __dirname + '/errors/';
  24. fs.readdirSync(edir).forEach(function (testCase) {
  25. if (/\.input\.json$/.test(testCase)) {
  26. test(testCase, function () {
  27. var stem = testCase.replace(/\.input\.json$/, '.');
  28. var input = fs.readFileSync(edir + testCase, 'utf8');
  29. input = lineJSON.parse(input);
  30. try {
  31. strip(input);
  32. throw new Error('Expected ' + testCase + ' to throw an exception.');
  33. } catch (ex) {
  34. if (!ex || !ex.code || ex.code.indexOf('PUG:') !== 0) throw ex;
  35. expect({
  36. msg: ex.msg,
  37. code: ex.code,
  38. line: ex.line
  39. }).toMatchSnapshot();
  40. }
  41. });
  42. }
  43. });