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.

test.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. * Module dependencies.
  3. */
  4. var fs = require('fs');
  5. var path = require('path');
  6. var assert = require('assert');
  7. var degenerator = require('../');
  8. describe('degenerator()', function () {
  9. describe('"expected" fixture tests', function () {
  10. fs.readdirSync(__dirname).forEach(function (n) {
  11. if ('test.js' == n) return;
  12. if (/\.expected\.js$/.test(n)) return;
  13. var expectedName = path.basename(n, '.js') + '.expected.js';
  14. it(n + ' → ' + expectedName, function () {
  15. var sourceName = path.resolve(__dirname, n);
  16. var compiledName = path.resolve(__dirname, expectedName);
  17. var js = fs.readFileSync(sourceName, 'utf8');
  18. var expected = fs.readFileSync(compiledName, 'utf8');
  19. // the test case can define the `names` to use as a
  20. // comment on the first line of the file
  21. var names = js.match(/\/\/\s*(.*)/);
  22. if (names) {
  23. // the comment should be a comma-separated list of function names
  24. names = names[1].split(/,\s*/);
  25. } else {
  26. // if no function names were passed in then convert them all
  27. names = [ /.*/ ];
  28. }
  29. var compiled = degenerator(js, names);
  30. assert.equal(expected.trim(), compiled.trim());
  31. });
  32. });
  33. });
  34. });