index.js 932 B

123456789101112131415161718192021222324
  1. 'sue strict'
  2. var t = require('tap')
  3. var uniqueFilename = require('../index.js')
  4. t.plan(6)
  5. var randomTmpfile = uniqueFilename('tmp')
  6. t.like(randomTmpfile, /^tmp.[a-f0-9]{8}$/, 'random tmp file')
  7. var randomAgain = uniqueFilename('tmp')
  8. t.notEqual(randomAgain, randomTmpfile, 'random tmp files are not the same')
  9. var randomPrefixedTmpfile = uniqueFilename('tmp', 'my-test')
  10. t.like(randomPrefixedTmpfile, /^tmp.my-test-[a-f0-9]{8}$/, 'random prefixed tmp file')
  11. var randomPrefixedAgain = uniqueFilename('tmp', 'my-test')
  12. t.notEqual(randomPrefixedAgain, randomPrefixedTmpfile, 'random prefixed tmp files are not the same')
  13. var uniqueTmpfile = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on')
  14. t.like(uniqueTmpfile, /^tmp.testing-7ddd44c0$/, 'unique filename')
  15. var uniqueAgain = uniqueFilename('tmp', 'testing', '/my/thing/to/uniq/on')
  16. t.is(uniqueTmpfile, uniqueAgain, 'same unique string component produces same filename')