redeyed-smoke.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict'
  2. // applying redeyed to a bunch of files of contained libraries as a smoke test
  3. var test = require('tape')
  4. var path = require('path')
  5. var fs = require('fs')
  6. var readdirp = require('readdirp')
  7. var redeyed = require('..')
  8. var nodeModules = path.join(__dirname, '..', 'node_modules')
  9. var esprimadir = path.join(nodeModules, 'esprima')
  10. test('esprima', function(t) {
  11. readdirp({ root: esprimadir, fileFilter: '*.js' })
  12. .on('data', function(entry) {
  13. var code = fs.readFileSync(entry.fullPath, 'utf-8')
  14. var resultAst = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: true }).code
  15. var resultTokenize = redeyed(code, { Keyword: { 'var': '+:-' } }, { buildAst: false }).code
  16. t.assert(~resultAst.indexOf('+var-') || !(~resultAst.indexOf('var ')), 'redeyed ' + entry.path)
  17. t.assert(~resultTokenize.indexOf('+var-') || !(~resultTokenize.indexOf('var ')), 'redeyed ' + entry.path)
  18. })
  19. .on('end', t.end.bind(t))
  20. })
  21. test('redeyed', function(t) {
  22. readdirp({
  23. root: path.join(__dirname, '..')
  24. , fileFilter: '*.js'
  25. , directoryFilter: [ '!.git', '!node_modules' ]
  26. })
  27. .on('data', function(entry) {
  28. var code = fs.readFileSync(entry.fullPath, 'utf-8')
  29. var result = redeyed(code, { Keyword: { 'var': '+:-' } }).code
  30. t.assert(~result.indexOf('+var-') || !(~result.indexOf('var ')), 'redeyed ' + entry.path)
  31. })
  32. .on('end', t.end.bind(t))
  33. })