index.test.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var assert = require('assert');
  2. var fs = require('fs');
  3. var link = require('../');
  4. function testDir (dir) {
  5. fs.readdirSync(dir).forEach(function (name) {
  6. if (!/\.input\.json$/.test(name)) return;
  7. test(name, function () {
  8. var actual = link(JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8')));
  9. expect(actual).toMatchSnapshot();
  10. });
  11. });
  12. }
  13. function testDirError (dir) {
  14. fs.readdirSync(dir).forEach(function (name) {
  15. if (!/\.input\.json$/.test(name)) return;
  16. test(name, function () {
  17. var input = JSON.parse(fs.readFileSync(dir + '/' + name, 'utf8'));
  18. var err;
  19. try {
  20. link(input);
  21. } catch (ex) {
  22. err = {
  23. msg: ex.msg,
  24. code: ex.code,
  25. line: ex.line
  26. };
  27. }
  28. if (!err) throw new Error('Expected error')
  29. expect(err).toMatchSnapshot();
  30. });
  31. });
  32. }
  33. describe('cases from pug', function () {
  34. testDir(__dirname + '/cases');
  35. });
  36. describe('special cases', function () {
  37. testDir(__dirname + '/special-cases');
  38. });
  39. describe('error handling', function () {
  40. testDirError(__dirname + '/errors');
  41. });