Skip to content

Commit

Permalink
Add test for long file paths
Browse files Browse the repository at this point in the history
This test reads and write a directory with a path
that is above 300 characters long, and checks
that it comes out the other side.

Currently, this test fails on Windows due to
https://www.npmjs.com/package/standard. A
subsequent commit will fix this.
  • Loading branch information
avital committed Mar 24, 2015
1 parent 6e78cee commit c07de3d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions examples/long-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This test creates a file with a path that's over 300 characters
// long, which is longer than the Windows limit unless you use the
// '\\?\' prefix.
// https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
//
// Then it passes that directory into and out of fstream, to see if
// that file comes out the other side. This tests
// https://github.com/npm/fstream/issues/30

var tap = require('tap')
var temp = require('temp').track()
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var fstream = require('../fstream.js')

tap.test('long file paths', function (t) {
var inputDir = temp.mkdirSync('fstream-test-input')
var outputDir = temp.mkdirSync('fstream-test-output')

var longDir = inputDir
while (longDir.length < 300) {
longDir = path.join(longDir, 'subdirectory')
}

var STAMP = 'stamp'

mkdirp.sync(longDir)
var inputStampedFile = path.join(longDir, 'file')
fs.writeFileSync(inputStampedFile, STAMP)

var onPipeComplete = function () {
var outputStampedFile = inputStampedFile.replace(inputDir, outputDir)
t.equal(fs.readFileSync(outputStampedFile, 'utf-8'), STAMP)
t.end()
}

var reader = fstream.Reader(inputDir)
reader.on('end', onPipeComplete)
reader.pipe(fstream.Writer(outputDir))
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
},
"devDependencies": {
"tap": "",
"standard": "^2.3.2"
"standard": "^2.3.2",
"temp": "^0.8.1"
},
"scripts": {
"test": "standard && tap examples/*.js"
Expand Down

0 comments on commit c07de3d

Please sign in to comment.