toolong.js 691 B

1234567891011121314151617181920212223242526272829
  1. var path = require('path')
  2. var test = require('tap').test
  3. var writeStream = require('../index.js')
  4. function repeat (times, string) {
  5. var output = ''
  6. for (var ii = 0; ii < times; ++ii) {
  7. output += string
  8. }
  9. return output
  10. }
  11. var target = path.resolve(__dirname, repeat(1000, 'test'))
  12. test('name too long', function (t) {
  13. t.plan(2)
  14. var stream = writeStream(target)
  15. var hadError = false
  16. stream.on('error', function (er) {
  17. if (!hadError) {
  18. t.is(er.code, 'ENAMETOOLONG', target.length + ' character name results in ENAMETOOLONG')
  19. hadError = true
  20. }
  21. })
  22. stream.on('close', function () {
  23. t.ok(hadError, 'got error before close')
  24. })
  25. stream.end()
  26. })